blob: 55b8de006e396219640557b8ab5591a365635cba [file] [log] [blame]
Harald Welteb8b85a12016-06-17 00:06:42 +02001/* Osmocom Visitor Location Register (VLR) code base */
2
3/* (C) 2016 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <osmocom/core/linuxlist.h>
23#include <osmocom/core/fsm.h>
24#include <osmocom/core/utils.h>
25#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
26#include <osmocom/gsm/gsup.h>
27#include <osmocom/gsm/apn.h>
Max43b01b02017-09-15 11:22:30 +020028#include <osmocom/gsm/gsm48.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020029#include <osmocom/msc/gsm_subscriber.h>
30#include <osmocom/msc/gsup_client.h>
31#include <osmocom/msc/vlr.h>
32#include <osmocom/msc/debug.h>
Harald Welteb8b85a12016-06-17 00:06:42 +020033
34#include <openssl/rand.h>
35
36#include <netinet/in.h>
37#include <arpa/inet.h>
38#include <limits.h>
Max43b01b02017-09-15 11:22:30 +020039#include <errno.h>
Harald Welteb8b85a12016-06-17 00:06:42 +020040
41#include "vlr_core.h"
42#include "vlr_auth_fsm.h"
43#include "vlr_lu_fsm.h"
44#include "vlr_access_req_fsm.h"
45
46#define SGSN_SUBSCR_MAX_RETRIES 3
47#define SGSN_SUBSCR_RETRY_INTERVAL 10
48
49/***********************************************************************
50 * Convenience functions
51 ***********************************************************************/
52
53const struct value_string vlr_ciph_names[] = {
54 OSMO_VALUE_STRING(VLR_CIPH_NONE),
55 OSMO_VALUE_STRING(VLR_CIPH_A5_1),
56 OSMO_VALUE_STRING(VLR_CIPH_A5_2),
57 OSMO_VALUE_STRING(VLR_CIPH_A5_3),
58 { 0, NULL }
59};
60
61uint32_t vlr_timer(struct vlr_instance *vlr, uint32_t timer)
62{
63 uint32_t tidx = 0xffffffff;
64
65 switch (timer) {
66 case 3270:
67 tidx = VLR_T_3270;
68 break;
69 case 3260:
70 tidx = VLR_T_3260;
71 break;
72 case 3250:
73 tidx = VLR_T_3250;
74 break;
75 }
76
77 OSMO_ASSERT(tidx < sizeof(vlr->cfg.timer));
78 return vlr->cfg.timer[tidx];
79}
80
81struct vlr_subscr *_vlr_subscr_find_by_imsi(struct vlr_instance *vlr,
82 const char *imsi,
83 const char *file, int line)
84{
85 struct vlr_subscr *vsub;
86
87 if (!imsi || !*imsi)
88 return NULL;
89
90 llist_for_each_entry(vsub, &vlr->subscribers, list) {
91 if (vlr_subscr_matches_imsi(vsub, imsi))
92 return _vlr_subscr_get(vsub, file, line);
93 }
94 return NULL;
95}
96
97struct vlr_subscr *_vlr_subscr_find_by_tmsi(struct vlr_instance *vlr,
98 uint32_t tmsi,
99 const char *file, int line)
100{
101 struct vlr_subscr *vsub;
102
103 if (tmsi == GSM_RESERVED_TMSI)
104 return NULL;
105
106 llist_for_each_entry(vsub, &vlr->subscribers, list) {
107 if (vlr_subscr_matches_tmsi(vsub, tmsi))
108 return _vlr_subscr_get(vsub, file, line);
109 }
110 return NULL;
111}
112
113struct vlr_subscr *_vlr_subscr_find_by_msisdn(struct vlr_instance *vlr,
114 const char *msisdn,
115 const char *file, int line)
116{
117 struct vlr_subscr *vsub;
118
119 if (!msisdn || !*msisdn)
120 return NULL;
121
122 llist_for_each_entry(vsub, &vlr->subscribers, list) {
123 if (vlr_subscr_matches_msisdn(vsub, msisdn))
124 return _vlr_subscr_get(vsub, file, line);
125 }
126 return NULL;
127}
128
129/* Transmit GSUP message to HLR */
130static int vlr_tx_gsup_message(struct vlr_instance *vlr,
131 struct osmo_gsup_message *gsup_msg)
132{
133 struct msgb *msg = gsup_client_msgb_alloc();
134
135 osmo_gsup_encode(msg, gsup_msg);
136
137 if (!vlr->gsup_client) {
138 LOGP(DVLR, LOGL_NOTICE, "GSUP link is down, cannot "
139 "send GSUP: %s\n", msgb_hexdump(msg));
140 msgb_free(msg);
141 return -ENOTSUP;
142 }
143
144 LOGP(DVLR, LOGL_DEBUG, "GSUP tx: %s\n",
145 osmo_hexdump_nospc(msg->data, msg->len));
146
147 return gsup_client_send(vlr->gsup_client, msg);
148}
149
150/* Transmit GSUP message for subscriber to HLR, using IMSI from subscriber */
151static int vlr_subscr_tx_gsup_message(struct vlr_subscr *vsub,
152 struct osmo_gsup_message *gsup_msg)
153{
154 struct vlr_instance *vlr = vsub->vlr;
155
156 if (strlen(gsup_msg->imsi) == 0)
157 osmo_strlcpy(gsup_msg->imsi, vsub->imsi, sizeof(gsup_msg->imsi));
158
159 return vlr_tx_gsup_message(vlr, gsup_msg);
160}
161
162/* Transmit GSUP error in response to original message */
163static int vlr_tx_gsup_error_reply(struct vlr_instance *vlr,
164 struct osmo_gsup_message *gsup_orig,
165 enum gsm48_gmm_cause cause)
166{
167 struct osmo_gsup_message gsup_reply = {0};
168
169 osmo_strlcpy(gsup_reply.imsi, gsup_orig->imsi, sizeof(gsup_reply.imsi));
170 gsup_reply.cause = cause;
171 gsup_reply.message_type =
172 OSMO_GSUP_TO_MSGT_ERROR(gsup_orig->message_type);
173
174 return vlr_tx_gsup_message(vlr, &gsup_reply);
175}
176
177struct vlr_subscr *_vlr_subscr_get(struct vlr_subscr *sub, const char *file, int line)
178{
179 if (!sub)
180 return NULL;
181 OSMO_ASSERT(sub->use_count < INT_MAX);
182 sub->use_count++;
183 LOGPSRC(DREF, LOGL_DEBUG, file, line,
184 "VLR subscr %s usage increases to: %d\n",
185 vlr_subscr_name(sub), sub->use_count);
186 return sub;
187}
188
189struct vlr_subscr *_vlr_subscr_put(struct vlr_subscr *sub, const char *file, int line)
190{
191 if (!sub)
192 return NULL;
193 sub->use_count--;
194 LOGPSRC(DREF, sub->use_count >= 0? LOGL_DEBUG : LOGL_ERROR,
195 file, line,
196 "VLR subscr %s usage decreases to: %d\n",
197 vlr_subscr_name(sub), sub->use_count);
198 if (sub->use_count <= 0)
199 vlr_subscr_free(sub);
200 return NULL;
201}
202
203/* Allocate a new subscriber and insert it into list */
204static struct vlr_subscr *_vlr_subscr_alloc(struct vlr_instance *vlr)
205{
206 struct vlr_subscr *vsub;
207 int i;
208
209 vsub = talloc_zero(vlr, struct vlr_subscr);
210 vsub->vlr = vlr;
211 vsub->tmsi = GSM_RESERVED_TMSI;
212 vsub->tmsi_new = GSM_RESERVED_TMSI;
213
214 for (i = 0; i < ARRAY_SIZE(vsub->auth_tuples); i++)
215 vsub->auth_tuples[i].key_seq = GSM_KEY_SEQ_INVAL;
216
217 INIT_LLIST_HEAD(&vsub->cs.requests);
218 INIT_LLIST_HEAD(&vsub->ps.pdp_list);
219
220 llist_add_tail(&vsub->list, &vlr->subscribers);
221 return vsub;
222}
223
224struct vlr_subscr *vlr_subscr_alloc(struct vlr_instance *vlr)
225{
226 return vlr_subscr_get(_vlr_subscr_alloc(vlr));
227}
228
229/* Send a GSUP Purge MS request.
230 * TODO: this should be sent to the *previous* VLR when this VLR is "taking"
231 * this subscriber, not to the HLR? */
232int vlr_subscr_purge(struct vlr_subscr *vsub)
233{
234 struct osmo_gsup_message gsup_msg = {0};
235
236 gsup_msg.message_type = OSMO_GSUP_MSGT_PURGE_MS_REQUEST;
237
238 /* provide HLR number in case we know it */
239 gsup_msg.hlr_enc_len = vsub->hlr.len;
240 gsup_msg.hlr_enc = vsub->hlr.buf;
241
242 return vlr_subscr_tx_gsup_message(vsub, &gsup_msg);
243}
244
245void vlr_subscr_cancel(struct vlr_subscr *vsub, enum gsm48_gmm_cause cause)
246{
247 if (!vsub)
248 return;
249
250 if (vsub->lu_fsm) {
251 if (vsub->lu_fsm->state == VLR_ULA_S_WAIT_HLR_UPD)
252 osmo_fsm_inst_dispatch(vsub->lu_fsm,
253 VLR_ULA_E_HLR_LU_RES,
254 (void*)&cause);
255 else
256 osmo_fsm_inst_term(vsub->lu_fsm, OSMO_FSM_TERM_ERROR,
257 0);
258 }
259
260 if (vsub->proc_arq_fsm)
261 osmo_fsm_inst_term(vsub->proc_arq_fsm, OSMO_FSM_TERM_ERROR, 0);
262}
263
264/* Call vlr_subscr_cancel(), then completely drop the entry from the VLR */
265void vlr_subscr_free(struct vlr_subscr *vsub)
266{
267 llist_del(&vsub->list);
268 DEBUGP(DREF, "freeing VLR subscr %s\n", vlr_subscr_name(vsub));
269 talloc_free(vsub);
270}
271
272/* Generate a new TMSI and store in vsub->tmsi_new.
273 * Search all known subscribers to ensure that the TMSI is unique. */
274int vlr_subscr_alloc_tmsi(struct vlr_subscr *vsub)
275{
276 struct vlr_instance *vlr = vsub->vlr;
277 uint32_t tmsi;
278 int tried;
279
280 for (tried = 0; tried < 100; tried++) {
281 if (RAND_bytes((uint8_t *) &tmsi, sizeof(tmsi)) != 1) {
282 LOGP(DVLR, LOGL_ERROR, "RAND_bytes failed\n");
283 return -1;
284 }
285 /* throw the dice again, if the TSMI doesn't fit */
286 if (tmsi == GSM_RESERVED_TMSI)
287 continue;
288
289 /* Section 2.4 of 23.003: MSC has two MSB 00/01/10, SGSN 11 */
290 if (vlr->cfg.is_ps) {
291 /* SGSN */
292 tmsi |= 0xC000000;
293 } else {
294 /* MSC */
295 if ((tmsi & 0xC0000000) == 0xC0000000)
296 tmsi &= ~0xC0000000;
297 }
298
299 /* If this TMSI is already in use, try another one. */
300 if (vlr_subscr_find_by_tmsi(vlr, tmsi))
301 continue;
302
303 vsub->tmsi_new = tmsi;
304 return 0;
305 }
306
307 LOGP(DVLR, LOGL_ERROR, "subscr %s: unable to generate valid TMSI"
308 " after %d tries\n", vlr_subscr_name(vsub), tried);
309 return -1;
310}
311
312/* Find subscriber by IMSI, or create new subscriber if not found.
313 * \param[in] vlr VLR instace.
314 * \param[in] imsi IMSI string.
315 * \param[out] created if non-NULL, returns whether a new entry was created. */
316struct vlr_subscr *_vlr_subscr_find_or_create_by_imsi(struct vlr_instance *vlr,
317 const char *imsi,
318 bool *created,
319 const char *file,
320 int line)
321{
322 struct vlr_subscr *vsub;
323 vsub = _vlr_subscr_find_by_imsi(vlr, imsi, file, line);
324 if (vsub) {
325 if (created)
326 *created = false;
327 return vsub;
328 }
329
330 vsub = _vlr_subscr_get(_vlr_subscr_alloc(vlr), file, line);
331 if (!vsub)
332 return NULL;
333 vlr_subscr_set_imsi(vsub, imsi);
334 LOGP(DVLR, LOGL_INFO, "New subscr, IMSI: %s\n", vsub->imsi);
335 if (created)
336 *created = true;
337 return vsub;
338}
339
340/* Find subscriber by TMSI, or create new subscriber if not found.
341 * \param[in] vlr VLR instace.
342 * \param[in] tmsi TMSI.
343 * \param[out] created if non-NULL, returns whether a new entry was created. */
344struct vlr_subscr *_vlr_subscr_find_or_create_by_tmsi(struct vlr_instance *vlr,
345 uint32_t tmsi,
346 bool *created,
347 const char *file,
348 int line)
349{
350 struct vlr_subscr *vsub;
351 vsub = _vlr_subscr_find_by_tmsi(vlr, tmsi, file, line);
352 if (vsub) {
353 if (created)
354 *created = false;
355 return vsub;
356 }
357
358 vsub = _vlr_subscr_get(_vlr_subscr_alloc(vlr), file, line);
359 if (!vsub)
360 return NULL;
361 vsub->tmsi = tmsi;
362 LOGP(DVLR, LOGL_INFO, "New subscr, TMSI: 0x%08x\n", vsub->tmsi);
363 if (created)
364 *created = true;
365 return vsub;
366}
367
368void vlr_subscr_set_imsi(struct vlr_subscr *vsub, const char *imsi)
369{
370 if (!vsub)
371 return;
372 osmo_strlcpy(vsub->imsi, imsi, sizeof(vsub->imsi));
373 vsub->id = atoll(vsub->imsi);
374 DEBUGP(DVLR, "set IMSI on subscriber; IMSI=%s id=%llu\n",
375 vsub->imsi, vsub->id);
376}
377
378void vlr_subscr_set_imei(struct vlr_subscr *vsub, const char *imei)
379{
380 if (!vsub)
381 return;
382 osmo_strlcpy(vsub->imei, imei, sizeof(vsub->imei));
383 DEBUGP(DVLR, "set IMEI on subscriber; IMSI=%s IMEI=%s\n",
384 vsub->imsi, vsub->imei);
385}
386
387void vlr_subscr_set_imeisv(struct vlr_subscr *vsub, const char *imeisv)
388{
389 if (!vsub)
390 return;
391 osmo_strlcpy(vsub->imeisv, imeisv, sizeof(vsub->imeisv));
392 DEBUGP(DVLR, "set IMEISV on subscriber; IMSI=%s IMEISV=%s\n",
393 vsub->imsi, vsub->imeisv);
394}
395
396/* Safely copy the given MSISDN string to vsub->msisdn */
397void vlr_subscr_set_msisdn(struct vlr_subscr *vsub, const char *msisdn)
398{
399 if (!vsub)
400 return;
401 osmo_strlcpy(vsub->msisdn, msisdn, sizeof(vsub->msisdn));
402 DEBUGP(DVLR, "set MSISDN on subscriber; IMSI=%s MSISDN=%s\n",
403 vsub->imsi, vsub->msisdn);
404}
405
406bool vlr_subscr_matches_imsi(struct vlr_subscr *vsub, const char *imsi)
407{
408 return vsub && imsi && vsub->imsi[0] && !strcmp(vsub->imsi, imsi);
409}
410
411bool vlr_subscr_matches_tmsi(struct vlr_subscr *vsub, uint32_t tmsi)
412{
413 return vsub && tmsi != GSM_RESERVED_TMSI
414 && (vsub->tmsi == tmsi || vsub->tmsi_new == tmsi);
415}
416
417bool vlr_subscr_matches_msisdn(struct vlr_subscr *vsub, const char *msisdn)
418{
419 return vsub && msisdn && vsub->msisdn[0]
420 && !strcmp(vsub->msisdn, msisdn);
421}
422
423bool vlr_subscr_matches_imei(struct vlr_subscr *vsub, const char *imei)
424{
425 return vsub && imei && vsub->imei[0]
426 && !strcmp(vsub->imei, imei);
427}
428
429/* Send updated subscriber information to HLR */
430int vlr_subscr_changed(struct vlr_subscr *vsub)
431{
432 /* FIXME */
433 LOGP(DVLR, LOGL_ERROR, "Not implemented: %s\n", __func__);
434 return 0;
435}
436
437/***********************************************************************
438 * PDP context data
439 ***********************************************************************/
440
Neels Hofmeyrbac22762017-07-06 18:39:28 +0200441#define GSM_APN_LENGTH 102
442
443/* see GSM 09.02, 17.7.1, PDP-Context and GPRSSubscriptionData */
444/* see GSM 09.02, B.1, gprsSubscriptionData */
445struct sgsn_subscriber_pdp_data {
446 struct llist_head list;
447
448 unsigned int context_id;
449 uint16_t pdp_type;
450 char apn_str[GSM_APN_LENGTH];
451 uint8_t qos_subscribed[20];
452 size_t qos_subscribed_len;
453};
454
Harald Welteb8b85a12016-06-17 00:06:42 +0200455struct sgsn_subscriber_pdp_data *
456vlr_subscr_pdp_data_alloc(struct vlr_subscr *vsub)
457{
458 struct sgsn_subscriber_pdp_data* pdata;
459
460 pdata = talloc_zero(vsub, struct sgsn_subscriber_pdp_data);
461
462 llist_add_tail(&pdata->list, &vsub->ps.pdp_list);
463
464 return pdata;
465}
466
467static int vlr_subscr_pdp_data_clear(struct vlr_subscr *vsub)
468{
469 struct sgsn_subscriber_pdp_data *pdp, *pdp2;
470 int count = 0;
471
472 llist_for_each_entry_safe(pdp, pdp2, &vsub->ps.pdp_list, list) {
473 llist_del(&pdp->list);
474 talloc_free(pdp);
475 count += 1;
476 }
477
478 return count;
479}
480
481static struct sgsn_subscriber_pdp_data *
482vlr_subscr_pdp_data_get_by_id(struct vlr_subscr *vsub, unsigned context_id)
483{
484 struct sgsn_subscriber_pdp_data *pdp;
485
486 llist_for_each_entry(pdp, &vsub->ps.pdp_list, list) {
487 if (pdp->context_id == context_id)
488 return pdp;
489 }
490
491 return NULL;
492}
493
494/***********************************************************************
495 * Actual Implementation
496 ***********************************************************************/
497
498static int vlr_rx_gsup_unknown_imsi(struct vlr_instance *vlr,
499 struct osmo_gsup_message *gsup_msg)
500{
501 if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) {
502 vlr_tx_gsup_error_reply(vlr, gsup_msg,
503 GMM_CAUSE_IMSI_UNKNOWN);
504 LOGP(DVLR, LOGL_NOTICE,
505 "Unknown IMSI %s, discarding GSUP request "
506 "of type 0x%02x\n",
507 gsup_msg->imsi, gsup_msg->message_type);
508 } else if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
509 LOGP(DVLR, LOGL_NOTICE,
510 "Unknown IMSI %s, discarding GSUP error "
511 "of type 0x%02x, cause '%s' (%d)\n",
512 gsup_msg->imsi, gsup_msg->message_type,
513 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
514 gsup_msg->cause);
515 } else {
516 LOGP(DVLR, LOGL_NOTICE,
517 "Unknown IMSI %s, discarding GSUP response "
518 "of type 0x%02x\n",
519 gsup_msg->imsi, gsup_msg->message_type);
520 }
521
522 return -GMM_CAUSE_IMSI_UNKNOWN;
523}
524
525static int vlr_rx_gsup_purge_no_subscr(struct vlr_instance *vlr,
526 struct osmo_gsup_message *gsup_msg)
527{
528 if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
529 LOGGSUPP(LOGL_NOTICE, gsup_msg,
530 "Purge MS has failed with cause '%s' (%d)\n",
531 get_value_string(gsm48_gmm_cause_names, gsup_msg->cause),
532 gsup_msg->cause);
533 return -gsup_msg->cause;
534 }
535 LOGGSUPP(LOGL_INFO, gsup_msg, "Completing purge MS\n");
536 return 0;
537}
538
539/* VLR internal call to request UpdateLocation from HLR */
540int vlr_subscr_req_lu(struct vlr_subscr *vsub, bool is_ps)
541{
542 struct osmo_gsup_message gsup_msg = {0};
543 int rc;
544
545 gsup_msg.message_type = OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST;
546 rc = vlr_subscr_tx_gsup_message(vsub, &gsup_msg);
547
548 return rc;
549}
550
551/* VLR internal call to request tuples from HLR */
552int vlr_subscr_req_sai(struct vlr_subscr *vsub,
553 const uint8_t *auts, const uint8_t *auts_rand)
554{
555 struct osmo_gsup_message gsup_msg = {0};
556
557 gsup_msg.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST;
558 gsup_msg.auts = auts;
559 gsup_msg.rand = auts_rand;
560
561 return vlr_subscr_tx_gsup_message(vsub, &gsup_msg);
562}
563
564/* Tell HLR that authentication failure occurred */
565int vlr_subscr_tx_auth_fail_rep(struct vlr_subscr *vsub)
566{
567 struct osmo_gsup_message gsup_msg = {0};
568
569 gsup_msg.message_type = OSMO_GSUP_MSGT_AUTH_FAIL_REPORT;
570 osmo_strlcpy(gsup_msg.imsi, vsub->imsi, sizeof(gsup_msg.imsi));
571 return vlr_tx_gsup_message(vsub->vlr, &gsup_msg);
572}
573
574/* Update the subscriber with GSUP-received auth tuples */
575void vlr_subscr_update_tuples(struct vlr_subscr *vsub,
576 const struct osmo_gsup_message *gsup)
577{
578 unsigned int i;
579 unsigned int got_tuples;
580
581 if (gsup->num_auth_vectors) {
582 memset(&vsub->auth_tuples, 0, sizeof(vsub->auth_tuples));
583 for (i = 0; i < ARRAY_SIZE(vsub->auth_tuples); i++)
584 vsub->auth_tuples[i].key_seq = GSM_KEY_SEQ_INVAL;
585 }
586
587 got_tuples = 0;
588 for (i = 0; i < gsup->num_auth_vectors; i++) {
589 size_t key_seq = i;
590
591 if (key_seq >= ARRAY_SIZE(vsub->auth_tuples)) {
592 LOGVSUBP(LOGL_NOTICE, vsub,
593 "Skipping auth tuple wih invalid cksn %zu\n",
594 key_seq);
595 continue;
596 }
597 vsub->auth_tuples[i].vec = gsup->auth_vectors[i];
598 vsub->auth_tuples[i].key_seq = key_seq;
599 got_tuples ++;
600 }
601
602 LOGVSUBP(LOGL_DEBUG, vsub, "Received %u auth tuples\n", got_tuples);
603
604 if (!got_tuples) {
605 /* FIXME what now? */
606 // vlr_subscr_cancel(vsub, GMM_CAUSE_GSM_AUTH_UNACCEPT); ?
607 }
608
609 /* New tuples means last_tuple becomes invalid */
610 vsub->last_tuple = NULL;
611}
612
613/* Handle SendAuthInfo Result/Error from HLR */
614static int vlr_subscr_handle_sai_res(struct vlr_subscr *vsub,
615 const struct osmo_gsup_message *gsup)
616{
617 struct osmo_fsm_inst *auth_fi = vsub->auth_fsm;
618 void *data = (void *) gsup;
619
620 switch (gsup->message_type) {
621 case OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT:
622 osmo_fsm_inst_dispatch(auth_fi, VLR_AUTH_E_HLR_SAI_ACK, data);
623 break;
624 case OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR:
625 osmo_fsm_inst_dispatch(auth_fi, VLR_AUTH_E_HLR_SAI_NACK, data);
626 break;
627 default:
628 return -1;
629 }
630
631 return 0;
632}
633
634static int decode_bcd_number_safe(char *output, int output_len,
635 const uint8_t *bcd_lv, int input_len,
636 int h_len)
637{
638 uint8_t len;
639 OSMO_ASSERT(output_len >= 1);
640 *output = '\0';
641 if (input_len < 1)
642 return -EIO;
643 len = bcd_lv[0];
644 if (input_len < len)
645 return -EIO;
646 return gsm48_decode_bcd_number(output, output_len, bcd_lv, h_len);
647}
648
649static void vlr_subscr_gsup_insert_data(struct vlr_subscr *vsub,
650 const struct osmo_gsup_message *gsup_msg)
651{
652 unsigned idx;
653 int rc;
654
655 if (gsup_msg->msisdn_enc) {
656 decode_bcd_number_safe(vsub->msisdn, sizeof(vsub->msisdn),
657 gsup_msg->msisdn_enc,
658 gsup_msg->msisdn_enc_len, 0);
659 LOGP(DVLR, LOGL_DEBUG, "IMSI:%s has MSISDN:%s\n",
660 vsub->imsi, vsub->msisdn);
661 }
662
663 if (gsup_msg->hlr_enc) {
664 if (gsup_msg->hlr_enc_len > sizeof(vsub->hlr.buf)) {
665 LOGP(DVLR, LOGL_ERROR, "HLR-Number too long (%zu)\n",
666 gsup_msg->hlr_enc_len);
667 vsub->hlr.len = 0;
668 } else {
669 memcpy(vsub->hlr.buf, gsup_msg->hlr_enc,
670 gsup_msg->hlr_enc_len);
671 vsub->hlr.len = gsup_msg->hlr_enc_len;
672 }
673 }
674
675 if (gsup_msg->pdp_info_compl) {
676 rc = vlr_subscr_pdp_data_clear(vsub);
677 if (rc > 0)
678 LOGP(DVLR, LOGL_INFO, "Cleared existing PDP info\n");
679 }
680
681 for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) {
682 const struct osmo_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx];
683 size_t ctx_id = pdp_info->context_id;
684 struct sgsn_subscriber_pdp_data *pdp_data;
685
686 if (pdp_info->apn_enc_len >= sizeof(pdp_data->apn_str)-1) {
687 LOGVSUBP(LOGL_ERROR, vsub,
688 "APN too long, context id = %zu, APN = %s\n",
689 ctx_id, osmo_hexdump(pdp_info->apn_enc,
690 pdp_info->apn_enc_len));
691 continue;
692 }
693
694 if (pdp_info->qos_enc_len > sizeof(pdp_data->qos_subscribed)) {
695 LOGVSUBP(LOGL_ERROR, vsub,
696 "QoS info too long (%zu)\n",
697 pdp_info->qos_enc_len);
698 continue;
699 }
700
701 LOGVSUBP(LOGL_INFO, vsub,
702 "Will set PDP info, context id = %zu, APN = %s\n",
703 ctx_id, osmo_hexdump(pdp_info->apn_enc, pdp_info->apn_enc_len));
704
705 /* Set PDP info [ctx_id] */
706 pdp_data = vlr_subscr_pdp_data_get_by_id(vsub, ctx_id);
707 if (!pdp_data) {
708 pdp_data = vlr_subscr_pdp_data_alloc(vsub);
709 pdp_data->context_id = ctx_id;
710 }
711
712 OSMO_ASSERT(pdp_data != NULL);
713 pdp_data->pdp_type = pdp_info->pdp_type;
714 osmo_apn_to_str(pdp_data->apn_str,
715 pdp_info->apn_enc, pdp_info->apn_enc_len);
716 memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len);
717 pdp_data->qos_subscribed_len = pdp_info->qos_enc_len;
718 }
719}
720
721
722/* Handle InsertSubscrData Result from HLR */
723static int vlr_subscr_handle_isd_req(struct vlr_subscr *vsub,
724 const struct osmo_gsup_message *gsup)
725{
726 struct osmo_gsup_message gsup_reply = {0};
727
728 vlr_subscr_gsup_insert_data(vsub, gsup);
729 vsub->vlr->ops.subscr_update(vsub);
730
731 gsup_reply.message_type = OSMO_GSUP_MSGT_INSERT_DATA_RESULT;
732 return vlr_subscr_tx_gsup_message(vsub, &gsup_reply);
733}
734
735/* Handle UpdateLocation Result from HLR */
736static int vlr_subscr_handle_lu_res(struct vlr_subscr *vsub,
737 const struct osmo_gsup_message *gsup)
738{
739 if (!vsub->lu_fsm) {
740 LOGVSUBP(LOGL_ERROR, vsub, "Rx GSUP LU Result "
741 "without LU in progress\n");
742 return -ENODEV;
743 }
744
745 /* contrary to MAP, we allow piggy-backing subscriber data onto the
746 * UPDATE LOCATION RESULT, and don't mandate the use of a separate
747 * nested INSERT SUBSCRIBER DATA transaction */
748 vlr_subscr_gsup_insert_data(vsub, gsup);
749
750 osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_HLR_LU_RES, NULL);
751
752 return 0;
753}
754
755/* Handle UpdateLocation Result from HLR */
756static int vlr_subscr_handle_lu_err(struct vlr_subscr *vsub,
757 const struct osmo_gsup_message *gsup)
758{
759 if (!vsub->lu_fsm) {
760 LOGVSUBP(LOGL_ERROR, vsub, "Rx GSUP LU Error "
761 "without LU in progress\n");
762 return -ENODEV;
763 }
764
765 LOGVSUBP(LOGL_DEBUG, vsub, "UpdateLocation failed; gmm_cause: %s\n",
766 get_value_string(gsm48_gmm_cause_names, gsup->cause));
767
768 osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_HLR_LU_RES,
769 (void *)&gsup->cause);
770
771 return 0;
772}
773
774/* Handle LOCATION CANCEL request from HLR */
775static int vlr_subscr_handle_cancel_req(struct vlr_subscr *vsub,
776 struct osmo_gsup_message *gsup_msg)
777{
778 struct osmo_gsup_message gsup_reply = {0};
779 int is_update_procedure = !gsup_msg->cancel_type ||
780 gsup_msg->cancel_type == OSMO_GSUP_CANCEL_TYPE_UPDATE;
781
782 LOGVSUBP(LOGL_INFO, vsub, "Cancelling MS subscriber (%s)\n",
783 is_update_procedure ?
784 "update procedure" : "subscription withdraw");
785
786 gsup_reply.message_type = OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT;
787 vlr_subscr_tx_gsup_message(vsub, &gsup_reply);
788
789 vlr_subscr_cancel(vsub, gsup_msg->cause);
790
791 return 0;
792}
793
794/* Incoming handler for GSUP from HLR.
795 * Keep this function non-static for direct invocation by unit tests. */
796int vlr_gsupc_read_cb(struct gsup_client *gsupc, struct msgb *msg)
797{
798 struct vlr_instance *vlr = (struct vlr_instance *) gsupc->data;
799 struct vlr_subscr *vsub;
800 struct osmo_gsup_message gsup;
801 int rc;
802
803 DEBUGP(DVLR, "GSUP rx %u: %s\n", msgb_l2len(msg),
804 osmo_hexdump_nospc(msgb_l2(msg), msgb_l2len(msg)));
805
806 rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup);
807 if (rc < 0) {
808 LOGP(DVLR, LOGL_ERROR,
809 "decoding GSUP message fails with error '%s' (%d)\n",
810 get_value_string(gsm48_gmm_cause_names, -rc), -rc);
Neels Hofmeyrb3fa3552017-11-18 22:22:59 +0100811 goto msgb_free_and_return;
Harald Welteb8b85a12016-06-17 00:06:42 +0200812 }
813
814 if (!gsup.imsi[0]) {
815 LOGP(DVLR, LOGL_ERROR, "Missing IMSI in GSUP message\n");
816 if (OSMO_GSUP_IS_MSGT_REQUEST(gsup.message_type))
817 vlr_tx_gsup_error_reply(vlr, &gsup,
818 GMM_CAUSE_INV_MAND_INFO);
Neels Hofmeyrb3fa3552017-11-18 22:22:59 +0100819 rc = -GMM_CAUSE_INV_MAND_INFO;
820 goto msgb_free_and_return;
Harald Welteb8b85a12016-06-17 00:06:42 +0200821 }
822
823 vsub = vlr_subscr_find_by_imsi(vlr, gsup.imsi);
824 if (!vsub) {
825 switch (gsup.message_type) {
826 case OSMO_GSUP_MSGT_PURGE_MS_RESULT:
827 case OSMO_GSUP_MSGT_PURGE_MS_ERROR:
Neels Hofmeyrb3fa3552017-11-18 22:22:59 +0100828 rc = vlr_rx_gsup_purge_no_subscr(vlr, &gsup);
829 goto msgb_free_and_return;
Harald Welteb8b85a12016-06-17 00:06:42 +0200830 default:
Neels Hofmeyrb3fa3552017-11-18 22:22:59 +0100831 rc = vlr_rx_gsup_unknown_imsi(vlr, &gsup);
832 goto msgb_free_and_return;
Harald Welteb8b85a12016-06-17 00:06:42 +0200833 }
834 }
835
836 switch (gsup.message_type) {
837 case OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT:
838 case OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR:
839 rc = vlr_subscr_handle_sai_res(vsub, &gsup);
840 break;
841 case OSMO_GSUP_MSGT_INSERT_DATA_REQUEST:
842 rc = vlr_subscr_handle_isd_req(vsub, &gsup);
843 break;
844 case OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST:
845 rc = vlr_subscr_handle_cancel_req(vsub, &gsup);
846 break;
847 case OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT:
848 rc = vlr_subscr_handle_lu_res(vsub, &gsup);
849 break;
850 case OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR:
851 rc = vlr_subscr_handle_lu_err(vsub, &gsup);
852 break;
853 case OSMO_GSUP_MSGT_PURGE_MS_ERROR:
854 case OSMO_GSUP_MSGT_PURGE_MS_RESULT:
855 case OSMO_GSUP_MSGT_DELETE_DATA_REQUEST:
856 LOGVSUBP(LOGL_ERROR, vsub,
857 "Rx GSUP msg_type=%d not yet implemented\n",
858 gsup.message_type);
859 rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
860 break;
861 default:
862 LOGVSUBP(LOGL_ERROR, vsub,
863 "Rx GSUP msg_type=%d not valid at VLR/SGSN side\n",
864 gsup.message_type);
865 rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
866 break;
867 }
868
869 vlr_subscr_put(vsub);
Neels Hofmeyrb3fa3552017-11-18 22:22:59 +0100870
871msgb_free_and_return:
872 msgb_free(msg);
Harald Welteb8b85a12016-06-17 00:06:42 +0200873 return rc;
874}
875
876/* MSC->VLR: Subscriber has provided IDENTITY RESPONSE */
877int vlr_subscr_rx_id_resp(struct vlr_subscr *vsub,
878 const uint8_t *mi, size_t mi_len)
879{
880 char mi_string[GSM48_MI_SIZE];
881 uint8_t mi_type = mi[0] & GSM_MI_TYPE_MASK;
882
883 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
884
885 /* update the vlr_subscr with the given identity */
886 switch (mi_type) {
887 case GSM_MI_TYPE_IMSI:
888 if (vsub->imsi[0]
889 && !vlr_subscr_matches_imsi(vsub, mi_string)) {
890 LOGVSUBP(LOGL_ERROR, vsub, "IMSI in ID RESP differs:"
891 " %s\n", mi_string);
892 } else
893 vlr_subscr_set_imsi(vsub, mi_string);
894 break;
895 case GSM_MI_TYPE_IMEI:
896 vlr_subscr_set_imei(vsub, mi_string);
897 break;
898 case GSM_MI_TYPE_IMEISV:
899 vlr_subscr_set_imeisv(vsub, mi_string);
900 break;
901 }
902
903 if (vsub->auth_fsm) {
904 switch (mi_type) {
905 case GSM_MI_TYPE_IMSI:
906 osmo_fsm_inst_dispatch(vsub->auth_fsm,
907 VLR_AUTH_E_MS_ID_IMSI, mi_string);
908 break;
909 }
910 }
911
912 if (vsub->lu_fsm) {
913 uint32_t event = 0;
914 switch (mi_type) {
915 case GSM_MI_TYPE_IMSI:
916 event = VLR_ULA_E_ID_IMSI;
917 break;
918 case GSM_MI_TYPE_IMEI:
919 event = VLR_ULA_E_ID_IMEI;
920 break;
921 case GSM_MI_TYPE_IMEISV:
922 event = VLR_ULA_E_ID_IMEISV;
923 break;
924 default:
925 OSMO_ASSERT(0);
926 break;
927 }
928 osmo_fsm_inst_dispatch(vsub->lu_fsm, event, mi_string);
929 } else {
930 LOGVSUBP(LOGL_NOTICE, vsub, "gratuitous ID RESPONSE?!?\n");
931 }
932
933 return 0;
934}
935
936/* MSC->VLR: Subscriber has provided IDENTITY RESPONSE */
937int vlr_subscr_rx_tmsi_reall_compl(struct vlr_subscr *vsub)
938{
939 if (vsub->lu_fsm) {
940 return osmo_fsm_inst_dispatch(vsub->lu_fsm,
941 VLR_ULA_E_NEW_TMSI_ACK, NULL);
942 } else if (vsub->proc_arq_fsm) {
943 return osmo_fsm_inst_dispatch(vsub->proc_arq_fsm,
944 PR_ARQ_E_TMSI_ACK, NULL);
945 } else {
946 LOGVSUBP(LOGL_NOTICE, vsub,
947 "gratuitous TMSI REALLOC COMPL");
948 return -EINVAL;
949 }
950}
951
952int vlr_subscr_rx_imsi_detach(struct vlr_subscr *vsub)
953{
954 /* paranoia: should any LU or PARQ FSMs still be running, stop them. */
955 vlr_subscr_cancel(vsub, GMM_CAUSE_IMPL_DETACHED);
956
957 vsub->imsi_detached_flag = true;
958 if (vsub->lu_complete) {
959 vsub->lu_complete = false;
960 /* balancing the get from vlr_lu_compl_fsm_success() */
961 vlr_subscr_put(vsub);
962 }
963 return 0;
964}
965
966/* Tear down any running FSMs due to MSC connection timeout.
967 * Visit all vsub->*_fsm pointers and give them a queue to send a final reject
968 * message before the entire connection is torn down.
969 * \param[in] vsub subscriber to tear down
970 */
971void vlr_subscr_conn_timeout(struct vlr_subscr *vsub)
972{
973 if (!vsub)
974 return;
975
Neels Hofmeyr3bae8362017-11-18 23:26:24 +0100976 vlr_subscr_get(vsub);
977 if (vsub->lu_fsm)
978 vlr_loc_update_conn_timeout(vsub->lu_fsm);
979 if (vsub->proc_arq_fsm)
980 vlr_parq_conn_timeout(vsub->proc_arq_fsm);
981 vlr_subscr_put(vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200982}
983
984struct vlr_instance *vlr_alloc(void *ctx, const struct vlr_ops *ops)
985{
986 struct vlr_instance *vlr = talloc_zero(ctx, struct vlr_instance);
987 OSMO_ASSERT(vlr);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200988
989 /* Some of these are needed only on UTRAN, but in case the caller wants
990 * only GERAN, she should just provide dummy callbacks. */
Harald Welteb8b85a12016-06-17 00:06:42 +0200991 OSMO_ASSERT(ops->tx_auth_req);
992 OSMO_ASSERT(ops->tx_auth_rej);
993 OSMO_ASSERT(ops->tx_id_req);
994 OSMO_ASSERT(ops->tx_lu_acc);
995 OSMO_ASSERT(ops->tx_lu_rej);
996 OSMO_ASSERT(ops->tx_cm_serv_acc);
997 OSMO_ASSERT(ops->tx_cm_serv_rej);
998 OSMO_ASSERT(ops->set_ciph_mode);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200999 OSMO_ASSERT(ops->tx_common_id);
Harald Welteb8b85a12016-06-17 00:06:42 +02001000 OSMO_ASSERT(ops->subscr_update);
1001 OSMO_ASSERT(ops->subscr_assoc);
1002
1003 INIT_LLIST_HEAD(&vlr->subscribers);
1004 INIT_LLIST_HEAD(&vlr->operations);
1005 memcpy(&vlr->ops, ops, sizeof(vlr->ops));
1006
Neels Hofmeyr0b8dec72017-10-29 01:57:35 +02001007 /* defaults */
1008 vlr->cfg.assign_tmsi = true;
1009
Harald Welteb8b85a12016-06-17 00:06:42 +02001010 /* osmo_auth_fsm.c */
1011 osmo_fsm_register(&vlr_auth_fsm);
1012 /* osmo_lu_fsm.c */
1013 vlr_lu_fsm_init();
1014 /* vlr_access_request_fsm.c */
1015 vlr_parq_fsm_init();
1016
1017 return vlr;
1018}
1019
1020int vlr_start(const char *gsup_unit_name, struct vlr_instance *vlr,
1021 const char *gsup_server_addr_str, uint16_t gsup_server_port)
1022{
1023 OSMO_ASSERT(vlr);
1024
1025 vlr->gsup_client = gsup_client_create(gsup_unit_name,
1026 gsup_server_addr_str,
1027 gsup_server_port,
1028 &vlr_gsupc_read_cb, NULL);
1029 if (!vlr->gsup_client)
1030 return -ENOMEM;
1031 vlr->gsup_client->data = vlr;
1032
1033 return 0;
1034}
1035
1036/* MSC->VLR: Subscribre has disconnected */
1037int vlr_subscr_disconnected(struct vlr_subscr *vsub)
1038{
1039 /* This corresponds to a MAP-ABORT from MSC->VLR on a classic B
1040 * interface */
1041 osmo_fsm_inst_term(vsub->lu_fsm, OSMO_FSM_TERM_REQUEST, NULL);
1042 osmo_fsm_inst_term(vsub->auth_fsm, OSMO_FSM_TERM_REQUEST, NULL);
1043 vsub->msc_conn_ref = NULL;
1044
1045 return 0;
1046}
1047
1048/* MSC->VLR: Receive Authentication Failure from Subscriber */
1049int vlr_subscr_rx_auth_fail(struct vlr_subscr *vsub, const uint8_t *auts)
1050{
1051 struct vlr_auth_resp_par par = {0};
1052 par.auts = auts;
1053
1054 osmo_fsm_inst_dispatch(vsub->auth_fsm, VLR_AUTH_E_MS_AUTH_FAIL, &par);
1055 return 0;
1056}
1057
1058/* MSC->VLR: Receive Authentication Response from MS
1059 * \returns 1 in case of success, 0 in case of delay, -1 on auth error */
1060int vlr_subscr_rx_auth_resp(struct vlr_subscr *vsub, bool is_r99,
1061 bool is_utran, const uint8_t *res, uint8_t res_len)
1062{
1063 struct osmo_fsm_inst *auth_fi = vsub->auth_fsm;
1064 struct vlr_auth_resp_par par;
1065
1066 par.is_r99 = is_r99;
1067 par.is_utran = is_utran;
1068 par.res = res;
1069 par.res_len = res_len;
1070 osmo_fsm_inst_dispatch(auth_fi, VLR_AUTH_E_MS_AUTH_RESP, (void *) &par);
1071
1072 return 0;
1073}
1074
1075/* MSC->VLR: Receive result of Ciphering Mode Command from MS */
1076void vlr_subscr_rx_ciph_res(struct vlr_subscr *vsub, struct vlr_ciph_result *res)
1077{
1078 if (vsub->lu_fsm && vsub->lu_fsm->state == VLR_ULA_S_WAIT_CIPH)
1079 osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_CIPH_RES, res);
1080 if (vsub->proc_arq_fsm
1081 && vsub->proc_arq_fsm->state == PR_ARQ_S_WAIT_CIPH)
1082 osmo_fsm_inst_dispatch(vsub->proc_arq_fsm, PR_ARQ_E_CIPH_RES,
1083 res);
1084}
1085
1086/* Internal evaluation of requested ciphering mode.
1087 * Send set_ciph_mode() to MSC depending on the ciph_mode argument.
1088 * \param[in] vlr VLR instance.
1089 * \param[in] fi Calling FSM instance, for logging.
1090 * \param[in] msc_conn_ref MSC conn to send to.
1091 * \param[in] ciph_mode Ciphering config, to decide whether to do ciphering.
1092 * \returns 0 if no ciphering is needed or message was sent successfully,
1093 * or a negative value if ciph_mode is invalid or sending failed.
1094 */
1095int vlr_set_ciph_mode(struct vlr_instance *vlr,
1096 struct osmo_fsm_inst *fi,
1097 void *msc_conn_ref,
1098 enum vlr_ciph ciph_mode,
1099 bool retrieve_imeisv)
1100{
1101 switch (ciph_mode) {
1102 case VLR_CIPH_NONE:
1103 return 0;
1104
1105 case VLR_CIPH_A5_1:
1106 case VLR_CIPH_A5_3:
Neels Hofmeyr4cf4fdd2017-12-14 05:31:27 +01001107 LOGPFSML(fi, LOGL_DEBUG, "Set Ciphering Mode: %d=%s\n",
1108 ciph_mode, vlr_ciph_name(ciph_mode));
Harald Welteb8b85a12016-06-17 00:06:42 +02001109 return vlr->ops.set_ciph_mode(msc_conn_ref,
1110 ciph_mode,
1111 retrieve_imeisv);
1112
1113 case VLR_CIPH_A5_2:
1114 /* TODO policy by user config? */
1115 LOGPFSML(fi, LOGL_ERROR, "A5/2 ciphering is not allowed\n");
1116 return -EINVAL;
1117
1118 default:
1119 LOGPFSML(fi, LOGL_ERROR, "unknown ciphering value: %d\n",
1120 ciph_mode);
1121 return -EINVAL;
1122 }
1123}
1124
Neels Hofmeyre3d72d72017-12-18 02:06:44 +01001125/* Decide whether UMTS AKA should be used.
1126 * UTRAN networks are by definition R99 capable, and the auth vector is required to contain UMTS AKA
1127 * tokens. This is expected to be verified by the caller. On GERAN, UMTS AKA must be used iff MS and
1128 * GERAN are R99 capable and UMTS AKA tokens are available.
1129 * \param[in] vec Auth tokens (received from the HLR).
1130 * \param[in] is_r99 True when BTS and GERAN are R99 capable.
1131 * \returns true to use UMTS AKA, false to use pre-R99 GSM AKA.
1132 */
1133bool vlr_use_umts_aka(struct osmo_auth_vector *vec, bool is_r99)
1134{
1135 if (!is_r99)
1136 return false;
1137 if (!(vec->auth_types & OSMO_AUTH_TYPE_UMTS))
1138 return false;
1139 return true;
1140}
1141
Harald Welteb8b85a12016-06-17 00:06:42 +02001142void log_set_filter_vlr_subscr(struct log_target *target,
1143 struct vlr_subscr *vlr_subscr)
1144{
1145 struct vlr_subscr **fsub = (void*)&target->filter_data[LOG_FLT_VLR_SUBSCR];
1146
1147 /* free the old data */
1148 if (*fsub) {
1149 vlr_subscr_put(*fsub);
1150 *fsub = NULL;
1151 }
1152
1153 if (vlr_subscr) {
1154 target->filter_map |= (1 << LOG_FLT_VLR_SUBSCR);
1155 *fsub = vlr_subscr_get(vlr_subscr);
1156 } else
1157 target->filter_map &= ~(1 << LOG_FLT_VLR_SUBSCR);
1158}