Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | #ifndef _GPRS_SGSN_H |
| 2 | #define _GPRS_SGSN_H |
| 3 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 5 | #include <netinet/in.h> |
| 6 | |
| 7 | #include <osmocore/gsm48.h> |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 8 | |
Harald Welte | 496aee4 | 2010-06-30 19:59:55 +0200 | [diff] [blame] | 9 | #include <osmocom/crypt/gprs_cipher.h> |
| 10 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 11 | #define GSM_IMSI_LENGTH 17 |
| 12 | #define GSM_IMEI_LENGTH 17 |
| 13 | #define GSM_EXTENSION_LENGTH 15 |
| 14 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 15 | struct gprs_llc_lle; |
| 16 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 17 | /* TS 04.08 4.1.3.3 GMM mobility management states on the network side */ |
| 18 | enum 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 Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 26 | enum gprs_mm_ctr { |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 27 | 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 Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 40 | enum 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 Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 47 | enum gprs_t3350_mode { |
| 48 | GMM_T3350_MODE_ATT, |
| 49 | GMM_T3350_MODE_RAU, |
| 50 | GMM_T3350_MODE_PTMSI_REALL, |
| 51 | }; |
| 52 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 53 | #define MS_RADIO_ACCESS_CAPA |
| 54 | |
| 55 | /* According to TS 03.60, Table 5: SGSN MM and PDP Contexts */ |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 56 | /* Extended by 3GPP TS 23.060, Table 6: SGSN MM and PDP Contexts */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 57 | struct sgsn_mm_ctx { |
| 58 | struct llist_head list; |
| 59 | |
| 60 | char imsi[GSM_IMSI_LENGTH]; |
| 61 | enum gprs_mm_state mm_state; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 62 | uint32_t p_tmsi; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 63 | uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 64 | uint32_t p_tmsi_sig; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 65 | char imei[GSM_IMEI_LENGTH]; |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 66 | /* Opt: Software Version Numbber / TS 23.195 */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 67 | char msisdn[GSM_EXTENSION_LENGTH]; |
| 68 | struct gprs_ra_id ra; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 69 | 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 Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 73 | /* VLR number */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 74 | uint32_t new_sgsn_addr; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 75 | /* Authentication Triplets */ |
| 76 | /* Kc */ |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 77 | /* Iu: CK, IK, KSI */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 78 | /* CKSN */ |
| 79 | enum gprs_ciph_algo ciph_algo; |
| 80 | struct { |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 81 | uint8_t buf[14]; /* 10.5.5.12a */ |
| 82 | uint8_t len; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 83 | } ms_radio_access_capa; |
| 84 | struct { |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 85 | uint8_t buf[4]; /* 10.5.5.12 */ |
| 86 | uint8_t len; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 87 | } ms_network_capa; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 88 | uint16_t drx_parms; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 89 | 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 Welte | ba850c5 | 2010-05-02 14:40:32 +0200 | [diff] [blame] | 94 | uint8_t radio_prio_sms; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 95 | |
| 96 | struct llist_head pdp_list; |
| 97 | |
| 98 | /* Additional bits not present in the GSM TS */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 99 | struct gprs_llc_llme *llme; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 100 | uint32_t tlli; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 101 | uint32_t tlli_new; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 102 | uint16_t nsei; |
| 103 | uint16_t bvci; |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 104 | struct rate_ctr_group *ctrg; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 105 | struct timer_list timer; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 106 | 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 Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 111 | }; |
| 112 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 113 | /* look-up a SGSN MM context based on TLLI + RAI */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 114 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 115 | const struct gprs_ra_id *raid); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 116 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 117 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi); |
| 118 | |
| 119 | /* Allocate a new SGSN MM context */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 120 | struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 121 | const struct gprs_ra_id *raid); |
| 122 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 123 | |
| 124 | enum pdp_ctx_state { |
| 125 | PDP_STATE_NONE, |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 126 | PDP_STATE_CR_REQ, |
| 127 | PDP_STATE_CR_CONF, |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame^] | 128 | |
| 129 | /* 04.08 / Figure 6.2 / 6.1.2.2 */ |
| 130 | PDP_STATE_INACT_PEND, |
| 131 | PDP_STATE_INACTIVE = PDP_STATE_NONE, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | enum pdp_type { |
| 135 | PDP_TYPE_NONE, |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 136 | PDP_TYPE_ETSI_PPP, |
| 137 | PDP_TYPE_IANA_IPv4, |
| 138 | PDP_TYPE_IANA_IPv6, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | struct sgsn_pdp_ctx { |
| 142 | struct llist_head list; /* list_head for mmctx->pdp_list */ |
| 143 | struct llist_head g_list; /* list_head for global list */ |
| 144 | struct sgsn_mm_ctx *mm; /* back pointer to MM CTX */ |
| 145 | struct sgsn_ggsn_ctx *ggsn; /* which GGSN serves this PDP */ |
Harald Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 146 | struct rate_ctr_group *ctrg; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 147 | |
| 148 | //unsigned int id; |
| 149 | struct pdp_t *lib; /* pointer to libgtp PDP ctx */ |
| 150 | enum pdp_ctx_state state; |
| 151 | enum pdp_type type; |
| 152 | uint32_t address; |
| 153 | char *apn_subscribed; |
| 154 | //char *apn_used; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 155 | uint16_t nsapi; /* SNDCP */ |
| 156 | uint16_t sapi; /* LLC */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 157 | uint8_t ti; /* transaction identifier */ |
| 158 | int vplmn_allowed; |
| 159 | uint32_t qos_profile_subscr; |
| 160 | //uint32_t qos_profile_req; |
| 161 | //uint32_t qos_profile_neg; |
| 162 | uint8_t radio_prio; |
| 163 | uint32_t tx_npdu_nr; |
| 164 | uint32_t rx_npdu_nr; |
| 165 | uint32_t tx_gtp_snd; |
| 166 | uint32_t rx_gtp_snu; |
| 167 | //uint32_t charging_id; |
| 168 | int reordering_reqd; |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame^] | 169 | |
| 170 | struct timer_list timer; |
| 171 | unsigned int T; /* Txxxx number */ |
| 172 | unsigned int num_T_exp; /* number of consecutive T expirations */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 176 | /* look up PDP context by MM context and NSAPI */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 177 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm, |
| 178 | uint8_t nsapi); |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 179 | /* look up PDP context by MM context and transaction ID */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 180 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm, |
| 181 | uint8_t tid); |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 182 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 183 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm, |
| 184 | uint8_t nsapi); |
| 185 | void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp); |
| 186 | |
| 187 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 188 | struct sgsn_ggsn_ctx { |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 189 | struct llist_head list; |
| 190 | uint32_t id; |
| 191 | unsigned int gtp_version; |
| 192 | struct in_addr remote_addr; |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame^] | 193 | int remote_restart_ctr; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 194 | struct gsn_t *gsn; |
| 195 | }; |
Harald Welte | cd4dd4d | 2010-05-18 17:20:49 +0200 | [diff] [blame] | 196 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id); |
| 197 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame^] | 198 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr); |
Harald Welte | cd4dd4d | 2010-05-18 17:20:49 +0200 | [diff] [blame] | 199 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 200 | |
| 201 | struct apn_ctx { |
| 202 | struct llist_head list; |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 203 | struct sgsn_ggsn_ctx *ggsn; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 204 | char *name; |
| 205 | char *description; |
| 206 | }; |
| 207 | |
| 208 | extern struct llist_head sgsn_mm_ctxts; |
| 209 | extern struct llist_head sgsn_ggsn_ctxts; |
| 210 | extern struct llist_head sgsn_apn_ctxts; |
| 211 | extern struct llist_head sgsn_pdp_ctxts; |
| 212 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 213 | uint32_t sgsn_alloc_ptmsi(void); |
| 214 | |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame^] | 215 | /* High-level function to be called in case a GGSN has disappeared or |
| 216 | * ottherwise lost state (recovery procedure) */ |
| 217 | int drop_all_pdp_for_ggsn(struct sgsn_ggsn_ctx *ggsn); |
| 218 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 219 | #endif /* _GPRS_SGSN_H */ |