pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/30260 )


Change subject: WIP: Add modem app
......................................................................

WIP: Add modem app

Change-Id: I8a1121b3287da7d7330c30e3118affa8fd1da61b
---
M src/host/layer23/configure.ac
M src/host/layer23/include/osmocom/bb/Makefile.am
A src/host/layer23/include/osmocom/bb/modem/Makefile.am
A src/host/layer23/include/osmocom/bb/modem/modem.h
M src/host/layer23/src/Makefile.am
A src/host/layer23/src/modem/Makefile.am
A src/host/layer23/src/modem/modem_main.c
7 files changed, 210 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/60/30260/1

diff --git a/src/host/layer23/configure.ac b/src/host/layer23/configure.ac
index 2817ed1..07779f2 100644
--- a/src/host/layer23/configure.ac
+++ b/src/host/layer23/configure.ac
@@ -44,6 +44,7 @@
 PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.10.0)
 PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm)
 PKG_CHECK_MODULES(LIBOSMOCODEC, libosmocodec)
+PKG_CHECK_MODULES(LIBOSMOGPRSLLC, libosmo-gprs-llc)
 AC_CHECK_LIB(gps, gps_waiting, LIBGPS_CFLAGS=" -D_HAVE_GPSD" LIBGPS_LIBS=" 
-lgps ",,)
 AC_SUBST([LIBGPS_CFLAGS])
 AC_SUBST([LIBGPS_LIBS])
@@ -69,10 +70,12 @@
     src/common/Makefile
     src/misc/Makefile
     src/mobile/Makefile
+    src/modem/Makefile
     include/Makefile
     include/osmocom/Makefile
     include/osmocom/bb/Makefile
     include/osmocom/bb/common/Makefile
     include/osmocom/bb/misc/Makefile
     include/osmocom/bb/mobile/Makefile
+    include/osmocom/bb/modem/Makefile
     Makefile)
