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