blob: b1c5001a95e03963772d8cb72f14250ec93c564a [file] [log] [blame]
Holger Hans Peter Freyther5ccab102010-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 Freythercacbc732010-06-30 14:59:23 +080022#include <openbsc/debug.h>
Holger Hans Peter Freyther5ccab102010-06-30 14:33:01 +080023#include <openbsc/gsm_data.h>
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +080024#include <openbsc/osmo_bsc_rf.h>
Holger Hans Peter Freyther5ccab102010-06-30 14:33:01 +080025
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +080026#include <osmocom/vty/command.h>
27#include <osmocore/talloc.h>
28
29#define _GNU_SOURCE
30#include <getopt.h>
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <time.h>
35
36#include "bscconfig.h"
37
38static struct log_target *stderr_target;
Holger Hans Peter Freyther5ccab102010-06-30 14:33:01 +080039struct gsm_network *bsc_gsmnet = 0;
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +080040static const char *config_file = "openbsc.cfg";
41static const char *rf_ctl = NULL;
42
43extern void bsc_vty_init(void);
44extern int bsc_bootstrap_network(int (*layer4)(struct gsm_network *, int, void *), const char *cfg_file);
45
46static void print_usage()
47{
48 printf("Usage: bsc_msc_ip\n");
49}
50
51static void print_help()
52{
53 printf(" Some useful help...\n");
54 printf(" -h --help this text\n");
55 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
56 printf(" -s --disable-color\n");
57 printf(" -T --timestamp. Print a timestamp in the debug output.\n");
58 printf(" -c --config-file filename The config file to use.\n");
59 printf(" -l --local=IP. The local address of the MGCP.\n");
60 printf(" -e --log-level number. Set a global loglevel.\n");
61 printf(" -r --rf-ctl NAME. A unix domain socket to listen for cmds.\n");
62 printf(" -t --testmode. A special mode to provoke failures at the MSC.\n");
63}
64
65static void handle_options(int argc, char** argv)
66{
67 while (1) {
68 int option_index = 0, c;
69 static struct option long_options[] = {
70 {"help", 0, 0, 'h'},
71 {"debug", 1, 0, 'd'},
72 {"config-file", 1, 0, 'c'},
73 {"disable-color", 0, 0, 's'},
74 {"timestamp", 0, 0, 'T'},
75 {"msc", 1, 0, 'm'},
76 {"local", 1, 0, 'l'},
77 {"log-level", 1, 0, 'e'},
78 {"rf-ctl", 1, 0, 'r'},
79 {"testmode", 0, 0, 't'},
80 {0, 0, 0, 0}
81 };
82
83 c = getopt_long(argc, argv, "hd:sTc:e:r:t",
84 long_options, &option_index);
85 if (c == -1)
86 break;
87
88 switch (c) {
89 case 'h':
90 print_usage();
91 print_help();
92 exit(0);
93 case 's':
94 log_set_use_color(stderr_target, 0);
95 break;
96 case 'd':
97 log_parse_category_mask(stderr_target, optarg);
98 break;
99 case 'c':
100 config_file = strdup(optarg);
101 break;
102 case 'T':
103 log_set_print_timestamp(stderr_target, 1);
104 break;
105 case 'P':
106 ipacc_rtp_direct = 0;
107 break;
108 case 'e':
109 log_set_log_level(stderr_target, atoi(optarg));
110 break;
111 case 'r':
112 rf_ctl = optarg;
113 break;
114 default:
115 /* ignore */
116 break;
117 }
118 }
119}
120
121extern int bts_model_unknown_init(void);
122extern int bts_model_bs11_init(void);
123extern int bts_model_nanobts_init(void);
124
125extern enum node_type bsc_vty_go_parent(struct vty *vty);
126
127static struct vty_app_info vty_info = {
128 .name = "OpenBSC Osmo BSC",
129 .version = PACKAGE_VERSION,
130 .go_parent_cb = bsc_vty_go_parent,
131};
132
Holger Hans Peter Freyther5ccab102010-06-30 14:33:01 +0800133
134int main(int argc, char **argv)
135{
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800136 char *msc;
137 int rc;
138
139 log_init(&log_info);
140 tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc");
141 stderr_target = log_target_create_stderr();
142 log_add_target(stderr_target);
143
144 bts_model_unknown_init();
145 bts_model_bs11_init();
146 bts_model_nanobts_init();
147
148 /* enable filters */
149 log_set_all_filter(stderr_target, 1);
150
151 /* This needs to precede handle_options() */
152 vty_init(&vty_info);
153 bsc_vty_init();
154
155 /* parse options */
156 handle_options(argc, argv);
157
158 /* seed the PRNG */
159 srand(time(NULL));
160
161
162 rc = bsc_bootstrap_network(NULL, config_file);
163 if (rc < 0) {
164 fprintf(stderr, "Bootstrapping the network failed. exiting.\n");
165 exit(1);
166 }
167
168 if (rf_ctl) {
169 struct osmo_bsc_rf *rf;
170 rf = osmo_bsc_rf_create(rf_ctl, bsc_gsmnet);
171 if (!rf) {
172 fprintf(stderr, "Failed to create the RF service.\n");
173 exit(1);
174 }
175 }
176
177
178 while (1) {
179 bsc_select_main(0);
180 }
181
Holger Hans Peter Freyther5ccab102010-06-30 14:33:01 +0800182 return 0;
183}