Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 1 | /* (C) 2008 by Jan Luebbe <jluebbe@debian.org> |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 2 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 6 | * 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 |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 8 | * (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 Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * 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/>. |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 20 | #include <openbsc/debug.h> |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 21 | #include <openbsc/db.h> |
Holger Hans Peter Freyther | ef3b59d | 2010-12-22 18:21:14 +0100 | [diff] [blame] | 22 | #include <openbsc/gsm_subscriber.h> |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 23 | |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 24 | #include <osmocom/core/application.h> |
| 25 | |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <string.h> |
Harald Welte | 5bc7c17 | 2009-05-21 07:23:02 +0000 | [diff] [blame] | 28 | #include <stdlib.h> |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 29 | |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 30 | static struct gsm_network dummy_net; |
| 31 | |
| 32 | #define SUBSCR_PUT(sub) \ |
| 33 | sub->net = &dummy_net; \ |
| 34 | subscr_put(sub); |
| 35 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 36 | #define COMPARE(original, copy) \ |
| 37 | if (original->id != copy->id) \ |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 38 | printf("Ids do not match in %s:%d %llu %llu\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 39 | __FUNCTION__, __LINE__, original->id, copy->id); \ |
| 40 | if (original->lac != copy->lac) \ |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 41 | printf("LAC do not match in %s:%d %d %d\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 42 | __FUNCTION__, __LINE__, original->lac, copy->lac); \ |
| 43 | if (original->authorized != copy->authorized) \ |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 44 | printf("Authorize do not match in %s:%d %d %d\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 45 | __FUNCTION__, __LINE__, original->authorized, \ |
| 46 | copy->authorized); \ |
| 47 | if (strcmp(original->imsi, copy->imsi) != 0) \ |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 48 | printf("IMSIs do not match in %s:%d '%s' '%s'\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 49 | __FUNCTION__, __LINE__, original->imsi, copy->imsi); \ |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 50 | if (original->tmsi != copy->tmsi) \ |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 51 | printf("TMSIs do not match in %s:%d '%u' '%u'\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 52 | __FUNCTION__, __LINE__, original->tmsi, copy->tmsi); \ |
| 53 | if (strcmp(original->name, copy->name) != 0) \ |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 54 | printf("names do not match in %s:%d '%s' '%s'\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 55 | __FUNCTION__, __LINE__, original->name, copy->name); \ |
| 56 | if (strcmp(original->extension, copy->extension) != 0) \ |
Alexander Chemeris | 35f1290 | 2013-10-04 02:42:24 +0200 | [diff] [blame] | 57 | printf("Extensions do not match in %s:%d '%s' '%s'\n", \ |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 58 | __FUNCTION__, __LINE__, original->extension, copy->extension); \ |
| 59 | |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 60 | int main() |
| 61 | { |
| 62 | printf("Testing subscriber database code.\n"); |
| 63 | osmo_init_logging(&log_info); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 64 | |
Holger Freyther | 761fdec | 2009-06-06 13:54:20 +0000 | [diff] [blame] | 65 | if (db_init("hlr.sqlite3")) { |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 66 | printf("DB: Failed to init database. Please check the option settings.\n"); |
| 67 | return 1; |
| 68 | } |
| 69 | printf("DB: Database initialized.\n"); |
| 70 | |
| 71 | if (db_prepare()) { |
| 72 | printf("DB: Failed to prepare database.\n"); |
| 73 | return 1; |
| 74 | } |
| 75 | printf("DB: Database prepared.\n"); |
| 76 | |
| 77 | struct gsm_subscriber *alice = NULL; |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 78 | struct gsm_subscriber *alice_db; |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 79 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 80 | char *alice_imsi = "3243245432345"; |
Holger Hans Peter Freyther | abe587d | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 81 | alice = db_create_subscriber(alice_imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 82 | db_sync_subscriber(alice); |
Holger Hans Peter Freyther | abe587d | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 83 | alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice->imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 84 | COMPARE(alice, alice_db); |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 85 | SUBSCR_PUT(alice_db); |
| 86 | SUBSCR_PUT(alice); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 87 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 88 | alice_imsi = "3693245423445"; |
Holger Hans Peter Freyther | abe587d | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 89 | alice = db_create_subscriber(alice_imsi); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 90 | db_subscriber_assoc_imei(alice, "1234567890"); |
| 91 | db_subscriber_alloc_tmsi(alice); |
| 92 | alice->lac=42; |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 93 | db_sync_subscriber(alice); |
Holger Hans Peter Freyther | abe587d | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 94 | alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice_imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 95 | COMPARE(alice, alice_db); |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 96 | SUBSCR_PUT(alice); |
| 97 | SUBSCR_PUT(alice_db); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 98 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 99 | alice_imsi = "9993245423445"; |
Holger Hans Peter Freyther | abe587d | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 100 | alice = db_create_subscriber(alice_imsi); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 101 | db_subscriber_alloc_tmsi(alice); |
| 102 | alice->lac=42; |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 103 | db_sync_subscriber(alice); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 104 | db_subscriber_assoc_imei(alice, "1234567890"); |
| 105 | db_subscriber_assoc_imei(alice, "6543560920"); |
Holger Hans Peter Freyther | abe587d | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 106 | alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice_imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 107 | COMPARE(alice, alice_db); |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 108 | SUBSCR_PUT(alice); |
| 109 | SUBSCR_PUT(alice_db); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 110 | |
| 111 | db_fini(); |
| 112 | |
Holger Hans Peter Freyther | 99f47fb | 2012-01-06 14:27:08 +0100 | [diff] [blame] | 113 | printf("Done\n"); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 114 | return 0; |
| 115 | } |
Holger Freyther | 4b8eadf | 2009-04-12 05:37:07 +0000 | [diff] [blame] | 116 | |
| 117 | /* stubs */ |
Holger Hans Peter Freyther | 0fe0c8c | 2010-12-29 11:07:22 +0100 | [diff] [blame] | 118 | void vty_out() {} |