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