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