blob: 678c1de6a6a896cf064c7e3808f4942a16e404ec [file] [log] [blame]
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +01001/* MS subscriber data handling */
2
3/* (C) 2014 by sysmocom s.f.m.c. GmbH
Holger Hans Peter Freyther9ba273d2015-04-23 09:53:53 -04004 * (C) 2015 by Holger Hans Peter Freyther
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +01005 *
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 Erlbeck39f040d2014-12-18 12:46:47 +010024#include <openbsc/gprs_gsup_client.h>
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010025
26#include <openbsc/sgsn.h>
27#include <openbsc/gprs_sgsn.h>
28#include <openbsc/gprs_gmm.h>
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +010029#include <openbsc/gprs_gsup_messages.h>
Jacob Erlbeck0e8add62014-12-17 14:03:35 +010030#include <openbsc/gprs_utils.h>
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010031
32#include <openbsc/debug.h>
33
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010034#include <netinet/in.h>
35#include <arpa/inet.h>
36
Jacob Erlbeck743dec42015-01-08 15:18:39 +010037#define SGSN_SUBSCR_MAX_RETRIES 3
38#define SGSN_SUBSCR_RETRY_INTERVAL 10
39
Jacob Erlbeck929acdf2015-01-27 13:47:24 +010040#define LOGGSUPP(level, gsup, fmt, args...) \
41 LOGP(DGPRS, level, "GSUP(%s) " fmt, \
42 (gsup)->imsi, \
43 ## args)
44
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010045extern void *tall_bsc_ctx;
46
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010047static 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
55int gprs_subscr_init(struct sgsn_instance *sgi)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010056{
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010057 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 Hofmeyr9c534fd2015-10-12 11:57:37 +020066 &gsup_read_cb,
67 &sgi->cfg.oap);
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010068
69 if (!sgi->gsup_client)
70 return -1;
71
72 return 1;
73}
74
75static 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 Erlbecke154d8b2014-12-19 19:15:55 +010080 msgb_free(msg);
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010081 if (rc < 0)
82 return -1;
83
84 return rc;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010085}
86
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +010087int gprs_subscr_purge(struct gsm_subscriber *subscr);
88
Jacob Erlbecka1e03732014-12-02 11:28:38 +010089static struct sgsn_subscriber_data *sgsn_subscriber_data_alloc(void *ctx)
90{
91 struct sgsn_subscriber_data *sdata;
Jacob Erlbeck7921ab12014-12-08 15:52:00 +010092 int idx;
Jacob Erlbecka1e03732014-12-02 11:28:38 +010093
94 sdata = talloc_zero(ctx, struct sgsn_subscriber_data);
95
Jacob Erlbeckd6267d12015-01-19 11:10:04 +010096 sdata->error_cause = SGSN_ERROR_CAUSE_NONE;
97
Jacob Erlbeck7921ab12014-12-08 15:52:00 +010098 for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++)
99 sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL;
100
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100101 INIT_LLIST_HEAD(&sdata->pdp_list);
102
Jacob Erlbecka1e03732014-12-02 11:28:38 +0100103 return sdata;
104}
105
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100106struct 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 Erlbeck33b6dad2014-11-12 10:12:11 +0100118struct 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 Erlbecka1e03732014-12-02 11:28:38 +0100126 if (!subscr->sgsn_data)
127 subscr->sgsn_data = sgsn_subscriber_data_alloc(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100128 return subscr;
129}
130
131struct gsm_subscriber *gprs_subscr_get_by_imsi(const char *imsi)
132{
133 return subscr_active_by_imsi(NULL, imsi);
134}
135
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100136void gprs_subscr_cleanup(struct gsm_subscriber *subscr)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100137{
Jacob Erlbecka1e03732014-12-02 11:28:38 +0100138 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 Erlbeck33b6dad2014-11-12 10:12:11 +0100142 }
143
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +0100144 if (subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE) {
145 gprs_subscr_purge(subscr);
146 subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100147 }
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100148}
149
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100150void gprs_subscr_cancel(struct gsm_subscriber *subscr)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100151{
152 subscr->authorized = 0;
153 subscr->flags |= GPRS_SUBSCRIBER_CANCELLED;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100154 subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100155
156 gprs_subscr_update(subscr);
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100157 gprs_subscr_cleanup(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100158}
159
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100160static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr,
161 struct gprs_gsup_message *gsup_msg)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100162{
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100163 struct msgb *msg = gprs_gsup_msgb_alloc();
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100164
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100165 if (strlen(gsup_msg->imsi) == 0 && subscr)
166 strncpy(gsup_msg->imsi, subscr->imsi, sizeof(gsup_msg->imsi) - 1);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100167
168 gprs_gsup_encode(msg, gsup_msg);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100169
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100170 LOGGSUBSCRP(LOGL_INFO, subscr,
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100171 "Sending GSUP, will send: %s\n", msgb_hexdump(msg));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100172
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100173 if (!sgsn->gsup_client) {
174 msgb_free(msg);
175 return -ENOTSUP;
176 }
177
178 return gprs_gsup_client_send(sgsn->gsup_client, msg);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100179}
180
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100181static 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 Erlbecka6ddc2d2014-12-12 15:01:37 +0100195static 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 Erlbeckbf34c672014-12-23 14:24:16 +0100201 LOGGSUBSCRP(LOGL_INFO, subscr,
Harald Welte121e9a42016-04-20 13:13:19 +0200202 "Got SendAuthenticationInfoResult, num_auth_vectors = %zu\n",
203 gsup_msg->num_auth_vectors);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100204
Harald Welte121e9a42016-04-20 13:13:19 +0200205 if (gsup_msg->num_auth_vectors > 0) {
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100206 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
Harald Welte121e9a42016-04-20 13:13:19 +0200212 for (idx = 0; idx < gsup_msg->num_auth_vectors; idx++) {
213 size_t key_seq = idx;
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100214 LOGGSUBSCRP(LOGL_DEBUG, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400215 "Adding auth tuple, cksn = %zu\n", key_seq);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100216 if (key_seq >= ARRAY_SIZE(sdata->auth_triplets)) {
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100217 LOGGSUBSCRP(LOGL_NOTICE, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400218 "Skipping auth triplet with invalid cksn %zu\n",
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100219 key_seq);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100220 continue;
221 }
Harald Welte121e9a42016-04-20 13:13:19 +0200222 sdata->auth_triplets[key_seq].vec = gsup_msg->auth_vectors[idx];
223 sdata->auth_triplets[key_seq].key_seq = key_seq;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100224 }
225
226 sdata->auth_triplets_updated = 1;
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100227 sdata->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100228
229 gprs_subscr_update_auth_info(subscr);
230
231 return 0;
232}
233
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100234static int gprs_subscr_pdp_data_clear(struct gsm_subscriber *subscr)
235{
236 struct sgsn_subscriber_pdp_data *pdp, *pdp2;
237 int count = 0;
238
239 llist_for_each_entry_safe(pdp, pdp2, &subscr->sgsn_data->pdp_list, list) {
240 llist_del(&pdp->list);
241 talloc_free(pdp);
242 count += 1;
243 }
244
245 return count;
246}
247
248static struct sgsn_subscriber_pdp_data *gprs_subscr_pdp_data_get_by_id(
249 struct gsm_subscriber *subscr, unsigned context_id)
250{
251 struct sgsn_subscriber_pdp_data *pdp;
252
253 llist_for_each_entry(pdp, &subscr->sgsn_data->pdp_list, list) {
254 if (pdp->context_id == context_id)
255 return pdp;
256 }
257
258 return NULL;
259}
260
261
262static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr,
263 struct gprs_gsup_message *gsup_msg)
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100264{
Holger Hans Peter Freyther9ba273d2015-04-23 09:53:53 -0400265 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100266 unsigned idx;
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100267 int rc;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100268
Holger Hans Peter Freyther9ba273d2015-04-23 09:53:53 -0400269 if (gsup_msg->msisdn_enc) {
270 if (gsup_msg->msisdn_enc_len > sizeof(sdata->msisdn)) {
271 LOGP(DGPRS, LOGL_ERROR, "MSISDN too long (%zu)\n",
272 gsup_msg->msisdn_enc_len);
273 sdata->msisdn_len = 0;
274 } else {
275 memcpy(sdata->msisdn, gsup_msg->msisdn_enc,
276 gsup_msg->msisdn_enc_len);
277 sdata->msisdn_len = gsup_msg->msisdn_enc_len;
278 }
279 }
280
Holger Hans Peter Freyther10c0f562015-05-17 20:58:40 +0200281 if (gsup_msg->hlr_enc) {
282 if (gsup_msg->hlr_enc_len > sizeof(sdata->hlr)) {
283 LOGP(DGPRS, LOGL_ERROR, "HLR-Number too long (%zu)\n",
284 gsup_msg->hlr_enc_len);
285 sdata->hlr_len = 0;
286 } else {
287 memcpy(sdata->hlr, gsup_msg->hlr_enc,
288 gsup_msg->hlr_enc_len);
289 sdata->hlr_len = gsup_msg->hlr_enc_len;
290 }
291 }
292
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100293 if (gsup_msg->pdp_info_compl) {
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100294 rc = gprs_subscr_pdp_data_clear(subscr);
295 if (rc > 0)
296 LOGP(DGPRS, LOGL_INFO, "Cleared existing PDP info\n");
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100297 }
298
299 for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) {
300 struct gprs_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx];
301 size_t ctx_id = pdp_info->context_id;
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100302 struct sgsn_subscriber_pdp_data *pdp_data;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100303
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100304 if (pdp_info->apn_enc_len >= sizeof(pdp_data->apn_str)-1) {
305 LOGGSUBSCRP(LOGL_ERROR, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400306 "APN too long, context id = %zu, APN = %s\n",
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100307 ctx_id, osmo_hexdump(pdp_info->apn_enc,
308 pdp_info->apn_enc_len));
309 continue;
310 }
311
Holger Hans Peter Freyther8cedded2015-04-23 11:33:35 -0400312 if (pdp_info->qos_enc_len > sizeof(pdp_data->qos_subscribed)) {
313 LOGGSUBSCRP(LOGL_ERROR, subscr,
314 "QoS info too long (%zu)\n",
315 pdp_info->qos_enc_len);
316 continue;
317 }
318
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100319 LOGGSUBSCRP(LOGL_INFO, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400320 "Will set PDP info, context id = %zu, APN = %s\n",
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100321 ctx_id, osmo_hexdump(pdp_info->apn_enc, pdp_info->apn_enc_len));
322
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100323 /* Set PDP info [ctx_id] */
324 pdp_data = gprs_subscr_pdp_data_get_by_id(subscr, ctx_id);
325 if (!pdp_data) {
326 pdp_data = sgsn_subscriber_pdp_data_alloc(subscr->sgsn_data);
327 pdp_data->context_id = ctx_id;
328 }
329
330 OSMO_ASSERT(pdp_data != NULL);
331 pdp_data->pdp_type = pdp_info->pdp_type;
332 gprs_apn_to_str(pdp_data->apn_str,
333 pdp_info->apn_enc, pdp_info->apn_enc_len);
Holger Hans Peter Freyther8cedded2015-04-23 11:33:35 -0400334 memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len);
335 pdp_data->qos_subscribed_len = pdp_info->qos_enc_len;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100336 }
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100337}
338
339static int gprs_subscr_handle_gsup_upd_loc_res(struct gsm_subscriber *subscr,
340 struct gprs_gsup_message *gsup_msg)
341{
342 gprs_subscr_gsup_insert_data(subscr, gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100343
344 subscr->authorized = 1;
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100345 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100346
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100347 subscr->flags |= GPRS_SUBSCRIBER_ENABLE_PURGE;
348
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100349 gprs_subscr_update(subscr);
350 return 0;
351}
352
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100353static int check_cause(int cause)
354{
355 switch (cause) {
356 case GMM_CAUSE_IMSI_UNKNOWN ... GMM_CAUSE_ILLEGAL_ME:
357 case GMM_CAUSE_GPRS_NOTALLOWED ... GMM_CAUSE_NO_GPRS_PLMN:
358 return EACCES;
359
360 case GMM_CAUSE_MSC_TEMP_NOTREACH ... GMM_CAUSE_CONGESTION:
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100361 return EHOSTUNREACH;
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100362
363 case GMM_CAUSE_SEM_INCORR_MSG ... GMM_CAUSE_PROTO_ERR_UNSPEC:
364 default:
365 return EINVAL;
366 }
367}
368
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100369static int gprs_subscr_handle_gsup_auth_err(struct gsm_subscriber *subscr,
370 struct gprs_gsup_message *gsup_msg)
371{
372 unsigned idx;
373 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100374 int cause_err;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100375
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100376 cause_err = check_cause(gsup_msg->cause);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100377
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100378 LOGGSUBSCRP(LOGL_DEBUG, subscr,
379 "Send authentication info has failed with cause %d, "
380 "handled as: %s\n",
381 gsup_msg->cause, strerror(cause_err));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100382
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100383 switch (cause_err) {
384 case EACCES:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100385 LOGGSUBSCRP(LOGL_NOTICE, subscr,
386 "GPRS send auth info req failed, access denied, "
387 "GMM cause = '%s' (%d)\n",
388 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
389 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100390 /* Clear auth tuples */
391 memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets));
392 for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++)
393 sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100394
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100395 subscr->authorized = 0;
396 sdata->error_cause = gsup_msg->cause;
397 gprs_subscr_update_auth_info(subscr);
398 break;
399
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100400 case EHOSTUNREACH:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100401 LOGGSUBSCRP(LOGL_NOTICE, subscr,
402 "GPRS send auth info req failed, GMM cause = '%s' (%d)\n",
403 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
404 gsup_msg->cause);
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100405
406 sdata->error_cause = gsup_msg->cause;
407 gprs_subscr_update_auth_info(subscr);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100408 break;
409
410 default:
411 case EINVAL:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100412 LOGGSUBSCRP(LOGL_ERROR, subscr,
413 "GSUP protocol remote error, GMM cause = '%s' (%d)\n",
414 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
415 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100416 break;
417 }
418
419 return -gsup_msg->cause;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100420}
421
422static int gprs_subscr_handle_gsup_upd_loc_err(struct gsm_subscriber *subscr,
423 struct gprs_gsup_message *gsup_msg)
424{
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100425 int cause_err;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100426
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100427 cause_err = check_cause(gsup_msg->cause);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100428
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100429 LOGGSUBSCRP(LOGL_DEBUG, subscr,
430 "Update location has failed with cause %d, handled as: %s\n",
431 gsup_msg->cause, strerror(cause_err));
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100432
433 switch (cause_err) {
434 case EACCES:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100435 LOGGSUBSCRP(LOGL_NOTICE, subscr,
436 "GPRS update location failed, access denied, "
437 "GMM cause = '%s' (%d)\n",
438 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
439 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100440
441 subscr->authorized = 0;
442 subscr->sgsn_data->error_cause = gsup_msg->cause;
443 gprs_subscr_update_auth_info(subscr);
444 break;
445
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100446 case EHOSTUNREACH:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100447 LOGGSUBSCRP(LOGL_NOTICE, subscr,
448 "GPRS update location failed, GMM cause = '%s' (%d)\n",
449 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
450 gsup_msg->cause);
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100451
452 subscr->sgsn_data->error_cause = gsup_msg->cause;
453 gprs_subscr_update_auth_info(subscr);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100454 break;
455
456 default:
457 case EINVAL:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100458 LOGGSUBSCRP(LOGL_ERROR, subscr,
459 "GSUP protocol remote error, GMM cause = '%s' (%d)\n",
460 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
461 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100462 break;
463 }
464
465 return -gsup_msg->cause;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100466}
467
Jacob Erlbeck929acdf2015-01-27 13:47:24 +0100468static int gprs_subscr_handle_gsup_purge_no_subscr(
469 struct gprs_gsup_message *gsup_msg)
470{
471 if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
472 LOGGSUPP(LOGL_NOTICE, gsup_msg,
473 "Purge MS has failed with cause '%s' (%d)\n",
474 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
475 gsup_msg->cause);
476 return -gsup_msg->cause;
477 }
478
479 LOGGSUPP(LOGL_INFO, gsup_msg, "Completing purge MS\n");
480 return 0;
481}
482
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100483static int gprs_subscr_handle_gsup_purge_res(struct gsm_subscriber *subscr,
484 struct gprs_gsup_message *gsup_msg)
485{
486 LOGGSUBSCRP(LOGL_INFO, subscr, "Completing purge MS\n");
487
488 /* Force silent cancellation */
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100489 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100490 gprs_subscr_cancel(subscr);
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100491
492 return 0;
493}
494
495static int gprs_subscr_handle_gsup_purge_err(struct gsm_subscriber *subscr,
496 struct gprs_gsup_message *gsup_msg)
497{
498 LOGGSUBSCRP(LOGL_NOTICE, subscr,
499 "Purge MS has failed with cause '%s' (%d)\n",
500 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
501 gsup_msg->cause);
502
503 /* In GSM 09.02, 19.1.4.4, the text and the SDL diagram imply that
504 * the subscriber data is not removed if the request has failed. On the
505 * other hand, keeping the subscriber data in either error case
506 * (subscriber unknown, syntactical message error, connection error)
507 * doesn't seem to give any advantage, since the data will be restored
508 * on the next Attach Request anyway.
509 * This approach ensures, that the subscriber record will not stick if
510 * an error happens.
511 */
512
513 /* TODO: Check whether this behaviour is acceptable and either just
514 * remove this TODO-notice or change the implementation to not delete
515 * the subscriber data (eventually resetting the ENABLE_PURGE flag and
516 * restarting the expiry timer based on the cause).
517 *
518 * Subscriber Unknown: cancel subscr
519 * Temporary network problems: do nothing (handled by timer based retry)
520 * Message problems (syntax, nyi, ...): cancel subscr (retry won't help)
521 */
522
523 gprs_subscr_handle_gsup_purge_res(subscr, gsup_msg);
524
525 return -gsup_msg->cause;
526}
527
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100528static int gprs_subscr_handle_loc_cancel_req(struct gsm_subscriber *subscr,
529 struct gprs_gsup_message *gsup_msg)
530{
531 struct gprs_gsup_message gsup_reply = {0};
Jacob Erlbeck5b512052015-04-07 17:49:48 +0200532 int is_update_procedure = !gsup_msg->cancel_type ||
533 gsup_msg->cancel_type == GPRS_GSUP_CANCEL_TYPE_UPDATE;
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100534
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100535 LOGGSUBSCRP(LOGL_INFO, subscr, "Cancelling MS subscriber (%s)\n",
536 is_update_procedure ?
537 "update procedure" : "subscription withdraw");
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100538
539 gsup_reply.message_type = GPRS_GSUP_MSGT_LOCATION_CANCEL_RESULT;
540 gprs_subscr_tx_gsup_message(subscr, &gsup_reply);
541
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100542 if (is_update_procedure)
543 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
544 else
545 /* Since a withdraw cause is not specified, just abort the
546 * current attachment. The following re-attachment should then
547 * be rejected with a proper cause value.
548 */
549 subscr->sgsn_data->error_cause = GMM_CAUSE_IMPL_DETACHED;
550
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100551 gprs_subscr_cancel(subscr);
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100552
553 return 0;
554}
555
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100556static int gprs_subscr_handle_unknown_imsi(struct gprs_gsup_message *gsup_msg)
557{
558 if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) {
559 gprs_subscr_tx_gsup_error_reply(NULL, gsup_msg,
560 GMM_CAUSE_IMSI_UNKNOWN);
561 LOGP(DGPRS, LOGL_NOTICE,
562 "Unknown IMSI %s, discarding GSUP request "
563 "of type 0x%02x\n",
564 gsup_msg->imsi, gsup_msg->message_type);
565 } else if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
566 LOGP(DGPRS, LOGL_NOTICE,
567 "Unknown IMSI %s, discarding GSUP error "
568 "of type 0x%02x, cause '%s' (%d)\n",
569 gsup_msg->imsi, gsup_msg->message_type,
570 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
571 gsup_msg->cause);
572 } else {
573 LOGP(DGPRS, LOGL_NOTICE,
574 "Unknown IMSI %s, discarding GSUP response "
575 "of type 0x%02x\n",
576 gsup_msg->imsi, gsup_msg->message_type);
577 }
578
579 return -GMM_CAUSE_IMSI_UNKNOWN;
580}
581
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100582int gprs_subscr_rx_gsup_message(struct msgb *msg)
583{
584 uint8_t *data = msgb_l2(msg);
585 size_t data_len = msgb_l2len(msg);
586 int rc = 0;
587
588 struct gprs_gsup_message gsup_msg = {0};
589 struct gsm_subscriber *subscr;
590
591 rc = gprs_gsup_decode(data, data_len, &gsup_msg);
592 if (rc < 0) {
593 LOGP(DGPRS, LOGL_ERROR,
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100594 "decoding GSUP message fails with error '%s' (%d)\n",
595 get_value_string(gsm48_gmm_cause_names, -rc), -rc);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100596 return rc;
597 }
598
Jacob Erlbeck07f6e362015-01-29 14:00:28 +0100599 if (!gsup_msg.imsi[0]) {
600 LOGP(DGPRS, LOGL_ERROR, "Missing IMSI in GSUP message\n");
601
602 if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type))
603 gprs_subscr_tx_gsup_error_reply(NULL, &gsup_msg,
604 GMM_CAUSE_INV_MAND_INFO);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100605 return -GMM_CAUSE_INV_MAND_INFO;
Jacob Erlbeck07f6e362015-01-29 14:00:28 +0100606 }
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100607
Jacob Erlbeck9ff82892015-01-29 14:17:51 +0100608 if (!gsup_msg.cause && GPRS_GSUP_IS_MSGT_ERROR(gsup_msg.message_type))
609 gsup_msg.cause = GMM_CAUSE_NET_FAIL;
610
Jacob Erlbeck4dedb272015-01-15 17:50:16 +0100611 subscr = gprs_subscr_get_by_imsi(gsup_msg.imsi);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100612
Jacob Erlbeck929acdf2015-01-27 13:47:24 +0100613 if (!subscr) {
614 switch (gsup_msg.message_type) {
615 case GPRS_GSUP_MSGT_PURGE_MS_RESULT:
616 case GPRS_GSUP_MSGT_PURGE_MS_ERROR:
617 return gprs_subscr_handle_gsup_purge_no_subscr(&gsup_msg);
618 default:
619 return gprs_subscr_handle_unknown_imsi(&gsup_msg);
620 }
621 }
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100622
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100623 LOGGSUBSCRP(LOGL_INFO, subscr,
624 "Received GSUP message of type 0x%02x\n", gsup_msg.message_type);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100625
626 switch (gsup_msg.message_type) {
627 case GPRS_GSUP_MSGT_LOCATION_CANCEL_REQUEST:
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100628 rc = gprs_subscr_handle_loc_cancel_req(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100629 break;
630
631 case GPRS_GSUP_MSGT_SEND_AUTH_INFO_RESULT:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100632 rc = gprs_subscr_handle_gsup_auth_res(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100633 break;
634
635 case GPRS_GSUP_MSGT_SEND_AUTH_INFO_ERROR:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100636 rc = gprs_subscr_handle_gsup_auth_err(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100637 break;
638
639 case GPRS_GSUP_MSGT_UPDATE_LOCATION_RESULT:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100640 rc = gprs_subscr_handle_gsup_upd_loc_res(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100641 break;
642
643 case GPRS_GSUP_MSGT_UPDATE_LOCATION_ERROR:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100644 rc = gprs_subscr_handle_gsup_upd_loc_err(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100645 break;
646
647 case GPRS_GSUP_MSGT_PURGE_MS_ERROR:
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100648 rc = gprs_subscr_handle_gsup_purge_err(subscr, &gsup_msg);
649 break;
650
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100651 case GPRS_GSUP_MSGT_PURGE_MS_RESULT:
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100652 rc = gprs_subscr_handle_gsup_purge_res(subscr, &gsup_msg);
653 break;
654
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100655 case GPRS_GSUP_MSGT_INSERT_DATA_REQUEST:
656 case GPRS_GSUP_MSGT_DELETE_DATA_REQUEST:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100657 LOGGSUBSCRP(LOGL_ERROR, subscr,
658 "Rx GSUP message type %d not yet implemented\n",
659 gsup_msg.message_type);
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100660 gprs_subscr_tx_gsup_error_reply(subscr, &gsup_msg,
661 GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100662 rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
663 break;
664
665 default:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100666 LOGGSUBSCRP(LOGL_ERROR, subscr,
667 "Rx GSUP message type %d not valid at SGSN\n",
668 gsup_msg.message_type);
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100669 if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type))
670 gprs_subscr_tx_gsup_error_reply(
671 subscr, &gsup_msg, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL);
672 rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100673 break;
674 };
675
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100676 subscr_put(subscr);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100677
678 return rc;
679}
680
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100681int gprs_subscr_purge(struct gsm_subscriber *subscr)
682{
Holger Hans Peter Freyther10c0f562015-05-17 20:58:40 +0200683 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100684 struct gprs_gsup_message gsup_msg = {0};
685
686 LOGGSUBSCRP(LOGL_INFO, subscr, "purging MS subscriber\n");
687
688 gsup_msg.message_type = GPRS_GSUP_MSGT_PURGE_MS_REQUEST;
Holger Hans Peter Freyther10c0f562015-05-17 20:58:40 +0200689
690 /* Provide the HLR number in case it is known */
691 gsup_msg.hlr_enc_len = sdata->hlr_len;
692 gsup_msg.hlr_enc = sdata->hlr;
693
Jacob Erlbeckca69b0f2015-02-03 19:45:46 +0100694 return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100695}
696
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100697int gprs_subscr_query_auth_info(struct gsm_subscriber *subscr)
698{
699 struct gprs_gsup_message gsup_msg = {0};
700
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100701 LOGGSUBSCRP(LOGL_INFO, subscr,
702 "subscriber auth info is not available\n");
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100703
704 gsup_msg.message_type = GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST;
705 return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
706}
707
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100708int gprs_subscr_location_update(struct gsm_subscriber *subscr)
709{
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100710 struct gprs_gsup_message gsup_msg = {0};
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100711
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100712 LOGGSUBSCRP(LOGL_INFO, subscr,
713 "subscriber data is not available\n");
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100714
715 gsup_msg.message_type = GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST;
716 return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100717}
718
719void gprs_subscr_update(struct gsm_subscriber *subscr)
720{
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100721 LOGGSUBSCRP(LOGL_DEBUG, subscr, "Updating subscriber data\n");
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100722
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100723 subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100724 subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT;
725
Jacob Erlbeck555b2e52015-01-26 13:52:42 +0100726 if (subscr->sgsn_data->mm)
727 sgsn_update_subscriber_data(subscr->sgsn_data->mm);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100728}
729
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100730void gprs_subscr_update_auth_info(struct gsm_subscriber *subscr)
731{
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100732 LOGGSUBSCRP(LOGL_DEBUG, subscr,
733 "Updating subscriber authentication info\n");
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100734
735 subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING;
736 subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT;
737
Jacob Erlbeck555b2e52015-01-26 13:52:42 +0100738 if (subscr->sgsn_data->mm)
739 sgsn_update_subscriber_data(subscr->sgsn_data->mm);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100740}
741
742struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100743{
744 struct gsm_subscriber *subscr = NULL;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100745
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100746 if (mmctx->subscr)
747 return subscr_get(mmctx->subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100748
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100749 if (mmctx->imsi[0])
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100750 subscr = gprs_subscr_get_by_imsi(mmctx->imsi);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100751
752 if (!subscr) {
753 subscr = gprs_subscr_get_or_create(mmctx->imsi);
754 subscr->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100755 subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100756 }
757
758 if (strcpy(subscr->equipment.imei, mmctx->imei) != 0) {
759 strncpy(subscr->equipment.imei, mmctx->imei, GSM_IMEI_LENGTH-1);
760 subscr->equipment.imei[GSM_IMEI_LENGTH-1] = 0;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100761 }
762
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100763 if (subscr->lac != mmctx->ra.lac)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100764 subscr->lac = mmctx->ra.lac;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100765
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100766 subscr->sgsn_data->mm = mmctx;
767 mmctx->subscr = subscr_get(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100768
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100769 return subscr;
770}
771
772int gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx)
773{
774 struct gsm_subscriber *subscr = NULL;
775 int rc;
776
777 LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber data update\n");
778
779 subscr = gprs_subscr_get_or_create_by_mmctx(mmctx);
780
781 subscr->flags |= GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING;
782
783 rc = gprs_subscr_location_update(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100784 subscr_put(subscr);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100785 return rc;
786}
787
788int gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx)
789{
790 struct gsm_subscriber *subscr = NULL;
791 int rc;
792
793 LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber authentication info\n");
794
795 subscr = gprs_subscr_get_or_create_by_mmctx(mmctx);
796
797 subscr->flags |= GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING;
798
799 rc = gprs_subscr_query_auth_info(subscr);
800 subscr_put(subscr);
801 return rc;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100802}