blob: fcf91ae51f6a22efb507272e14d8017367bb9281 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* Dummy implementation of a subscriber database, roghly HLR/VLR functionality */
2
3/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00004 *
Harald Welte52b1f982008-12-23 20:25:15 +00005 * 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 Welte75a983f2008-12-27 21:34:06 +000023#include <unistd.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
Harald Welte52b1f982008-12-23 20:25:15 +000027
Harald Welte8470bf22008-12-25 23:28:35 +000028#include <openbsc/gsm_subscriber.h>
Harald Welte75a983f2008-12-27 21:34:06 +000029#include <openbsc/db.h>
Harald Welte52b1f982008-12-23 20:25:15 +000030
Harald Welte75a983f2008-12-27 21:34:06 +000031struct gsm_subscriber *subscr_alloc(void)
Harald Welte52b1f982008-12-23 20:25:15 +000032{
Harald Welte75a983f2008-12-27 21:34:06 +000033 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 Welte52b1f982008-12-23 20:25:15 +000042}
Harald Welte75a983f2008-12-27 21:34:06 +000043
44void subscr_free(struct gsm_subscriber *subscr)
Harald Welte52b1f982008-12-23 20:25:15 +000045{
Harald Welte75a983f2008-12-27 21:34:06 +000046 free(subscr);
47}
48
49struct 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
64struct 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 Welte52b1f982008-12-23 20:25:15 +000077}
78
79int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts)
80{
Harald Welte75a983f2008-12-27 21:34:06 +000081 return db_set_subscriber(s);
Harald Welte52b1f982008-12-23 20:25:15 +000082}