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/signal.h>
33 #include <arpa/inet.h>
47 struct log_target *stderr_target;
50 struct llist_head ms_list;
51 static uint32_t gsmtap_ip = 0;
52 unsigned short vty_port = 4247;
54 char *config_dir = NULL;
56 int mobile_delete(struct osmocom_ms *ms, int force);
57 int mobile_signal_cb(unsigned int subsys, unsigned int signal,
58 void *handler_data, void *signal_data);
59 int mobile_work(struct osmocom_ms *ms);
60 int mobile_exit(struct osmocom_ms *ms, int force);
63 const char *openbsc_copyright =
64 "Copyright (C) 2008-2010 ...\n"
65 "Contributions by ...\n\n"
66 "License GPLv2+: GNU GPL version 2 or later "
67 "<http://gnu.org/licenses/gpl.html>\n"
68 "This is free software: you are free to change and redistribute it.\n"
69 "There is NO WARRANTY, to the extent permitted by law.\n";
71 static void print_usage(const char *app)
73 printf("Usage: %s\n", app);
76 static void print_help()
78 printf(" Some help...\n");
79 printf(" -h --help this text\n");
80 printf(" -i --gsmtap-ip The destination IP used for GSMTAP.\n");
81 printf(" -v --vty-port The VTY port number to telnet to. "
82 "(default %u)\n", vty_port);
83 printf(" -d --debug Change debug flags.\n");
86 static void handle_options(int argc, char **argv)
88 struct sockaddr_in gsmtap;
90 int option_index = 0, c;
91 static struct option long_options[] = {
93 {"gsmtap-ip", 1, 0, 'i'},
94 {"vty-port", 1, 0, 'v'},
99 c = getopt_long(argc, argv, "hi:v:d:",
100 long_options, &option_index);
106 print_usage(argv[0]);
111 if (!inet_aton(optarg, &gsmtap.sin_addr)) {
115 gsmtap_ip = ntohl(gsmtap.sin_addr.s_addr);
118 vty_port = atoi(optarg);
121 log_parse_category_mask(stderr_target, optarg);
130 void sighandler(int sigset)
132 if (sigset == SIGHUP || sigset == SIGPIPE)
135 fprintf(stderr, "Signal %d received.\n", sigset);
137 /* in case there is a lockup during exit */
138 signal(SIGINT, SIG_DFL);
139 signal(SIGHUP, SIG_DFL);
140 signal(SIGTERM, SIG_DFL);
141 signal(SIGPIPE, SIG_DFL);
143 dispatch_signal(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL);
146 int main(int argc, char **argv)
152 const char osmocomcfg[] = ".osmocom/bb/mobile.cfg";
153 char *config_file = NULL;
155 printf("%s\n", openbsc_copyright);
159 INIT_LLIST_HEAD(&ms_list);
161 stderr_target = log_target_create_stderr();
162 log_add_target(stderr_target);
163 log_set_all_filter(stderr_target, 1);
165 l23_ctx = talloc_named_const(NULL, 1, "layer2 context");
167 handle_options(argc, argv);
170 log_parse_category_mask(stderr_target, "DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
171 log_set_log_level(stderr_target, LOGL_INFO);
174 rc = gsmtap_init(gsmtap_ip);
176 fprintf(stderr, "Failed during gsmtap_init()\n");
181 home = getenv("HOME");
183 len = strlen(home) + 1 + sizeof(osmocomcfg);
184 config_file = talloc_size(l23_ctx, len);
185 if (config_file != NULL)
186 snprintf(config_file, len, "%s/%s", home, osmocomcfg);
188 /* save the config file directory name */
189 config_dir = talloc_strdup(l23_ctx, config_file);
190 config_dir = dirname(config_dir);
192 rc = l23_app_init(NULL, config_file, vty_port);
196 signal(SIGINT, sighandler);
197 signal(SIGHUP, sighandler);
198 signal(SIGTERM, sighandler);
199 signal(SIGPIPE, sighandler);
203 if (quit && llist_empty(&ms_list))