misc: Fix crash in cell_log due missing l1_prim_cb
[osmocom-bb.git] / src / host / layer23 / src / common / main.c
index a791ccf..666e94a 100644 (file)
 #include <osmocom/bb/common/logging.h>
 #include <osmocom/bb/common/l23_app.h>
 
-#include <osmocore/msgb.h>
-#include <osmocore/talloc.h>
-#include <osmocore/select.h>
-#include <osmocore/linuxlist.h>
-#include <osmocore/gsmtap_util.h>
-#include <osmocore/utils.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/gsmtap_util.h>
+#include <osmocom/core/gsmtap.h>
+#include <osmocom/core/utils.h>
 
 #include <arpa/inet.h>
 
 struct log_target *stderr_target;
 
 void *l23_ctx = NULL;
+
 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;
+static char *gsmtap_ip = NULL;
+
 unsigned short vty_port = 4247;
 int (*l23_app_work) (struct osmocom_ms *ms) = NULL;
 int (*l23_app_exit) (struct osmocom_ms *ms) = NULL;
 int quit = 0;
+struct gsmtap_inst *gsmtap_inst;
 
 const char *openbsc_copyright =
        "%s"
@@ -110,6 +114,9 @@ static void print_help()
 static void build_config(char **opt, struct option **option)
 {
        struct l23_app_info *app;
+       struct option *app_opp = NULL;
+       int app_len = 0, len;
+
        static struct option long_options[] = {
                {"help", 0, 0, 'h'},
                {"socket", 1, 0, 's'},
@@ -124,14 +131,18 @@ static void build_config(char **opt, struct option **option)
        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);
+
+       len = ARRAY_SIZE(long_options);
+       if (app && app->cfg_getopt_opt)
+               app_len = app->cfg_getopt_opt(&app_opp);
+
+       *option = talloc_zero_array(l23_ctx, struct option, len + app_len + 1);
        memcpy(*option, long_options, sizeof(long_options));
+       memcpy(*option + len, app_opp, app_len * sizeof(struct option));
 }
 
 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;
@@ -162,11 +173,7 @@ static void handle_options(int argc, char **argv)
                        ms->test_arfcn = atoi(optarg);
                        break;
                case 'i':
-                       if (!inet_aton(optarg, &gsmtap.sin_addr)) {
-                               perror("inet_aton");
-                               exit(2);
-                       }
-                       gsmtap_ip = ntohl(gsmtap.sin_addr.s_addr);
+                       gsmtap_ip = optarg;
                        break;
                case 'v':
                        vty_port = atoi(optarg);
@@ -247,19 +254,24 @@ int main(int argc, char **argv)
        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);
+       ms->lapdm_channel.lapdm_dcch.l1_ctx = ms;
+       ms->lapdm_channel.lapdm_dcch.l3_ctx = ms;
+       ms->lapdm_channel.lapdm_acch.l1_ctx = ms;
+       ms->lapdm_channel.lapdm_acch.l3_ctx = ms;
+       lapdm_channel_init(&ms->lapdm_channel, LAPDM_MODE_MS);
+       lapdm_channel_set_l1(&ms->lapdm_channel, l1ctl_ph_prim_cb, ms);
 
        rc = l23_app_init(ms);
        if (rc < 0)
                exit(1);
 
        if (gsmtap_ip) {
-               rc = gsmtap_init(gsmtap_ip);
-               if (rc < 0) {
+               gsmtap_inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1);
+               if (!gsmtap_inst) {
                        fprintf(stderr, "Failed during gsmtap_init()\n");
                        exit(1);
                }
+               gsmtap_source_add_sink(gsmtap_inst);
        }
 
        signal(SIGINT, sighandler);
@@ -270,7 +282,7 @@ int main(int argc, char **argv)
        while (!quit) {
                if (l23_app_work)
                        l23_app_work(ms);
-               bsc_select_main(0);
+               osmo_select_main(0);
        }
 
        return 0;