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