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