Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* Dummy implementation of a subscriber database, roghly HLR/VLR functionality */ |
| 2 | |
| 3 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 4 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 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 General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 23 | #include <unistd.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 27 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 28 | #include <openbsc/gsm_subscriber.h> |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 29 | #include <openbsc/db.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 30 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 31 | struct gsm_subscriber *subscr_alloc(void) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 32 | { |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 33 | struct gsm_subscriber *s; |
| 34 | |
| 35 | s = malloc(sizeof(struct gsm_subscriber)); |
| 36 | if (!s) |
| 37 | return NULL; |
| 38 | |
| 39 | memset(s, 0, sizeof(*s)); |
| 40 | |
| 41 | return s; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 42 | } |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 43 | |
| 44 | void subscr_free(struct gsm_subscriber *subscr) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 45 | { |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 46 | free(subscr); |
| 47 | } |
| 48 | |
| 49 | struct gsm_subscriber *subscr_get_by_tmsi(char *tmsi) |
| 50 | { |
| 51 | struct gsm_subscriber *subscr = subscr_alloc(); |
| 52 | |
| 53 | strncpy(subscr->tmsi, tmsi, sizeof(subscr->tmsi)); |
| 54 | subscr->tmsi[sizeof(subscr->tmsi)-1] = '\0'; |
| 55 | |
| 56 | if (db_get_subscriber(GSM_SUBSCRIBER_TMSI, subscr) != 0) { |
| 57 | subscr_free(subscr); |
| 58 | subscr = NULL; |
| 59 | } |
| 60 | |
| 61 | return subscr; |
| 62 | } |
| 63 | |
| 64 | struct gsm_subscriber *subscr_get_by_imsi(char *imsi) |
| 65 | { |
| 66 | struct gsm_subscriber *subscr = subscr_alloc(); |
| 67 | |
| 68 | strncpy(subscr->imsi, imsi, sizeof(subscr->imsi)); |
| 69 | subscr->imsi[sizeof(subscr->imsi)-1] = '\0'; |
| 70 | |
| 71 | if (db_get_subscriber(GSM_SUBSCRIBER_IMSI, subscr) != 0) { |
| 72 | subscr_free(subscr); |
| 73 | subscr = NULL; |
| 74 | } |
| 75 | |
| 76 | return subscr; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts) |
| 80 | { |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 81 | return db_set_subscriber(s); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 82 | } |