blob: 3c5de9026d9eb3a571003b89e5affbb250660158 [file] [log] [blame]
Jan Luebbefaaa49c2008-12-27 01:07:07 +00001/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
Holger Freyther12aa50d2009-01-01 18:02:05 +00002 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Jan Luebbefaaa49c2008-12-27 01:07:07 +00003 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01006 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
Jan Luebbefaaa49c2008-12-27 01:07:07 +00008 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Jan Luebbefaaa49c2008-12-27 01:07:07 +000017 *
18 */
19
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010020#include <openbsc/debug.h>
Jan Luebbefaaa49c2008-12-27 01:07:07 +000021#include <openbsc/db.h>
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010022#include <openbsc/gsm_subscriber.h>
Jan Luebbe7398eb92008-12-27 00:45:41 +000023
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010024#include <osmocom/core/application.h>
25
Jan Luebbe7398eb92008-12-27 00:45:41 +000026#include <stdio.h>
Jan Luebbe5c15c852008-12-27 15:59:25 +000027#include <string.h>
Harald Welte12247c62009-05-21 07:23:02 +000028#include <stdlib.h>
Jan Luebbe7398eb92008-12-27 00:45:41 +000029
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010030static struct gsm_network dummy_net;
31
32#define SUBSCR_PUT(sub) \
33 sub->net = &dummy_net; \
34 subscr_put(sub);
35
Holger Freyther12aa50d2009-01-01 18:02:05 +000036#define COMPARE(original, copy) \
37 if (original->id != copy->id) \
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010038 printf("Ids do not match in %s:%d %llu %llu\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000039 __FUNCTION__, __LINE__, original->id, copy->id); \
40 if (original->lac != copy->lac) \
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010041 printf("LAC do not match in %s:%d %d %d\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000042 __FUNCTION__, __LINE__, original->lac, copy->lac); \
43 if (original->authorized != copy->authorized) \
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010044 printf("Authorize do not match in %s:%d %d %d\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000045 __FUNCTION__, __LINE__, original->authorized, \
46 copy->authorized); \
47 if (strcmp(original->imsi, copy->imsi) != 0) \
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010048 printf("IMSIs do not match in %s:%d '%s' '%s'\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000049 __FUNCTION__, __LINE__, original->imsi, copy->imsi); \
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +020050 if (original->tmsi != copy->tmsi) \
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010051 printf("TMSIs do not match in %s:%d '%u' '%u'\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000052 __FUNCTION__, __LINE__, original->tmsi, copy->tmsi); \
53 if (strcmp(original->name, copy->name) != 0) \
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010054 printf("names do not match in %s:%d '%s' '%s'\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000055 __FUNCTION__, __LINE__, original->name, copy->name); \
56 if (strcmp(original->extension, copy->extension) != 0) \
Alexander Chemeris86d46c52013-10-04 02:42:24 +020057 printf("Extensions do not match in %s:%d '%s' '%s'\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000058 __FUNCTION__, __LINE__, original->extension, copy->extension); \
59
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010060int main()
61{
62 printf("Testing subscriber database code.\n");
63 osmo_init_logging(&log_info);
Jan Luebbe7398eb92008-12-27 00:45:41 +000064
Holger Freytherc7b86f92009-06-06 13:54:20 +000065 if (db_init("hlr.sqlite3")) {
Jan Luebbe5c15c852008-12-27 15:59:25 +000066 printf("DB: Failed to init database. Please check the option settings.\n");
67 return 1;
68 }
69 printf("DB: Database initialized.\n");
Jan Luebbe7398eb92008-12-27 00:45:41 +000070
Jan Luebbe5c15c852008-12-27 15:59:25 +000071 if (db_prepare()) {
72 printf("DB: Failed to prepare database.\n");
73 return 1;
74 }
75 printf("DB: Database prepared.\n");
Jan Luebbe7398eb92008-12-27 00:45:41 +000076
Jan Luebbe5c15c852008-12-27 15:59:25 +000077 struct gsm_subscriber *alice = NULL;
Holger Freyther12aa50d2009-01-01 18:02:05 +000078 struct gsm_subscriber *alice_db;
Jan Luebbe7398eb92008-12-27 00:45:41 +000079
Holger Freyther12aa50d2009-01-01 18:02:05 +000080 char *alice_imsi = "3243245432345";
Holger Hans Peter Freyther7634ec12013-10-04 08:35:11 +020081 alice = db_create_subscriber(alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000082 db_sync_subscriber(alice);
Holger Hans Peter Freyther7634ec12013-10-04 08:35:11 +020083 alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice->imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000084 COMPARE(alice, alice_db);
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010085 SUBSCR_PUT(alice_db);
86 SUBSCR_PUT(alice);
Jan Luebbe7398eb92008-12-27 00:45:41 +000087
Holger Freyther12aa50d2009-01-01 18:02:05 +000088 alice_imsi = "3693245423445";
Holger Hans Peter Freyther7634ec12013-10-04 08:35:11 +020089 alice = db_create_subscriber(alice_imsi);
Jan Luebbe391d86e2008-12-27 22:33:34 +000090 db_subscriber_assoc_imei(alice, "1234567890");
Jan Luebbe5c15c852008-12-27 15:59:25 +000091 db_subscriber_alloc_tmsi(alice);
92 alice->lac=42;
Holger Freyther12aa50d2009-01-01 18:02:05 +000093 db_sync_subscriber(alice);
Holger Hans Peter Freyther7634ec12013-10-04 08:35:11 +020094 alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000095 COMPARE(alice, alice_db);
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +010096 SUBSCR_PUT(alice);
97 SUBSCR_PUT(alice_db);
Jan Luebbe7398eb92008-12-27 00:45:41 +000098
Holger Freyther12aa50d2009-01-01 18:02:05 +000099 alice_imsi = "9993245423445";
Holger Hans Peter Freyther7634ec12013-10-04 08:35:11 +0200100 alice = db_create_subscriber(alice_imsi);
Jan Luebbe5c15c852008-12-27 15:59:25 +0000101 db_subscriber_alloc_tmsi(alice);
102 alice->lac=42;
Holger Freyther12aa50d2009-01-01 18:02:05 +0000103 db_sync_subscriber(alice);
Jan Luebbefac25fc2008-12-27 18:04:34 +0000104 db_subscriber_assoc_imei(alice, "1234567890");
105 db_subscriber_assoc_imei(alice, "6543560920");
Holger Hans Peter Freyther7634ec12013-10-04 08:35:11 +0200106 alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +0000107 COMPARE(alice, alice_db);
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +0100108 SUBSCR_PUT(alice);
109 SUBSCR_PUT(alice_db);
Jan Luebbe5c15c852008-12-27 15:59:25 +0000110
111 db_fini();
112
Holger Hans Peter Freyther45222a72012-01-06 14:27:08 +0100113 printf("Done\n");
Jan Luebbe5c15c852008-12-27 15:59:25 +0000114 return 0;
Jan Luebbe7398eb92008-12-27 00:45:41 +0000115}
Holger Freytherbab9cd92009-04-12 05:37:07 +0000116
117/* stubs */
Holger Hans Peter Freyther763b42a2010-12-29 11:07:22 +0100118void vty_out() {}