blob: 7ddf91d26b5bd2331857aafdcbfd5bec0811d2ec [file] [log] [blame]
Holger Hans Peter Freyther770954e2010-06-30 14:33:01 +08001/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
2 * (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2009-2010 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080022#include <openbsc/debug.h>
Holger Hans Peter Freyther770954e2010-06-30 14:33:01 +080023#include <openbsc/gsm_data.h>
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080024#include <openbsc/osmo_bsc_rf.h>
Holger Hans Peter Freyther770954e2010-06-30 14:33:01 +080025
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080026#include <osmocom/vty/command.h>
27#include <osmocore/talloc.h>
Harald Weltec4ae1762010-08-25 19:43:54 +020028#include <osmocore/process.h>
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080029
Harald Welte90e5eae2010-08-03 15:11:51 +020030#include <osmocom/sccp/sccp.h>
Holger Hans Peter Freythera8dffc12010-07-30 02:53:14 +080031
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080032#define _GNU_SOURCE
33#include <getopt.h>
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <time.h>
38
39#include "bscconfig.h"
40
41static struct log_target *stderr_target;
Holger Hans Peter Freyther770954e2010-06-30 14:33:01 +080042struct gsm_network *bsc_gsmnet = 0;
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080043static const char *config_file = "openbsc.cfg";
44static const char *rf_ctl = NULL;
Harald Weltec4ae1762010-08-25 19:43:54 +020045static int daemonize = 0;
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080046
47extern void bsc_vty_init(void);
48extern int bsc_bootstrap_network(int (*layer4)(struct gsm_network *, int, void *), const char *cfg_file);
49
50static void print_usage()
51{
52 printf("Usage: bsc_msc_ip\n");
53}
54
55static void print_help()
56{
57 printf(" Some useful help...\n");
58 printf(" -h --help this text\n");
Harald Weltec4ae1762010-08-25 19:43:54 +020059 printf(" -D --daemonize Fork the process into a background daemon\n");
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080060 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
61 printf(" -s --disable-color\n");
62 printf(" -T --timestamp. Print a timestamp in the debug output.\n");
63 printf(" -c --config-file filename The config file to use.\n");
64 printf(" -l --local=IP. The local address of the MGCP.\n");
65 printf(" -e --log-level number. Set a global loglevel.\n");
66 printf(" -r --rf-ctl NAME. A unix domain socket to listen for cmds.\n");
67 printf(" -t --testmode. A special mode to provoke failures at the MSC.\n");
68}
69
70static void handle_options(int argc, char** argv)
71{
72 while (1) {
73 int option_index = 0, c;
74 static struct option long_options[] = {
75 {"help", 0, 0, 'h'},
76 {"debug", 1, 0, 'd'},
Harald Weltec4ae1762010-08-25 19:43:54 +020077 {"daemonize", 0, 0, 'D'},
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080078 {"config-file", 1, 0, 'c'},
79 {"disable-color", 0, 0, 's'},
80 {"timestamp", 0, 0, 'T'},
81 {"msc", 1, 0, 'm'},
82 {"local", 1, 0, 'l'},
83 {"log-level", 1, 0, 'e'},
84 {"rf-ctl", 1, 0, 'r'},
85 {"testmode", 0, 0, 't'},
86 {0, 0, 0, 0}
87 };
88
Harald Weltec4ae1762010-08-25 19:43:54 +020089 c = getopt_long(argc, argv, "hd:DsTc:e:r:t",
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +080090 long_options, &option_index);
91 if (c == -1)
92 break;
93
94 switch (c) {
95 case 'h':
96 print_usage();
97 print_help();
98 exit(0);
99 case 's':
100 log_set_use_color(stderr_target, 0);
101 break;
102 case 'd':
103 log_parse_category_mask(stderr_target, optarg);
104 break;
Harald Weltec4ae1762010-08-25 19:43:54 +0200105 case 'D':
106 daemonize = 1;
107 break;
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +0800108 case 'c':
109 config_file = strdup(optarg);
110 break;
111 case 'T':
112 log_set_print_timestamp(stderr_target, 1);
113 break;
114 case 'P':
115 ipacc_rtp_direct = 0;
116 break;
117 case 'e':
118 log_set_log_level(stderr_target, atoi(optarg));
119 break;
120 case 'r':
121 rf_ctl = optarg;
122 break;
123 default:
124 /* ignore */
125 break;
126 }
127 }
128}
129
130extern int bts_model_unknown_init(void);
131extern int bts_model_bs11_init(void);
132extern int bts_model_nanobts_init(void);
133
134extern enum node_type bsc_vty_go_parent(struct vty *vty);
135
136static struct vty_app_info vty_info = {
137 .name = "OpenBSC Osmo BSC",
138 .version = PACKAGE_VERSION,
139 .go_parent_cb = bsc_vty_go_parent,
140};
141
Holger Hans Peter Freyther770954e2010-06-30 14:33:01 +0800142
143int main(int argc, char **argv)
144{
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +0800145 char *msc;
146 int rc;
147
148 log_init(&log_info);
149 tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc");
150 stderr_target = log_target_create_stderr();
151 log_add_target(stderr_target);
152
153 bts_model_unknown_init();
154 bts_model_bs11_init();
155 bts_model_nanobts_init();
156
157 /* enable filters */
158 log_set_all_filter(stderr_target, 1);
159
160 /* This needs to precede handle_options() */
161 vty_init(&vty_info);
162 bsc_vty_init();
163
164 /* parse options */
165 handle_options(argc, argv);
166
167 /* seed the PRNG */
168 srand(time(NULL));
169
Holger Hans Peter Freythera8dffc12010-07-30 02:53:14 +0800170 /* initialize SCCP */
171 sccp_set_log_area(DSCCP);
172
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +0800173
174 rc = bsc_bootstrap_network(NULL, config_file);
175 if (rc < 0) {
176 fprintf(stderr, "Bootstrapping the network failed. exiting.\n");
177 exit(1);
178 }
179
180 if (rf_ctl) {
181 struct osmo_bsc_rf *rf;
182 rf = osmo_bsc_rf_create(rf_ctl, bsc_gsmnet);
183 if (!rf) {
184 fprintf(stderr, "Failed to create the RF service.\n");
185 exit(1);
186 }
187 }
188
Harald Weltec4ae1762010-08-25 19:43:54 +0200189 if (daemonize) {
190 rc = osmo_daemonize();
191 if (rc < 0) {
192 perror("Error during daemonize");
193 exit(1);
194 }
195 }
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +0800196
197 while (1) {
198 bsc_select_main(0);
199 }
200
Holger Hans Peter Freyther770954e2010-06-30 14:33:01 +0800201 return 0;
202}