Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 1 | /* Gb-proxy TLLI state handling */ |
| 2 | |
| 3 | /* (C) 2014 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 6e68808 | 2014-08-24 17:38:18 +0200 | [diff] [blame] | 21 | #include <osmocom/gsm/gsm48.h> |
| 22 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 23 | #include <openbsc/gb_proxy.h> |
| 24 | |
| 25 | #include <openbsc/gprs_utils.h> |
| 26 | #include <openbsc/gprs_gb_parse.h> |
| 27 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 28 | #include <openbsc/debug.h> |
| 29 | |
| 30 | #include <osmocom/gsm/gsm_utils.h> |
| 31 | |
| 32 | #include <osmocom/core/rate_ctr.h> |
| 33 | #include <osmocom/core/talloc.h> |
| 34 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 35 | struct gbproxy_tlli_info *gbproxy_tlli_info_by_tlli(struct gbproxy_peer *peer, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 36 | uint32_t tlli) |
| 37 | { |
| 38 | struct gbproxy_tlli_info *tlli_info; |
| 39 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 40 | |
| 41 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) |
| 42 | if (tlli_info->tlli.current == tlli || |
| 43 | tlli_info->tlli.assigned == tlli) |
| 44 | return tlli_info; |
| 45 | |
| 46 | return NULL; |
| 47 | } |
| 48 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 49 | struct gbproxy_tlli_info *gbproxy_tlli_info_by_ptmsi( |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 50 | struct gbproxy_peer *peer, |
| 51 | uint32_t ptmsi) |
| 52 | { |
| 53 | struct gbproxy_tlli_info *tlli_info; |
| 54 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 55 | |
| 56 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) |
| 57 | if (tlli_info->tlli.ptmsi == ptmsi) |
| 58 | return tlli_info; |
| 59 | |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 63 | struct gbproxy_tlli_info *gbproxy_tlli_info_by_any_sgsn_tlli( |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 64 | struct gbproxy_peer *peer, |
| 65 | uint32_t tlli) |
| 66 | { |
| 67 | struct gbproxy_tlli_info *tlli_info; |
| 68 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 69 | |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 70 | /* Don't care about the NSEI */ |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 71 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) |
| 72 | if (tlli_info->sgsn_tlli.current == tlli || |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 73 | tlli_info->sgsn_tlli.assigned == tlli) |
| 74 | return tlli_info; |
| 75 | |
| 76 | return NULL; |
| 77 | } |
| 78 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 79 | struct gbproxy_tlli_info *gbproxy_tlli_info_by_sgsn_tlli( |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 80 | struct gbproxy_peer *peer, |
| 81 | uint32_t tlli, uint32_t sgsn_nsei) |
| 82 | { |
| 83 | struct gbproxy_tlli_info *tlli_info; |
| 84 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 85 | |
| 86 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) |
| 87 | if ((tlli_info->sgsn_tlli.current == tlli || |
| 88 | tlli_info->sgsn_tlli.assigned == tlli) && |
| 89 | tlli_info->sgsn_nsei == sgsn_nsei) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 90 | return tlli_info; |
| 91 | |
| 92 | return NULL; |
| 93 | } |
| 94 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 95 | struct gbproxy_tlli_info *gbproxy_tlli_info_by_imsi( |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 96 | struct gbproxy_peer *peer, |
Jacob Erlbeck | 2fd1ba4 | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 97 | const uint8_t *imsi, |
| 98 | size_t imsi_len) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 99 | { |
| 100 | struct gbproxy_tlli_info *tlli_info; |
| 101 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 102 | |
Jacob Erlbeck | 2fd1ba4 | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 103 | if (!gprs_is_mi_imsi(imsi, imsi_len)) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 104 | return NULL; |
| 105 | |
| 106 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) { |
Jacob Erlbeck | 2fd1ba4 | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 107 | if (tlli_info->imsi_len != imsi_len) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 108 | continue; |
Jacob Erlbeck | 2fd1ba4 | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 109 | if (memcmp(tlli_info->imsi, imsi, imsi_len) != 0) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 110 | continue; |
| 111 | |
| 112 | return tlli_info; |
| 113 | } |
| 114 | |
| 115 | return NULL; |
| 116 | } |
| 117 | |
Jacob Erlbeck | 3159114 | 2014-09-03 11:59:48 +0200 | [diff] [blame] | 118 | void gbproxy_tlli_info_discard_messages(struct gbproxy_tlli_info *tlli_info) |
| 119 | { |
| 120 | struct msgb *msg, *nxt; |
| 121 | |
| 122 | llist_for_each_entry_safe(msg, nxt, &tlli_info->stored_msgs, list) { |
| 123 | llist_del(&msg->list); |
| 124 | msgb_free(msg); |
| 125 | } |
| 126 | } |
| 127 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 128 | void gbproxy_delete_tlli_info(struct gbproxy_peer *peer, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 129 | struct gbproxy_tlli_info *tlli_info) |
| 130 | { |
| 131 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 132 | |
Jacob Erlbeck | 3159114 | 2014-09-03 11:59:48 +0200 | [diff] [blame] | 133 | gbproxy_tlli_info_discard_messages(tlli_info); |
| 134 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 135 | llist_del(&tlli_info->list); |
| 136 | talloc_free(tlli_info); |
| 137 | state->enabled_tllis_count -= 1; |
| 138 | |
| 139 | peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current = |
| 140 | state->enabled_tllis_count; |
| 141 | } |
| 142 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 143 | void gbproxy_delete_tlli_infos(struct gbproxy_peer *peer) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 144 | { |
| 145 | struct gbproxy_tlli_info *tlli_info, *nxt; |
| 146 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 147 | |
| 148 | llist_for_each_entry_safe(tlli_info, nxt, &state->enabled_tllis, list) |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 149 | gbproxy_delete_tlli_info(peer, tlli_info); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 150 | |
| 151 | OSMO_ASSERT(state->enabled_tllis_count == 0); |
| 152 | OSMO_ASSERT(llist_empty(&state->enabled_tllis)); |
| 153 | } |
| 154 | |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 155 | void gbproxy_attach_tlli_info(struct gbproxy_peer *peer, time_t now, |
| 156 | struct gbproxy_tlli_info *tlli_info) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 157 | { |
| 158 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 159 | |
| 160 | tlli_info->timestamp = now; |
| 161 | llist_add(&tlli_info->list, &state->enabled_tllis); |
| 162 | state->enabled_tllis_count += 1; |
| 163 | |
| 164 | peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current = |
| 165 | state->enabled_tllis_count; |
| 166 | } |
| 167 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 168 | int gbproxy_remove_stale_tlli_infos(struct gbproxy_peer *peer, time_t now) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 169 | { |
| 170 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 171 | int exceeded_max_len = 0; |
| 172 | int deleted_count = 0; |
| 173 | int check_for_age; |
| 174 | |
| 175 | if (peer->cfg->tlli_max_len > 0) |
| 176 | exceeded_max_len = |
| 177 | state->enabled_tllis_count - peer->cfg->tlli_max_len; |
| 178 | |
| 179 | check_for_age = peer->cfg->tlli_max_age > 0; |
| 180 | |
| 181 | for (; exceeded_max_len > 0; exceeded_max_len--) { |
| 182 | struct gbproxy_tlli_info *tlli_info; |
| 183 | OSMO_ASSERT(!llist_empty(&state->enabled_tllis)); |
| 184 | tlli_info = llist_entry(state->enabled_tllis.prev, |
| 185 | struct gbproxy_tlli_info, |
| 186 | list); |
| 187 | LOGP(DGPRS, LOGL_INFO, |
| 188 | "Removing TLLI %08x from list " |
| 189 | "(stale, length %d, max_len exceeded)\n", |
| 190 | tlli_info->tlli.current, state->enabled_tllis_count); |
| 191 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 192 | gbproxy_delete_tlli_info(peer, tlli_info); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 193 | deleted_count += 1; |
| 194 | } |
| 195 | |
| 196 | while (check_for_age && !llist_empty(&state->enabled_tllis)) { |
| 197 | time_t age; |
| 198 | struct gbproxy_tlli_info *tlli_info; |
| 199 | tlli_info = llist_entry(state->enabled_tllis.prev, |
| 200 | struct gbproxy_tlli_info, |
| 201 | list); |
| 202 | age = now - tlli_info->timestamp; |
| 203 | /* age < 0 only happens after system time jumps, discard entry */ |
| 204 | if (age <= peer->cfg->tlli_max_age && age >= 0) { |
| 205 | check_for_age = 0; |
| 206 | continue; |
| 207 | } |
| 208 | |
| 209 | LOGP(DGPRS, LOGL_INFO, |
| 210 | "Removing TLLI %08x from list " |
| 211 | "(stale, age %d, max_age exceeded)\n", |
| 212 | tlli_info->tlli.current, (int)age); |
| 213 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 214 | gbproxy_delete_tlli_info(peer, tlli_info); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 215 | deleted_count += 1; |
| 216 | } |
| 217 | |
| 218 | return deleted_count; |
| 219 | } |
| 220 | |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 221 | struct gbproxy_tlli_info *gbproxy_tlli_info_alloc( struct gbproxy_peer *peer) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 222 | { |
| 223 | struct gbproxy_tlli_info *tlli_info; |
| 224 | |
| 225 | tlli_info = talloc_zero(peer, struct gbproxy_tlli_info); |
| 226 | tlli_info->tlli.ptmsi = GSM_RESERVED_TMSI; |
| 227 | tlli_info->sgsn_tlli.ptmsi = GSM_RESERVED_TMSI; |
| 228 | |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 229 | INIT_LLIST_HEAD(&tlli_info->stored_msgs); |
| 230 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 231 | return tlli_info; |
| 232 | } |
| 233 | |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 234 | void gbproxy_detach_tlli_info( |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 235 | struct gbproxy_peer *peer, |
| 236 | struct gbproxy_tlli_info *tlli_info) |
| 237 | { |
| 238 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 239 | |
| 240 | llist_del(&tlli_info->list); |
| 241 | OSMO_ASSERT(state->enabled_tllis_count > 0); |
| 242 | state->enabled_tllis_count -= 1; |
| 243 | |
| 244 | peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current = |
| 245 | state->enabled_tllis_count; |
| 246 | } |
| 247 | |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 248 | void gbproxy_update_tlli_info(struct gbproxy_tlli_info *tlli_info, |
| 249 | const uint8_t *imsi, size_t imsi_len) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 250 | { |
| 251 | if (!gprs_is_mi_imsi(imsi, imsi_len)) |
| 252 | return; |
| 253 | |
Jacob Erlbeck | 2fd1ba4 | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 254 | tlli_info->imsi_len = imsi_len; |
| 255 | tlli_info->imsi = |
| 256 | talloc_realloc_size(tlli_info, tlli_info->imsi, imsi_len); |
| 257 | OSMO_ASSERT(tlli_info->imsi != NULL); |
| 258 | memcpy(tlli_info->imsi, imsi, imsi_len); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void gbproxy_reassign_tlli(struct gbproxy_tlli_state *tlli_state, |
| 262 | struct gbproxy_peer *peer, uint32_t new_tlli) |
| 263 | { |
| 264 | if (new_tlli == tlli_state->current) |
| 265 | return; |
| 266 | |
| 267 | LOGP(DGPRS, LOGL_INFO, |
| 268 | "The TLLI has been reassigned from %08x to %08x\n", |
| 269 | tlli_state->current, new_tlli); |
| 270 | |
| 271 | /* Remember assigned TLLI */ |
| 272 | tlli_state->assigned = new_tlli; |
| 273 | tlli_state->bss_validated = 0; |
| 274 | tlli_state->net_validated = 0; |
| 275 | } |
| 276 | |
| 277 | uint32_t gbproxy_map_tlli(uint32_t other_tlli, |
| 278 | struct gbproxy_tlli_info *tlli_info, int to_bss) |
| 279 | { |
| 280 | uint32_t tlli = 0; |
| 281 | struct gbproxy_tlli_state *src, *dst; |
| 282 | if (to_bss) { |
| 283 | src = &tlli_info->sgsn_tlli; |
| 284 | dst = &tlli_info->tlli; |
| 285 | } else { |
| 286 | src = &tlli_info->tlli; |
| 287 | dst = &tlli_info->sgsn_tlli; |
| 288 | } |
| 289 | if (src->current == other_tlli) |
| 290 | tlli = dst->current; |
| 291 | else if (src->assigned == other_tlli) |
| 292 | tlli = dst->assigned; |
| 293 | |
| 294 | return tlli; |
| 295 | } |
| 296 | |
| 297 | static void gbproxy_validate_tlli(struct gbproxy_tlli_state *tlli_state, |
| 298 | uint32_t tlli, int to_bss) |
| 299 | { |
| 300 | LOGP(DGPRS, LOGL_DEBUG, |
| 301 | "%s({current = %08x, assigned = %08x, net_vld = %d, bss_vld = %d}, %08x)\n", |
| 302 | __func__, tlli_state->current, tlli_state->assigned, |
| 303 | tlli_state->net_validated, tlli_state->bss_validated, tlli); |
| 304 | |
| 305 | if (!tlli_state->assigned || tlli_state->assigned != tlli) |
| 306 | return; |
| 307 | |
| 308 | /* TODO: Is this ok? Check spec */ |
| 309 | if (gprs_tlli_type(tlli) != TLLI_LOCAL) |
| 310 | return; |
| 311 | |
| 312 | /* See GSM 04.08, 4.7.1.5 */ |
| 313 | if (to_bss) |
| 314 | tlli_state->net_validated = 1; |
| 315 | else |
| 316 | tlli_state->bss_validated = 1; |
| 317 | |
| 318 | if (!tlli_state->bss_validated || !tlli_state->net_validated) |
| 319 | return; |
| 320 | |
| 321 | LOGP(DGPRS, LOGL_INFO, |
| 322 | "The TLLI %08x has been validated (was %08x)\n", |
| 323 | tlli_state->assigned, tlli_state->current); |
| 324 | |
| 325 | tlli_state->current = tlli; |
| 326 | tlli_state->assigned = 0; |
| 327 | } |
| 328 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 329 | static void gbproxy_touch_tlli_info(struct gbproxy_peer *peer, |
| 330 | struct gbproxy_tlli_info *tlli_info, |
| 331 | time_t now) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 332 | { |
| 333 | gbproxy_detach_tlli_info(peer, tlli_info); |
| 334 | gbproxy_attach_tlli_info(peer, now, tlli_info); |
| 335 | } |
| 336 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 337 | static void gbproxy_unregister_tlli_info(struct gbproxy_peer *peer, |
| 338 | struct gbproxy_tlli_info *tlli_info) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 339 | { |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 340 | if (!tlli_info) |
| 341 | return; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 342 | |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 343 | if (tlli_info->tlli.ptmsi == GSM_RESERVED_TMSI && !tlli_info->imsi_len) { |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 344 | LOGP(DGPRS, LOGL_INFO, |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 345 | "Removing TLLI %08x from list (P-TMSI or IMSI are not set)\n", |
| 346 | tlli_info->tlli.current); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 347 | gbproxy_delete_tlli_info(peer, tlli_info); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 348 | return; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 349 | } |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 350 | |
| 351 | tlli_info->tlli.current = 0; |
| 352 | tlli_info->tlli.assigned = 0; |
| 353 | tlli_info->sgsn_tlli.current = 0; |
| 354 | tlli_info->sgsn_tlli.assigned = 0; |
| 355 | |
| 356 | tlli_info->is_deregistered = 1; |
| 357 | |
| 358 | return; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 361 | int gbproxy_imsi_matches(struct gbproxy_peer *peer, |
Jacob Erlbeck | 18a3787 | 2014-09-08 09:59:16 +0200 | [diff] [blame] | 362 | struct gbproxy_tlli_info *tlli_info) |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 363 | { |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 364 | if (!peer->cfg->check_imsi) |
| 365 | return 1; |
| 366 | |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 367 | return tlli_info != NULL && tlli_info->imsi_matches; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 370 | void gbproxy_assign_imsi(struct gbproxy_peer *peer, |
| 371 | struct gbproxy_tlli_info *tlli_info, |
| 372 | struct gprs_gb_parse_context *parse_ctx) |
| 373 | { |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 374 | int imsi_matches; |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 375 | struct gbproxy_tlli_info *other_tlli_info; |
| 376 | |
| 377 | /* Make sure that there is a second entry with the same IMSI */ |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 378 | other_tlli_info = gbproxy_tlli_info_by_imsi( |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 379 | peer, parse_ctx->imsi, parse_ctx->imsi_len); |
| 380 | |
| 381 | if (other_tlli_info && other_tlli_info != tlli_info) { |
| 382 | char mi_buf[200]; |
| 383 | mi_buf[0] = '\0'; |
| 384 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
| 385 | parse_ctx->imsi, parse_ctx->imsi_len); |
| 386 | LOGP(DGPRS, LOGL_INFO, |
| 387 | "Removing TLLI %08x from list (IMSI %s re-used)\n", |
| 388 | other_tlli_info->tlli.current, mi_buf); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 389 | gbproxy_delete_tlli_info(peer, other_tlli_info); |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* Update the IMSI field */ |
| 393 | gbproxy_update_tlli_info(tlli_info, |
| 394 | parse_ctx->imsi, parse_ctx->imsi_len); |
| 395 | |
| 396 | /* Check, whether the IMSI matches */ |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 397 | imsi_matches = gbproxy_check_imsi(peer, parse_ctx->imsi, |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 398 | parse_ctx->imsi_len); |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 399 | if (imsi_matches >= 0) |
| 400 | tlli_info->imsi_matches = imsi_matches; |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Jacob Erlbeck | 1a02442 | 2014-09-16 14:10:27 +0200 | [diff] [blame] | 403 | static int gbproxy_tlli_match(const struct gbproxy_tlli_state *a, |
| 404 | const struct gbproxy_tlli_state *b) |
| 405 | { |
| 406 | if (a->current && a->current == b->current) |
| 407 | return 1; |
| 408 | |
| 409 | if (a->assigned && a->assigned == b->assigned) |
| 410 | return 1; |
| 411 | |
| 412 | if (a->ptmsi != GSM_RESERVED_TMSI && a->ptmsi == b->ptmsi) |
| 413 | return 1; |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 418 | static void gbproxy_remove_matching_tlli_infos( |
| 419 | struct gbproxy_peer *peer, struct gbproxy_tlli_info *tlli_info) |
Jacob Erlbeck | 1a02442 | 2014-09-16 14:10:27 +0200 | [diff] [blame] | 420 | { |
| 421 | struct gbproxy_tlli_info *info, *nxt; |
| 422 | struct gbproxy_patch_state *state = &peer->patch_state; |
| 423 | |
| 424 | /* Make sure that there is no second entry with the same P-TMSI or TLLI */ |
| 425 | llist_for_each_entry_safe(info, nxt, &state->enabled_tllis, list) { |
| 426 | if (info == tlli_info) |
| 427 | continue; |
| 428 | |
| 429 | if (!gbproxy_tlli_match(&tlli_info->tlli, &info->tlli) && |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 430 | (tlli_info->sgsn_nsei != info->sgsn_nsei || |
| 431 | !gbproxy_tlli_match(&tlli_info->sgsn_tlli, &info->sgsn_tlli))) |
Jacob Erlbeck | 1a02442 | 2014-09-16 14:10:27 +0200 | [diff] [blame] | 432 | continue; |
| 433 | |
| 434 | LOGP(DGPRS, LOGL_INFO, |
| 435 | "Removing TLLI %08x from list (P-TMSI/TLLI re-used)\n", |
| 436 | info->tlli.current); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 437 | gbproxy_delete_tlli_info(peer, info); |
Jacob Erlbeck | 1a02442 | 2014-09-16 14:10:27 +0200 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 441 | struct gbproxy_tlli_info *gbproxy_get_tlli_info_ul( |
| 442 | struct gbproxy_peer *peer, |
| 443 | struct gprs_gb_parse_context *parse_ctx) |
| 444 | { |
| 445 | struct gbproxy_tlli_info *tlli_info = NULL; |
| 446 | |
| 447 | if (parse_ctx->tlli_enc) |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 448 | tlli_info = gbproxy_tlli_info_by_tlli(peer, parse_ctx->tlli); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 449 | |
| 450 | if (!tlli_info && parse_ctx->imsi) |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 451 | tlli_info = gbproxy_tlli_info_by_imsi( |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 452 | peer, parse_ctx->imsi, parse_ctx->imsi_len); |
| 453 | |
| 454 | if (!tlli_info && parse_ctx->ptmsi_enc && !parse_ctx->old_raid_is_foreign) { |
| 455 | uint32_t bss_ptmsi; |
| 456 | if (!gprs_parse_mi_tmsi(parse_ctx->ptmsi_enc, GSM48_TMSI_LEN, |
| 457 | &bss_ptmsi)) |
| 458 | LOGP(DGPRS, LOGL_ERROR, |
| 459 | "Failed to parse P-TMSI (TLLI is %08x)\n", |
| 460 | parse_ctx->tlli); |
| 461 | else |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 462 | tlli_info = gbproxy_tlli_info_by_ptmsi(peer, bss_ptmsi); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if (tlli_info) |
| 466 | tlli_info->is_deregistered = 0; |
| 467 | |
| 468 | return tlli_info; |
| 469 | } |
| 470 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 471 | struct gbproxy_tlli_info *gbproxy_update_tlli_state_ul( |
| 472 | struct gbproxy_peer *peer, |
| 473 | time_t now, |
| 474 | struct gprs_gb_parse_context *parse_ctx) |
| 475 | { |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 476 | struct gbproxy_tlli_info *tlli_info; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 477 | |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 478 | tlli_info = gbproxy_get_tlli_info_ul(peer, parse_ctx); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 479 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 480 | if (parse_ctx->tlli_enc && parse_ctx->llc) { |
| 481 | uint32_t sgsn_tlli; |
| 482 | if (!tlli_info) { |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 483 | LOGP(DGPRS, LOGL_INFO, "Adding TLLI %08x to list\n", |
| 484 | parse_ctx->tlli); |
| 485 | tlli_info = gbproxy_tlli_info_alloc(peer); |
| 486 | gbproxy_attach_tlli_info(peer, now, tlli_info); |
| 487 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 488 | /* Setup TLLIs */ |
| 489 | sgsn_tlli = gbproxy_make_sgsn_tlli(peer, tlli_info, |
| 490 | parse_ctx->tlli); |
| 491 | tlli_info->sgsn_tlli.current = sgsn_tlli; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 492 | tlli_info->tlli.current = parse_ctx->tlli;; |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 493 | } else if (!tlli_info->tlli.current) { |
| 494 | /* New TLLI (info found by IMSI or P-TMSI) */ |
| 495 | tlli_info->tlli.current = parse_ctx->tlli; |
| 496 | tlli_info->sgsn_tlli.current = |
| 497 | gbproxy_make_sgsn_tlli(peer, tlli_info, |
| 498 | parse_ctx->tlli); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 499 | gbproxy_touch_tlli_info(peer, tlli_info, now); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 500 | } else { |
| 501 | sgsn_tlli = gbproxy_map_tlli(parse_ctx->tlli, tlli_info, 0); |
| 502 | if (!sgsn_tlli) |
| 503 | sgsn_tlli = gbproxy_make_sgsn_tlli(peer, tlli_info, |
| 504 | parse_ctx->tlli); |
| 505 | |
| 506 | gbproxy_validate_tlli(&tlli_info->tlli, |
| 507 | parse_ctx->tlli, 0); |
| 508 | gbproxy_validate_tlli(&tlli_info->sgsn_tlli, |
| 509 | sgsn_tlli, 0); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 510 | gbproxy_touch_tlli_info(peer, tlli_info, now); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 511 | } |
| 512 | } else if (tlli_info) { |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 513 | gbproxy_touch_tlli_info(peer, tlli_info, now); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 516 | if (parse_ctx->imsi && tlli_info && tlli_info->imsi_len == 0) |
| 517 | gbproxy_assign_imsi(peer, tlli_info, parse_ctx); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 518 | |
| 519 | return tlli_info; |
| 520 | } |
| 521 | |
| 522 | struct gbproxy_tlli_info *gbproxy_update_tlli_state_dl( |
| 523 | struct gbproxy_peer *peer, |
| 524 | time_t now, |
| 525 | struct gprs_gb_parse_context *parse_ctx) |
| 526 | { |
| 527 | struct gbproxy_tlli_info *tlli_info = NULL; |
| 528 | |
| 529 | if (parse_ctx->tlli_enc) |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 530 | tlli_info = gbproxy_tlli_info_by_sgsn_tlli( |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 531 | peer, parse_ctx->tlli, parse_ctx->peer_nsei); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 532 | |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 533 | if (parse_ctx->tlli_enc && parse_ctx->new_ptmsi_enc && tlli_info) { |
| 534 | /* A new P-TMSI has been signalled in the message, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 535 | * register new TLLI */ |
| 536 | uint32_t new_sgsn_ptmsi; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 537 | uint32_t new_bss_ptmsi; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 538 | if (!gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc, GSM48_TMSI_LEN, |
| 539 | &new_sgsn_ptmsi)) { |
| 540 | LOGP(DGPRS, LOGL_ERROR, |
| 541 | "Failed to parse new TLLI/PTMSI (current is %08x)\n", |
| 542 | parse_ctx->tlli); |
| 543 | return tlli_info; |
| 544 | } |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 545 | new_bss_ptmsi = gbproxy_make_bss_ptmsi(peer, new_sgsn_ptmsi); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 546 | |
Jacob Erlbeck | b1ee5cd | 2014-09-04 14:53:30 +0200 | [diff] [blame] | 547 | LOGP(DGPRS, LOGL_INFO, |
| 548 | "Got new PTMSI %08x from SGSN, using %08x for BSS\n", |
| 549 | new_sgsn_ptmsi, new_bss_ptmsi); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 550 | /* Setup PTMSIs */ |
| 551 | tlli_info->sgsn_tlli.ptmsi = new_sgsn_ptmsi; |
| 552 | tlli_info->tlli.ptmsi = new_bss_ptmsi; |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 553 | } else if (parse_ctx->tlli_enc && parse_ctx->new_ptmsi_enc && !tlli_info && |
| 554 | !peer->cfg->patch_ptmsi) { |
| 555 | /* A new P-TMSI has been signalled in the message with an unknown |
| 556 | * TLLI, create a new tlli_info */ |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 557 | /* TODO: Add a test case for this branch */ |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 558 | uint32_t new_ptmsi; |
| 559 | if (!gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc, GSM48_TMSI_LEN, |
| 560 | &new_ptmsi)) { |
| 561 | LOGP(DGPRS, LOGL_ERROR, |
| 562 | "Failed to parse new PTMSI (TLLI is %08x)\n", |
| 563 | parse_ctx->tlli); |
| 564 | return tlli_info; |
| 565 | } |
| 566 | |
| 567 | LOGP(DGPRS, LOGL_INFO, |
| 568 | "Adding TLLI %08x to list (SGSN, new P-TMSI is %08x)\n", |
| 569 | parse_ctx->tlli, new_ptmsi); |
| 570 | |
| 571 | tlli_info = gbproxy_tlli_info_alloc(peer); |
| 572 | tlli_info->sgsn_tlli.current = parse_ctx->tlli;; |
| 573 | tlli_info->tlli.current = parse_ctx->tlli;; |
| 574 | tlli_info->sgsn_tlli.ptmsi = new_ptmsi; |
| 575 | tlli_info->tlli.ptmsi = new_ptmsi; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 576 | gbproxy_attach_tlli_info(peer, now, tlli_info); |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 577 | } else if (parse_ctx->tlli_enc && parse_ctx->llc && !tlli_info && |
| 578 | !peer->cfg->patch_ptmsi) { |
| 579 | /* Unknown SGSN TLLI, create a new tlli_info */ |
| 580 | uint32_t new_ptmsi; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 581 | tlli_info = gbproxy_tlli_info_alloc(peer); |
| 582 | LOGP(DGPRS, LOGL_INFO, "Adding TLLI %08x to list (SGSN)\n", |
| 583 | parse_ctx->tlli); |
| 584 | |
| 585 | gbproxy_attach_tlli_info(peer, now, tlli_info); |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 586 | |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 587 | /* Setup TLLIs */ |
| 588 | tlli_info->sgsn_tlli.current = parse_ctx->tlli; |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 589 | tlli_info->tlli.current = parse_ctx->tlli; |
| 590 | |
| 591 | if (!parse_ctx->new_ptmsi_enc) |
| 592 | return tlli_info; |
| 593 | /* A new P-TMSI has been signalled in the message */ |
| 594 | |
| 595 | if (!gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc, |
| 596 | GSM48_TMSI_LEN, &new_ptmsi)) { |
| 597 | LOGP(DGPRS, LOGL_ERROR, |
| 598 | "Failed to parse new PTMSI (TLLI is %08x)\n", |
| 599 | parse_ctx->tlli); |
| 600 | return tlli_info; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 601 | } |
Jacob Erlbeck | 37fda77 | 2014-09-05 10:22:27 +0200 | [diff] [blame] | 602 | LOGP(DGPRS, LOGL_INFO, |
| 603 | "Assigning new P-TMSI %08x\n", new_ptmsi); |
| 604 | /* Setup P-TMSIs */ |
| 605 | tlli_info->sgsn_tlli.ptmsi = new_ptmsi; |
| 606 | tlli_info->tlli.ptmsi = new_ptmsi; |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 607 | } else if (parse_ctx->tlli_enc && parse_ctx->llc && tlli_info) { |
| 608 | uint32_t bss_tlli = gbproxy_map_tlli(parse_ctx->tlli, |
| 609 | tlli_info, 1); |
| 610 | gbproxy_validate_tlli(&tlli_info->sgsn_tlli, parse_ctx->tlli, 1); |
| 611 | gbproxy_validate_tlli(&tlli_info->tlli, bss_tlli, 1); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 612 | gbproxy_touch_tlli_info(peer, tlli_info, now); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 613 | } else if (tlli_info) { |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 614 | gbproxy_touch_tlli_info(peer, tlli_info, now); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 615 | } |
| 616 | |
Jacob Erlbeck | 16a3cd3 | 2014-09-15 11:46:42 +0200 | [diff] [blame] | 617 | if (parse_ctx->imsi && tlli_info && tlli_info->imsi_len == 0) |
| 618 | gbproxy_assign_imsi(peer, tlli_info, parse_ctx); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 619 | |
| 620 | return tlli_info; |
| 621 | } |
| 622 | |
| 623 | void gbproxy_update_tlli_state_after( |
| 624 | struct gbproxy_peer *peer, |
| 625 | struct gbproxy_tlli_info *tlli_info, |
| 626 | time_t now, |
| 627 | struct gprs_gb_parse_context *parse_ctx) |
| 628 | { |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 629 | if (parse_ctx->invalidate_tlli && tlli_info) { |
| 630 | int keep_info = |
| 631 | peer->cfg->keep_tlli_infos == GBPROX_KEEP_ALWAYS || |
| 632 | (peer->cfg->keep_tlli_infos == GBPROX_KEEP_REATTACH && |
| 633 | parse_ctx->await_reattach) || |
| 634 | (peer->cfg->keep_tlli_infos == GBPROX_KEEP_IDENTIFIED && |
| 635 | tlli_info->imsi_len > 0); |
| 636 | if (keep_info) { |
| 637 | LOGP(DGPRS, LOGL_INFO, "Unregistering TLLI %08x\n", |
| 638 | tlli_info->tlli.current); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 639 | gbproxy_unregister_tlli_info(peer, tlli_info); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 640 | } else { |
| 641 | LOGP(DGPRS, LOGL_INFO, "Removing TLLI %08x from list\n", |
| 642 | tlli_info->tlli.current); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 643 | gbproxy_delete_tlli_info(peer, tlli_info); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 644 | } |
Jacob Erlbeck | b1ee5cd | 2014-09-04 14:53:30 +0200 | [diff] [blame] | 645 | } else if (parse_ctx->to_bss && parse_ctx->tlli_enc && |
| 646 | parse_ctx->new_ptmsi_enc && tlli_info) { |
| 647 | /* A new PTMSI has been signaled in the message, |
| 648 | * register new TLLI */ |
| 649 | uint32_t new_sgsn_ptmsi = tlli_info->sgsn_tlli.ptmsi; |
| 650 | uint32_t new_bss_ptmsi = tlli_info->tlli.ptmsi; |
| 651 | uint32_t new_sgsn_tlli; |
| 652 | uint32_t new_bss_tlli = 0; |
| 653 | |
| 654 | new_sgsn_tlli = gprs_tmsi2tlli(new_sgsn_ptmsi, TLLI_LOCAL); |
| 655 | if (new_bss_ptmsi != GSM_RESERVED_TMSI) |
| 656 | new_bss_tlli = gprs_tmsi2tlli(new_bss_ptmsi, TLLI_LOCAL); |
| 657 | LOGP(DGPRS, LOGL_INFO, |
| 658 | "Assigning new TLLI %08x to SGSN, %08x to BSS\n", |
| 659 | new_sgsn_tlli, new_bss_tlli); |
| 660 | |
| 661 | gbproxy_reassign_tlli(&tlli_info->sgsn_tlli, |
| 662 | peer, new_sgsn_tlli); |
| 663 | gbproxy_reassign_tlli(&tlli_info->tlli, |
| 664 | peer, new_bss_tlli); |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 665 | gbproxy_remove_matching_tlli_infos(peer, tlli_info); |
Jacob Erlbeck | b1ee5cd | 2014-09-04 14:53:30 +0200 | [diff] [blame] | 666 | } |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 667 | |
Jacob Erlbeck | 9a7b0d5 | 2014-09-19 13:30:14 +0200 | [diff] [blame^] | 668 | gbproxy_remove_stale_tlli_infos(peer, now); |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | |