Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 1 | /* MS subscriber data handling */ |
| 2 | |
| 3 | /* (C) 2014 by sysmocom s.f.m.c. GmbH |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 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 |
| 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 |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 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/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/gsm_subscriber.h> |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 23 | #include <openbsc/gprs_gsup_client.h> |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 24 | |
| 25 | #include <openbsc/sgsn.h> |
| 26 | #include <openbsc/gprs_sgsn.h> |
| 27 | #include <openbsc/gprs_gmm.h> |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 28 | #include <openbsc/gprs_gsup_messages.h> |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 29 | |
| 30 | #include <openbsc/debug.h> |
| 31 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 32 | #include <netinet/in.h> |
| 33 | #include <arpa/inet.h> |
| 34 | |
Jacob Erlbeck | 743dec4 | 2015-01-08 15:18:39 +0100 | [diff] [blame] | 35 | #define SGSN_SUBSCR_MAX_RETRIES 3 |
| 36 | #define SGSN_SUBSCR_RETRY_INTERVAL 10 |
| 37 | |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 38 | extern void *tall_bsc_ctx; |
| 39 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 40 | static int gsup_read_cb(struct gprs_gsup_client *gsupc, struct msgb *msg); |
| 41 | |
| 42 | /* TODO: Some functions are specific to the SGSN, but this file is more general |
| 43 | * (it has gprs_* name). Either move these functions elsewhere, split them and |
| 44 | * move a part, or replace the gprs_ prefix by sgsn_. The applies to |
| 45 | * gprs_subscr_init, gsup_read_cb, and gprs_subscr_tx_gsup_message. |
| 46 | */ |
| 47 | |
| 48 | int gprs_subscr_init(struct sgsn_instance *sgi) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 49 | { |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 50 | const char *addr_str; |
| 51 | |
| 52 | if (!sgi->cfg.gsup_server_addr.sin_addr.s_addr) |
| 53 | return 0; |
| 54 | |
| 55 | addr_str = inet_ntoa(sgi->cfg.gsup_server_addr.sin_addr); |
| 56 | |
| 57 | sgi->gsup_client = gprs_gsup_client_create( |
| 58 | addr_str, sgi->cfg.gsup_server_port, |
| 59 | &gsup_read_cb); |
| 60 | |
| 61 | if (!sgi->gsup_client) |
| 62 | return -1; |
| 63 | |
| 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | static int gsup_read_cb(struct gprs_gsup_client *gsupc, struct msgb *msg) |
| 68 | { |
| 69 | int rc; |
| 70 | |
| 71 | rc = gprs_subscr_rx_gsup_message(msg); |
Jacob Erlbeck | e154d8b | 2014-12-19 19:15:55 +0100 | [diff] [blame] | 72 | msgb_free(msg); |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 73 | if (rc < 0) |
| 74 | return -1; |
| 75 | |
| 76 | return rc; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 79 | static int check_blocking( |
| 80 | struct gsm_subscriber *subscr, |
| 81 | enum sgsn_subscriber_proc what) |
| 82 | { |
| 83 | if (subscr->sgsn_data->blocked_by == SGSN_SUBSCR_PROC_NONE || |
| 84 | subscr->sgsn_data->blocked_by == what) |
| 85 | return 1; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static void abort_blocking_procedure(struct gsm_subscriber *subscr) |
| 91 | { |
| 92 | /* Best effort, stop retries at least */ |
| 93 | subscr->sgsn_data->retries = SGSN_SUBSCR_MAX_RETRIES; |
| 94 | } |
| 95 | |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 96 | static void sgsn_subscriber_timeout_cb(void *subscr_); |
| 97 | int gprs_subscr_purge(struct gsm_subscriber *subscr); |
| 98 | |
| 99 | void gprs_subscr_stop_timer(struct gsm_subscriber *subscr) |
| 100 | { |
| 101 | if (subscr->sgsn_data->timer.data) { |
| 102 | osmo_timer_del(&subscr->sgsn_data->timer); |
| 103 | subscr->sgsn_data->timer.cb = NULL; |
| 104 | OSMO_ASSERT(subscr->sgsn_data->timer.data == subscr); |
| 105 | subscr->sgsn_data->timer.data = NULL; |
| 106 | subscr_put(subscr); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void gprs_subscr_start_timer(struct gsm_subscriber *subscr, unsigned seconds) |
| 111 | { |
| 112 | if (!subscr->sgsn_data->timer.data) { |
| 113 | subscr->sgsn_data->timer.cb = sgsn_subscriber_timeout_cb; |
| 114 | subscr->sgsn_data->timer.data = subscr_get(subscr); |
Jacob Erlbeck | 743dec4 | 2015-01-08 15:18:39 +0100 | [diff] [blame] | 115 | subscr->sgsn_data->retries = 0; |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | osmo_timer_schedule(&subscr->sgsn_data->timer, seconds, 0); |
| 119 | } |
| 120 | |
| 121 | static void sgsn_subscriber_timeout_cb(void *subscr_) |
| 122 | { |
| 123 | struct gsm_subscriber *subscr = subscr_; |
| 124 | |
| 125 | LOGGSUBSCRP(LOGL_INFO, subscr, |
| 126 | "Expired, deleting subscriber entry\n"); |
| 127 | |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 128 | subscr_get(subscr); |
| 129 | |
| 130 | /* Check, whether to cleanup immediately */ |
Jacob Erlbeck | 743dec4 | 2015-01-08 15:18:39 +0100 | [diff] [blame] | 131 | if (!(subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE) || |
| 132 | subscr->sgsn_data->retries >= SGSN_SUBSCR_MAX_RETRIES) |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 133 | goto force_cleanup; |
| 134 | |
| 135 | /* Send a 'purge MS' message to the HLR */ |
| 136 | if (gprs_subscr_purge(subscr) < 0) |
| 137 | goto force_cleanup; |
| 138 | |
| 139 | /* Purge request has been sent */ |
| 140 | |
Jacob Erlbeck | 743dec4 | 2015-01-08 15:18:39 +0100 | [diff] [blame] | 141 | /* Check, whether purge is still enabled */ |
| 142 | if (!(subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE)) |
| 143 | goto force_cleanup; |
| 144 | |
| 145 | /* Make sure this will be tried again if there is no response in time */ |
| 146 | subscr->sgsn_data->retries += 1; |
| 147 | gprs_subscr_start_timer(subscr, SGSN_SUBSCR_RETRY_INTERVAL); |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 148 | subscr_put(subscr); |
| 149 | return; |
| 150 | |
| 151 | force_cleanup: |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 152 | /* Make sure to clear blocking */ |
| 153 | if (check_blocking(subscr, SGSN_SUBSCR_PROC_PURGE)) |
| 154 | subscr->sgsn_data->blocked_by = SGSN_SUBSCR_PROC_NONE; |
| 155 | |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 156 | /* Make sure, the timer is cleaned up */ |
| 157 | subscr->keep_in_ram = 0; |
| 158 | gprs_subscr_stop_timer(subscr); |
| 159 | /* The subscr is freed now, if the timer was the last user */ |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 160 | subscr_put(subscr); |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 163 | static struct sgsn_subscriber_data *sgsn_subscriber_data_alloc(void *ctx) |
| 164 | { |
| 165 | struct sgsn_subscriber_data *sdata; |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 166 | int idx; |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 167 | |
| 168 | sdata = talloc_zero(ctx, struct sgsn_subscriber_data); |
| 169 | |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 170 | for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++) |
| 171 | sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL; |
| 172 | |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 173 | return sdata; |
| 174 | } |
| 175 | |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 176 | struct gsm_subscriber *gprs_subscr_get_or_create(const char *imsi) |
| 177 | { |
| 178 | struct gsm_subscriber *subscr; |
| 179 | |
| 180 | subscr = subscr_get_or_create(NULL, imsi); |
| 181 | if (!subscr) |
| 182 | return NULL; |
| 183 | |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 184 | if (!subscr->sgsn_data) |
| 185 | subscr->sgsn_data = sgsn_subscriber_data_alloc(subscr); |
| 186 | |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 187 | gprs_subscr_stop_timer(subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 188 | |
| 189 | return subscr; |
| 190 | } |
| 191 | |
| 192 | struct gsm_subscriber *gprs_subscr_get_by_imsi(const char *imsi) |
| 193 | { |
| 194 | return subscr_active_by_imsi(NULL, imsi); |
| 195 | } |
| 196 | |
| 197 | void gprs_subscr_delete(struct gsm_subscriber *subscr) |
| 198 | { |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 199 | if (subscr->sgsn_data->mm) { |
| 200 | subscr_put(subscr->sgsn_data->mm->subscr); |
| 201 | subscr->sgsn_data->mm->subscr = NULL; |
| 202 | subscr->sgsn_data->mm = NULL; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | if ((subscr->flags & GPRS_SUBSCRIBER_CANCELLED) || |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 206 | (subscr->flags & GSM_SUBSCRIBER_FIRST_CONTACT)) { |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 207 | subscr->keep_in_ram = 0; |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 208 | gprs_subscr_stop_timer(subscr); |
| 209 | } else if (sgsn->cfg.subscriber_expiry_timeout != SGSN_TIMEOUT_NEVER) { |
| 210 | gprs_subscr_start_timer(subscr, sgsn->cfg.subscriber_expiry_timeout); |
| 211 | } else { |
| 212 | subscr->keep_in_ram = 1; |
| 213 | } |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 214 | |
| 215 | subscr_put(subscr); |
| 216 | } |
| 217 | |
| 218 | void gprs_subscr_put_and_cancel(struct gsm_subscriber *subscr) |
| 219 | { |
| 220 | subscr->authorized = 0; |
| 221 | subscr->flags |= GPRS_SUBSCRIBER_CANCELLED; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 222 | subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 223 | |
| 224 | gprs_subscr_update(subscr); |
| 225 | |
| 226 | gprs_subscr_delete(subscr); |
| 227 | } |
| 228 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 229 | static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr, |
| 230 | struct gprs_gsup_message *gsup_msg) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 231 | { |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 232 | struct msgb *msg = gprs_gsup_msgb_alloc(); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 233 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 234 | if (strlen(gsup_msg->imsi) == 0 && subscr) |
| 235 | strncpy(gsup_msg->imsi, subscr->imsi, sizeof(gsup_msg->imsi) - 1); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 236 | |
| 237 | gprs_gsup_encode(msg, gsup_msg); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 238 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 239 | LOGGSUBSCRP(LOGL_INFO, subscr, |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 240 | "Sending GSUP, will send: %s\n", msgb_hexdump(msg)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 241 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 242 | if (!sgsn->gsup_client) { |
| 243 | msgb_free(msg); |
| 244 | return -ENOTSUP; |
| 245 | } |
| 246 | |
| 247 | return gprs_gsup_client_send(sgsn->gsup_client, msg); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 250 | static int gprs_subscr_tx_gsup_error_reply(struct gsm_subscriber *subscr, |
| 251 | struct gprs_gsup_message *gsup_orig, |
| 252 | enum gsm48_gmm_cause cause) |
| 253 | { |
| 254 | struct gprs_gsup_message gsup_reply = {0}; |
| 255 | |
| 256 | strncpy(gsup_reply.imsi, gsup_orig->imsi, sizeof(gsup_reply.imsi) - 1); |
| 257 | gsup_reply.cause = cause; |
| 258 | gsup_reply.message_type = |
| 259 | GPRS_GSUP_TO_MSGT_ERROR(gsup_orig->message_type); |
| 260 | |
| 261 | return gprs_subscr_tx_gsup_message(subscr, &gsup_reply); |
| 262 | } |
| 263 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 264 | static int gprs_subscr_handle_gsup_auth_res(struct gsm_subscriber *subscr, |
| 265 | struct gprs_gsup_message *gsup_msg) |
| 266 | { |
| 267 | unsigned idx; |
| 268 | struct sgsn_subscriber_data *sdata = subscr->sgsn_data; |
| 269 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 270 | LOGGSUBSCRP(LOGL_INFO, subscr, |
| 271 | "Got SendAuthenticationInfoResult, num_auth_tuples = %d\n", |
| 272 | gsup_msg->num_auth_tuples); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 273 | |
| 274 | if (gsup_msg->num_auth_tuples > 0) { |
| 275 | memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets)); |
| 276 | |
| 277 | for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++) |
| 278 | sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL; |
| 279 | } |
| 280 | |
| 281 | for (idx = 0; idx < gsup_msg->num_auth_tuples; idx++) { |
| 282 | size_t key_seq = gsup_msg->auth_tuples[idx].key_seq; |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 283 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 284 | "Adding auth tuple, cksn = %d\n", key_seq); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 285 | if (key_seq >= ARRAY_SIZE(sdata->auth_triplets)) { |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 286 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 287 | "Skipping auth triplet with invalid cksn %d\n", |
| 288 | key_seq); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 289 | continue; |
| 290 | } |
| 291 | sdata->auth_triplets[key_seq] = gsup_msg->auth_tuples[idx]; |
| 292 | } |
| 293 | |
| 294 | sdata->auth_triplets_updated = 1; |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 295 | sdata->error_cause = 0; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 296 | |
| 297 | gprs_subscr_update_auth_info(subscr); |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int gprs_subscr_handle_gsup_upd_loc_res(struct gsm_subscriber *subscr, |
| 303 | struct gprs_gsup_message *gsup_msg) |
| 304 | { |
| 305 | unsigned idx; |
| 306 | |
| 307 | if (gsup_msg->pdp_info_compl) { |
| 308 | LOGP(DGPRS, LOGL_INFO, "Would clear existing PDP info\n"); |
| 309 | |
| 310 | /* TODO: clear existing PDP info entries */ |
| 311 | } |
| 312 | |
| 313 | for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) { |
| 314 | struct gprs_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx]; |
| 315 | size_t ctx_id = pdp_info->context_id; |
| 316 | |
| 317 | LOGP(DGPRS, LOGL_INFO, |
| 318 | "Would set PDP info, context id = %d, APN = %s\n", |
| 319 | ctx_id, osmo_hexdump(pdp_info->apn_enc, pdp_info->apn_enc_len)); |
| 320 | |
| 321 | /* TODO: set PDP info [ctx_id] */ |
| 322 | } |
| 323 | |
| 324 | subscr->authorized = 1; |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 325 | subscr->sgsn_data->error_cause = 0; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 326 | |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 327 | subscr->flags |= GPRS_SUBSCRIBER_ENABLE_PURGE; |
| 328 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 329 | gprs_subscr_update(subscr); |
| 330 | return 0; |
| 331 | } |
| 332 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 333 | static int check_cause(int cause) |
| 334 | { |
| 335 | switch (cause) { |
| 336 | case GMM_CAUSE_IMSI_UNKNOWN ... GMM_CAUSE_ILLEGAL_ME: |
| 337 | case GMM_CAUSE_GPRS_NOTALLOWED ... GMM_CAUSE_NO_GPRS_PLMN: |
| 338 | return EACCES; |
| 339 | |
| 340 | case GMM_CAUSE_MSC_TEMP_NOTREACH ... GMM_CAUSE_CONGESTION: |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 341 | return EHOSTUNREACH; |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 342 | |
| 343 | case GMM_CAUSE_SEM_INCORR_MSG ... GMM_CAUSE_PROTO_ERR_UNSPEC: |
| 344 | default: |
| 345 | return EINVAL; |
| 346 | } |
| 347 | } |
| 348 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 349 | static int gprs_subscr_handle_gsup_auth_err(struct gsm_subscriber *subscr, |
| 350 | struct gprs_gsup_message *gsup_msg) |
| 351 | { |
| 352 | unsigned idx; |
| 353 | struct sgsn_subscriber_data *sdata = subscr->sgsn_data; |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 354 | int cause_err; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 355 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 356 | cause_err = check_cause(gsup_msg->cause); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 357 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 358 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 359 | "Send authentication info has failed with cause %d, " |
| 360 | "handled as: %s\n", |
| 361 | gsup_msg->cause, strerror(cause_err)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 362 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 363 | switch (cause_err) { |
| 364 | case EACCES: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 365 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 366 | "GPRS send auth info req failed, access denied, " |
| 367 | "GMM cause = '%s' (%d)\n", |
| 368 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 369 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 370 | /* Clear auth tuples */ |
| 371 | memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets)); |
| 372 | for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++) |
| 373 | sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 374 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 375 | subscr->authorized = 0; |
| 376 | sdata->error_cause = gsup_msg->cause; |
| 377 | gprs_subscr_update_auth_info(subscr); |
| 378 | break; |
| 379 | |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 380 | case EHOSTUNREACH: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 381 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 382 | "GPRS send auth info req failed, GMM cause = '%s' (%d)\n", |
| 383 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 384 | gsup_msg->cause); |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 385 | |
| 386 | sdata->error_cause = gsup_msg->cause; |
| 387 | gprs_subscr_update_auth_info(subscr); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | default: |
| 391 | case EINVAL: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 392 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 393 | "GSUP protocol remote error, GMM cause = '%s' (%d)\n", |
| 394 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 395 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 396 | break; |
| 397 | } |
| 398 | |
| 399 | return -gsup_msg->cause; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static int gprs_subscr_handle_gsup_upd_loc_err(struct gsm_subscriber *subscr, |
| 403 | struct gprs_gsup_message *gsup_msg) |
| 404 | { |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 405 | int cause_err; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 406 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 407 | cause_err = check_cause(gsup_msg->cause); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 408 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 409 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 410 | "Update location has failed with cause %d, handled as: %s\n", |
| 411 | gsup_msg->cause, strerror(cause_err)); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 412 | |
| 413 | switch (cause_err) { |
| 414 | case EACCES: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 415 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 416 | "GPRS update location failed, access denied, " |
| 417 | "GMM cause = '%s' (%d)\n", |
| 418 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 419 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 420 | |
| 421 | subscr->authorized = 0; |
| 422 | subscr->sgsn_data->error_cause = gsup_msg->cause; |
| 423 | gprs_subscr_update_auth_info(subscr); |
| 424 | break; |
| 425 | |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 426 | case EHOSTUNREACH: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 427 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 428 | "GPRS update location failed, GMM cause = '%s' (%d)\n", |
| 429 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 430 | gsup_msg->cause); |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 431 | |
| 432 | subscr->sgsn_data->error_cause = gsup_msg->cause; |
| 433 | gprs_subscr_update_auth_info(subscr); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 434 | break; |
| 435 | |
| 436 | default: |
| 437 | case EINVAL: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 438 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 439 | "GSUP protocol remote error, GMM cause = '%s' (%d)\n", |
| 440 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 441 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 442 | break; |
| 443 | } |
| 444 | |
| 445 | return -gsup_msg->cause; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 448 | static int gprs_subscr_handle_gsup_purge_res(struct gsm_subscriber *subscr, |
| 449 | struct gprs_gsup_message *gsup_msg) |
| 450 | { |
| 451 | LOGGSUBSCRP(LOGL_INFO, subscr, "Completing purge MS\n"); |
| 452 | |
| 453 | /* Force silent cancellation */ |
| 454 | subscr->sgsn_data->error_cause = 0; |
| 455 | gprs_subscr_put_and_cancel(subscr_get(subscr)); |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static int gprs_subscr_handle_gsup_purge_err(struct gsm_subscriber *subscr, |
| 461 | struct gprs_gsup_message *gsup_msg) |
| 462 | { |
| 463 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 464 | "Purge MS has failed with cause '%s' (%d)\n", |
| 465 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 466 | gsup_msg->cause); |
| 467 | |
| 468 | /* In GSM 09.02, 19.1.4.4, the text and the SDL diagram imply that |
| 469 | * the subscriber data is not removed if the request has failed. On the |
| 470 | * other hand, keeping the subscriber data in either error case |
| 471 | * (subscriber unknown, syntactical message error, connection error) |
| 472 | * doesn't seem to give any advantage, since the data will be restored |
| 473 | * on the next Attach Request anyway. |
| 474 | * This approach ensures, that the subscriber record will not stick if |
| 475 | * an error happens. |
| 476 | */ |
| 477 | |
| 478 | /* TODO: Check whether this behaviour is acceptable and either just |
| 479 | * remove this TODO-notice or change the implementation to not delete |
| 480 | * the subscriber data (eventually resetting the ENABLE_PURGE flag and |
| 481 | * restarting the expiry timer based on the cause). |
| 482 | * |
| 483 | * Subscriber Unknown: cancel subscr |
| 484 | * Temporary network problems: do nothing (handled by timer based retry) |
| 485 | * Message problems (syntax, nyi, ...): cancel subscr (retry won't help) |
| 486 | */ |
| 487 | |
| 488 | gprs_subscr_handle_gsup_purge_res(subscr, gsup_msg); |
| 489 | |
| 490 | return -gsup_msg->cause; |
| 491 | } |
| 492 | |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 493 | static int gprs_subscr_handle_loc_cancel_req(struct gsm_subscriber *subscr, |
| 494 | struct gprs_gsup_message *gsup_msg) |
| 495 | { |
| 496 | struct gprs_gsup_message gsup_reply = {0}; |
| 497 | |
| 498 | LOGGSUBSCRP(LOGL_INFO, subscr, "purging MS subscriber\n"); |
| 499 | |
| 500 | gsup_reply.message_type = GPRS_GSUP_MSGT_LOCATION_CANCEL_RESULT; |
| 501 | gprs_subscr_tx_gsup_message(subscr, &gsup_reply); |
| 502 | |
| 503 | subscr->sgsn_data->error_cause = 0; |
| 504 | gprs_subscr_put_and_cancel(subscr_get(subscr)); |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 509 | static int gprs_subscr_handle_unknown_imsi(struct gprs_gsup_message *gsup_msg) |
| 510 | { |
| 511 | if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) { |
| 512 | gprs_subscr_tx_gsup_error_reply(NULL, gsup_msg, |
| 513 | GMM_CAUSE_IMSI_UNKNOWN); |
| 514 | LOGP(DGPRS, LOGL_NOTICE, |
| 515 | "Unknown IMSI %s, discarding GSUP request " |
| 516 | "of type 0x%02x\n", |
| 517 | gsup_msg->imsi, gsup_msg->message_type); |
| 518 | } else if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { |
| 519 | LOGP(DGPRS, LOGL_NOTICE, |
| 520 | "Unknown IMSI %s, discarding GSUP error " |
| 521 | "of type 0x%02x, cause '%s' (%d)\n", |
| 522 | gsup_msg->imsi, gsup_msg->message_type, |
| 523 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 524 | gsup_msg->cause); |
| 525 | } else { |
| 526 | LOGP(DGPRS, LOGL_NOTICE, |
| 527 | "Unknown IMSI %s, discarding GSUP response " |
| 528 | "of type 0x%02x\n", |
| 529 | gsup_msg->imsi, gsup_msg->message_type); |
| 530 | } |
| 531 | |
| 532 | return -GMM_CAUSE_IMSI_UNKNOWN; |
| 533 | } |
| 534 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 535 | int gprs_subscr_rx_gsup_message(struct msgb *msg) |
| 536 | { |
| 537 | uint8_t *data = msgb_l2(msg); |
| 538 | size_t data_len = msgb_l2len(msg); |
| 539 | int rc = 0; |
| 540 | |
| 541 | struct gprs_gsup_message gsup_msg = {0}; |
| 542 | struct gsm_subscriber *subscr; |
| 543 | |
| 544 | rc = gprs_gsup_decode(data, data_len, &gsup_msg); |
| 545 | if (rc < 0) { |
| 546 | LOGP(DGPRS, LOGL_ERROR, |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 547 | "decoding GSUP message fails with error '%s' (%d)\n", |
| 548 | get_value_string(gsm48_gmm_cause_names, -rc), -rc); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 549 | return rc; |
| 550 | } |
| 551 | |
| 552 | if (!gsup_msg.imsi[0]) |
| 553 | return -GMM_CAUSE_INV_MAND_INFO; |
| 554 | |
Jacob Erlbeck | 4dedb27 | 2015-01-15 17:50:16 +0100 | [diff] [blame] | 555 | subscr = gprs_subscr_get_by_imsi(gsup_msg.imsi); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 556 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 557 | if (!subscr) |
| 558 | return gprs_subscr_handle_unknown_imsi(&gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 559 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 560 | LOGGSUBSCRP(LOGL_INFO, subscr, |
| 561 | "Received GSUP message of type 0x%02x\n", gsup_msg.message_type); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 562 | |
| 563 | switch (gsup_msg.message_type) { |
| 564 | case GPRS_GSUP_MSGT_LOCATION_CANCEL_REQUEST: |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 565 | rc = gprs_subscr_handle_loc_cancel_req(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 566 | break; |
| 567 | |
| 568 | case GPRS_GSUP_MSGT_SEND_AUTH_INFO_RESULT: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 569 | rc = gprs_subscr_handle_gsup_auth_res(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 570 | break; |
| 571 | |
| 572 | case GPRS_GSUP_MSGT_SEND_AUTH_INFO_ERROR: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 573 | rc = gprs_subscr_handle_gsup_auth_err(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 574 | break; |
| 575 | |
| 576 | case GPRS_GSUP_MSGT_UPDATE_LOCATION_RESULT: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 577 | rc = gprs_subscr_handle_gsup_upd_loc_res(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 578 | break; |
| 579 | |
| 580 | case GPRS_GSUP_MSGT_UPDATE_LOCATION_ERROR: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 581 | rc = gprs_subscr_handle_gsup_upd_loc_err(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 582 | break; |
| 583 | |
| 584 | case GPRS_GSUP_MSGT_PURGE_MS_ERROR: |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 585 | rc = gprs_subscr_handle_gsup_purge_err(subscr, &gsup_msg); |
| 586 | break; |
| 587 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 588 | case GPRS_GSUP_MSGT_PURGE_MS_RESULT: |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 589 | rc = gprs_subscr_handle_gsup_purge_res(subscr, &gsup_msg); |
| 590 | break; |
| 591 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 592 | case GPRS_GSUP_MSGT_INSERT_DATA_REQUEST: |
| 593 | case GPRS_GSUP_MSGT_DELETE_DATA_REQUEST: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 594 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 595 | "Rx GSUP message type %d not yet implemented\n", |
| 596 | gsup_msg.message_type); |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 597 | gprs_subscr_tx_gsup_error_reply(subscr, &gsup_msg, |
| 598 | GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 599 | rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; |
| 600 | break; |
| 601 | |
| 602 | default: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 603 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 604 | "Rx GSUP message type %d not valid at SGSN\n", |
| 605 | gsup_msg.message_type); |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 606 | if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) |
| 607 | gprs_subscr_tx_gsup_error_reply( |
| 608 | subscr, &gsup_msg, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
| 609 | rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 610 | break; |
| 611 | }; |
| 612 | |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 613 | subscr_put(subscr); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 614 | |
| 615 | return rc; |
| 616 | } |
| 617 | |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 618 | int gprs_subscr_purge(struct gsm_subscriber *subscr) |
| 619 | { |
| 620 | struct gprs_gsup_message gsup_msg = {0}; |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 621 | int rc; |
| 622 | |
| 623 | if (!check_blocking(subscr, SGSN_SUBSCR_PROC_PURGE)) { |
| 624 | LOGGSUBSCRP( |
| 625 | LOGL_NOTICE, subscr, |
| 626 | "Cannot purge MS subscriber, blocked\n"); |
| 627 | return -EAGAIN; |
| 628 | } |
| 629 | |
| 630 | /* GSM 09.02, 19.4.1.4 requires other MAP requests to be blocked until |
| 631 | * this procedure is completed |
| 632 | */ |
| 633 | subscr->sgsn_data->blocked_by = SGSN_SUBSCR_PROC_PURGE; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 634 | |
| 635 | LOGGSUBSCRP(LOGL_INFO, subscr, "purging MS subscriber\n"); |
| 636 | |
| 637 | gsup_msg.message_type = GPRS_GSUP_MSGT_PURGE_MS_REQUEST; |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 638 | rc = gprs_subscr_tx_gsup_message(subscr, &gsup_msg); |
| 639 | if (rc < 0) |
| 640 | subscr->sgsn_data->blocked_by = SGSN_SUBSCR_PROC_NONE; |
| 641 | |
| 642 | return rc; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 643 | } |
| 644 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 645 | int gprs_subscr_query_auth_info(struct gsm_subscriber *subscr) |
| 646 | { |
| 647 | struct gprs_gsup_message gsup_msg = {0}; |
| 648 | |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 649 | if (!check_blocking(subscr, SGSN_SUBSCR_PROC_UPD_AUTH)) { |
| 650 | LOGGSUBSCRP( |
| 651 | LOGL_NOTICE, subscr, |
| 652 | "Cannot start update auth info request procedure, blocked\n"); |
| 653 | abort_blocking_procedure(subscr); |
| 654 | return -EAGAIN; |
| 655 | } |
| 656 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 657 | LOGGSUBSCRP(LOGL_INFO, subscr, |
| 658 | "subscriber auth info is not available\n"); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 659 | |
| 660 | gsup_msg.message_type = GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST; |
| 661 | return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); |
| 662 | } |
| 663 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 664 | int gprs_subscr_location_update(struct gsm_subscriber *subscr) |
| 665 | { |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 666 | struct gprs_gsup_message gsup_msg = {0}; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 667 | |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 668 | if (!check_blocking(subscr, SGSN_SUBSCR_PROC_UPD_LOC)) { |
| 669 | LOGGSUBSCRP( |
| 670 | LOGL_NOTICE, subscr, |
| 671 | "Cannot start update location procedure, blocked\n"); |
| 672 | abort_blocking_procedure(subscr); |
| 673 | return -EAGAIN; |
| 674 | } |
| 675 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 676 | LOGGSUBSCRP(LOGL_INFO, subscr, |
| 677 | "subscriber data is not available\n"); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 678 | |
| 679 | gsup_msg.message_type = GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST; |
| 680 | return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | void gprs_subscr_update(struct gsm_subscriber *subscr) |
| 684 | { |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 685 | LOGGSUBSCRP(LOGL_DEBUG, subscr, "Updating subscriber data\n"); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 686 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 687 | subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 688 | subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT; |
| 689 | |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 690 | sgsn_update_subscriber_data(subscr->sgsn_data->mm, subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 691 | } |
| 692 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 693 | void gprs_subscr_update_auth_info(struct gsm_subscriber *subscr) |
| 694 | { |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 695 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 696 | "Updating subscriber authentication info\n"); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 697 | |
| 698 | subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING; |
| 699 | subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT; |
| 700 | |
| 701 | sgsn_update_subscriber_data(subscr->sgsn_data->mm, subscr); |
| 702 | } |
| 703 | |
| 704 | struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 705 | { |
| 706 | struct gsm_subscriber *subscr = NULL; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 707 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 708 | if (mmctx->subscr) |
| 709 | return subscr_get(mmctx->subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 710 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 711 | if (mmctx->imsi[0]) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 712 | subscr = gprs_subscr_get_by_imsi(mmctx->imsi); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 713 | |
| 714 | if (!subscr) { |
| 715 | subscr = gprs_subscr_get_or_create(mmctx->imsi); |
| 716 | subscr->flags |= GSM_SUBSCRIBER_FIRST_CONTACT; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 717 | subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | if (strcpy(subscr->equipment.imei, mmctx->imei) != 0) { |
| 721 | strncpy(subscr->equipment.imei, mmctx->imei, GSM_IMEI_LENGTH-1); |
| 722 | subscr->equipment.imei[GSM_IMEI_LENGTH-1] = 0; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 725 | if (subscr->lac != mmctx->ra.lac) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 726 | subscr->lac = mmctx->ra.lac; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 727 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 728 | subscr->sgsn_data->mm = mmctx; |
| 729 | mmctx->subscr = subscr_get(subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 730 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 731 | return subscr; |
| 732 | } |
| 733 | |
| 734 | int gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) |
| 735 | { |
| 736 | struct gsm_subscriber *subscr = NULL; |
| 737 | int rc; |
| 738 | |
| 739 | LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber data update\n"); |
| 740 | |
| 741 | subscr = gprs_subscr_get_or_create_by_mmctx(mmctx); |
| 742 | |
| 743 | subscr->flags |= GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING; |
| 744 | |
| 745 | rc = gprs_subscr_location_update(subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 746 | subscr_put(subscr); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 747 | return rc; |
| 748 | } |
| 749 | |
| 750 | int gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx) |
| 751 | { |
| 752 | struct gsm_subscriber *subscr = NULL; |
| 753 | int rc; |
| 754 | |
| 755 | LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber authentication info\n"); |
| 756 | |
| 757 | subscr = gprs_subscr_get_or_create_by_mmctx(mmctx); |
| 758 | |
| 759 | subscr->flags |= GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING; |
| 760 | |
| 761 | rc = gprs_subscr_query_auth_info(subscr); |
| 762 | subscr_put(subscr); |
| 763 | return rc; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 764 | } |