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