Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | /* GPRS SGSN functionality */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 22 | #include <stdint.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 23 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 24 | #include <osmocom/core/linuxlist.h> |
| 25 | #include <osmocom/core/talloc.h> |
| 26 | #include <osmocom/core/timer.h> |
| 27 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 28 | #include <openbsc/gsm_subscriber.h> |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 29 | #include <openbsc/debug.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 30 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | cb99163 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 31 | #include <openbsc/gprs_ns.h> |
| 32 | #include <openbsc/gprs_bssgp.h> |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 33 | #include <openbsc/sgsn.h> |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 34 | #include <openbsc/gsm_04_08_gprs.h> |
| 35 | #include <openbsc/gprs_gmm.h> |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 36 | |
| 37 | extern struct sgsn_instance *sgsn; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 38 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 39 | LLIST_HEAD(sgsn_mm_ctxts); |
| 40 | LLIST_HEAD(sgsn_ggsn_ctxts); |
| 41 | LLIST_HEAD(sgsn_apn_ctxts); |
| 42 | LLIST_HEAD(sgsn_pdp_ctxts); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 43 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 44 | static const struct rate_ctr_desc mmctx_ctr_description[] = { |
| 45 | { "sign.packets.in", "Signalling Messages ( In)" }, |
| 46 | { "sign.packets.out", "Signalling Messages (Out)" }, |
| 47 | { "udata.packets.in", "User Data Messages ( In)" }, |
| 48 | { "udata.packets.out", "User Data Messages (Out)" }, |
| 49 | { "udata.bytes.in", "User Data Bytes ( In)" }, |
| 50 | { "udata.bytes.out", "User Data Bytes (Out)" }, |
| 51 | { "pdp_ctx_act", "PDP Context Activations " }, |
| 52 | { "suspend", "SUSPEND Count " }, |
| 53 | { "paging.ps", "Paging Packet Switched " }, |
| 54 | { "paging.cs", "Paging Circuit Switched " }, |
| 55 | { "ra_update", "Routing Area Update " }, |
| 56 | }; |
| 57 | |
| 58 | static const struct rate_ctr_group_desc mmctx_ctrg_desc = { |
| 59 | .group_name_prefix = "sgsn.mmctx", |
| 60 | .group_description = "SGSN MM Context Statistics", |
| 61 | .num_ctr = ARRAY_SIZE(mmctx_ctr_description), |
| 62 | .ctr_desc = mmctx_ctr_description, |
| 63 | }; |
| 64 | |
Harald Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 65 | static const struct rate_ctr_desc pdpctx_ctr_description[] = { |
| 66 | { "udata.packets.in", "User Data Messages ( In)" }, |
| 67 | { "udata.packets.out", "User Data Messages (Out)" }, |
| 68 | { "udata.bytes.in", "User Data Bytes ( In)" }, |
| 69 | { "udata.bytes.out", "User Data Bytes (Out)" }, |
| 70 | }; |
| 71 | |
| 72 | static const struct rate_ctr_group_desc pdpctx_ctrg_desc = { |
| 73 | .group_name_prefix = "sgsn.pdpctx", |
| 74 | .group_description = "SGSN PDP Context Statistics", |
| 75 | .num_ctr = ARRAY_SIZE(pdpctx_ctr_description), |
| 76 | .ctr_desc = pdpctx_ctr_description, |
| 77 | }; |
| 78 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 79 | static int ra_id_equals(const struct gprs_ra_id *id1, |
| 80 | const struct gprs_ra_id *id2) |
| 81 | { |
| 82 | return (id1->mcc == id2->mcc && id1->mnc == id2->mnc && |
| 83 | id1->lac == id2->lac && id1->rac == id2->rac); |
| 84 | } |
| 85 | |
Harald Welte | f6bd340 | 2010-12-23 23:34:43 +0100 | [diff] [blame] | 86 | /* See 03.02 Chapter 2.6 */ |
| 87 | static inline uint32_t tlli_foreign(uint32_t tlli) |
| 88 | { |
| 89 | return ((tlli | 0x80000000) & ~0x40000000); |
| 90 | } |
| 91 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 92 | /* look-up a SGSN MM context based on TLLI + RAI */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 93 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 94 | const struct gprs_ra_id *raid) |
| 95 | { |
| 96 | struct sgsn_mm_ctx *ctx; |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 97 | int tlli_type; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 98 | |
| 99 | llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) { |
| 100 | if (tlli == ctx->tlli && |
| 101 | ra_id_equals(raid, &ctx->ra)) |
| 102 | return ctx; |
| 103 | } |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 104 | |
| 105 | tlli_type = gprs_tlli_type(tlli); |
Harald Welte | f6bd340 | 2010-12-23 23:34:43 +0100 | [diff] [blame] | 106 | switch (tlli_type) { |
| 107 | case TLLI_LOCAL: |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 108 | llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) { |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 109 | if ((ctx->p_tmsi | 0xC0000000) == tlli || |
| 110 | (ctx->p_tmsi_old && (ctx->p_tmsi_old | 0xC0000000) == tlli)) { |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 111 | ctx->tlli = tlli; |
| 112 | return ctx; |
| 113 | } |
| 114 | } |
Harald Welte | f6bd340 | 2010-12-23 23:34:43 +0100 | [diff] [blame] | 115 | break; |
| 116 | case TLLI_FOREIGN: |
| 117 | llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) { |
| 118 | if (tlli == tlli_foreign(ctx->tlli) && |
| 119 | ra_id_equals(raid, &ctx->ra)) |
| 120 | return ctx; |
| 121 | } |
| 122 | break; |
| 123 | default: |
| 124 | break; |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 127 | return NULL; |
| 128 | } |
| 129 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 130 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t p_tmsi) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 131 | { |
| 132 | struct sgsn_mm_ctx *ctx; |
| 133 | |
| 134 | llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) { |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 135 | if (p_tmsi == ctx->p_tmsi || |
| 136 | (ctx->p_tmsi_old && ctx->p_tmsi_old == p_tmsi)) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 137 | return ctx; |
| 138 | } |
| 139 | return NULL; |
| 140 | } |
| 141 | |
| 142 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi) |
| 143 | { |
| 144 | struct sgsn_mm_ctx *ctx; |
| 145 | |
| 146 | llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) { |
| 147 | if (!strcmp(imsi, ctx->imsi)) |
| 148 | return ctx; |
| 149 | } |
| 150 | return NULL; |
| 151 | |
| 152 | } |
| 153 | |
| 154 | /* Allocate a new SGSN MM context */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 155 | struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 156 | const struct gprs_ra_id *raid) |
| 157 | { |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 158 | struct sgsn_mm_ctx *ctx; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 159 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 160 | ctx = talloc_zero(tall_bsc_ctx, struct sgsn_mm_ctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 161 | if (!ctx) |
| 162 | return NULL; |
| 163 | |
| 164 | memcpy(&ctx->ra, raid, sizeof(ctx->ra)); |
| 165 | ctx->tlli = tlli; |
| 166 | ctx->mm_state = GMM_DEREGISTERED; |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 167 | ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, tlli); |
Harald Welte | 6ffbaab | 2010-05-18 12:44:45 +0200 | [diff] [blame] | 168 | INIT_LLIST_HEAD(&ctx->pdp_list); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 169 | |
| 170 | llist_add(&ctx->list, &sgsn_mm_ctxts); |
| 171 | |
| 172 | return ctx; |
| 173 | } |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 174 | |
Harald Welte | c728eea | 2010-12-24 23:07:18 +0100 | [diff] [blame] | 175 | void sgsn_mm_ctx_free(struct sgsn_mm_ctx *mm) |
| 176 | { |
| 177 | struct sgsn_pdp_ctx *pdp, *pdp2; |
| 178 | |
| 179 | /* Unlink from global list of MM contexts */ |
| 180 | llist_del(&mm->list); |
| 181 | |
| 182 | /* Free all PDP contexts */ |
| 183 | llist_for_each_entry_safe(pdp, pdp2, &mm->pdp_list, list) |
| 184 | sgsn_pdp_ctx_free(pdp); |
| 185 | |
| 186 | rate_ctr_group_free(mm->ctrg); |
| 187 | |
| 188 | talloc_free(mm); |
| 189 | } |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 190 | |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 191 | /* look up PDP context by MM context and NSAPI */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 192 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm, |
| 193 | uint8_t nsapi) |
| 194 | { |
| 195 | struct sgsn_pdp_ctx *pdp; |
| 196 | |
| 197 | llist_for_each_entry(pdp, &mm->pdp_list, list) { |
| 198 | if (pdp->nsapi == nsapi) |
| 199 | return pdp; |
| 200 | } |
| 201 | return NULL; |
| 202 | } |
| 203 | |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 204 | /* look up PDP context by MM context and transaction ID */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 205 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm, |
| 206 | uint8_t tid) |
| 207 | { |
| 208 | struct sgsn_pdp_ctx *pdp; |
| 209 | |
| 210 | llist_for_each_entry(pdp, &mm->pdp_list, list) { |
| 211 | if (pdp->ti == tid) |
| 212 | return pdp; |
| 213 | } |
| 214 | return NULL; |
| 215 | } |
| 216 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 217 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm, |
| 218 | uint8_t nsapi) |
| 219 | { |
| 220 | struct sgsn_pdp_ctx *pdp; |
| 221 | |
| 222 | pdp = sgsn_pdp_ctx_by_nsapi(mm, nsapi); |
| 223 | if (pdp) |
| 224 | return NULL; |
| 225 | |
| 226 | pdp = talloc_zero(tall_bsc_ctx, struct sgsn_pdp_ctx); |
| 227 | if (!pdp) |
| 228 | return NULL; |
| 229 | |
| 230 | pdp->mm = mm; |
| 231 | pdp->nsapi = nsapi; |
Harald Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 232 | pdp->ctrg = rate_ctr_group_alloc(pdp, &pdpctx_ctrg_desc, nsapi); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 233 | llist_add(&pdp->list, &mm->pdp_list); |
| 234 | llist_add(&pdp->g_list, &sgsn_pdp_ctxts); |
| 235 | |
| 236 | return pdp; |
| 237 | } |
| 238 | |
| 239 | void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp) |
| 240 | { |
Harald Welte | 376d5e5 | 2010-06-28 18:57:21 +0200 | [diff] [blame] | 241 | rate_ctr_group_free(pdp->ctrg); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 242 | llist_del(&pdp->list); |
| 243 | llist_del(&pdp->g_list); |
| 244 | talloc_free(pdp); |
| 245 | } |
| 246 | |
| 247 | /* GGSN contexts */ |
| 248 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 249 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id) |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 250 | { |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 251 | struct sgsn_ggsn_ctx *ggc; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 252 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 253 | ggc = talloc_zero(tall_bsc_ctx, struct sgsn_ggsn_ctx); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 254 | if (!ggc) |
| 255 | return NULL; |
| 256 | |
| 257 | ggc->id = id; |
| 258 | ggc->gtp_version = 1; |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 259 | ggc->remote_restart_ctr = -1; |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 260 | /* if we are called from config file parse, this gsn doesn't exist yet */ |
| 261 | ggc->gsn = sgsn->gsn; |
Harald Welte | 119c2ba | 2010-05-18 18:39:00 +0200 | [diff] [blame] | 262 | llist_add(&ggc->list, &sgsn_ggsn_ctxts); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 263 | |
| 264 | return ggc; |
| 265 | } |
| 266 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 267 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id) |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 268 | { |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 269 | struct sgsn_ggsn_ctx *ggc; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 270 | |
| 271 | llist_for_each_entry(ggc, &sgsn_ggsn_ctxts, list) { |
| 272 | if (id == ggc->id) |
| 273 | return ggc; |
| 274 | } |
| 275 | return NULL; |
| 276 | } |
| 277 | |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 278 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr) |
| 279 | { |
| 280 | struct sgsn_ggsn_ctx *ggc; |
| 281 | |
| 282 | llist_for_each_entry(ggc, &sgsn_ggsn_ctxts, list) { |
| 283 | if (!memcmp(addr, &ggc->remote_addr, sizeof(*addr))) |
| 284 | return ggc; |
| 285 | } |
| 286 | return NULL; |
| 287 | } |
| 288 | |
| 289 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 290 | struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id) |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 291 | { |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 292 | struct sgsn_ggsn_ctx *ggc; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 293 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 294 | ggc = sgsn_ggsn_ctx_by_id(id); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 295 | if (!ggc) |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 296 | ggc = sgsn_ggsn_ctx_alloc(id); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 297 | return ggc; |
| 298 | } |
| 299 | |
| 300 | /* APN contexts */ |
| 301 | |
| 302 | #if 0 |
| 303 | struct apn_ctx *apn_ctx_alloc(const char *ap_name) |
| 304 | { |
| 305 | struct apn_ctx *actx; |
| 306 | |
| 307 | actx = talloc_zero(talloc_bsc_ctx, struct apn_ctx); |
| 308 | if (!actx) |
| 309 | return NULL; |
| 310 | actx->name = talloc_strdup(actx, ap_name); |
| 311 | |
| 312 | return actx; |
| 313 | } |
| 314 | |
| 315 | struct apn_ctx *apn_ctx_by_name(const char *name) |
| 316 | { |
| 317 | struct apn_ctx *actx; |
| 318 | |
| 319 | llist_for_each_entry(actx, &sgsn_apn_ctxts, list) { |
| 320 | if (!strcmp(name, actx->name)) |
| 321 | return actx; |
| 322 | } |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | struct apn_ctx *apn_ctx_find_alloc(const char *name) |
| 327 | { |
| 328 | struct apn_ctx *actx; |
| 329 | |
| 330 | actx = apn_ctx_by_name(name); |
| 331 | if (!actx) |
| 332 | actx = apn_ctx_alloc(name); |
| 333 | |
| 334 | return actx; |
| 335 | } |
| 336 | #endif |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 337 | |
| 338 | uint32_t sgsn_alloc_ptmsi(void) |
| 339 | { |
| 340 | struct sgsn_mm_ctx *mm; |
| 341 | uint32_t ptmsi; |
| 342 | |
| 343 | restart: |
| 344 | ptmsi = rand(); |
| 345 | llist_for_each_entry(mm, &sgsn_mm_ctxts, list) { |
| 346 | if (mm->p_tmsi == ptmsi) |
| 347 | goto restart; |
| 348 | } |
| 349 | |
| 350 | return ptmsi; |
| 351 | } |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 352 | |
| 353 | static void drop_one_pdp(struct sgsn_pdp_ctx *pdp) |
| 354 | { |
| 355 | if (pdp->mm->mm_state == GMM_REGISTERED_NORMAL) |
| 356 | gsm48_tx_gsm_deact_pdp_req(pdp, GSM_CAUSE_NET_FAIL); |
| 357 | else { |
| 358 | /* FIXME: GPRS paging in case MS is SUSPENDED */ |
| 359 | LOGP(DGPRS, LOGL_NOTICE, "Hard-dropping PDP ctx due to GGSN " |
| 360 | "recovery\n"); |
| 361 | sgsn_pdp_ctx_free(pdp); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /* High-level function to be called in case a GGSN has disappeared or |
| 366 | * ottherwise lost state (recovery procedure) */ |
| 367 | int drop_all_pdp_for_ggsn(struct sgsn_ggsn_ctx *ggsn) |
| 368 | { |
| 369 | struct sgsn_mm_ctx *mm; |
| 370 | int num = 0; |
| 371 | |
| 372 | llist_for_each_entry(mm, &sgsn_mm_ctxts, list) { |
| 373 | struct sgsn_pdp_ctx *pdp; |
| 374 | llist_for_each_entry(pdp, &mm->pdp_list, list) { |
| 375 | if (pdp->ggsn == ggsn) { |
| 376 | drop_one_pdp(pdp); |
| 377 | num++; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return num; |
| 383 | } |