diff --git a/src/host/layer23/include/osmocom/bb/Makefile.am 
b/src/host/layer23/include/osmocom/bb/Makefile.am
index 58a5f7f..3b6a4d8 100644
--- a/src/host/layer23/include/osmocom/bb/Makefile.am
+++ b/src/host/layer23/include/osmocom/bb/Makefile.am
@@ -1 +1 @@
-SUBDIRS = common misc mobile
+SUBDIRS = common misc mobile modem
diff --git a/src/host/layer23/include/osmocom/bb/modem/Makefile.am 
b/src/host/layer23/include/osmocom/bb/modem/Makefile.am
new file mode 100644
index 0000000..d99240d
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/modem/Makefile.am
@@ -0,0 +1 @@
+noinst_HEADERS = modem.h
diff --git a/src/host/layer23/include/osmocom/bb/modem/modem.h 
b/src/host/layer23/include/osmocom/bb/modem/modem.h
new file mode 100644
index 0000000..3945804
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/modem/modem.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include <stdbool.h>
+
+int modem_start(void);
+
diff --git a/src/host/layer23/src/Makefile.am b/src/host/layer23/src/Makefile.am
index 58a5f7f..3b6a4d8 100644
--- a/src/host/layer23/src/Makefile.am
+++ b/src/host/layer23/src/Makefile.am
@@ -1 +1 @@
-SUBDIRS = common misc mobile
+SUBDIRS = common misc mobile modem
diff --git a/src/host/layer23/src/modem/Makefile.am 
b/src/host/layer23/src/modem/Makefile.am
new file mode 100644
index 0000000..2af7ecc
--- /dev/null
+++ b/src/host/layer23/src/modem/Makefile.am
@@ -0,0 +1,29 @@
+AM_CPPFLAGS = \
+       $(all_includes) \
+       -I$(top_srcdir)/include \
+       $(NULL)
+
+AM_CFLAGS = \
+       -Wall \
+       $(LIBOSMOCORE_CFLAGS) \
+       $(LIBOSMOVTY_CFLAGS) \
+       $(LIBOSMOGSM_CFLAGS) \
+       $(LIBOSMOCODEC_CFLAGS) \
+       $(LIBOSMOGPRSLLC_CFLAGS) \
+       $(LIBGPS_CFLAGS) \
+       $(LIBLUA_CFLAGS) \
+       $(NULL)
+
+bin_PROGRAMS = modem
+
+modem_SOURCES = modem_main.c
+modem_LDADD = \
+       $(top_builddir)/src/common/liblayer23.a \
+       $(LIBOSMOCORE_LIBS) \
+       $(LIBOSMOVTY_LIBS) \
+       $(LIBOSMOGSM_LIBS) \
+       $(LIBOSMOCODEC_LIBS) \
+       $(LIBOSMOGPRSLLC_LIBS) \
+       $(LIBGPS_LIBS) \
+       $(LIBLUA_LIBS) \
+       $(NULL)
diff --git a/src/host/layer23/src/modem/modem_main.c 
b/src/host/layer23/src/modem/modem_main.c
new file mode 100644
index 0000000..2aadcb3
--- /dev/null
+++ b/src/host/layer23/src/modem/modem_main.c
@@ -0,0 +1,169 @@
+/* modem app (gprs) */
+
+/* (C) 2022 by sysmocom - s.m.f.c. GmbH <[email protected]>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#include <osmocom/bb/common/osmocom_data.h>
+#include <osmocom/bb/common/logging.h>
+#include <osmocom/bb/modem/modem.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/signal.h>
+#include <osmocom/core/application.h>
+
+#include <arpa/inet.h>
+
+#define _GNU_SOURCE
+#include <getopt.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+void *tall_modem_ctx = NULL;
+int daemonize = 0;
+
+static void print_usage(const char *app)
+{
+       printf("Usage: %s\n", app);
+}
+
+static void print_help(void)
+{
+       printf(" Some help...\n");
+       printf("  -h --help             this text\n");
+       printf("  -d --debug            Change debug flags.\n");
+       printf("  -D --daemonize        Run as daemon\n");
+}
+
+static int handle_options(int argc, char **argv)
+{
+       while (1) {
+               int option_index = 0, c;
+               static struct option long_options[] = {
+                       {"help", 0, 0, 'h'},
+                       {"debug", 1, 0, 'd'},
+                       {"daemonize", 0, 0, 'D'},
+                       {0, 0, 0, 0},
+               };
+
+               c = getopt_long(argc, argv, "hi:u:c:v:d:Dm",
+                               long_options, &option_index);
+               if (c == -1)
+                       break;
+
+               switch (c) {
+               case 'h':
+                       print_usage(argv[0]);
+                       print_help();
+                       exit(0);
+                       break;
+               case 'd':
+                       log_parse_category_mask(osmo_stderr_target, optarg);
+                       break;
+               case 'D':
+                       daemonize = 1;
+                       break;
+               default:
+                       /* Unknown parameter passed */
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+
+void signal_handler(int signum)
+{
+       fprintf(stdout, "signal %u received\n", signum);
+
+       switch (signum) {
+       case SIGINT:
+       case SIGTERM:
+               exit(0);
+               break;
+       case SIGABRT:
+               /* in case of abort, we want to obtain a talloc report and
+                * then run default SIGABRT handler, who will generate coredump
+                * and abort the process. abort() should do this for us after we
+                * return, but program wouldn't exit if an external SIGABRT is
+                * received.
+                */
+               talloc_report_full(tall_modem_ctx, stderr);
+               signal(SIGABRT, SIG_DFL);
+               raise(SIGABRT);
+               break;
+       case SIGUSR1:
+               talloc_report(tall_modem_ctx, stderr);;
+               break;
+       case SIGUSR2:
+               talloc_report_full(tall_modem_ctx, stderr);
+               break;
+       default:
+               break;
+       }
+}
+
+int modem_start(void)
+{
+       printf("Nothing to be done yet\n");
+       return 0;
+}
+
+int main(int argc, char **argv)
+{
+       int rc;
+
+       tall_modem_ctx = talloc_named_const(NULL, 1, "modem");
+       msgb_talloc_ctx_init(tall_modem_ctx, 0);
+       osmo_signal_talloc_ctx_init(tall_modem_ctx);
+
+       osmo_init_logging2(tall_modem_ctx, &log_info);
+
+       rc = handle_options(argc, argv);
+       if (rc) { /* Abort in case of parsing errors */
+               fprintf(stderr, "Error in command line options. Exiting.\n");
+               return 1;
+       }
+
+       signal(SIGINT, &signal_handler);
+       signal(SIGTERM, &signal_handler);
+       signal(SIGABRT, &signal_handler);
+       signal(SIGUSR1, &signal_handler);
+       signal(SIGUSR2, &signal_handler);
+       osmo_init_ignore_signals();
+
+       if (daemonize) {
+               printf("Running as daemon\n");
+               rc = osmo_daemonize();
+               if (rc)
+                       fprintf(stderr, "Failed to run as daemon\n");
+       }
+
+       modem_start();
+
+       while (!osmo_select_shutdown_done()) {
+               osmo_select_main_ctx(0);
+       }
+
+       talloc_report_full(tall_modem_ctx, stderr);
+       return 0;
+}

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30260
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I8a1121b3287da7d7330c30e3118affa8fd1da61b
Gerrit-Change-Number: 30260
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to