blob: 648f91204fea0d683e333a0c327e70f336ab4d9e [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
Harald Welte53373bc2016-04-20 17:11:43 +020023#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010024#include <openbsc/gsm_subscriber.h>
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010025#include <openbsc/gprs_gsup_client.h>
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010026
27#include <openbsc/sgsn.h>
28#include <openbsc/gprs_sgsn.h>
29#include <openbsc/gprs_gmm.h>
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +010030#include <openbsc/gprs_gsup_messages.h>
Jacob Erlbeck0e8add62014-12-17 14:03:35 +010031#include <openbsc/gprs_utils.h>
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010032
33#include <openbsc/debug.h>
34
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010035#include <netinet/in.h>
36#include <arpa/inet.h>
37
Jacob Erlbeck743dec42015-01-08 15:18:39 +010038#define SGSN_SUBSCR_MAX_RETRIES 3
39#define SGSN_SUBSCR_RETRY_INTERVAL 10
40
Jacob Erlbeck929acdf2015-01-27 13:47:24 +010041#define LOGGSUPP(level, gsup, fmt, args...) \
42 LOGP(DGPRS, level, "GSUP(%s) " fmt, \
43 (gsup)->imsi, \
44 ## args)
45
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010046extern void *tall_bsc_ctx;
47
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010048static int gsup_read_cb(struct gprs_gsup_client *gsupc, struct msgb *msg);
49
50/* TODO: Some functions are specific to the SGSN, but this file is more general
51 * (it has gprs_* name). Either move these functions elsewhere, split them and
52 * move a part, or replace the gprs_ prefix by sgsn_. The applies to
53 * gprs_subscr_init, gsup_read_cb, and gprs_subscr_tx_gsup_message.
54 */
55
56int gprs_subscr_init(struct sgsn_instance *sgi)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010057{
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010058 const char *addr_str;
59
60 if (!sgi->cfg.gsup_server_addr.sin_addr.s_addr)
61 return 0;
62
63 addr_str = inet_ntoa(sgi->cfg.gsup_server_addr.sin_addr);
64
65 sgi->gsup_client = gprs_gsup_client_create(
66 addr_str, sgi->cfg.gsup_server_port,
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +020067 &gsup_read_cb,
68 &sgi->cfg.oap);
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010069
70 if (!sgi->gsup_client)
71 return -1;
72
73 return 1;
74}
75
76static int gsup_read_cb(struct gprs_gsup_client *gsupc, struct msgb *msg)
77{
78 int rc;
79
80 rc = gprs_subscr_rx_gsup_message(msg);
Jacob Erlbecke154d8b2014-12-19 19:15:55 +010081 msgb_free(msg);
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010082 if (rc < 0)
83 return -1;
84
85 return rc;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010086}
87
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +010088int gprs_subscr_purge(struct gsm_subscriber *subscr);
89
Jacob Erlbecka1e03732014-12-02 11:28:38 +010090static struct sgsn_subscriber_data *sgsn_subscriber_data_alloc(void *ctx)
91{
92 struct sgsn_subscriber_data *sdata;
Jacob Erlbeck7921ab12014-12-08 15:52:00 +010093 int idx;
Jacob Erlbecka1e03732014-12-02 11:28:38 +010094
95 sdata = talloc_zero(ctx, struct sgsn_subscriber_data);
96
Jacob Erlbeckd6267d12015-01-19 11:10:04 +010097 sdata->error_cause = SGSN_ERROR_CAUSE_NONE;
98
Jacob Erlbeck7921ab12014-12-08 15:52:00 +010099 for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++)
100 sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL;
101
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100102 INIT_LLIST_HEAD(&sdata->pdp_list);
103
Jacob Erlbecka1e03732014-12-02 11:28:38 +0100104 return sdata;
105}
106
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100107struct sgsn_subscriber_pdp_data* sgsn_subscriber_pdp_data_alloc(
108 struct sgsn_subscriber_data *sdata)
109{
110 struct sgsn_subscriber_pdp_data* pdata;
111
112 pdata = talloc_zero(sdata, struct sgsn_subscriber_pdp_data);
113
114 llist_add_tail(&pdata->list, &sdata->pdp_list);
115
116 return pdata;
117}
118
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100119struct gsm_subscriber *gprs_subscr_get_or_create(const char *imsi)
120{
121 struct gsm_subscriber *subscr;
122
123 subscr = subscr_get_or_create(NULL, imsi);
124 if (!subscr)
125 return NULL;
126
Jacob Erlbecka1e03732014-12-02 11:28:38 +0100127 if (!subscr->sgsn_data)
128 subscr->sgsn_data = sgsn_subscriber_data_alloc(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100129 return subscr;
130}
131
132struct gsm_subscriber *gprs_subscr_get_by_imsi(const char *imsi)
133{
134 return subscr_active_by_imsi(NULL, imsi);
135}
136
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100137void gprs_subscr_cleanup(struct gsm_subscriber *subscr)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100138{
Jacob Erlbecka1e03732014-12-02 11:28:38 +0100139 if (subscr->sgsn_data->mm) {
140 subscr_put(subscr->sgsn_data->mm->subscr);
141 subscr->sgsn_data->mm->subscr = NULL;
142 subscr->sgsn_data->mm = NULL;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100143 }
144
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +0100145 if (subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE) {
146 gprs_subscr_purge(subscr);
147 subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100148 }
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100149}
150
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100151void gprs_subscr_cancel(struct gsm_subscriber *subscr)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100152{
153 subscr->authorized = 0;
154 subscr->flags |= GPRS_SUBSCRIBER_CANCELLED;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100155 subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100156
157 gprs_subscr_update(subscr);
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100158 gprs_subscr_cleanup(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100159}
160
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100161static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr,
162 struct gprs_gsup_message *gsup_msg)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100163{
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100164 struct msgb *msg = gprs_gsup_msgb_alloc();
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100165
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100166 if (strlen(gsup_msg->imsi) == 0 && subscr)
167 strncpy(gsup_msg->imsi, subscr->imsi, sizeof(gsup_msg->imsi) - 1);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100168
169 gprs_gsup_encode(msg, gsup_msg);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100170
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100171 LOGGSUBSCRP(LOGL_INFO, subscr,
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100172 "Sending GSUP, will send: %s\n", msgb_hexdump(msg));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100173
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100174 if (!sgsn->gsup_client) {
175 msgb_free(msg);
176 return -ENOTSUP;
177 }
178
179 return gprs_gsup_client_send(sgsn->gsup_client, msg);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100180}
181
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100182static int gprs_subscr_tx_gsup_error_reply(struct gsm_subscriber *subscr,
183 struct gprs_gsup_message *gsup_orig,
184 enum gsm48_gmm_cause cause)
185{
186 struct gprs_gsup_message gsup_reply = {0};
187
188 strncpy(gsup_reply.imsi, gsup_orig->imsi, sizeof(gsup_reply.imsi) - 1);
189 gsup_reply.cause = cause;
190 gsup_reply.message_type =
191 GPRS_GSUP_TO_MSGT_ERROR(gsup_orig->message_type);
192
193 return gprs_subscr_tx_gsup_message(subscr, &gsup_reply);
194}
195
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100196static int gprs_subscr_handle_gsup_auth_res(struct gsm_subscriber *subscr,
197 struct gprs_gsup_message *gsup_msg)
198{
199 unsigned idx;
200 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
201
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100202 LOGGSUBSCRP(LOGL_INFO, subscr,
Harald Welte121e9a42016-04-20 13:13:19 +0200203 "Got SendAuthenticationInfoResult, num_auth_vectors = %zu\n",
204 gsup_msg->num_auth_vectors);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100205
Harald Welte121e9a42016-04-20 13:13:19 +0200206 if (gsup_msg->num_auth_vectors > 0) {
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100207 memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets));
208
209 for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++)
210 sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL;
211 }
212
Harald Welte121e9a42016-04-20 13:13:19 +0200213 for (idx = 0; idx < gsup_msg->num_auth_vectors; idx++) {
214 size_t key_seq = idx;
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100215 LOGGSUBSCRP(LOGL_DEBUG, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400216 "Adding auth tuple, cksn = %zu\n", key_seq);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100217 if (key_seq >= ARRAY_SIZE(sdata->auth_triplets)) {
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100218 LOGGSUBSCRP(LOGL_NOTICE, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400219 "Skipping auth triplet with invalid cksn %zu\n",
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100220 key_seq);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100221 continue;
222 }
Harald Welte121e9a42016-04-20 13:13:19 +0200223 sdata->auth_triplets[key_seq].vec = gsup_msg->auth_vectors[idx];
224 sdata->auth_triplets[key_seq].key_seq = key_seq;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100225 }
226
227 sdata->auth_triplets_updated = 1;
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100228 sdata->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100229
230 gprs_subscr_update_auth_info(subscr);
231
232 return 0;
233}
234
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100235static int gprs_subscr_pdp_data_clear(struct gsm_subscriber *subscr)
236{
237 struct sgsn_subscriber_pdp_data *pdp, *pdp2;
238 int count = 0;
239
240 llist_for_each_entry_safe(pdp, pdp2, &subscr->sgsn_data->pdp_list, list) {
241 llist_del(&pdp->list);
242 talloc_free(pdp);
243 count += 1;
244 }
245
246 return count;
247}
248
249static struct sgsn_subscriber_pdp_data *gprs_subscr_pdp_data_get_by_id(
250 struct gsm_subscriber *subscr, unsigned context_id)
251{
252 struct sgsn_subscriber_pdp_data *pdp;
253
254 llist_for_each_entry(pdp, &subscr->sgsn_data->pdp_list, list) {
255 if (pdp->context_id == context_id)
256 return pdp;
257 }
258
259 return NULL;
260}
261
262
263static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr,
264 struct gprs_gsup_message *gsup_msg)
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100265{
Holger Hans Peter Freyther9ba273d2015-04-23 09:53:53 -0400266 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100267 unsigned idx;
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100268 int rc;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100269
Holger Hans Peter Freyther9ba273d2015-04-23 09:53:53 -0400270 if (gsup_msg->msisdn_enc) {
271 if (gsup_msg->msisdn_enc_len > sizeof(sdata->msisdn)) {
272 LOGP(DGPRS, LOGL_ERROR, "MSISDN too long (%zu)\n",
273 gsup_msg->msisdn_enc_len);
274 sdata->msisdn_len = 0;
275 } else {
276 memcpy(sdata->msisdn, gsup_msg->msisdn_enc,
277 gsup_msg->msisdn_enc_len);
278 sdata->msisdn_len = gsup_msg->msisdn_enc_len;
279 }
280 }
281
Holger Hans Peter Freyther10c0f562015-05-17 20:58:40 +0200282 if (gsup_msg->hlr_enc) {
283 if (gsup_msg->hlr_enc_len > sizeof(sdata->hlr)) {
284 LOGP(DGPRS, LOGL_ERROR, "HLR-Number too long (%zu)\n",
285 gsup_msg->hlr_enc_len);
286 sdata->hlr_len = 0;
287 } else {
288 memcpy(sdata->hlr, gsup_msg->hlr_enc,
289 gsup_msg->hlr_enc_len);
290 sdata->hlr_len = gsup_msg->hlr_enc_len;
291 }
292 }
293
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100294 if (gsup_msg->pdp_info_compl) {
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100295 rc = gprs_subscr_pdp_data_clear(subscr);
296 if (rc > 0)
297 LOGP(DGPRS, LOGL_INFO, "Cleared existing PDP info\n");
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100298 }
299
300 for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) {
301 struct gprs_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx];
302 size_t ctx_id = pdp_info->context_id;
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100303 struct sgsn_subscriber_pdp_data *pdp_data;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100304
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100305 if (pdp_info->apn_enc_len >= sizeof(pdp_data->apn_str)-1) {
306 LOGGSUBSCRP(LOGL_ERROR, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400307 "APN too long, context id = %zu, APN = %s\n",
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100308 ctx_id, osmo_hexdump(pdp_info->apn_enc,
309 pdp_info->apn_enc_len));
310 continue;
311 }
312
Holger Hans Peter Freyther8cedded2015-04-23 11:33:35 -0400313 if (pdp_info->qos_enc_len > sizeof(pdp_data->qos_subscribed)) {
314 LOGGSUBSCRP(LOGL_ERROR, subscr,
315 "QoS info too long (%zu)\n",
316 pdp_info->qos_enc_len);
317 continue;
318 }
319
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100320 LOGGSUBSCRP(LOGL_INFO, subscr,
Holger Hans Peter Freyther8e6ecc92015-04-23 11:55:23 -0400321 "Will set PDP info, context id = %zu, APN = %s\n",
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100322 ctx_id, osmo_hexdump(pdp_info->apn_enc, pdp_info->apn_enc_len));
323
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100324 /* Set PDP info [ctx_id] */
325 pdp_data = gprs_subscr_pdp_data_get_by_id(subscr, ctx_id);
326 if (!pdp_data) {
327 pdp_data = sgsn_subscriber_pdp_data_alloc(subscr->sgsn_data);
328 pdp_data->context_id = ctx_id;
329 }
330
331 OSMO_ASSERT(pdp_data != NULL);
332 pdp_data->pdp_type = pdp_info->pdp_type;
333 gprs_apn_to_str(pdp_data->apn_str,
334 pdp_info->apn_enc, pdp_info->apn_enc_len);
Holger Hans Peter Freyther8cedded2015-04-23 11:33:35 -0400335 memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len);
336 pdp_data->qos_subscribed_len = pdp_info->qos_enc_len;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100337 }
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100338}
339
340static int gprs_subscr_handle_gsup_upd_loc_res(struct gsm_subscriber *subscr,
341 struct gprs_gsup_message *gsup_msg)
342{
343 gprs_subscr_gsup_insert_data(subscr, gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100344
345 subscr->authorized = 1;
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100346 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100347
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100348 subscr->flags |= GPRS_SUBSCRIBER_ENABLE_PURGE;
349
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100350 gprs_subscr_update(subscr);
351 return 0;
352}
353
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100354static int check_cause(int cause)
355{
356 switch (cause) {
357 case GMM_CAUSE_IMSI_UNKNOWN ... GMM_CAUSE_ILLEGAL_ME:
358 case GMM_CAUSE_GPRS_NOTALLOWED ... GMM_CAUSE_NO_GPRS_PLMN:
359 return EACCES;
360
361 case GMM_CAUSE_MSC_TEMP_NOTREACH ... GMM_CAUSE_CONGESTION:
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100362 return EHOSTUNREACH;
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100363
364 case GMM_CAUSE_SEM_INCORR_MSG ... GMM_CAUSE_PROTO_ERR_UNSPEC:
365 default:
366 return EINVAL;
367 }
368}
369
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100370static int gprs_subscr_handle_gsup_auth_err(struct gsm_subscriber *subscr,
371 struct gprs_gsup_message *gsup_msg)
372{
373 unsigned idx;
374 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100375 int cause_err;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100376
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100377 cause_err = check_cause(gsup_msg->cause);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100378
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100379 LOGGSUBSCRP(LOGL_DEBUG, subscr,
380 "Send authentication info has failed with cause %d, "
381 "handled as: %s\n",
382 gsup_msg->cause, strerror(cause_err));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100383
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100384 switch (cause_err) {
385 case EACCES:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100386 LOGGSUBSCRP(LOGL_NOTICE, subscr,
387 "GPRS send auth info req failed, access denied, "
388 "GMM cause = '%s' (%d)\n",
389 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
390 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100391 /* Clear auth tuples */
392 memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets));
393 for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++)
394 sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100395
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100396 subscr->authorized = 0;
397 sdata->error_cause = gsup_msg->cause;
398 gprs_subscr_update_auth_info(subscr);
399 break;
400
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100401 case EHOSTUNREACH:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100402 LOGGSUBSCRP(LOGL_NOTICE, subscr,
403 "GPRS send auth info req failed, GMM cause = '%s' (%d)\n",
404 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
405 gsup_msg->cause);
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100406
407 sdata->error_cause = gsup_msg->cause;
408 gprs_subscr_update_auth_info(subscr);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100409 break;
410
411 default:
412 case EINVAL:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100413 LOGGSUBSCRP(LOGL_ERROR, subscr,
414 "GSUP protocol remote error, GMM cause = '%s' (%d)\n",
415 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
416 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100417 break;
418 }
419
420 return -gsup_msg->cause;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100421}
422
423static int gprs_subscr_handle_gsup_upd_loc_err(struct gsm_subscriber *subscr,
424 struct gprs_gsup_message *gsup_msg)
425{
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100426 int cause_err;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100427
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100428 cause_err = check_cause(gsup_msg->cause);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100429
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100430 LOGGSUBSCRP(LOGL_DEBUG, subscr,
431 "Update location has failed with cause %d, handled as: %s\n",
432 gsup_msg->cause, strerror(cause_err));
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100433
434 switch (cause_err) {
435 case EACCES:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100436 LOGGSUBSCRP(LOGL_NOTICE, subscr,
437 "GPRS update location failed, access denied, "
438 "GMM cause = '%s' (%d)\n",
439 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
440 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100441
442 subscr->authorized = 0;
443 subscr->sgsn_data->error_cause = gsup_msg->cause;
444 gprs_subscr_update_auth_info(subscr);
445 break;
446
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100447 case EHOSTUNREACH:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100448 LOGGSUBSCRP(LOGL_NOTICE, subscr,
449 "GPRS update location failed, GMM cause = '%s' (%d)\n",
450 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
451 gsup_msg->cause);
Jacob Erlbeckf06fe292015-01-05 16:20:47 +0100452
453 subscr->sgsn_data->error_cause = gsup_msg->cause;
454 gprs_subscr_update_auth_info(subscr);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100455 break;
456
457 default:
458 case EINVAL:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100459 LOGGSUBSCRP(LOGL_ERROR, subscr,
460 "GSUP protocol remote error, GMM cause = '%s' (%d)\n",
461 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
462 gsup_msg->cause);
Jacob Erlbeck9aa99912015-01-05 18:38:41 +0100463 break;
464 }
465
466 return -gsup_msg->cause;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100467}
468
Jacob Erlbeck929acdf2015-01-27 13:47:24 +0100469static int gprs_subscr_handle_gsup_purge_no_subscr(
470 struct gprs_gsup_message *gsup_msg)
471{
472 if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
473 LOGGSUPP(LOGL_NOTICE, gsup_msg,
474 "Purge MS has failed with cause '%s' (%d)\n",
475 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
476 gsup_msg->cause);
477 return -gsup_msg->cause;
478 }
479
480 LOGGSUPP(LOGL_INFO, gsup_msg, "Completing purge MS\n");
481 return 0;
482}
483
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100484static int gprs_subscr_handle_gsup_purge_res(struct gsm_subscriber *subscr,
485 struct gprs_gsup_message *gsup_msg)
486{
487 LOGGSUBSCRP(LOGL_INFO, subscr, "Completing purge MS\n");
488
489 /* Force silent cancellation */
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100490 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100491 gprs_subscr_cancel(subscr);
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100492
493 return 0;
494}
495
496static int gprs_subscr_handle_gsup_purge_err(struct gsm_subscriber *subscr,
497 struct gprs_gsup_message *gsup_msg)
498{
499 LOGGSUBSCRP(LOGL_NOTICE, subscr,
500 "Purge MS has failed with cause '%s' (%d)\n",
501 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
502 gsup_msg->cause);
503
504 /* In GSM 09.02, 19.1.4.4, the text and the SDL diagram imply that
505 * the subscriber data is not removed if the request has failed. On the
506 * other hand, keeping the subscriber data in either error case
507 * (subscriber unknown, syntactical message error, connection error)
508 * doesn't seem to give any advantage, since the data will be restored
509 * on the next Attach Request anyway.
510 * This approach ensures, that the subscriber record will not stick if
511 * an error happens.
512 */
513
514 /* TODO: Check whether this behaviour is acceptable and either just
515 * remove this TODO-notice or change the implementation to not delete
516 * the subscriber data (eventually resetting the ENABLE_PURGE flag and
517 * restarting the expiry timer based on the cause).
518 *
519 * Subscriber Unknown: cancel subscr
520 * Temporary network problems: do nothing (handled by timer based retry)
521 * Message problems (syntax, nyi, ...): cancel subscr (retry won't help)
522 */
523
524 gprs_subscr_handle_gsup_purge_res(subscr, gsup_msg);
525
526 return -gsup_msg->cause;
527}
528
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100529static int gprs_subscr_handle_loc_cancel_req(struct gsm_subscriber *subscr,
530 struct gprs_gsup_message *gsup_msg)
531{
532 struct gprs_gsup_message gsup_reply = {0};
Jacob Erlbeck5b512052015-04-07 17:49:48 +0200533 int is_update_procedure = !gsup_msg->cancel_type ||
534 gsup_msg->cancel_type == GPRS_GSUP_CANCEL_TYPE_UPDATE;
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100535
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100536 LOGGSUBSCRP(LOGL_INFO, subscr, "Cancelling MS subscriber (%s)\n",
537 is_update_procedure ?
538 "update procedure" : "subscription withdraw");
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100539
540 gsup_reply.message_type = GPRS_GSUP_MSGT_LOCATION_CANCEL_RESULT;
541 gprs_subscr_tx_gsup_message(subscr, &gsup_reply);
542
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100543 if (is_update_procedure)
544 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
545 else
546 /* Since a withdraw cause is not specified, just abort the
547 * current attachment. The following re-attachment should then
548 * be rejected with a proper cause value.
549 */
550 subscr->sgsn_data->error_cause = GMM_CAUSE_IMPL_DETACHED;
551
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100552 gprs_subscr_cancel(subscr);
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100553
554 return 0;
555}
556
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100557static int gprs_subscr_handle_unknown_imsi(struct gprs_gsup_message *gsup_msg)
558{
559 if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) {
560 gprs_subscr_tx_gsup_error_reply(NULL, gsup_msg,
561 GMM_CAUSE_IMSI_UNKNOWN);
562 LOGP(DGPRS, LOGL_NOTICE,
563 "Unknown IMSI %s, discarding GSUP request "
564 "of type 0x%02x\n",
565 gsup_msg->imsi, gsup_msg->message_type);
566 } else if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
567 LOGP(DGPRS, LOGL_NOTICE,
568 "Unknown IMSI %s, discarding GSUP error "
569 "of type 0x%02x, cause '%s' (%d)\n",
570 gsup_msg->imsi, gsup_msg->message_type,
571 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
572 gsup_msg->cause);
573 } else {
574 LOGP(DGPRS, LOGL_NOTICE,
575 "Unknown IMSI %s, discarding GSUP response "
576 "of type 0x%02x\n",
577 gsup_msg->imsi, gsup_msg->message_type);
578 }
579
580 return -GMM_CAUSE_IMSI_UNKNOWN;
581}
582
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100583int gprs_subscr_rx_gsup_message(struct msgb *msg)
584{
585 uint8_t *data = msgb_l2(msg);
586 size_t data_len = msgb_l2len(msg);
587 int rc = 0;
588
589 struct gprs_gsup_message gsup_msg = {0};
590 struct gsm_subscriber *subscr;
591
592 rc = gprs_gsup_decode(data, data_len, &gsup_msg);
593 if (rc < 0) {
594 LOGP(DGPRS, LOGL_ERROR,
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100595 "decoding GSUP message fails with error '%s' (%d)\n",
596 get_value_string(gsm48_gmm_cause_names, -rc), -rc);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100597 return rc;
598 }
599
Jacob Erlbeck07f6e362015-01-29 14:00:28 +0100600 if (!gsup_msg.imsi[0]) {
601 LOGP(DGPRS, LOGL_ERROR, "Missing IMSI in GSUP message\n");
602
603 if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type))
604 gprs_subscr_tx_gsup_error_reply(NULL, &gsup_msg,
605 GMM_CAUSE_INV_MAND_INFO);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100606 return -GMM_CAUSE_INV_MAND_INFO;
Jacob Erlbeck07f6e362015-01-29 14:00:28 +0100607 }
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100608
Jacob Erlbeck9ff82892015-01-29 14:17:51 +0100609 if (!gsup_msg.cause && GPRS_GSUP_IS_MSGT_ERROR(gsup_msg.message_type))
610 gsup_msg.cause = GMM_CAUSE_NET_FAIL;
611
Jacob Erlbeck4dedb272015-01-15 17:50:16 +0100612 subscr = gprs_subscr_get_by_imsi(gsup_msg.imsi);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100613
Jacob Erlbeck929acdf2015-01-27 13:47:24 +0100614 if (!subscr) {
615 switch (gsup_msg.message_type) {
616 case GPRS_GSUP_MSGT_PURGE_MS_RESULT:
617 case GPRS_GSUP_MSGT_PURGE_MS_ERROR:
618 return gprs_subscr_handle_gsup_purge_no_subscr(&gsup_msg);
619 default:
620 return gprs_subscr_handle_unknown_imsi(&gsup_msg);
621 }
622 }
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100623
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100624 LOGGSUBSCRP(LOGL_INFO, subscr,
625 "Received GSUP message of type 0x%02x\n", gsup_msg.message_type);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100626
627 switch (gsup_msg.message_type) {
628 case GPRS_GSUP_MSGT_LOCATION_CANCEL_REQUEST:
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100629 rc = gprs_subscr_handle_loc_cancel_req(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100630 break;
631
632 case GPRS_GSUP_MSGT_SEND_AUTH_INFO_RESULT:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100633 rc = gprs_subscr_handle_gsup_auth_res(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100634 break;
635
636 case GPRS_GSUP_MSGT_SEND_AUTH_INFO_ERROR:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100637 rc = gprs_subscr_handle_gsup_auth_err(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100638 break;
639
640 case GPRS_GSUP_MSGT_UPDATE_LOCATION_RESULT:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100641 rc = gprs_subscr_handle_gsup_upd_loc_res(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100642 break;
643
644 case GPRS_GSUP_MSGT_UPDATE_LOCATION_ERROR:
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100645 rc = gprs_subscr_handle_gsup_upd_loc_err(subscr, &gsup_msg);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100646 break;
647
648 case GPRS_GSUP_MSGT_PURGE_MS_ERROR:
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100649 rc = gprs_subscr_handle_gsup_purge_err(subscr, &gsup_msg);
650 break;
651
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100652 case GPRS_GSUP_MSGT_PURGE_MS_RESULT:
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100653 rc = gprs_subscr_handle_gsup_purge_res(subscr, &gsup_msg);
654 break;
655
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100656 case GPRS_GSUP_MSGT_INSERT_DATA_REQUEST:
657 case GPRS_GSUP_MSGT_DELETE_DATA_REQUEST:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100658 LOGGSUBSCRP(LOGL_ERROR, subscr,
659 "Rx GSUP message type %d not yet implemented\n",
660 gsup_msg.message_type);
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100661 gprs_subscr_tx_gsup_error_reply(subscr, &gsup_msg,
662 GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100663 rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
664 break;
665
666 default:
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100667 LOGGSUBSCRP(LOGL_ERROR, subscr,
668 "Rx GSUP message type %d not valid at SGSN\n",
669 gsup_msg.message_type);
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100670 if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type))
671 gprs_subscr_tx_gsup_error_reply(
672 subscr, &gsup_msg, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL);
673 rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100674 break;
675 };
676
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100677 subscr_put(subscr);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100678
679 return rc;
680}
681
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100682int gprs_subscr_purge(struct gsm_subscriber *subscr)
683{
Holger Hans Peter Freyther10c0f562015-05-17 20:58:40 +0200684 struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100685 struct gprs_gsup_message gsup_msg = {0};
686
687 LOGGSUBSCRP(LOGL_INFO, subscr, "purging MS subscriber\n");
688
689 gsup_msg.message_type = GPRS_GSUP_MSGT_PURGE_MS_REQUEST;
Holger Hans Peter Freyther10c0f562015-05-17 20:58:40 +0200690
691 /* Provide the HLR number in case it is known */
692 gsup_msg.hlr_enc_len = sdata->hlr_len;
693 gsup_msg.hlr_enc = sdata->hlr;
694
Jacob Erlbeckca69b0f2015-02-03 19:45:46 +0100695 return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100696}
697
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100698int gprs_subscr_query_auth_info(struct gsm_subscriber *subscr)
699{
700 struct gprs_gsup_message gsup_msg = {0};
701
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100702 LOGGSUBSCRP(LOGL_INFO, subscr,
703 "subscriber auth info is not available\n");
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100704
705 gsup_msg.message_type = GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST;
706 return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
707}
708
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100709int gprs_subscr_location_update(struct gsm_subscriber *subscr)
710{
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100711 struct gprs_gsup_message gsup_msg = {0};
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100712
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100713 LOGGSUBSCRP(LOGL_INFO, subscr,
714 "subscriber data is not available\n");
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100715
716 gsup_msg.message_type = GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST;
717 return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100718}
719
720void gprs_subscr_update(struct gsm_subscriber *subscr)
721{
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100722 LOGGSUBSCRP(LOGL_DEBUG, subscr, "Updating subscriber data\n");
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100723
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100724 subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100725 subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT;
726
Jacob Erlbeck555b2e52015-01-26 13:52:42 +0100727 if (subscr->sgsn_data->mm)
728 sgsn_update_subscriber_data(subscr->sgsn_data->mm);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100729}
730
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100731void gprs_subscr_update_auth_info(struct gsm_subscriber *subscr)
732{
Jacob Erlbeckbf34c672014-12-23 14:24:16 +0100733 LOGGSUBSCRP(LOGL_DEBUG, subscr,
734 "Updating subscriber authentication info\n");
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100735
736 subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING;
737 subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT;
738
Jacob Erlbeck555b2e52015-01-26 13:52:42 +0100739 if (subscr->sgsn_data->mm)
740 sgsn_update_subscriber_data(subscr->sgsn_data->mm);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100741}
742
743struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100744{
745 struct gsm_subscriber *subscr = NULL;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100746
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100747 if (mmctx->subscr)
748 return subscr_get(mmctx->subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100749
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100750 if (mmctx->imsi[0])
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100751 subscr = gprs_subscr_get_by_imsi(mmctx->imsi);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100752
753 if (!subscr) {
754 subscr = gprs_subscr_get_or_create(mmctx->imsi);
755 subscr->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100756 subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100757 }
758
759 if (strcpy(subscr->equipment.imei, mmctx->imei) != 0) {
Harald Welted3fa84d2016-04-20 17:50:17 +0200760 strncpy(subscr->equipment.imei, mmctx->imei,
761 sizeof(subscr->equipment.imei)-1);
762 subscr->equipment.imei[sizeof(subscr->equipment.imei)-1] = 0;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100763 }
764
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100765 if (subscr->lac != mmctx->ra.lac)
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100766 subscr->lac = mmctx->ra.lac;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100767
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100768 subscr->sgsn_data->mm = mmctx;
769 mmctx->subscr = subscr_get(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100770
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100771 return subscr;
772}
773
774int gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx)
775{
776 struct gsm_subscriber *subscr = NULL;
777 int rc;
778
779 LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber data update\n");
780
781 subscr = gprs_subscr_get_or_create_by_mmctx(mmctx);
782
783 subscr->flags |= GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING;
784
785 rc = gprs_subscr_location_update(subscr);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100786 subscr_put(subscr);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100787 return rc;
788}
789
790int gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx)
791{
792 struct gsm_subscriber *subscr = NULL;
793 int rc;
794
795 LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber authentication info\n");
796
797 subscr = gprs_subscr_get_or_create_by_mmctx(mmctx);
798
799 subscr->flags |= GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING;
800
801 rc = gprs_subscr_query_auth_info(subscr);
802 subscr_put(subscr);
803 return rc;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100804}