Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 1 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 52b0921 | 2011-04-07 23:23:27 +0200 | [diff] [blame] | 2 | * (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2009-2011 by On-Waves |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Holger Hans Peter Freyther | 13aa545 | 2012-03-16 11:54:55 +0100 | [diff] [blame] | 21 | #include <openbsc/bss.h> |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 22 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 23 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 24 | #include <openbsc/osmo_bsc.h> |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 25 | #include <openbsc/osmo_bsc_rf.h> |
Neels Hofmeyr | 3863935 | 2017-02-23 21:49:55 +0100 | [diff] [blame] | 26 | #include <openbsc/bsc_msc_data.h> |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 27 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 19ce77c | 2010-08-26 15:38:42 +0800 | [diff] [blame] | 28 | #include <openbsc/vty.h> |
Daniel Willmann | c3e308d | 2011-02-18 16:17:58 +0100 | [diff] [blame] | 29 | #include <openbsc/ipaccess.h> |
Harald Welte | 5919b6a | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 30 | #include <openbsc/ctrl.h> |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 31 | |
Harald Welte | 5919b6a | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 32 | #include <osmocom/ctrl/control_cmd.h> |
| 33 | #include <osmocom/ctrl/control_if.h> |
Harald Welte | 6bcd303 | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 34 | #include <osmocom/ctrl/ports.h> |
Neels Hofmeyr | 4d92c43 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 35 | #include <osmocom/ctrl/control_vty.h> |
Daniel Willmann | 5c3bad9 | 2011-07-22 17:55:42 +0200 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 37 | #include <osmocom/core/application.h> |
Daniel Willmann | ba5eb24 | 2011-06-30 11:03:07 +0200 | [diff] [blame] | 38 | #include <osmocom/core/linuxlist.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 39 | #include <osmocom/core/talloc.h> |
Jacob Erlbeck | 63fac68 | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 40 | #include <osmocom/core/stats.h> |
Daniel Willmann | c3e308d | 2011-02-18 16:17:58 +0100 | [diff] [blame] | 41 | #include <osmocom/gsm/protocol/gsm_12_21.h> |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 42 | |
Holger Hans Peter Freyther | 13aa545 | 2012-03-16 11:54:55 +0100 | [diff] [blame] | 43 | #include <osmocom/abis/abis.h> |
| 44 | |
Harald Welte | 90e5eae | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 45 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | a8dffc1 | 2010-07-30 02:53:14 +0800 | [diff] [blame] | 46 | |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 47 | #define _GNU_SOURCE |
| 48 | #include <getopt.h> |
| 49 | |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 50 | #include <signal.h> |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 51 | #include <stdio.h> |
| 52 | #include <stdlib.h> |
| 53 | #include <time.h> |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 54 | #include <unistd.h> |
| 55 | |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 56 | |
Harald Welte | d9dea59 | 2011-03-04 13:53:51 +0100 | [diff] [blame] | 57 | #include "../../bscconfig.h" |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 58 | |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 59 | struct gsm_network *bsc_gsmnet = 0; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 60 | static const char *config_file = "openbsc.cfg"; |
Holger Hans Peter Freyther | 410ee27 | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 61 | static const char *rf_ctrl = NULL; |
Holger Hans Peter Freyther | 971532f | 2010-09-11 13:28:42 +0800 | [diff] [blame] | 62 | extern const char *openbsc_copyright; |
Harald Welte | c4ae176 | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 63 | static int daemonize = 0; |
Holger Hans Peter Freyther | 48f9a4e | 2015-04-05 20:53:42 +0200 | [diff] [blame] | 64 | static struct llist_head access_lists; |
| 65 | |
| 66 | struct llist_head *bsc_access_lists(void) |
| 67 | { |
| 68 | return &access_lists; |
| 69 | } |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 70 | |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 71 | static void print_usage() |
| 72 | { |
Holger Hans Peter Freyther | 0eebfcc | 2011-04-13 09:17:40 +0200 | [diff] [blame] | 73 | printf("Usage: osmo-bsc\n"); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void print_help() |
| 77 | { |
| 78 | printf(" Some useful help...\n"); |
| 79 | printf(" -h --help this text\n"); |
Harald Welte | c4ae176 | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 80 | printf(" -D --daemonize Fork the process into a background daemon\n"); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 81 | printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n"); |
| 82 | printf(" -s --disable-color\n"); |
| 83 | printf(" -T --timestamp. Print a timestamp in the debug output.\n"); |
| 84 | printf(" -c --config-file filename The config file to use.\n"); |
| 85 | printf(" -l --local=IP. The local address of the MGCP.\n"); |
| 86 | printf(" -e --log-level number. Set a global loglevel.\n"); |
| 87 | printf(" -r --rf-ctl NAME. A unix domain socket to listen for cmds.\n"); |
| 88 | printf(" -t --testmode. A special mode to provoke failures at the MSC.\n"); |
| 89 | } |
| 90 | |
Holger Hans Peter Freyther | dfd61a3 | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 91 | static void handle_options(int argc, char **argv) |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 92 | { |
| 93 | while (1) { |
| 94 | int option_index = 0, c; |
| 95 | static struct option long_options[] = { |
| 96 | {"help", 0, 0, 'h'}, |
| 97 | {"debug", 1, 0, 'd'}, |
Harald Welte | c4ae176 | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 98 | {"daemonize", 0, 0, 'D'}, |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 99 | {"config-file", 1, 0, 'c'}, |
| 100 | {"disable-color", 0, 0, 's'}, |
| 101 | {"timestamp", 0, 0, 'T'}, |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 102 | {"local", 1, 0, 'l'}, |
| 103 | {"log-level", 1, 0, 'e'}, |
| 104 | {"rf-ctl", 1, 0, 'r'}, |
| 105 | {"testmode", 0, 0, 't'}, |
| 106 | {0, 0, 0, 0} |
| 107 | }; |
| 108 | |
Harald Welte | c4ae176 | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 109 | c = getopt_long(argc, argv, "hd:DsTc:e:r:t", |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 110 | long_options, &option_index); |
| 111 | if (c == -1) |
| 112 | break; |
| 113 | |
| 114 | switch (c) { |
| 115 | case 'h': |
| 116 | print_usage(); |
| 117 | print_help(); |
| 118 | exit(0); |
| 119 | case 's': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 120 | log_set_use_color(osmo_stderr_target, 0); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 121 | break; |
| 122 | case 'd': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 123 | log_parse_category_mask(osmo_stderr_target, optarg); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 124 | break; |
Harald Welte | c4ae176 | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 125 | case 'D': |
| 126 | daemonize = 1; |
| 127 | break; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 128 | case 'c': |
Holger Hans Peter Freyther | e00ed29 | 2014-06-12 11:19:38 +0200 | [diff] [blame] | 129 | config_file = optarg; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 130 | break; |
| 131 | case 'T': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 132 | log_set_print_timestamp(osmo_stderr_target, 1); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 133 | break; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 134 | case 'e': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 135 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 136 | break; |
| 137 | case 'r': |
Holger Hans Peter Freyther | 410ee27 | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 138 | rf_ctrl = optarg; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 139 | break; |
| 140 | default: |
| 141 | /* ignore */ |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
Holger Hans Peter Freyther | 4ac8cd1 | 2015-09-24 15:38:38 +0200 | [diff] [blame] | 147 | extern int bsc_vty_go_parent(struct vty *vty); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 148 | |
| 149 | static struct vty_app_info vty_info = { |
Harald Welte | 9af42c3 | 2011-02-24 23:57:06 +0100 | [diff] [blame] | 150 | .name = "OsmoBSC", |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 151 | .version = PACKAGE_VERSION, |
| 152 | .go_parent_cb = bsc_vty_go_parent, |
Holger Hans Peter Freyther | 19ce77c | 2010-08-26 15:38:42 +0800 | [diff] [blame] | 153 | .is_config_node = bsc_vty_is_config_node, |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 154 | }; |
| 155 | |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 156 | extern int bsc_shutdown_net(struct gsm_network *net); |
| 157 | static void signal_handler(int signal) |
| 158 | { |
Neels Hofmeyr | dea1fa3 | 2017-02-23 21:57:23 +0100 | [diff] [blame^] | 159 | struct bsc_msc_data *msc; |
Holger Hans Peter Freyther | 9c5dc14 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 160 | |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 161 | fprintf(stdout, "signal %u received\n", signal); |
| 162 | |
| 163 | switch (signal) { |
| 164 | case SIGINT: |
| 165 | bsc_shutdown_net(bsc_gsmnet); |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 166 | osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL); |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 167 | sleep(3); |
| 168 | exit(0); |
| 169 | break; |
| 170 | case SIGABRT: |
| 171 | /* in case of abort, we want to obtain a talloc report |
| 172 | * and then return to the caller, who will abort the process */ |
| 173 | case SIGUSR1: |
| 174 | talloc_report(tall_vty_ctx, stderr); |
| 175 | talloc_report_full(tall_bsc_ctx, stderr); |
| 176 | break; |
| 177 | case SIGUSR2: |
Holger Hans Peter Freyther | 4d61417 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 178 | if (!bsc_gsmnet->bsc_data) |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 179 | return; |
Holger Hans Peter Freyther | 9c5dc14 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 180 | llist_for_each_entry(msc, &bsc_gsmnet->bsc_data->mscs, entry) |
| 181 | bsc_msc_lost(msc->msc_con); |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 182 | break; |
| 183 | default: |
| 184 | break; |
| 185 | } |
| 186 | } |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 187 | |
| 188 | int main(int argc, char **argv) |
| 189 | { |
Neels Hofmeyr | dea1fa3 | 2017-02-23 21:57:23 +0100 | [diff] [blame^] | 190 | struct bsc_msc_data *msc; |
Holger Hans Peter Freyther | 4d61417 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 191 | struct osmo_bsc_data *data; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 192 | int rc; |
| 193 | |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 194 | tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc"); |
Neels Hofmeyr | 20215f1 | 2016-09-16 02:31:17 +0200 | [diff] [blame] | 195 | msgb_talloc_ctx_init(tall_bsc_ctx, 0); |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 196 | |
Neels Hofmeyr | 7e64394 | 2016-10-24 01:53:38 +0200 | [diff] [blame] | 197 | /* Allocate global gsm_network struct */ |
| 198 | rc = bsc_network_alloc(NULL); |
| 199 | if (rc) { |
| 200 | fprintf(stderr, "Allocation failed. exiting.\n"); |
| 201 | exit(1); |
| 202 | } |
| 203 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 204 | osmo_init_logging(&log_info); |
Jacob Erlbeck | 63fac68 | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 205 | osmo_stats_init(tall_bsc_ctx); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 206 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 207 | bts_init(); |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 208 | libosmo_abis_init(tall_bsc_ctx); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 209 | |
| 210 | /* enable filters */ |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 211 | |
| 212 | /* This needs to precede handle_options() */ |
Holger Hans Peter Freyther | 971532f | 2010-09-11 13:28:42 +0800 | [diff] [blame] | 213 | vty_info.copyright = openbsc_copyright; |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 214 | vty_init(&vty_info); |
Max | 09c26f1 | 2017-01-12 19:35:11 +0100 | [diff] [blame] | 215 | bsc_vty_init(bsc_gsmnet); |
Holger Hans Peter Freyther | fd74c39 | 2015-04-05 19:46:20 +0200 | [diff] [blame] | 216 | bsc_msg_lst_vty_init(tall_bsc_ctx, &access_lists, BSC_NODE); |
Neels Hofmeyr | 4d92c43 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 217 | ctrl_vty_init(tall_bsc_ctx); |
Holger Hans Peter Freyther | fd74c39 | 2015-04-05 19:46:20 +0200 | [diff] [blame] | 218 | |
| 219 | INIT_LLIST_HEAD(&access_lists); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 220 | |
| 221 | /* parse options */ |
| 222 | handle_options(argc, argv); |
| 223 | |
| 224 | /* seed the PRNG */ |
| 225 | srand(time(NULL)); |
| 226 | |
Holger Hans Peter Freyther | a8dffc1 | 2010-07-30 02:53:14 +0800 | [diff] [blame] | 227 | /* initialize SCCP */ |
| 228 | sccp_set_log_area(DSCCP); |
| 229 | |
Neels Hofmeyr | 7e64394 | 2016-10-24 01:53:38 +0200 | [diff] [blame] | 230 | /* Read the config */ |
Neels Hofmeyr | 6318d9f | 2016-05-11 14:12:00 +0200 | [diff] [blame] | 231 | rc = bsc_network_configure(config_file); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 232 | if (rc < 0) { |
| 233 | fprintf(stderr, "Bootstrapping the network failed. exiting.\n"); |
| 234 | exit(1); |
| 235 | } |
Holger Hans Peter Freyther | 7d23130 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 236 | bsc_api_init(bsc_gsmnet, osmo_bsc_api()); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 237 | |
Neels Hofmeyr | 4d92c43 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 238 | /* start control interface after reading config for |
| 239 | * ctrl_vty_get_bind_addr() */ |
Neels Hofmeyr | 4d92c43 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 240 | bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, |
| 241 | ctrl_vty_get_bind_addr(), |
| 242 | OSMO_CTRL_PORT_NITB_BSC); |
Neels Hofmeyr | 1813a34 | 2016-02-24 00:42:44 +0100 | [diff] [blame] | 243 | if (!bsc_gsmnet->ctrl) { |
Daniel Willmann | 6eb756f | 2011-08-05 12:22:35 +0200 | [diff] [blame] | 244 | fprintf(stderr, "Failed to init the control interface. Exiting.\n"); |
| 245 | exit(1); |
| 246 | } |
Daniel Willmann | 5c3bad9 | 2011-07-22 17:55:42 +0200 | [diff] [blame] | 247 | |
Daniel Willmann | 1c2e078 | 2011-10-28 14:23:48 +0200 | [diff] [blame] | 248 | rc = bsc_ctrl_cmds_install(bsc_gsmnet); |
Daniel Willmann | 6eb756f | 2011-08-05 12:22:35 +0200 | [diff] [blame] | 249 | if (rc < 0) { |
| 250 | fprintf(stderr, "Failed to install control commands. Exiting.\n"); |
| 251 | exit(1); |
| 252 | } |
Daniel Willmann | 5a6cd37 | 2011-02-18 14:30:25 +0100 | [diff] [blame] | 253 | |
Holger Hans Peter Freyther | 4d61417 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 254 | data = bsc_gsmnet->bsc_data; |
Holger Hans Peter Freyther | 410ee27 | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 255 | if (rf_ctrl) |
| 256 | bsc_replace_string(data, &data->rf_ctrl_name, rf_ctrl); |
Holger Hans Peter Freyther | 52b0921 | 2011-04-07 23:23:27 +0200 | [diff] [blame] | 257 | |
Holger Hans Peter Freyther | bcfa0b6 | 2014-02-07 20:07:51 +0100 | [diff] [blame] | 258 | data->rf_ctrl = osmo_bsc_rf_create(data->rf_ctrl_name, bsc_gsmnet); |
| 259 | if (!data->rf_ctrl) { |
| 260 | fprintf(stderr, "Failed to create the RF service.\n"); |
| 261 | exit(1); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 262 | } |
| 263 | |
Holger Hans Peter Freyther | 9c5dc14 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 264 | llist_for_each_entry(msc, &bsc_gsmnet->bsc_data->mscs, entry) { |
| 265 | if (osmo_bsc_msc_init(msc) != 0) { |
| 266 | LOGP(DNAT, LOGL_ERROR, "Failed to start up. Exiting.\n"); |
| 267 | exit(1); |
| 268 | } |
Holger Hans Peter Freyther | 05394bc | 2010-09-16 02:14:41 +0800 | [diff] [blame] | 269 | } |
| 270 | |
Holger Hans Peter Freyther | 9c5dc14 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 271 | |
Holger Hans Peter Freyther | 689e3cc | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 272 | if (osmo_bsc_sccp_init(bsc_gsmnet) != 0) { |
| 273 | LOGP(DNM, LOGL_ERROR, "Failed to register SCCP.\n"); |
| 274 | exit(1); |
| 275 | } |
| 276 | |
Holger Hans Peter Freyther | 3f79397 | 2010-11-14 20:38:06 +0100 | [diff] [blame] | 277 | if (osmo_bsc_audio_init(bsc_gsmnet) != 0) { |
| 278 | LOGP(DMSC, LOGL_ERROR, "Failed to register audio support.\n"); |
| 279 | exit(1); |
| 280 | } |
| 281 | |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 282 | signal(SIGINT, &signal_handler); |
| 283 | signal(SIGABRT, &signal_handler); |
| 284 | signal(SIGUSR1, &signal_handler); |
| 285 | signal(SIGUSR2, &signal_handler); |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 286 | osmo_init_ignore_signals(); |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 287 | |
Harald Welte | c4ae176 | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 288 | if (daemonize) { |
| 289 | rc = osmo_daemonize(); |
| 290 | if (rc < 0) { |
| 291 | perror("Error during daemonize"); |
| 292 | exit(1); |
| 293 | } |
| 294 | } |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 295 | |
| 296 | while (1) { |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 297 | osmo_select_main(0); |
Holger Hans Peter Freyther | 58ef6e4 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 298 | } |
| 299 | |
Holger Hans Peter Freyther | 770954e | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 300 | return 0; |
| 301 | } |