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 | |
Harald Welte | 53373bc | 2016-04-20 17:11:43 +0200 | [diff] [blame] | 23 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 24 | #include <osmocom/gsm/gsup.h> |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 25 | #include <osmocom/core/utils.h> |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 26 | #include <osmocom/core/logging.h> |
| 27 | #include <openbsc/gprs_subscriber.h> |
Neels Hofmeyr | eaaee92 | 2016-12-08 21:22:58 +0100 | [diff] [blame] | 28 | #include <openbsc/gsup_client.h> |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 29 | |
| 30 | #include <openbsc/sgsn.h> |
| 31 | #include <openbsc/gprs_sgsn.h> |
| 32 | #include <openbsc/gprs_gmm.h> |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 33 | #include <openbsc/gprs_utils.h> |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 34 | |
| 35 | #include <openbsc/debug.h> |
| 36 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 37 | #include <netinet/in.h> |
| 38 | #include <arpa/inet.h> |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 39 | #include <limits.h> |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 40 | |
Jacob Erlbeck | 743dec4 | 2015-01-08 15:18:39 +0100 | [diff] [blame] | 41 | #define SGSN_SUBSCR_MAX_RETRIES 3 |
| 42 | #define SGSN_SUBSCR_RETRY_INTERVAL 10 |
| 43 | |
Jacob Erlbeck | 929acdf | 2015-01-27 13:47:24 +0100 | [diff] [blame] | 44 | #define LOGGSUPP(level, gsup, fmt, args...) \ |
| 45 | LOGP(DGPRS, level, "GSUP(%s) " fmt, \ |
| 46 | (gsup)->imsi, \ |
| 47 | ## args) |
| 48 | |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 49 | extern void *tall_bsc_ctx; |
| 50 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 51 | LLIST_HEAD(_gprs_subscribers); |
| 52 | struct llist_head * const gprs_subscribers = &_gprs_subscribers; |
| 53 | |
Neels Hofmeyr | 814fef0 | 2016-12-08 21:19:57 +0100 | [diff] [blame] | 54 | static int gsup_read_cb(struct gsup_client *gsupc, struct msgb *msg); |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 55 | |
| 56 | /* TODO: Some functions are specific to the SGSN, but this file is more general |
| 57 | * (it has gprs_* name). Either move these functions elsewhere, split them and |
| 58 | * move a part, or replace the gprs_ prefix by sgsn_. The applies to |
| 59 | * gprs_subscr_init, gsup_read_cb, and gprs_subscr_tx_gsup_message. |
| 60 | */ |
| 61 | |
| 62 | int gprs_subscr_init(struct sgsn_instance *sgi) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 63 | { |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 64 | const char *addr_str; |
| 65 | |
| 66 | if (!sgi->cfg.gsup_server_addr.sin_addr.s_addr) |
| 67 | return 0; |
| 68 | |
| 69 | addr_str = inet_ntoa(sgi->cfg.gsup_server_addr.sin_addr); |
| 70 | |
Neels Hofmeyr | 814fef0 | 2016-12-08 21:19:57 +0100 | [diff] [blame] | 71 | sgi->gsup_client = gsup_client_create( |
Neels Hofmeyr | 398851f | 2017-03-04 03:15:53 +0100 | [diff] [blame] | 72 | "SGSN", |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 73 | addr_str, sgi->cfg.gsup_server_port, |
Neels Hofmeyr | 9c534fd | 2015-10-12 11:57:37 +0200 | [diff] [blame] | 74 | &gsup_read_cb, |
| 75 | &sgi->cfg.oap); |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 76 | |
| 77 | if (!sgi->gsup_client) |
| 78 | return -1; |
| 79 | |
| 80 | return 1; |
| 81 | } |
| 82 | |
Neels Hofmeyr | 814fef0 | 2016-12-08 21:19:57 +0100 | [diff] [blame] | 83 | static int gsup_read_cb(struct gsup_client *gsupc, struct msgb *msg) |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 84 | { |
| 85 | int rc; |
| 86 | |
| 87 | rc = gprs_subscr_rx_gsup_message(msg); |
Jacob Erlbeck | e154d8b | 2014-12-19 19:15:55 +0100 | [diff] [blame] | 88 | msgb_free(msg); |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 89 | if (rc < 0) |
| 90 | return -1; |
| 91 | |
| 92 | return rc; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 95 | int gprs_subscr_purge(struct gprs_subscr *subscr); |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 96 | |
Jacob Erlbeck | a1e0373 | 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 | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 100 | int idx; |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 101 | |
| 102 | sdata = talloc_zero(ctx, struct sgsn_subscriber_data); |
| 103 | |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 104 | sdata->error_cause = SGSN_ERROR_CAUSE_NONE; |
| 105 | |
Jacob Erlbeck | 7921ab1 | 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 | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 109 | INIT_LLIST_HEAD(&sdata->pdp_list); |
| 110 | |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 111 | return sdata; |
| 112 | } |
| 113 | |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 114 | struct sgsn_subscriber_pdp_data* sgsn_subscriber_pdp_data_alloc( |
| 115 | struct sgsn_subscriber_data *sdata) |
| 116 | { |
| 117 | struct sgsn_subscriber_pdp_data* pdata; |
| 118 | |
| 119 | pdata = talloc_zero(sdata, struct sgsn_subscriber_pdp_data); |
| 120 | |
| 121 | llist_add_tail(&pdata->list, &sdata->pdp_list); |
| 122 | |
| 123 | return pdata; |
| 124 | } |
| 125 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 126 | struct gprs_subscr *gprs_subscr_get_by_imsi(const char *imsi) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 127 | { |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 128 | struct gprs_subscr *gsub; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 129 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 130 | if (!imsi || !*imsi) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 131 | return NULL; |
| 132 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 133 | llist_for_each_entry(gsub, gprs_subscribers, entry) { |
| 134 | if (!strcmp(gsub->imsi, imsi)) |
| 135 | return gprs_subscr_get(gsub); |
| 136 | } |
| 137 | return NULL; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 140 | static struct gprs_subscr *gprs_subscr_alloc(void) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 141 | { |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 142 | struct gprs_subscr *gsub; |
| 143 | gsub = talloc_zero(tall_bsc_ctx, struct gprs_subscr); |
| 144 | if (!gsub) |
| 145 | return NULL; |
| 146 | llist_add_tail(&gsub->entry, gprs_subscribers); |
| 147 | gsub->use_count = 1; |
| 148 | gsub->tmsi = GSM_RESERVED_TMSI; |
| 149 | return gsub; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 152 | struct gprs_subscr *gprs_subscr_get_or_create(const char *imsi) |
| 153 | { |
| 154 | struct gprs_subscr *gsub; |
| 155 | |
| 156 | gsub = gprs_subscr_get_by_imsi(imsi); |
| 157 | if (!gsub) { |
| 158 | gsub = gprs_subscr_alloc(); |
| 159 | if (!gsub) |
| 160 | return NULL; |
Neels Hofmeyr | ca06e04 | 2017-03-08 18:30:22 +0100 | [diff] [blame] | 161 | osmo_strlcpy(gsub->imsi, imsi, sizeof(gsub->imsi)); |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (!gsub->sgsn_data) |
| 165 | gsub->sgsn_data = sgsn_subscriber_data_alloc(gsub); |
| 166 | return gsub; |
| 167 | } |
| 168 | |
| 169 | void gprs_subscr_cleanup(struct gprs_subscr *subscr) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 170 | { |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 171 | if (subscr->sgsn_data->mm) { |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 172 | gprs_subscr_put(subscr->sgsn_data->mm->subscr); |
Jacob Erlbeck | a1e0373 | 2014-12-02 11:28:38 +0100 | [diff] [blame] | 173 | subscr->sgsn_data->mm->subscr = NULL; |
| 174 | subscr->sgsn_data->mm = NULL; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 177 | if (subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE) { |
| 178 | gprs_subscr_purge(subscr); |
| 179 | subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE; |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 180 | } |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 183 | void gprs_subscr_cancel(struct gprs_subscr *subscr) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 184 | { |
| 185 | subscr->authorized = 0; |
| 186 | subscr->flags |= GPRS_SUBSCRIBER_CANCELLED; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 187 | subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 188 | |
| 189 | gprs_subscr_update(subscr); |
Jacob Erlbeck | 3e4e58f | 2015-01-26 11:07:24 +0100 | [diff] [blame] | 190 | gprs_subscr_cleanup(subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 193 | static int gprs_subscr_tx_gsup_message(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 194 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 195 | { |
Neels Hofmeyr | 814fef0 | 2016-12-08 21:19:57 +0100 | [diff] [blame] | 196 | struct msgb *msg = gsup_client_msgb_alloc(); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 197 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 198 | if (strlen(gsup_msg->imsi) == 0 && subscr) |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 199 | osmo_strlcpy(gsup_msg->imsi, subscr->imsi, |
| 200 | sizeof(gsup_msg->imsi)); |
Max | 896c6f8 | 2016-07-01 15:24:44 +0200 | [diff] [blame] | 201 | gsup_msg->cn_domain = OSMO_GSUP_CN_DOMAIN_PS; |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 202 | osmo_gsup_encode(msg, gsup_msg); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 203 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 204 | LOGGSUBSCRP(LOGL_INFO, subscr, |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 205 | "Sending GSUP, will send: %s\n", msgb_hexdump(msg)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 206 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 207 | if (!sgsn->gsup_client) { |
| 208 | msgb_free(msg); |
| 209 | return -ENOTSUP; |
| 210 | } |
| 211 | |
Neels Hofmeyr | 814fef0 | 2016-12-08 21:19:57 +0100 | [diff] [blame] | 212 | return gsup_client_send(sgsn->gsup_client, msg); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 215 | static int gprs_subscr_tx_gsup_error_reply(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 216 | struct osmo_gsup_message *gsup_orig, |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 217 | enum gsm48_gmm_cause cause) |
| 218 | { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 219 | struct osmo_gsup_message gsup_reply = {0}; |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 220 | |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 221 | osmo_strlcpy(gsup_reply.imsi, gsup_orig->imsi, |
| 222 | sizeof(gsup_reply.imsi)); |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 223 | gsup_reply.cause = cause; |
| 224 | gsup_reply.message_type = |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 225 | OSMO_GSUP_TO_MSGT_ERROR(gsup_orig->message_type); |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 226 | |
| 227 | return gprs_subscr_tx_gsup_message(subscr, &gsup_reply); |
| 228 | } |
| 229 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 230 | static int gprs_subscr_handle_gsup_auth_res(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 231 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 232 | { |
| 233 | unsigned idx; |
| 234 | struct sgsn_subscriber_data *sdata = subscr->sgsn_data; |
| 235 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 236 | LOGGSUBSCRP(LOGL_INFO, subscr, |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 237 | "Got SendAuthenticationInfoResult, num_auth_vectors = %zu\n", |
| 238 | gsup_msg->num_auth_vectors); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 239 | |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 240 | if (gsup_msg->num_auth_vectors > 0) { |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 241 | memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets)); |
| 242 | |
| 243 | for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++) |
| 244 | sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL; |
| 245 | } |
| 246 | |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 247 | for (idx = 0; idx < gsup_msg->num_auth_vectors; idx++) { |
| 248 | size_t key_seq = idx; |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 249 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 250 | "Adding auth tuple, cksn = %zu\n", key_seq); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 251 | if (key_seq >= ARRAY_SIZE(sdata->auth_triplets)) { |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 252 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 253 | "Skipping auth triplet with invalid cksn %zu\n", |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 254 | key_seq); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 255 | continue; |
| 256 | } |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 257 | sdata->auth_triplets[key_seq].vec = gsup_msg->auth_vectors[idx]; |
| 258 | sdata->auth_triplets[key_seq].key_seq = key_seq; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | sdata->auth_triplets_updated = 1; |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 262 | sdata->error_cause = SGSN_ERROR_CAUSE_NONE; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 263 | |
| 264 | gprs_subscr_update_auth_info(subscr); |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 269 | static int gprs_subscr_pdp_data_clear(struct gprs_subscr *subscr) |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 270 | { |
| 271 | struct sgsn_subscriber_pdp_data *pdp, *pdp2; |
| 272 | int count = 0; |
| 273 | |
| 274 | llist_for_each_entry_safe(pdp, pdp2, &subscr->sgsn_data->pdp_list, list) { |
| 275 | llist_del(&pdp->list); |
| 276 | talloc_free(pdp); |
| 277 | count += 1; |
| 278 | } |
| 279 | |
| 280 | return count; |
| 281 | } |
| 282 | |
| 283 | static struct sgsn_subscriber_pdp_data *gprs_subscr_pdp_data_get_by_id( |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 284 | struct gprs_subscr *subscr, unsigned context_id) |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 285 | { |
| 286 | struct sgsn_subscriber_pdp_data *pdp; |
| 287 | |
| 288 | llist_for_each_entry(pdp, &subscr->sgsn_data->pdp_list, list) { |
| 289 | if (pdp->context_id == context_id) |
| 290 | return pdp; |
| 291 | } |
| 292 | |
| 293 | return NULL; |
| 294 | } |
| 295 | |
| 296 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 297 | static void gprs_subscr_gsup_insert_data(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 298 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 299 | { |
Holger Hans Peter Freyther | 9ba273d | 2015-04-23 09:53:53 -0400 | [diff] [blame] | 300 | struct sgsn_subscriber_data *sdata = subscr->sgsn_data; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 301 | unsigned idx; |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 302 | int rc; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 303 | |
Holger Hans Peter Freyther | 9ba273d | 2015-04-23 09:53:53 -0400 | [diff] [blame] | 304 | if (gsup_msg->msisdn_enc) { |
| 305 | if (gsup_msg->msisdn_enc_len > sizeof(sdata->msisdn)) { |
| 306 | LOGP(DGPRS, LOGL_ERROR, "MSISDN too long (%zu)\n", |
| 307 | gsup_msg->msisdn_enc_len); |
| 308 | sdata->msisdn_len = 0; |
| 309 | } else { |
| 310 | memcpy(sdata->msisdn, gsup_msg->msisdn_enc, |
| 311 | gsup_msg->msisdn_enc_len); |
| 312 | sdata->msisdn_len = gsup_msg->msisdn_enc_len; |
| 313 | } |
| 314 | } |
| 315 | |
Holger Hans Peter Freyther | 10c0f56 | 2015-05-17 20:58:40 +0200 | [diff] [blame] | 316 | if (gsup_msg->hlr_enc) { |
| 317 | if (gsup_msg->hlr_enc_len > sizeof(sdata->hlr)) { |
| 318 | LOGP(DGPRS, LOGL_ERROR, "HLR-Number too long (%zu)\n", |
| 319 | gsup_msg->hlr_enc_len); |
| 320 | sdata->hlr_len = 0; |
| 321 | } else { |
| 322 | memcpy(sdata->hlr, gsup_msg->hlr_enc, |
| 323 | gsup_msg->hlr_enc_len); |
| 324 | sdata->hlr_len = gsup_msg->hlr_enc_len; |
| 325 | } |
| 326 | } |
| 327 | |
Holger Hans Peter Freyther | 5db6857 | 2017-07-09 13:18:17 +0200 | [diff] [blame] | 328 | if (gsup_msg->pdp_charg_enc && gsup_msg->pdp_charg_enc_len >= sizeof(sdata->pdp_charg)) { |
| 329 | memcpy(&sdata->pdp_charg, gsup_msg->pdp_charg_enc, sizeof(sdata->pdp_charg)); |
| 330 | sdata->has_pdp_charg = 1; |
| 331 | } else { |
| 332 | sdata->has_pdp_charg = 0; |
| 333 | } |
| 334 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 335 | if (gsup_msg->pdp_info_compl) { |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 336 | rc = gprs_subscr_pdp_data_clear(subscr); |
| 337 | if (rc > 0) |
| 338 | LOGP(DGPRS, LOGL_INFO, "Cleared existing PDP info\n"); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 342 | struct osmo_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx]; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 343 | size_t ctx_id = pdp_info->context_id; |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 344 | struct sgsn_subscriber_pdp_data *pdp_data; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 345 | |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 346 | if (pdp_info->apn_enc_len >= sizeof(pdp_data->apn_str)-1) { |
| 347 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 348 | "APN too long, context id = %zu, APN = %s\n", |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 349 | ctx_id, osmo_hexdump(pdp_info->apn_enc, |
| 350 | pdp_info->apn_enc_len)); |
| 351 | continue; |
| 352 | } |
| 353 | |
Holger Hans Peter Freyther | 8cedded | 2015-04-23 11:33:35 -0400 | [diff] [blame] | 354 | if (pdp_info->qos_enc_len > sizeof(pdp_data->qos_subscribed)) { |
| 355 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 356 | "QoS info too long (%zu)\n", |
| 357 | pdp_info->qos_enc_len); |
| 358 | continue; |
| 359 | } |
| 360 | |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 361 | LOGGSUBSCRP(LOGL_INFO, subscr, |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 362 | "Will set PDP info, context id = %zu, APN = %s\n", |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 363 | ctx_id, osmo_hexdump(pdp_info->apn_enc, pdp_info->apn_enc_len)); |
| 364 | |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 365 | /* Set PDP info [ctx_id] */ |
| 366 | pdp_data = gprs_subscr_pdp_data_get_by_id(subscr, ctx_id); |
| 367 | if (!pdp_data) { |
| 368 | pdp_data = sgsn_subscriber_pdp_data_alloc(subscr->sgsn_data); |
| 369 | pdp_data->context_id = ctx_id; |
| 370 | } |
| 371 | |
| 372 | OSMO_ASSERT(pdp_data != NULL); |
| 373 | pdp_data->pdp_type = pdp_info->pdp_type; |
| 374 | gprs_apn_to_str(pdp_data->apn_str, |
| 375 | pdp_info->apn_enc, pdp_info->apn_enc_len); |
Holger Hans Peter Freyther | 8cedded | 2015-04-23 11:33:35 -0400 | [diff] [blame] | 376 | memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len); |
| 377 | pdp_data->qos_subscribed_len = pdp_info->qos_enc_len; |
Holger Hans Peter Freyther | 5db6857 | 2017-07-09 13:18:17 +0200 | [diff] [blame] | 378 | |
| 379 | if (pdp_info->pdp_charg_enc && pdp_info->pdp_charg_enc_len >= sizeof(pdp_data->pdp_charg)) { |
| 380 | memcpy(&pdp_data->pdp_charg, pdp_info->pdp_charg_enc, sizeof(pdp_data->pdp_charg)); |
| 381 | pdp_data->has_pdp_charg = 1; |
| 382 | } else { |
| 383 | pdp_data->has_pdp_charg = 0; |
| 384 | } |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 385 | } |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 388 | static int gprs_subscr_handle_gsup_upd_loc_res(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 389 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 390 | { |
Harald Welte | 5f2524f | 2016-05-05 18:25:12 +0200 | [diff] [blame] | 391 | /* contrary to MAP, we allow piggy-backing subscriber data onto |
| 392 | * the UPDATE LOCATION RESULT, and don't mandate the use of a |
| 393 | * separate nested INSERT SUBSCRIBER DATA transaction */ |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 394 | gprs_subscr_gsup_insert_data(subscr, gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 395 | |
| 396 | subscr->authorized = 1; |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 397 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 398 | |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 399 | subscr->flags |= GPRS_SUBSCRIBER_ENABLE_PURGE; |
| 400 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 401 | gprs_subscr_update(subscr); |
| 402 | return 0; |
| 403 | } |
| 404 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 405 | static int gprs_subscr_handle_gsup_dsd_req(struct gprs_subscr *subscr, |
Max | a66d8cf | 2017-02-15 11:43:59 +0100 | [diff] [blame] | 406 | struct osmo_gsup_message *gsup_msg) |
| 407 | { |
| 408 | struct osmo_gsup_message gsup_reply = {0}; |
| 409 | |
| 410 | if (gsup_msg->cn_domain != OSMO_GSUP_CN_DOMAIN_PS) { |
| 411 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 412 | "Rx GSUP message %s not supported for CS\n", |
| 413 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
| 414 | gsup_reply.cause = GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; |
| 415 | gsup_reply.message_type = OSMO_GSUP_MSGT_DELETE_DATA_ERROR; |
| 416 | } else { |
| 417 | gsm0408_gprs_access_cancelled(subscr->sgsn_data->mm, |
| 418 | GMM_CAUSE_GPRS_NOTALLOWED); |
| 419 | gsup_reply.message_type = OSMO_GSUP_MSGT_DELETE_DATA_RESULT; |
| 420 | } |
| 421 | |
| 422 | return gprs_subscr_tx_gsup_message(subscr, &gsup_reply); |
| 423 | } |
| 424 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 425 | static int gprs_subscr_handle_gsup_isd_req(struct gprs_subscr *subscr, |
Harald Welte | 5f2524f | 2016-05-05 18:25:12 +0200 | [diff] [blame] | 426 | struct osmo_gsup_message *gsup_msg) |
| 427 | { |
| 428 | struct osmo_gsup_message gsup_reply = {0}; |
| 429 | |
| 430 | gprs_subscr_gsup_insert_data(subscr, gsup_msg); |
| 431 | |
| 432 | subscr->authorized = 1; |
| 433 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
| 434 | subscr->flags |= GPRS_SUBSCRIBER_ENABLE_PURGE; |
| 435 | gprs_subscr_update(subscr); |
| 436 | |
| 437 | gsup_reply.message_type = OSMO_GSUP_MSGT_INSERT_DATA_RESULT; |
| 438 | return gprs_subscr_tx_gsup_message(subscr, &gsup_reply); |
| 439 | } |
| 440 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 441 | static int check_cause(int cause) |
| 442 | { |
| 443 | switch (cause) { |
| 444 | case GMM_CAUSE_IMSI_UNKNOWN ... GMM_CAUSE_ILLEGAL_ME: |
| 445 | case GMM_CAUSE_GPRS_NOTALLOWED ... GMM_CAUSE_NO_GPRS_PLMN: |
| 446 | return EACCES; |
| 447 | |
| 448 | case GMM_CAUSE_MSC_TEMP_NOTREACH ... GMM_CAUSE_CONGESTION: |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 449 | return EHOSTUNREACH; |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 450 | |
| 451 | case GMM_CAUSE_SEM_INCORR_MSG ... GMM_CAUSE_PROTO_ERR_UNSPEC: |
| 452 | default: |
| 453 | return EINVAL; |
| 454 | } |
| 455 | } |
| 456 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 457 | static int gprs_subscr_handle_gsup_auth_err(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 458 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 459 | { |
| 460 | unsigned idx; |
| 461 | struct sgsn_subscriber_data *sdata = subscr->sgsn_data; |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 462 | int cause_err; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 463 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 464 | cause_err = check_cause(gsup_msg->cause); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 465 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 466 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 467 | "Send authentication info has failed with cause %d, " |
| 468 | "handled as: %s\n", |
| 469 | gsup_msg->cause, strerror(cause_err)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 470 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 471 | switch (cause_err) { |
| 472 | case EACCES: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 473 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 474 | "GPRS send auth info req failed, access denied, " |
| 475 | "GMM cause = '%s' (%d)\n", |
| 476 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 477 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 478 | /* Clear auth tuples */ |
| 479 | memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets)); |
| 480 | for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++) |
| 481 | sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 482 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 483 | subscr->authorized = 0; |
| 484 | sdata->error_cause = gsup_msg->cause; |
| 485 | gprs_subscr_update_auth_info(subscr); |
| 486 | break; |
| 487 | |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 488 | case EHOSTUNREACH: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 489 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 490 | "GPRS send auth info req failed, GMM cause = '%s' (%d)\n", |
| 491 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 492 | gsup_msg->cause); |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 493 | |
| 494 | sdata->error_cause = gsup_msg->cause; |
| 495 | gprs_subscr_update_auth_info(subscr); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 496 | break; |
| 497 | |
| 498 | default: |
| 499 | case EINVAL: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 500 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 501 | "GSUP protocol remote error, GMM cause = '%s' (%d)\n", |
| 502 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 503 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 504 | break; |
| 505 | } |
| 506 | |
| 507 | return -gsup_msg->cause; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 510 | static int gprs_subscr_handle_gsup_upd_loc_err(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 511 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 512 | { |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 513 | int cause_err; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 514 | |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 515 | cause_err = check_cause(gsup_msg->cause); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 516 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 517 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 518 | "Update location has failed with cause %d, handled as: %s\n", |
| 519 | gsup_msg->cause, strerror(cause_err)); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 520 | |
| 521 | switch (cause_err) { |
| 522 | case EACCES: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 523 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 524 | "GPRS update location failed, access denied, " |
| 525 | "GMM cause = '%s' (%d)\n", |
| 526 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 527 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 528 | |
| 529 | subscr->authorized = 0; |
| 530 | subscr->sgsn_data->error_cause = gsup_msg->cause; |
| 531 | gprs_subscr_update_auth_info(subscr); |
| 532 | break; |
| 533 | |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 534 | case EHOSTUNREACH: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 535 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 536 | "GPRS update location failed, GMM cause = '%s' (%d)\n", |
| 537 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 538 | gsup_msg->cause); |
Jacob Erlbeck | f06fe29 | 2015-01-05 16:20:47 +0100 | [diff] [blame] | 539 | |
| 540 | subscr->sgsn_data->error_cause = gsup_msg->cause; |
| 541 | gprs_subscr_update_auth_info(subscr); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 542 | break; |
| 543 | |
| 544 | default: |
| 545 | case EINVAL: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 546 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
| 547 | "GSUP protocol remote error, GMM cause = '%s' (%d)\n", |
| 548 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 549 | gsup_msg->cause); |
Jacob Erlbeck | 9aa9991 | 2015-01-05 18:38:41 +0100 | [diff] [blame] | 550 | break; |
| 551 | } |
| 552 | |
| 553 | return -gsup_msg->cause; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 554 | } |
| 555 | |
Jacob Erlbeck | 929acdf | 2015-01-27 13:47:24 +0100 | [diff] [blame] | 556 | static int gprs_subscr_handle_gsup_purge_no_subscr( |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 557 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 929acdf | 2015-01-27 13:47:24 +0100 | [diff] [blame] | 558 | { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 559 | if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { |
Jacob Erlbeck | 929acdf | 2015-01-27 13:47:24 +0100 | [diff] [blame] | 560 | LOGGSUPP(LOGL_NOTICE, gsup_msg, |
| 561 | "Purge MS has failed with cause '%s' (%d)\n", |
| 562 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 563 | gsup_msg->cause); |
| 564 | return -gsup_msg->cause; |
| 565 | } |
| 566 | |
| 567 | LOGGSUPP(LOGL_INFO, gsup_msg, "Completing purge MS\n"); |
| 568 | return 0; |
| 569 | } |
| 570 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 571 | static int gprs_subscr_handle_gsup_purge_res(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 572 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 573 | { |
| 574 | LOGGSUBSCRP(LOGL_INFO, subscr, "Completing purge MS\n"); |
| 575 | |
| 576 | /* Force silent cancellation */ |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 577 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
Jacob Erlbeck | 37139e5 | 2015-01-23 13:52:55 +0100 | [diff] [blame] | 578 | gprs_subscr_cancel(subscr); |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 583 | static int gprs_subscr_handle_gsup_purge_err(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 584 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 585 | { |
| 586 | LOGGSUBSCRP(LOGL_NOTICE, subscr, |
| 587 | "Purge MS has failed with cause '%s' (%d)\n", |
| 588 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 589 | gsup_msg->cause); |
| 590 | |
| 591 | /* In GSM 09.02, 19.1.4.4, the text and the SDL diagram imply that |
| 592 | * the subscriber data is not removed if the request has failed. On the |
| 593 | * other hand, keeping the subscriber data in either error case |
| 594 | * (subscriber unknown, syntactical message error, connection error) |
| 595 | * doesn't seem to give any advantage, since the data will be restored |
| 596 | * on the next Attach Request anyway. |
| 597 | * This approach ensures, that the subscriber record will not stick if |
| 598 | * an error happens. |
| 599 | */ |
| 600 | |
| 601 | /* TODO: Check whether this behaviour is acceptable and either just |
| 602 | * remove this TODO-notice or change the implementation to not delete |
| 603 | * the subscriber data (eventually resetting the ENABLE_PURGE flag and |
| 604 | * restarting the expiry timer based on the cause). |
| 605 | * |
| 606 | * Subscriber Unknown: cancel subscr |
| 607 | * Temporary network problems: do nothing (handled by timer based retry) |
| 608 | * Message problems (syntax, nyi, ...): cancel subscr (retry won't help) |
| 609 | */ |
| 610 | |
| 611 | gprs_subscr_handle_gsup_purge_res(subscr, gsup_msg); |
| 612 | |
| 613 | return -gsup_msg->cause; |
| 614 | } |
| 615 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 616 | static int gprs_subscr_handle_loc_cancel_req(struct gprs_subscr *subscr, |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 617 | struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 618 | { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 619 | struct osmo_gsup_message gsup_reply = {0}; |
Jacob Erlbeck | 5b51205 | 2015-04-07 17:49:48 +0200 | [diff] [blame] | 620 | int is_update_procedure = !gsup_msg->cancel_type || |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 621 | gsup_msg->cancel_type == OSMO_GSUP_CANCEL_TYPE_UPDATE; |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 622 | |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 623 | LOGGSUBSCRP(LOGL_INFO, subscr, "Cancelling MS subscriber (%s)\n", |
| 624 | is_update_procedure ? |
| 625 | "update procedure" : "subscription withdraw"); |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 626 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 627 | gsup_reply.message_type = OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT; |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 628 | gprs_subscr_tx_gsup_message(subscr, &gsup_reply); |
| 629 | |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 630 | if (is_update_procedure) |
| 631 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
| 632 | else |
| 633 | /* Since a withdraw cause is not specified, just abort the |
| 634 | * current attachment. The following re-attachment should then |
| 635 | * be rejected with a proper cause value. |
| 636 | */ |
| 637 | subscr->sgsn_data->error_cause = GMM_CAUSE_IMPL_DETACHED; |
| 638 | |
Jacob Erlbeck | 37139e5 | 2015-01-23 13:52:55 +0100 | [diff] [blame] | 639 | gprs_subscr_cancel(subscr); |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 644 | static int gprs_subscr_handle_unknown_imsi(struct osmo_gsup_message *gsup_msg) |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 645 | { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 646 | if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) { |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 647 | gprs_subscr_tx_gsup_error_reply(NULL, gsup_msg, |
| 648 | GMM_CAUSE_IMSI_UNKNOWN); |
| 649 | LOGP(DGPRS, LOGL_NOTICE, |
| 650 | "Unknown IMSI %s, discarding GSUP request " |
| 651 | "of type 0x%02x\n", |
| 652 | gsup_msg->imsi, gsup_msg->message_type); |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 653 | } else if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 654 | LOGP(DGPRS, LOGL_NOTICE, |
| 655 | "Unknown IMSI %s, discarding GSUP error " |
| 656 | "of type 0x%02x, cause '%s' (%d)\n", |
| 657 | gsup_msg->imsi, gsup_msg->message_type, |
| 658 | get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), |
| 659 | gsup_msg->cause); |
| 660 | } else { |
| 661 | LOGP(DGPRS, LOGL_NOTICE, |
| 662 | "Unknown IMSI %s, discarding GSUP response " |
| 663 | "of type 0x%02x\n", |
| 664 | gsup_msg->imsi, gsup_msg->message_type); |
| 665 | } |
| 666 | |
| 667 | return -GMM_CAUSE_IMSI_UNKNOWN; |
| 668 | } |
| 669 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 670 | int gprs_subscr_rx_gsup_message(struct msgb *msg) |
| 671 | { |
| 672 | uint8_t *data = msgb_l2(msg); |
| 673 | size_t data_len = msgb_l2len(msg); |
| 674 | int rc = 0; |
| 675 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 676 | struct osmo_gsup_message gsup_msg = {0}; |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 677 | struct gprs_subscr *subscr; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 678 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 679 | rc = osmo_gsup_decode(data, data_len, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 680 | if (rc < 0) { |
| 681 | LOGP(DGPRS, LOGL_ERROR, |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 682 | "decoding GSUP message fails with error '%s' (%d)\n", |
| 683 | get_value_string(gsm48_gmm_cause_names, -rc), -rc); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 684 | return rc; |
| 685 | } |
| 686 | |
Jacob Erlbeck | 07f6e36 | 2015-01-29 14:00:28 +0100 | [diff] [blame] | 687 | if (!gsup_msg.imsi[0]) { |
| 688 | LOGP(DGPRS, LOGL_ERROR, "Missing IMSI in GSUP message\n"); |
| 689 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 690 | if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) |
Jacob Erlbeck | 07f6e36 | 2015-01-29 14:00:28 +0100 | [diff] [blame] | 691 | gprs_subscr_tx_gsup_error_reply(NULL, &gsup_msg, |
| 692 | GMM_CAUSE_INV_MAND_INFO); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 693 | return -GMM_CAUSE_INV_MAND_INFO; |
Jacob Erlbeck | 07f6e36 | 2015-01-29 14:00:28 +0100 | [diff] [blame] | 694 | } |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 695 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 696 | if (!gsup_msg.cause && OSMO_GSUP_IS_MSGT_ERROR(gsup_msg.message_type)) |
Jacob Erlbeck | 9ff8289 | 2015-01-29 14:17:51 +0100 | [diff] [blame] | 697 | gsup_msg.cause = GMM_CAUSE_NET_FAIL; |
| 698 | |
Jacob Erlbeck | 4dedb27 | 2015-01-15 17:50:16 +0100 | [diff] [blame] | 699 | subscr = gprs_subscr_get_by_imsi(gsup_msg.imsi); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 700 | |
Jacob Erlbeck | 929acdf | 2015-01-27 13:47:24 +0100 | [diff] [blame] | 701 | if (!subscr) { |
| 702 | switch (gsup_msg.message_type) { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 703 | case OSMO_GSUP_MSGT_PURGE_MS_RESULT: |
| 704 | case OSMO_GSUP_MSGT_PURGE_MS_ERROR: |
Jacob Erlbeck | 929acdf | 2015-01-27 13:47:24 +0100 | [diff] [blame] | 705 | return gprs_subscr_handle_gsup_purge_no_subscr(&gsup_msg); |
| 706 | default: |
| 707 | return gprs_subscr_handle_unknown_imsi(&gsup_msg); |
| 708 | } |
| 709 | } |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 710 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 711 | LOGGSUBSCRP(LOGL_INFO, subscr, |
Max | a66d8cf | 2017-02-15 11:43:59 +0100 | [diff] [blame] | 712 | "Received GSUP message %s\n", |
| 713 | osmo_gsup_message_type_name(gsup_msg.message_type)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 714 | |
| 715 | switch (gsup_msg.message_type) { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 716 | case OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST: |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 717 | rc = gprs_subscr_handle_loc_cancel_req(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 718 | break; |
| 719 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 720 | case OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 721 | rc = gprs_subscr_handle_gsup_auth_res(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 722 | break; |
| 723 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 724 | case OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 725 | rc = gprs_subscr_handle_gsup_auth_err(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 726 | break; |
| 727 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 728 | case OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 729 | rc = gprs_subscr_handle_gsup_upd_loc_res(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 730 | break; |
| 731 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 732 | case OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR: |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 733 | rc = gprs_subscr_handle_gsup_upd_loc_err(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 734 | break; |
| 735 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 736 | case OSMO_GSUP_MSGT_PURGE_MS_ERROR: |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 737 | rc = gprs_subscr_handle_gsup_purge_err(subscr, &gsup_msg); |
| 738 | break; |
| 739 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 740 | case OSMO_GSUP_MSGT_PURGE_MS_RESULT: |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 741 | rc = gprs_subscr_handle_gsup_purge_res(subscr, &gsup_msg); |
| 742 | break; |
| 743 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 744 | case OSMO_GSUP_MSGT_INSERT_DATA_REQUEST: |
Harald Welte | 5f2524f | 2016-05-05 18:25:12 +0200 | [diff] [blame] | 745 | rc = gprs_subscr_handle_gsup_isd_req(subscr, &gsup_msg); |
| 746 | break; |
| 747 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 748 | case OSMO_GSUP_MSGT_DELETE_DATA_REQUEST: |
Max | a66d8cf | 2017-02-15 11:43:59 +0100 | [diff] [blame] | 749 | rc = gprs_subscr_handle_gsup_dsd_req(subscr, &gsup_msg); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | default: |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 753 | LOGGSUBSCRP(LOGL_ERROR, subscr, |
Max | a66d8cf | 2017-02-15 11:43:59 +0100 | [diff] [blame] | 754 | "Rx GSUP message %s not valid at SGSN\n", |
| 755 | osmo_gsup_message_type_name(gsup_msg.message_type)); |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 756 | if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 757 | gprs_subscr_tx_gsup_error_reply( |
| 758 | subscr, &gsup_msg, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
| 759 | rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 760 | break; |
| 761 | }; |
| 762 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 763 | gprs_subscr_put(subscr); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 764 | |
| 765 | return rc; |
| 766 | } |
| 767 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 768 | int gprs_subscr_purge(struct gprs_subscr *subscr) |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 769 | { |
Holger Hans Peter Freyther | 10c0f56 | 2015-05-17 20:58:40 +0200 | [diff] [blame] | 770 | struct sgsn_subscriber_data *sdata = subscr->sgsn_data; |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 771 | struct osmo_gsup_message gsup_msg = {0}; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 772 | |
| 773 | LOGGSUBSCRP(LOGL_INFO, subscr, "purging MS subscriber\n"); |
| 774 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 775 | gsup_msg.message_type = OSMO_GSUP_MSGT_PURGE_MS_REQUEST; |
Holger Hans Peter Freyther | 10c0f56 | 2015-05-17 20:58:40 +0200 | [diff] [blame] | 776 | |
| 777 | /* Provide the HLR number in case it is known */ |
| 778 | gsup_msg.hlr_enc_len = sdata->hlr_len; |
| 779 | gsup_msg.hlr_enc = sdata->hlr; |
| 780 | |
Jacob Erlbeck | ca69b0f | 2015-02-03 19:45:46 +0100 | [diff] [blame] | 781 | return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 784 | static int gprs_subscr_query_auth_info(struct gprs_subscr *subscr, |
| 785 | const uint8_t *auts, |
| 786 | const uint8_t *auts_rand) |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 787 | { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 788 | struct osmo_gsup_message gsup_msg = {0}; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 789 | |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 790 | /* Make sure we have a complete resync or clearly no resync. */ |
| 791 | OSMO_ASSERT((auts != NULL) == (auts_rand != NULL)); |
| 792 | |
| 793 | LOGGSUBSCRP(LOGL_INFO, subscr, "requesting auth info%s\n", |
| 794 | auts ? " with AUTS (UMTS Resynch)" : ""); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 795 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 796 | gsup_msg.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST; |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 797 | gsup_msg.auts = auts; |
| 798 | gsup_msg.rand = auts_rand; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 799 | return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); |
| 800 | } |
| 801 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 802 | int gprs_subscr_location_update(struct gprs_subscr *subscr) |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 803 | { |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 804 | struct osmo_gsup_message gsup_msg = {0}; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 805 | |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 806 | LOGGSUBSCRP(LOGL_INFO, subscr, |
| 807 | "subscriber data is not available\n"); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 808 | |
Harald Welte | 28903a9 | 2016-04-25 14:53:43 +0200 | [diff] [blame] | 809 | gsup_msg.message_type = OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 810 | return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 811 | } |
| 812 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 813 | void gprs_subscr_update(struct gprs_subscr *subscr) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 814 | { |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 815 | LOGGSUBSCRP(LOGL_DEBUG, subscr, "Updating subscriber data\n"); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 816 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 817 | subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING; |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 818 | subscr->flags &= ~GPRS_SUBSCRIBER_FIRST_CONTACT; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 819 | |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 820 | if (subscr->sgsn_data->mm) |
| 821 | sgsn_update_subscriber_data(subscr->sgsn_data->mm); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 822 | } |
| 823 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 824 | void gprs_subscr_update_auth_info(struct gprs_subscr *subscr) |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 825 | { |
Jacob Erlbeck | bf34c67 | 2014-12-23 14:24:16 +0100 | [diff] [blame] | 826 | LOGGSUBSCRP(LOGL_DEBUG, subscr, |
| 827 | "Updating subscriber authentication info\n"); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 828 | |
| 829 | subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING; |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 830 | subscr->flags &= ~GPRS_SUBSCRIBER_FIRST_CONTACT; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 831 | |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 832 | if (subscr->sgsn_data->mm) |
| 833 | sgsn_update_subscriber_data(subscr->sgsn_data->mm); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 834 | } |
| 835 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 836 | struct gprs_subscr *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 837 | { |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 838 | struct gprs_subscr *subscr = NULL; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 839 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 840 | if (mmctx->subscr) |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 841 | return gprs_subscr_get(mmctx->subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 842 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 843 | if (mmctx->imsi[0]) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 844 | subscr = gprs_subscr_get_by_imsi(mmctx->imsi); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 845 | |
| 846 | if (!subscr) { |
| 847 | subscr = gprs_subscr_get_or_create(mmctx->imsi); |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 848 | subscr->flags |= GPRS_SUBSCRIBER_FIRST_CONTACT; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 849 | subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 850 | } |
| 851 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 852 | osmo_strlcpy(subscr->imei, mmctx->imei, sizeof(subscr->imei)); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 853 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 854 | if (subscr->lac != mmctx->ra.lac) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 855 | subscr->lac = mmctx->ra.lac; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 856 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 857 | subscr->sgsn_data->mm = mmctx; |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 858 | mmctx->subscr = gprs_subscr_get(subscr); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 859 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 860 | return subscr; |
| 861 | } |
| 862 | |
| 863 | int gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) |
| 864 | { |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 865 | struct gprs_subscr *subscr = NULL; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 866 | int rc; |
| 867 | |
| 868 | LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber data update\n"); |
| 869 | |
| 870 | subscr = gprs_subscr_get_or_create_by_mmctx(mmctx); |
| 871 | |
| 872 | subscr->flags |= GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING; |
| 873 | |
| 874 | rc = gprs_subscr_location_update(subscr); |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 875 | gprs_subscr_put(subscr); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 876 | return rc; |
| 877 | } |
| 878 | |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 879 | /*! \brief Send Update Auth Info request via GSUP, with or without resync. |
| 880 | * \param[in] mmctx MM context to request authentication tuples for. |
| 881 | * \param[in] auts 14 octet AUTS token for UMTS resync, or NULL. |
| 882 | * \param[in] auts_rand 16 octet Random token for UMTS resync, or NULL. |
| 883 | * In case of normal Authentication Info request, both \a auts and \a auts_rand |
| 884 | * must be NULL. For resync, both must be non-NULL. |
| 885 | */ |
| 886 | int gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx, |
| 887 | const uint8_t *auts, |
| 888 | const uint8_t *auts_rand) |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 889 | { |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 890 | struct gprs_subscr *subscr = NULL; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 891 | int rc; |
| 892 | |
| 893 | LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber authentication info\n"); |
| 894 | |
| 895 | subscr = gprs_subscr_get_or_create_by_mmctx(mmctx); |
| 896 | |
| 897 | subscr->flags |= GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING; |
| 898 | |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 899 | rc = gprs_subscr_query_auth_info(subscr, auts, auts_rand); |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 900 | gprs_subscr_put(subscr); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 901 | return rc; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 902 | } |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 903 | |
| 904 | static void gprs_subscr_free(struct gprs_subscr *gsub) |
| 905 | { |
| 906 | llist_del(&gsub->entry); |
| 907 | talloc_free(gsub); |
| 908 | } |
| 909 | |
| 910 | struct gprs_subscr *_gprs_subscr_get(struct gprs_subscr *gsub, |
| 911 | const char *file, int line) |
| 912 | { |
| 913 | OSMO_ASSERT(gsub->use_count < INT_MAX); |
| 914 | gsub->use_count++; |
| 915 | LOGPSRC(DREF, LOGL_DEBUG, file, line, |
| 916 | "subscr %s usage increases to: %d\n", |
| 917 | gsub->imsi, gsub->use_count); |
| 918 | return gsub; |
| 919 | } |
| 920 | |
| 921 | struct gprs_subscr *_gprs_subscr_put(struct gprs_subscr *gsub, |
| 922 | const char *file, int line) |
| 923 | { |
| 924 | gsub->use_count--; |
| 925 | LOGPSRC(DREF, gsub->use_count >= 0? LOGL_DEBUG : LOGL_ERROR, |
| 926 | file, line, |
| 927 | "subscr %s usage decreases to: %d%s\n", |
| 928 | gsub->imsi, gsub->use_count, |
| 929 | gsub->keep_in_ram? ", keep-in-ram flag is set" : ""); |
| 930 | if (gsub->use_count > 0) |
| 931 | return gsub; |
| 932 | if (gsub->keep_in_ram) |
| 933 | return gsub; |
| 934 | gprs_subscr_free(gsub); |
| 935 | return NULL; |
| 936 | } |