Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 1 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 55ef5fb | 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 | 5ccab10 | 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 | 9af6ddf | 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 | 5ccab10 | 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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 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 | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Holger Hans Peter Freyther | 4d31900 | 2012-03-16 11:54:55 +0100 | [diff] [blame] | 21 | #include <openbsc/bss.h> |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 22 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 23 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 24 | #include <openbsc/osmo_bsc.h> |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 25 | #include <openbsc/osmo_bsc_rf.h> |
Neels Hofmeyr | a42855f | 2017-02-23 21:49:55 +0100 | [diff] [blame] | 26 | #include <openbsc/bsc_msc_data.h> |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 27 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 7a2c86b | 2010-08-26 15:38:42 +0800 | [diff] [blame] | 28 | #include <openbsc/vty.h> |
Daniel Willmann | bc07090 | 2011-02-18 16:17:58 +0100 | [diff] [blame] | 29 | #include <openbsc/ipaccess.h> |
Harald Welte | ba874b8 | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 30 | #include <openbsc/ctrl.h> |
Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 31 | |
Harald Welte | ba874b8 | 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 | 55dc31e | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 34 | #include <osmocom/ctrl/ports.h> |
Neels Hofmeyr | 7382815 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 35 | #include <osmocom/ctrl/control_vty.h> |
Daniel Willmann | 6fc4a98 | 2011-07-22 17:55:42 +0200 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 37 | #include <osmocom/core/application.h> |
Daniel Willmann | 3118191 | 2011-06-30 11:03:07 +0200 | [diff] [blame] | 38 | #include <osmocom/core/linuxlist.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 39 | #include <osmocom/core/talloc.h> |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 40 | #include <osmocom/core/stats.h> |
Daniel Willmann | bc07090 | 2011-02-18 16:17:58 +0100 | [diff] [blame] | 41 | #include <osmocom/gsm/protocol/gsm_12_21.h> |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 42 | |
Holger Hans Peter Freyther | 4d31900 | 2012-03-16 11:54:55 +0100 | [diff] [blame] | 43 | #include <osmocom/abis/abis.h> |
| 44 | |
Harald Welte | d5db12c | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 45 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | 30e1ae9 | 2010-07-30 02:53:14 +0800 | [diff] [blame] | 46 | |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 47 | #define _GNU_SOURCE |
| 48 | #include <getopt.h> |
| 49 | |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 50 | #include <signal.h> |
Holger Hans Peter Freyther | cacbc73 | 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 | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 54 | #include <unistd.h> |
| 55 | |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 56 | |
Harald Welte | c08e8be | 2011-03-04 13:53:51 +0100 | [diff] [blame] | 57 | #include "../../bscconfig.h" |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 58 | |
Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 59 | struct gsm_network *bsc_gsmnet = 0; |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 60 | static const char *config_file = "openbsc.cfg"; |
Holger Hans Peter Freyther | 5e3bbba | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 61 | static const char *rf_ctrl = NULL; |
Holger Hans Peter Freyther | 38158fb | 2010-09-11 13:28:42 +0800 | [diff] [blame] | 62 | extern const char *openbsc_copyright; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 63 | static int daemonize = 0; |
Holger Hans Peter Freyther | ec0cb7c | 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 | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 70 | |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 71 | static void print_usage() |
| 72 | { |
Holger Hans Peter Freyther | fede54c | 2011-04-13 09:17:40 +0200 | [diff] [blame] | 73 | printf("Usage: osmo-bsc\n"); |
Holger Hans Peter Freyther | cacbc73 | 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 | 2c869ef | 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 | cacbc73 | 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 | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 91 | static void handle_options(int argc, char **argv) |
Holger Hans Peter Freyther | cacbc73 | 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 | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 98 | {"daemonize", 0, 0, 'D'}, |
Holger Hans Peter Freyther | cacbc73 | 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 | cacbc73 | 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 | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 109 | c = getopt_long(argc, argv, "hd:DsTc:e:r:t", |
Holger Hans Peter Freyther | cacbc73 | 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 | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 120 | log_set_use_color(osmo_stderr_target, 0); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 121 | break; |
| 122 | case 'd': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 123 | log_parse_category_mask(osmo_stderr_target, optarg); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 124 | break; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 125 | case 'D': |
| 126 | daemonize = 1; |
| 127 | break; |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 128 | case 'c': |
Holger Hans Peter Freyther | b07df2b | 2014-06-12 11:19:38 +0200 | [diff] [blame] | 129 | config_file = optarg; |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 130 | break; |
| 131 | case 'T': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 132 | log_set_print_timestamp(osmo_stderr_target, 1); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 133 | break; |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 134 | case 'e': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 135 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 136 | break; |
| 137 | case 'r': |
Holger Hans Peter Freyther | 5e3bbba | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 138 | rf_ctrl = optarg; |
Holger Hans Peter Freyther | cacbc73 | 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 | 3e4e8cf | 2015-09-24 15:38:38 +0200 | [diff] [blame] | 147 | extern int bsc_vty_go_parent(struct vty *vty); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 148 | |
| 149 | static struct vty_app_info vty_info = { |
Harald Welte | ec1921d | 2011-02-24 23:57:06 +0100 | [diff] [blame] | 150 | .name = "OsmoBSC", |
Holger Hans Peter Freyther | cacbc73 | 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 | 7a2c86b | 2010-08-26 15:38:42 +0800 | [diff] [blame] | 153 | .is_config_node = bsc_vty_is_config_node, |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 154 | }; |
| 155 | |
Holger Hans Peter Freyther | 3e8e046 | 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 | a369e24 | 2017-02-23 21:57:23 +0100 | [diff] [blame] | 159 | struct bsc_msc_data *msc; |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 160 | |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 161 | fprintf(stdout, "signal %u received\n", signal); |
| 162 | |
| 163 | switch (signal) { |
| 164 | case SIGINT: |
Harald Welte | 6f750e6 | 2017-08-20 20:50:06 +0200 | [diff] [blame^] | 165 | case SIGTERM: |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 166 | bsc_shutdown_net(bsc_gsmnet); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 167 | osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL); |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 168 | sleep(3); |
| 169 | exit(0); |
| 170 | break; |
| 171 | case SIGABRT: |
| 172 | /* in case of abort, we want to obtain a talloc report |
| 173 | * and then return to the caller, who will abort the process */ |
| 174 | case SIGUSR1: |
| 175 | talloc_report(tall_vty_ctx, stderr); |
| 176 | talloc_report_full(tall_bsc_ctx, stderr); |
| 177 | break; |
| 178 | case SIGUSR2: |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 179 | if (!bsc_gsmnet->bsc_data) |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 180 | return; |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 181 | llist_for_each_entry(msc, &bsc_gsmnet->bsc_data->mscs, entry) |
| 182 | bsc_msc_lost(msc->msc_con); |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 183 | break; |
| 184 | default: |
| 185 | break; |
| 186 | } |
| 187 | } |
Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 188 | |
| 189 | int main(int argc, char **argv) |
| 190 | { |
Neels Hofmeyr | a369e24 | 2017-02-23 21:57:23 +0100 | [diff] [blame] | 191 | struct bsc_msc_data *msc; |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 192 | struct osmo_bsc_data *data; |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 193 | int rc; |
| 194 | |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 195 | tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc"); |
Neels Hofmeyr | 4c2d4ab | 2016-09-16 02:31:17 +0200 | [diff] [blame] | 196 | msgb_talloc_ctx_init(tall_bsc_ctx, 0); |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 197 | |
Neels Hofmeyr | 2c05f75 | 2016-10-24 01:53:38 +0200 | [diff] [blame] | 198 | /* Allocate global gsm_network struct */ |
| 199 | rc = bsc_network_alloc(NULL); |
| 200 | if (rc) { |
| 201 | fprintf(stderr, "Allocation failed. exiting.\n"); |
| 202 | exit(1); |
| 203 | } |
| 204 | |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 205 | osmo_init_logging(&log_info); |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 206 | osmo_stats_init(tall_bsc_ctx); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 207 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 208 | bts_init(); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 209 | libosmo_abis_init(tall_bsc_ctx); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 210 | |
| 211 | /* enable filters */ |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 212 | |
| 213 | /* This needs to precede handle_options() */ |
Holger Hans Peter Freyther | 38158fb | 2010-09-11 13:28:42 +0800 | [diff] [blame] | 214 | vty_info.copyright = openbsc_copyright; |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 215 | vty_init(&vty_info); |
Max | db0e380 | 2017-01-12 19:35:11 +0100 | [diff] [blame] | 216 | bsc_vty_init(bsc_gsmnet); |
Holger Hans Peter Freyther | d633280 | 2015-04-05 19:46:20 +0200 | [diff] [blame] | 217 | bsc_msg_lst_vty_init(tall_bsc_ctx, &access_lists, BSC_NODE); |
Neels Hofmeyr | 7382815 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 218 | ctrl_vty_init(tall_bsc_ctx); |
Holger Hans Peter Freyther | d633280 | 2015-04-05 19:46:20 +0200 | [diff] [blame] | 219 | |
| 220 | INIT_LLIST_HEAD(&access_lists); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 221 | |
| 222 | /* parse options */ |
| 223 | handle_options(argc, argv); |
| 224 | |
| 225 | /* seed the PRNG */ |
| 226 | srand(time(NULL)); |
| 227 | |
Holger Hans Peter Freyther | 30e1ae9 | 2010-07-30 02:53:14 +0800 | [diff] [blame] | 228 | /* initialize SCCP */ |
| 229 | sccp_set_log_area(DSCCP); |
| 230 | |
Neels Hofmeyr | 2c05f75 | 2016-10-24 01:53:38 +0200 | [diff] [blame] | 231 | /* Read the config */ |
Neels Hofmeyr | e235441 | 2016-05-11 14:12:00 +0200 | [diff] [blame] | 232 | rc = bsc_network_configure(config_file); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 233 | if (rc < 0) { |
| 234 | fprintf(stderr, "Bootstrapping the network failed. exiting.\n"); |
| 235 | exit(1); |
| 236 | } |
Holger Hans Peter Freyther | 32aaef6 | 2010-09-16 17:26:35 +0800 | [diff] [blame] | 237 | bsc_api_init(bsc_gsmnet, osmo_bsc_api()); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 238 | |
Neels Hofmeyr | 7382815 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 239 | /* start control interface after reading config for |
| 240 | * ctrl_vty_get_bind_addr() */ |
Neels Hofmeyr | 7382815 | 2016-02-23 15:10:33 +0100 | [diff] [blame] | 241 | bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, |
| 242 | ctrl_vty_get_bind_addr(), |
| 243 | OSMO_CTRL_PORT_NITB_BSC); |
Neels Hofmeyr | 1901b92 | 2016-02-24 00:42:44 +0100 | [diff] [blame] | 244 | if (!bsc_gsmnet->ctrl) { |
Daniel Willmann | 5e95f45 | 2011-08-05 12:22:35 +0200 | [diff] [blame] | 245 | fprintf(stderr, "Failed to init the control interface. Exiting.\n"); |
| 246 | exit(1); |
| 247 | } |
Daniel Willmann | 6fc4a98 | 2011-07-22 17:55:42 +0200 | [diff] [blame] | 248 | |
Daniel Willmann | 806d654 | 2011-10-28 14:23:48 +0200 | [diff] [blame] | 249 | rc = bsc_ctrl_cmds_install(bsc_gsmnet); |
Daniel Willmann | 5e95f45 | 2011-08-05 12:22:35 +0200 | [diff] [blame] | 250 | if (rc < 0) { |
| 251 | fprintf(stderr, "Failed to install control commands. Exiting.\n"); |
| 252 | exit(1); |
| 253 | } |
Daniel Willmann | f7d557c | 2011-02-18 14:30:25 +0100 | [diff] [blame] | 254 | |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 255 | data = bsc_gsmnet->bsc_data; |
Holger Hans Peter Freyther | 5e3bbba | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 256 | if (rf_ctrl) |
Harald Welte | 4a824ca | 2017-05-29 13:54:27 +0200 | [diff] [blame] | 257 | osmo_talloc_replace_string(data, &data->rf_ctrl_name, rf_ctrl); |
Holger Hans Peter Freyther | 55ef5fb | 2011-04-07 23:23:27 +0200 | [diff] [blame] | 258 | |
Holger Hans Peter Freyther | 362d10f | 2014-02-07 20:07:51 +0100 | [diff] [blame] | 259 | data->rf_ctrl = osmo_bsc_rf_create(data->rf_ctrl_name, bsc_gsmnet); |
| 260 | if (!data->rf_ctrl) { |
| 261 | fprintf(stderr, "Failed to create the RF service.\n"); |
| 262 | exit(1); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 263 | } |
| 264 | |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 265 | llist_for_each_entry(msc, &bsc_gsmnet->bsc_data->mscs, entry) { |
| 266 | if (osmo_bsc_msc_init(msc) != 0) { |
| 267 | LOGP(DNAT, LOGL_ERROR, "Failed to start up. Exiting.\n"); |
| 268 | exit(1); |
| 269 | } |
Holger Hans Peter Freyther | 5832b3e | 2010-09-16 02:14:41 +0800 | [diff] [blame] | 270 | } |
| 271 | |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 272 | |
Holger Hans Peter Freyther | f3d1ae7 | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 273 | if (osmo_bsc_sccp_init(bsc_gsmnet) != 0) { |
| 274 | LOGP(DNM, LOGL_ERROR, "Failed to register SCCP.\n"); |
| 275 | exit(1); |
| 276 | } |
| 277 | |
Holger Hans Peter Freyther | 620c2e6 | 2010-11-14 20:38:06 +0100 | [diff] [blame] | 278 | if (osmo_bsc_audio_init(bsc_gsmnet) != 0) { |
| 279 | LOGP(DMSC, LOGL_ERROR, "Failed to register audio support.\n"); |
| 280 | exit(1); |
| 281 | } |
| 282 | |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 283 | signal(SIGINT, &signal_handler); |
Harald Welte | 6f750e6 | 2017-08-20 20:50:06 +0200 | [diff] [blame^] | 284 | signal(SIGTERM, &signal_handler); |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 285 | signal(SIGABRT, &signal_handler); |
| 286 | signal(SIGUSR1, &signal_handler); |
| 287 | signal(SIGUSR2, &signal_handler); |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 288 | osmo_init_ignore_signals(); |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 289 | |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 290 | if (daemonize) { |
| 291 | rc = osmo_daemonize(); |
| 292 | if (rc < 0) { |
| 293 | perror("Error during daemonize"); |
| 294 | exit(1); |
| 295 | } |
| 296 | } |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 297 | |
| 298 | while (1) { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 299 | osmo_select_main(0); |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 300 | } |
| 301 | |
Holger Hans Peter Freyther | 5ccab10 | 2010-06-30 14:33:01 +0800 | [diff] [blame] | 302 | return 0; |
| 303 | } |