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