Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 1 | /* The concept of a subscriber for the MSC, roughly HLR/VLR functionality */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 2 | |
| 3 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 4 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 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 General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
Holger Freyther | 85a7b36 | 2009-04-18 13:48:55 +0200 | [diff] [blame] | 28 | #include <assert.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 29 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 30 | #include <openbsc/gsm_subscriber.h> |
Holger Freyther | 3e0ef7c | 2009-06-02 02:54:48 +0000 | [diff] [blame] | 31 | #include <openbsc/debug.h> |
Harald Welte | ea5cf30 | 2009-07-29 23:14:15 +0200 | [diff] [blame] | 32 | #include <openbsc/signal.h> |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 33 | #include <openbsc/db.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 35 | extern struct llist_head *subscr_bsc_active_subscriber(void); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 36 | |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 37 | struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net, |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 38 | u_int32_t tmsi) |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 39 | { |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 40 | char tmsi_string[14]; |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 41 | struct gsm_subscriber *subscr; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 42 | |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 43 | /* we might have a record in memory already */ |
Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 44 | llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) { |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 45 | if (tmsi == subscr->tmsi) |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 46 | return subscr_get(subscr); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 49 | sprintf(tmsi_string, "%u", tmsi); |
| 50 | return db_get_subscriber(net, GSM_SUBSCRIBER_TMSI, tmsi_string); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 53 | struct gsm_subscriber *subscr_get_by_imsi(struct gsm_network *net, |
| 54 | const char *imsi) |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 55 | { |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 56 | struct gsm_subscriber *subscr; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 57 | |
Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 58 | llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) { |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 59 | if (strcmp(subscr->imsi, imsi) == 0) |
| 60 | return subscr_get(subscr); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 63 | return db_get_subscriber(net, GSM_SUBSCRIBER_IMSI, imsi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 66 | struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net, |
| 67 | const char *ext) |
Holger Freyther | 9c564b8 | 2009-02-09 23:39:20 +0000 | [diff] [blame] | 68 | { |
| 69 | struct gsm_subscriber *subscr; |
| 70 | |
Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 71 | llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) { |
Holger Freyther | 9c564b8 | 2009-02-09 23:39:20 +0000 | [diff] [blame] | 72 | if (strcmp(subscr->extension, ext) == 0) |
| 73 | return subscr_get(subscr); |
| 74 | } |
| 75 | |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 76 | return db_get_subscriber(net, GSM_SUBSCRIBER_EXTENSION, ext); |
Holger Freyther | 9c564b8 | 2009-02-09 23:39:20 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 79 | struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net, |
| 80 | unsigned long long id) |
| 81 | { |
| 82 | struct gsm_subscriber *subscr; |
| 83 | char buf[32]; |
| 84 | sprintf(buf, "%llu", id); |
| 85 | |
Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 86 | llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) { |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 87 | if (subscr->id == id) |
| 88 | return subscr_get(subscr); |
| 89 | } |
| 90 | |
| 91 | return db_get_subscriber(net, GSM_SUBSCRIBER_ID, buf); |
| 92 | } |
| 93 | |
| 94 | |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 95 | int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 96 | { |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 97 | /* FIXME: Migrate pending requests from one BSC to another */ |
| 98 | switch (reason) { |
| 99 | case GSM_SUBSCRIBER_UPDATE_ATTACHED: |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 100 | s->net = bts->network; |
Holger Freyther | 6d5200b | 2009-06-02 02:54:38 +0000 | [diff] [blame] | 101 | /* Indicate "attached to LAC" */ |
| 102 | s->lac = bts->location_area_code; |
Harald Welte | ea5cf30 | 2009-07-29 23:14:15 +0200 | [diff] [blame] | 103 | dispatch_signal(SS_SUBSCR, S_SUBSCR_ATTACHED, s); |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 104 | break; |
| 105 | case GSM_SUBSCRIBER_UPDATE_DETACHED: |
Holger Freyther | c3d4b2d | 2009-06-04 14:27:39 +0000 | [diff] [blame] | 106 | /* Only detach if we are currently in this area */ |
| 107 | if (bts->location_area_code == s->lac) |
Holger Hans Peter Freyther | e48b956 | 2009-10-01 04:07:15 +0200 | [diff] [blame] | 108 | s->lac = GSM_LAC_RESERVED_DETACHED; |
Harald Welte | ea5cf30 | 2009-07-29 23:14:15 +0200 | [diff] [blame] | 109 | dispatch_signal(SS_SUBSCR, S_SUBSCR_DETACHED, s); |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 110 | break; |
| 111 | default: |
| 112 | fprintf(stderr, "subscr_update with unknown reason: %d\n", |
| 113 | reason); |
| 114 | break; |
| 115 | }; |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 116 | return db_sync_subscriber(s); |
| 117 | } |
| 118 | |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 119 | |