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