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