Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* A hackish minimal BSC (+MSC +HLR) implementation */ |
| 2 | |
Harald Welte | 0677061 | 2010-01-12 10:46:27 +0100 | [diff] [blame] | 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | 219518d | 2009-01-02 22:04:43 +0000 | [diff] [blame] | 4 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 22 | #include <unistd.h> |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 23 | #include <time.h> |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 24 | #include <errno.h> |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 25 | #include <signal.h> |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 26 | #include <fcntl.h> |
| 27 | #include <sys/stat.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 28 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 29 | #define _GNU_SOURCE |
| 30 | #include <getopt.h> |
| 31 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 32 | #include <openbsc/db.h> |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 33 | #include <osmocore/select.h> |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 34 | #include <osmocore/process.h> |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 35 | #include <openbsc/debug.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 36 | #include <openbsc/e1_input.h> |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 37 | #include <osmocore/talloc.h> |
Harald Welte | 3961fcc | 2009-11-30 19:37:18 +0100 | [diff] [blame] | 38 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | ec4bfdc | 2010-06-30 14:30:35 +0800 | [diff] [blame] | 39 | #include <openbsc/osmo_msc.h> |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 40 | #include <openbsc/sms_queue.h> |
Holger Hans Peter Freyther | 7a2c86b | 2010-08-26 15:38:42 +0800 | [diff] [blame] | 41 | #include <openbsc/vty.h> |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 42 | |
| 43 | #include "../bscconfig.h" |
| 44 | |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 45 | /* MCC and MNC for the Location Area Identifier */ |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 46 | static struct log_target *stderr_target; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 47 | struct gsm_network *bsc_gsmnet = 0; |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 48 | static const char *database_name = "hlr.sqlite3"; |
Holger Hans Peter Freyther | d5d1cef | 2009-08-10 08:39:27 +0200 | [diff] [blame] | 49 | static const char *config_file = "openbsc.cfg"; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 50 | extern const char *openbsc_copyright; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 51 | static int daemonize = 0; |
Harald Welte | 02d9966 | 2010-12-23 01:31:07 +0100 | [diff] [blame] | 52 | static int use_mncc_sock = 0; |
Holger Hans Peter Freyther | 079353a | 2009-12-23 05:29:04 +0100 | [diff] [blame] | 53 | |
| 54 | /* timer to store statistics */ |
| 55 | #define DB_SYNC_INTERVAL 60, 0 |
| 56 | static struct timer_list db_sync_timer; |
| 57 | |
Holger Hans Peter Freyther | 1cc7184 | 2011-01-06 14:13:44 +0100 | [diff] [blame] | 58 | extern int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *), |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 59 | const char *cfg_file); |
| 60 | extern int bsc_shutdown_net(struct gsm_network *net); |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 61 | |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 62 | static void create_pcap_file(char *file) |
| 63 | { |
| 64 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
| 65 | int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode); |
| 66 | |
| 67 | if (fd < 0) { |
| 68 | perror("Failed to open file for pcap"); |
| 69 | return; |
| 70 | } |
| 71 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 72 | e1_set_pcap_fd(fd); |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 75 | static void print_usage() |
| 76 | { |
| 77 | printf("Usage: bsc_hack\n"); |
| 78 | } |
| 79 | |
| 80 | static void print_help() |
| 81 | { |
| 82 | printf(" Some useful help...\n"); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 83 | printf(" -h --help this text\n"); |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 84 | printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n"); |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 85 | printf(" -D --daemonize Fork the process into a background daemon\n"); |
Holger Hans Peter Freyther | d5d1cef | 2009-08-10 08:39:27 +0200 | [diff] [blame] | 86 | printf(" -c --config-file filename The config file to use.\n"); |
Holger Hans Peter Freyther | 009ad61 | 2010-03-25 02:41:38 +0100 | [diff] [blame] | 87 | printf(" -s --disable-color\n"); |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 88 | printf(" -l --database db-name The database to use\n"); |
Holger Hans Peter Freyther | 009ad61 | 2010-03-25 02:41:38 +0100 | [diff] [blame] | 89 | printf(" -a --authorize-everyone. Authorize every new subscriber. Dangerous!.\n"); |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 90 | printf(" -p --pcap file The filename of the pcap file\n"); |
Harald Welte | c70979a | 2009-08-12 21:52:11 +0200 | [diff] [blame] | 91 | printf(" -T --timestamp Prefix every log line with a timestamp\n"); |
Holger Hans Peter Freyther | 009ad61 | 2010-03-25 02:41:38 +0100 | [diff] [blame] | 92 | printf(" -V --version. Print the version of OpenBSC.\n"); |
Harald Welte | f314f68 | 2009-12-18 15:05:02 +0100 | [diff] [blame] | 93 | printf(" -P --rtp-proxy Enable the RTP Proxy code inside OpenBSC\n"); |
Holger Hans Peter Freyther | 829772d | 2010-03-25 02:39:15 +0100 | [diff] [blame] | 94 | printf(" -e --log-level number. Set a global loglevel.\n"); |
Harald Welte | 02d9966 | 2010-12-23 01:31:07 +0100 | [diff] [blame] | 95 | printf(" -m --mncc-sock Disable built-in MNCC handler and offer socket\n"); |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 98 | static void handle_options(int argc, char **argv) |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 99 | { |
| 100 | while (1) { |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 101 | int option_index = 0, c; |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 102 | static struct option long_options[] = { |
| 103 | {"help", 0, 0, 'h'}, |
| 104 | {"debug", 1, 0, 'd'}, |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 105 | {"daemonize", 0, 0, 'D'}, |
Holger Hans Peter Freyther | d5d1cef | 2009-08-10 08:39:27 +0200 | [diff] [blame] | 106 | {"config-file", 1, 0, 'c'}, |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 107 | {"disable-color", 0, 0, 's'}, |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 108 | {"database", 1, 0, 'l'}, |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 109 | {"authorize-everyone", 0, 0, 'a'}, |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 110 | {"pcap", 1, 0, 'p'}, |
Harald Welte | d3ff51d | 2009-06-09 20:21:57 +0000 | [diff] [blame] | 111 | {"timestamp", 0, 0, 'T'}, |
Harald Welte | 5a29c7f | 2010-03-23 00:09:32 +0800 | [diff] [blame] | 112 | {"version", 0, 0, 'V' }, |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 113 | {"rtp-proxy", 0, 0, 'P'}, |
Holger Hans Peter Freyther | 829772d | 2010-03-25 02:39:15 +0100 | [diff] [blame] | 114 | {"log-level", 1, 0, 'e'}, |
Harald Welte | 02d9966 | 2010-12-23 01:31:07 +0100 | [diff] [blame] | 115 | {"mncc-sock", 0, 0, 'm'}, |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 116 | {0, 0, 0, 0} |
| 117 | }; |
| 118 | |
Harald Welte | 02d9966 | 2010-12-23 01:31:07 +0100 | [diff] [blame] | 119 | c = getopt_long(argc, argv, "hd:Dsl:ar:p:TPVc:e:m", |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 120 | long_options, &option_index); |
| 121 | if (c == -1) |
| 122 | break; |
| 123 | |
| 124 | switch (c) { |
| 125 | case 'h': |
| 126 | print_usage(); |
| 127 | print_help(); |
| 128 | exit(0); |
Holger Freyther | efde7fb | 2008-12-28 14:14:56 +0000 | [diff] [blame] | 129 | case 's': |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 130 | log_set_use_color(stderr_target, 0); |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 131 | break; |
| 132 | case 'd': |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 133 | log_parse_category_mask(stderr_target, optarg); |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 134 | break; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 135 | case 'D': |
| 136 | daemonize = 1; |
| 137 | break; |
Harald Welte | 8965da4 | 2009-01-06 18:09:02 +0000 | [diff] [blame] | 138 | case 'l': |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 139 | database_name = strdup(optarg); |
| 140 | break; |
Holger Hans Peter Freyther | d5d1cef | 2009-08-10 08:39:27 +0200 | [diff] [blame] | 141 | case 'c': |
| 142 | config_file = strdup(optarg); |
| 143 | break; |
Holger Freyther | 9a3ee0f | 2009-01-02 00:40:15 +0000 | [diff] [blame] | 144 | case 'p': |
| 145 | create_pcap_file(optarg); |
| 146 | break; |
Harald Welte | d3ff51d | 2009-06-09 20:21:57 +0000 | [diff] [blame] | 147 | case 'T': |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 148 | log_set_print_timestamp(stderr_target, 1); |
Harald Welte | d3ff51d | 2009-06-09 20:21:57 +0000 | [diff] [blame] | 149 | break; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 150 | case 'P': |
| 151 | ipacc_rtp_direct = 0; |
| 152 | break; |
Holger Hans Peter Freyther | 829772d | 2010-03-25 02:39:15 +0100 | [diff] [blame] | 153 | case 'e': |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 154 | log_set_log_level(stderr_target, atoi(optarg)); |
Holger Hans Peter Freyther | 829772d | 2010-03-25 02:39:15 +0100 | [diff] [blame] | 155 | break; |
Harald Welte | 02d9966 | 2010-12-23 01:31:07 +0100 | [diff] [blame] | 156 | case 'm': |
| 157 | use_mncc_sock = 1; |
| 158 | break; |
Harald Welte | 5a29c7f | 2010-03-23 00:09:32 +0800 | [diff] [blame] | 159 | case 'V': |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 160 | print_version(1); |
Harald Welte | 5a29c7f | 2010-03-23 00:09:32 +0800 | [diff] [blame] | 161 | exit(0); |
| 162 | break; |
Holger Freyther | b332f61 | 2008-12-27 12:46:51 +0000 | [diff] [blame] | 163 | default: |
| 164 | /* ignore */ |
| 165 | break; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
Harald Welte | 3cefa9a | 2009-12-24 10:51:56 +0100 | [diff] [blame] | 170 | extern void *tall_vty_ctx; |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 171 | static void signal_handler(int signal) |
| 172 | { |
| 173 | fprintf(stdout, "signal %u received\n", signal); |
| 174 | |
| 175 | switch (signal) { |
Harald Welte | f294f45 | 2009-08-06 17:43:50 +0200 | [diff] [blame] | 176 | case SIGINT: |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 177 | bsc_shutdown_net(bsc_gsmnet); |
Harald Welte | 3961fcc | 2009-11-30 19:37:18 +0100 | [diff] [blame] | 178 | dispatch_signal(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL); |
Harald Welte | f294f45 | 2009-08-06 17:43:50 +0200 | [diff] [blame] | 179 | sleep(3); |
| 180 | exit(0); |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 181 | break; |
Harald Welte | 31c3d34 | 2009-08-07 00:29:44 +0200 | [diff] [blame] | 182 | case SIGABRT: |
| 183 | /* in case of abort, we want to obtain a talloc report |
| 184 | * and then return to the caller, who will abort the process */ |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 185 | case SIGUSR1: |
Harald Welte | 3cefa9a | 2009-12-24 10:51:56 +0100 | [diff] [blame] | 186 | talloc_report(tall_vty_ctx, stderr); |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 187 | talloc_report_full(tall_bsc_ctx, stderr); |
| 188 | break; |
Harald Welte | 3cefa9a | 2009-12-24 10:51:56 +0100 | [diff] [blame] | 189 | case SIGUSR2: |
| 190 | talloc_report_full(tall_vty_ctx, stderr); |
| 191 | break; |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 192 | default: |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
Holger Hans Peter Freyther | 079353a | 2009-12-23 05:29:04 +0100 | [diff] [blame] | 197 | /* timer handling */ |
| 198 | static int _db_store_counter(struct counter *counter, void *data) |
| 199 | { |
| 200 | return db_store_counter(counter); |
| 201 | } |
| 202 | |
| 203 | static void db_sync_timer_cb(void *data) |
| 204 | { |
| 205 | /* store counters to database and re-schedule */ |
| 206 | counters_for_each(_db_store_counter, NULL); |
| 207 | bsc_schedule_timer(&db_sync_timer, DB_SYNC_INTERVAL); |
| 208 | } |
| 209 | |
Daniel Willmann | 604d851 | 2010-01-11 13:50:44 +0100 | [diff] [blame] | 210 | extern int bts_model_unknown_init(void); |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 211 | extern int bts_model_bs11_init(void); |
| 212 | extern int bts_model_nanobts_init(void); |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 213 | extern int bts_model_rbs2k_init(void); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 214 | extern int bts_model_hslfemto_init(void); |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 215 | void talloc_ctx_init(void); |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 216 | |
Holger Hans Peter Freyther | 57da447 | 2010-06-08 16:11:06 +0800 | [diff] [blame] | 217 | extern enum node_type bsc_vty_go_parent(struct vty *vty); |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 218 | |
| 219 | static struct vty_app_info vty_info = { |
| 220 | .name = "OpenBSC", |
| 221 | .version = PACKAGE_VERSION, |
| 222 | .go_parent_cb = bsc_vty_go_parent, |
Holger Hans Peter Freyther | 7a2c86b | 2010-08-26 15:38:42 +0800 | [diff] [blame] | 223 | .is_config_node = bsc_vty_is_config_node, |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 224 | }; |
| 225 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 226 | int main(int argc, char **argv) |
| 227 | { |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 228 | int rc; |
| 229 | |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 230 | vty_info.copyright = openbsc_copyright; |
| 231 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 232 | log_init(&log_info); |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 233 | tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc"); |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 234 | talloc_ctx_init(); |
Harald Welte (local) | 50d1271 | 2009-08-13 13:52:14 +0200 | [diff] [blame] | 235 | on_dso_load_token(); |
Harald Welte (local) | b8afe81 | 2009-08-16 13:18:51 +0200 | [diff] [blame] | 236 | on_dso_load_rrlp(); |
Harald Welte | 8d77b95 | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 237 | on_dso_load_ho_dec(); |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 238 | stderr_target = log_target_create_stderr(); |
| 239 | log_add_target(stderr_target); |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 240 | |
Daniel Willmann | 604d851 | 2010-01-11 13:50:44 +0100 | [diff] [blame] | 241 | bts_model_unknown_init(); |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 242 | bts_model_bs11_init(); |
| 243 | bts_model_nanobts_init(); |
Harald Welte | 03cc8a8 | 2011-02-11 18:59:31 +0100 | [diff] [blame] | 244 | bts_model_rbs2k_init(); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 245 | bts_model_hslfemto_init(); |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 246 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 247 | e1inp_init(); |
| 248 | |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 249 | /* enable filters */ |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 250 | log_set_all_filter(stderr_target, 1); |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 251 | |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 252 | /* This needs to precede handle_options() */ |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 253 | vty_init(&vty_info); |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 254 | bsc_vty_init(); |
| 255 | |
Holger Hans Peter Freyther | 0c8aa73 | 2010-05-31 21:42:53 +0800 | [diff] [blame] | 256 | /* parse options */ |
| 257 | handle_options(argc, argv); |
| 258 | |
Harald Welte | 02d9966 | 2010-12-23 01:31:07 +0100 | [diff] [blame] | 259 | /* internal MNCC handler or MNCC socket? */ |
| 260 | if (use_mncc_sock) { |
| 261 | rc = bsc_bootstrap_network(mncc_sock_from_cc, config_file); |
| 262 | if (rc >= 0) |
| 263 | mncc_sock_init(bsc_gsmnet); |
| 264 | } else |
| 265 | rc = bsc_bootstrap_network(int_mncc_recv, config_file); |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 266 | if (rc < 0) |
| 267 | exit(1); |
Holger Hans Peter Freyther | ec4bfdc | 2010-06-30 14:30:35 +0800 | [diff] [blame] | 268 | bsc_api_init(bsc_gsmnet, msc_bsc_api()); |
Harald Welte | e8e432d | 2010-12-23 00:16:34 +0100 | [diff] [blame] | 269 | mncc_sock_init(bsc_gsmnet); |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 270 | |
Harald Welte | 65ccf88 | 2009-02-24 22:36:20 +0000 | [diff] [blame] | 271 | /* seed the PRNG */ |
| 272 | srand(time(NULL)); |
| 273 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 274 | if (db_init(database_name)) { |
| 275 | printf("DB: Failed to init database. Please check the option settings.\n"); |
| 276 | return -1; |
| 277 | } |
| 278 | printf("DB: Database initialized.\n"); |
| 279 | |
| 280 | if (db_prepare()) { |
| 281 | printf("DB: Failed to prepare database.\n"); |
| 282 | return -1; |
| 283 | } |
| 284 | printf("DB: Database prepared.\n"); |
| 285 | |
Holger Hans Peter Freyther | 079353a | 2009-12-23 05:29:04 +0100 | [diff] [blame] | 286 | /* setup the timer */ |
| 287 | db_sync_timer.cb = db_sync_timer_cb; |
| 288 | db_sync_timer.data = NULL; |
| 289 | bsc_schedule_timer(&db_sync_timer, DB_SYNC_INTERVAL); |
| 290 | |
Harald Welte | f294f45 | 2009-08-06 17:43:50 +0200 | [diff] [blame] | 291 | signal(SIGINT, &signal_handler); |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 292 | signal(SIGABRT, &signal_handler); |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 293 | signal(SIGUSR1, &signal_handler); |
Harald Welte | 3cefa9a | 2009-12-24 10:51:56 +0100 | [diff] [blame] | 294 | signal(SIGUSR2, &signal_handler); |
Holger Hans Peter Freyther | f49fac2 | 2009-11-24 20:06:41 +0100 | [diff] [blame] | 295 | signal(SIGPIPE, SIG_IGN); |
Harald Welte | d125250 | 2009-01-01 01:50:32 +0000 | [diff] [blame] | 296 | |
Holger Hans Peter Freyther | 11b28f9 | 2010-12-24 13:48:27 +0100 | [diff] [blame] | 297 | /* start the SMS queue */ |
Holger Hans Peter Freyther | a37e3bc | 2010-12-25 17:43:03 +0100 | [diff] [blame] | 298 | if (sms_queue_start(bsc_gsmnet, 20) != 0) |
Holger Hans Peter Freyther | 11b28f9 | 2010-12-24 13:48:27 +0100 | [diff] [blame] | 299 | return -1; |
| 300 | |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 301 | if (daemonize) { |
| 302 | rc = osmo_daemonize(); |
| 303 | if (rc < 0) { |
| 304 | perror("Error during daemonize"); |
| 305 | exit(1); |
| 306 | } |
| 307 | } |
| 308 | |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 309 | while (1) { |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 310 | log_reset_context(); |
Harald Welte | 04d3c92 | 2009-05-23 06:07:04 +0000 | [diff] [blame] | 311 | bsc_select_main(0); |
Harald Welte | f6b7a90 | 2008-12-26 00:05:11 +0000 | [diff] [blame] | 312 | } |
| 313 | } |