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