#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/l1l2_interface.h>
+#include <osmocom/bb/common/sap_interface.h>
#include <osmocom/bb/misc/layer3.h>
#include <osmocom/bb/common/lapdm.h>
#include <osmocom/bb/common/logging.h>
#include <osmocore/select.h>
#include <osmocore/linuxlist.h>
#include <osmocore/gsmtap_util.h>
+#include <osmocore/utils.h>
#include <arpa/inet.h>
struct log_target *stderr_target;
void *l23_ctx = NULL;
-static char *socket_path = "/tmp/osmocom_l2";
+static char *layer2_socket_path = "/tmp/osmocom_l2";
+static char *sap_socket_path = "/tmp/osmocom_sap";
struct llist_head ms_list;
static struct osmocom_ms *ms = NULL;
static uint32_t gsmtap_ip = 0;
int quit = 0;
const char *openbsc_copyright =
- "Copyright (C) 2008-2010 ...\n"
- "Contributions by ...\n\n"
+ "%s"
+ "%s\n"
"License GPLv2+: GNU GPL version 2 or later "
"<http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
- "There is NO WARRANTY, to the extent permitted by law.\n";
+ "There is NO WARRANTY, to the extent permitted by law.\n\n";
static void print_usage(const char *app)
{
static void print_help()
{
+ int options = 0xff;
+ struct l23_app_info *app = l23_app_info();
+
+ if (app && app->cfg_supported != 0)
+ options = app->cfg_supported();
+
printf(" Some help...\n");
printf(" -h --help this text\n");
printf(" -s --socket /tmp/osmocom_l2. Path to the unix "
- "domain socket\n");
- printf(" -a --arfcn NR The ARFCN to be used for layer2.\n");
- printf(" -i --gsmtap-ip The destination IP used for GSMTAP.\n");
- printf(" -v --vty-port The VTY port number to telnet to. "
- "(default %u)\n", vty_port);
- printf(" -d --debug Change debug flags.\n");
+ "domain socket (l2)\n");
+
+ if (options & L23_OPT_SAP)
+ printf(" -S --sap /tmp/osmocom_sap. Path to the "
+ "unix domain socket (BTSAP)\n");
+
+ if (options & L23_OPT_ARFCN)
+ printf(" -a --arfcn NR The ARFCN to be used for layer2.\n");
+
+ if (options & L23_OPT_TAP)
+ printf(" -i --gsmtap-ip The destination IP used for GSMTAP.\n");
+
+ if (options & L23_OPT_VTY)
+ printf(" -v --vty-port The VTY port number to telnet "
+ "to. (default %u)\n", vty_port);
+
+ if (options & L23_OPT_DBG)
+ printf(" -d --debug Change debug flags.\n");
+
+ if (app && app->cfg_print_help)
+ app->cfg_print_help();
+}
+
+static void build_config(char **opt, struct option **option)
+{
+ struct l23_app_info *app;
+ static struct option long_options[] = {
+ {"help", 0, 0, 'h'},
+ {"socket", 1, 0, 's'},
+ {"sap", 1, 0, 'S'},
+ {"arfcn", 1, 0, 'a'},
+ {"gsmtap-ip", 1, 0, 'i'},
+ {"vty-port", 1, 0, 'v'},
+ {"debug", 1, 0, 'd'},
+ };
+
+
+ app = l23_app_info();
+ *opt = talloc_asprintf(l23_ctx, "hs:S:a:i:v:d:%s",
+ app && app->getopt_string ? app->getopt_string : "");
+ *option = talloc_zero_array(l23_ctx, struct option,
+ ARRAY_SIZE(long_options) + 1);
+ memcpy(*option, long_options, sizeof(long_options));
}
static void handle_options(int argc, char **argv)
{
struct sockaddr_in gsmtap;
+ struct l23_app_info *app = l23_app_info();
+ struct option *long_options;
+ char *opt;
+
+ build_config(&opt, &long_options);
+
while (1) {
int option_index = 0, c;
- static struct option long_options[] = {
- {"help", 0, 0, 'h'},
- {"socket", 1, 0, 's'},
- {"arfcn", 1, 0, 'a'},
- {"gsmtap-ip", 1, 0, 'i'},
- {"vty-port", 1, 0, 'v'},
- {"debug", 1, 0, 'd'},
- {0, 0, 0, 0},
- };
-
- c = getopt_long(argc, argv, "hs:a:i:v:d:",
+
+ c = getopt_long(argc, argv, opt,
long_options, &option_index);
if (c == -1)
break;
exit(0);
break;
case 's':
- socket_path = talloc_strdup(l23_ctx, optarg);
+ layer2_socket_path = talloc_strdup(l23_ctx, optarg);
+ break;
+ case 'S':
+ sap_socket_path = talloc_strdup(l23_ctx, optarg);
break;
case 'a':
ms->test_arfcn = atoi(optarg);
log_parse_category_mask(stderr_target, optarg);
break;
default:
+ if (app && app->cfg_handle_opt)
+ app->cfg_handle_opt(c, optarg);
break;
}
}
+
+ talloc_free(opt);
+ talloc_free(long_options);
}
void sighandler(int sigset)
exit (0);
}
+static void print_copyright()
+{
+ struct l23_app_info *app;
+ app = l23_app_info();
+ printf(openbsc_copyright,
+ app && app->copyright ? app->copyright : "",
+ app && app->contribution ? app->contribution : "");
+}
+
int main(int argc, char **argv)
{
int rc;
- printf("%s\n", openbsc_copyright);
-
INIT_LLIST_HEAD(&ms_list);
log_init(&log_info);
stderr_target = log_target_create_stderr();
fprintf(stderr, "Failed to allocate MS\n");
exit(1);
}
+
+ print_copyright();
+
llist_add_tail(&ms->entity, &ms_list);
sprintf(ms->name, "1");
handle_options(argc, argv);
- rc = layer2_open(ms, socket_path);
+ rc = layer2_open(ms, layer2_socket_path);
if (rc < 0) {
fprintf(stderr, "Failed during layer2_open()\n");
exit(1);
}
+ rc = sap_open(ms, sap_socket_path);
+ if (rc < 0)
+ fprintf(stderr, "Failed during sap_open(), no SIM reader\n");
+
lapdm_init(&ms->l2_entity.lapdm_dcch, ms);
lapdm_init(&ms->l2_entity.lapdm_acch, ms);