1 /* Main method of the layer2/3 stack */
3 /* (C) 2010 by Holger Hans Peter Freyther
4 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <osmocom/bb/common/osmocom_data.h>
25 #include <osmocom/bb/common/logging.h>
26 #include <osmocom/bb/mobile/app_mobile.h>
28 #include <osmocom/core/talloc.h>
29 #include <osmocom/core/linuxlist.h>
30 #include <osmocom/core/gsmtap_util.h>
31 #include <osmocom/core/gsmtap.h>
32 #include <osmocom/core/signal.h>
34 #include <arpa/inet.h>
48 struct log_target *stderr_target;
51 struct llist_head ms_list;
52 static char *gsmtap_ip = 0;
53 struct gsmtap_inst *gsmtap_inst = NULL;
54 unsigned short vty_port = 4247;
56 char *config_dir = NULL;
58 int mobile_delete(struct osmocom_ms *ms, int force);
59 int mobile_signal_cb(unsigned int subsys, unsigned int signal,
60 void *handler_data, void *signal_data);
61 int mobile_work(struct osmocom_ms *ms);
62 int mobile_exit(struct osmocom_ms *ms, int force);
65 const char *openbsc_copyright =
66 "Copyright (C) 2008-2010 ...\n"
67 "Contributions by ...\n\n"
68 "License GPLv2+: GNU GPL version 2 or later "
69 "<http://gnu.org/licenses/gpl.html>\n"
70 "This is free software: you are free to change and redistribute it.\n"
71 "There is NO WARRANTY, to the extent permitted by law.\n";
73 static void print_usage(const char *app)
75 printf("Usage: %s\n", app);
78 static void print_help()
80 printf(" Some help...\n");
81 printf(" -h --help this text\n");
82 printf(" -i --gsmtap-ip The destination IP used for GSMTAP.\n");
83 printf(" -v --vty-port The VTY port number to telnet to. "
84 "(default %u)\n", vty_port);
85 printf(" -d --debug Change debug flags.\n");
88 static void handle_options(int argc, char **argv)
91 int option_index = 0, c;
92 static struct option long_options[] = {
94 {"gsmtap-ip", 1, 0, 'i'},
95 {"vty-port", 1, 0, 'v'},
100 c = getopt_long(argc, argv, "hi:v:d:",
101 long_options, &option_index);
107 print_usage(argv[0]);
115 vty_port = atoi(optarg);
118 log_parse_category_mask(stderr_target, optarg);
127 void sighandler(int sigset)
129 if (sigset == SIGHUP || sigset == SIGPIPE)
132 fprintf(stderr, "Signal %d received.\n", sigset);
134 /* in case there is a lockup during exit */
135 signal(SIGINT, SIG_DFL);
136 signal(SIGHUP, SIG_DFL);
137 signal(SIGTERM, SIG_DFL);
138 signal(SIGPIPE, SIG_DFL);
140 osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL);
143 int main(int argc, char **argv)
149 const char osmocomcfg[] = ".osmocom/bb/mobile.cfg";
150 char *config_file = NULL;
152 printf("%s\n", openbsc_copyright);
156 INIT_LLIST_HEAD(&ms_list);
158 stderr_target = log_target_create_stderr();
159 log_add_target(stderr_target);
160 log_set_all_filter(stderr_target, 1);
162 l23_ctx = talloc_named_const(NULL, 1, "layer2 context");
164 handle_options(argc, argv);
167 log_parse_category_mask(stderr_target, "DCS:DNB:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
168 log_set_log_level(stderr_target, LOGL_DEBUG);
171 gsmtap_inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1);
173 fprintf(stderr, "Failed during gsmtap_init()\n");
176 gsmtap_source_add_sink(gsmtap_inst);
179 home = getenv("HOME");
181 len = strlen(home) + 1 + sizeof(osmocomcfg);
182 config_file = talloc_size(l23_ctx, len);
183 if (config_file != NULL)
184 snprintf(config_file, len, "%s/%s", home, osmocomcfg);
186 /* save the config file directory name */
187 config_dir = talloc_strdup(l23_ctx, config_file);
188 config_dir = dirname(config_dir);
190 rc = l23_app_init(NULL, config_file, vty_port);
194 signal(SIGINT, sighandler);
195 signal(SIGHUP, sighandler);
196 signal(SIGTERM, sighandler);
197 signal(SIGPIPE, sighandler);
201 if (quit && llist_empty(&ms_list))