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