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