Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/4771

to look at the new patch set (#2).

mobile: Begin with a primitive interface on top of the code

We want the script interface to interface through a primitive
interface. This will allow to move it to a different thread or
a process in the future. The script interface will just use the
primitives.

It is not clear how "sap" will be used here. I am keeping it
at 0 right now. The first primitive is starting a timer with a
request and then getting an indication as a response.

Change-Id: Id2456b7fae35546553c4805f12a40c0812d9255c
---
M src/host/layer23/include/osmocom/bb/common/logging.h
M src/host/layer23/include/osmocom/bb/mobile/Makefile.am
A src/host/layer23/include/osmocom/bb/mobile/primitives.h
M src/host/layer23/src/common/logging.c
M src/host/layer23/src/mobile/Makefile.am
M src/host/layer23/src/mobile/main.c
A src/host/layer23/src/mobile/primitives.c
7 files changed, 170 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/71/4771/2

diff --git a/src/host/layer23/include/osmocom/bb/common/logging.h 
b/src/host/layer23/include/osmocom/bb/common/logging.h
index 3efa57a..fe7b6e9 100644
--- a/src/host/layer23/include/osmocom/bb/common/logging.h
+++ b/src/host/layer23/include/osmocom/bb/common/logging.h
@@ -22,6 +22,7 @@
        DSUM,
        DSIM,
        DGPS,
+       DPRIM,
 };
 
 extern const struct log_info log_info;
diff --git a/src/host/layer23/include/osmocom/bb/mobile/Makefile.am 
b/src/host/layer23/include/osmocom/bb/mobile/Makefile.am
index b58b952..12cf24b 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/Makefile.am
+++ b/src/host/layer23/include/osmocom/bb/mobile/Makefile.am
@@ -1,3 +1,3 @@
 noinst_HEADERS = gsm322.h gsm480_ss.h gsm411_sms.h gsm48_cc.h gsm48_mm.h \
                 gsm48_rr.h mncc.h settings.h subscriber.h support.h \
-                transaction.h vty.h mncc_sock.h
+                transaction.h vty.h mncc_sock.h primitives.h
diff --git a/src/host/layer23/include/osmocom/bb/mobile/primitives.h 
b/src/host/layer23/include/osmocom/bb/mobile/primitives.h
new file mode 100644
index 0000000..6a79eaa
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/mobile/primitives.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <osmocom/core/prim.h>
+
+/**
+ * Mobile Script<->App primitives. Application script will receive
+ * indications and will send primitives to the lower layers. Here
+ * we will convert from internal state/events to the primitives. In
+ * the future the indications might be generated at lower levels
+ * directly.
+ */
+enum mobile_prim {
+       PRIM_MOB_TIMER,
+       PRIM_MOB_TIMER_CANCEL,
+};
+
+struct mobile_prim_intf {
+       struct osmocom_ms *ms;
+       void (*indication)(struct mobile_prim_intf *, struct osmo_prim_hdr 
*hdr);
+
+       /* Internal state */
+       struct llist_head timers;
+};
+
+/**
+ * Primitive to create timers and get indication once they have
+ * expired. Currently there is no way to cancel timers.
+ */
+struct mobile_timer_prim {
+       struct osmo_prim_hdr hdr;       /*!< Primitive base class */
+       uint64_t timer_id;              /*!< Unique Id identifying the timer */
+       int seconds;                    /*!< Seconds the timer should fire in */
+};
+
+
+struct mobile_prim_intf *mobile_prim_intf_alloc(struct osmocom_ms *ms);
+int mobile_prim_intf_req(struct mobile_prim_intf *intf, struct osmo_prim_hdr 
*hdr);
+void mobile_prim_intf_free(struct mobile_prim_intf *intf);
diff --git a/src/host/layer23/src/common/logging.c 
b/src/host/layer23/src/common/logging.c
index d8fd076..0810e32 100644
--- a/src/host/layer23/src/common/logging.c
+++ b/src/host/layer23/src/common/logging.c
@@ -127,6 +127,12 @@
                .color = "\033[1;35m",
                .enabled = 1, .loglevel = LOGL_DEBUG,
        },
+       [DPRIM] = {
+               .name = "DPRIM",
+               .description = "PRIM",
+               .color = "\033[1;32m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
 };
 
 const struct log_info log_info = {
diff --git a/src/host/layer23/src/mobile/Makefile.am 
b/src/host/layer23/src/mobile/Makefile.am
index 04dd025..90468c0 100644
--- a/src/host/layer23/src/mobile/Makefile.am
+++ b/src/host/layer23/src/mobile/Makefile.am
@@ -5,7 +5,7 @@
 noinst_LIBRARIES = libmobile.a
 libmobile_a_SOURCES = gsm322.c gsm480_ss.c gsm411_sms.c gsm48_cc.c gsm48_mm.c \
        gsm48_rr.c mnccms.c settings.c subscriber.c support.c \
-       transaction.c vty_interface.c voice.c mncc_sock.c
+       transaction.c vty_interface.c voice.c mncc_sock.c primitives.c
 
 bin_PROGRAMS = mobile
 
diff --git a/src/host/layer23/src/mobile/main.c 
b/src/host/layer23/src/mobile/main.c
index 91ed341..4ef52d9 100644
--- a/src/host/layer23/src/mobile/main.c
+++ b/src/host/layer23/src/mobile/main.c
@@ -70,7 +70,7 @@
 
 
 const char *debug_default =
-       "DCS:DNB:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DSS:DLSMS:DPAG:DSUM:DSAP:DGPS";
+       
"DCS:DNB:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DSS:DLSMS:DPAG:DSUM:DSAP:DGPS:DPRIM";
 
 const char *openbsc_copyright =
        "Copyright (C) 2010-2015 Andreas Eversberg, Sylvain Munaut, Holger 
Freyther, Harald Welte\n"
diff --git a/src/host/layer23/src/mobile/primitives.c 
b/src/host/layer23/src/mobile/primitives.c
new file mode 100644
index 0000000..a5fb58d
--- /dev/null
+++ b/src/host/layer23/src/mobile/primitives.c
@@ -0,0 +1,122 @@
+/* (C) 2017 by Holger Hans Peter Freyther
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <osmocom/bb/mobile/primitives.h>
+#include <osmocom/bb/common/logging.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/core/talloc.h>
+
+struct timer_closure {
+       struct llist_head entry;
+       struct mobile_prim_intf *intf;
+       struct osmo_timer_list timer;
+       uint64_t id;
+};
+
+struct mobile_prim_intf *mobile_prim_intf_alloc(struct osmocom_ms *ms)
+{
+       struct mobile_prim_intf *intf;
+
+       intf = talloc_zero(ms, struct mobile_prim_intf);
+       intf->ms = ms;
+
+       INIT_LLIST_HEAD(&intf->timers);
+       return intf;
+}
+
+void mobile_prim_intf_free(struct mobile_prim_intf *intf)
+{
+       struct timer_closure *timer, *tmp;
+
+       llist_for_each_entry_safe(timer, tmp, &intf->timers, entry) {
+               osmo_timer_del(&timer->timer);
+               llist_del(&timer->entry);
+               talloc_free(timer);
+       }
+       talloc_free(intf);
+}
+
+static void timer_expired_cb(void *_closure)
+{
+       struct mobile_timer_prim prim = { 0, };
+       struct timer_closure *closure = _closure;
+       struct mobile_prim_intf *intf;
+
+       intf = closure->intf;
+       prim.timer_id = closure->id;
+       llist_del(&closure->entry);
+       talloc_free(closure);
+
+       osmo_prim_init(&prim.hdr, 0, PRIM_MOB_TIMER, PRIM_OP_INDICATION, NULL);
+       intf->indication(intf, &prim.hdr);
+}
+
+static int create_timer(struct mobile_prim_intf *intf, struct 
mobile_timer_prim *prim)
+{
+       struct timer_closure *closure;
+
+       LOGP(DPRIM, LOGL_DEBUG, "Creating timer with reference: %llu\n", 
prim->timer_id);
+
+       closure = talloc_zero(intf, struct timer_closure);
+       closure->intf = intf;
+       closure->id = prim->timer_id;
+       closure->timer.cb = timer_expired_cb;
+       closure->timer.data = closure;
+       llist_add_tail(&closure->entry, &intf->timers);
+       osmo_timer_schedule(&closure->timer, prim->seconds, 0);
+       return 0;
+}
+
+static int cancel_timer(struct mobile_prim_intf *intf, struct 
mobile_timer_prim *prim)
+{
+       struct timer_closure *closure;
+
+
+       llist_for_each_entry(closure, &intf->timers, entry) {
+               if (closure->id != prim->timer_id)
+                       continue;
+
+               LOGP(DPRIM, LOGL_DEBUG,
+                       "Canceling timer with reference: %llu\n", 
prim->timer_id);
+               osmo_timer_del(&closure->timer);
+               llist_del(&closure->entry);
+               talloc_free(closure);
+               return 0;
+       }
+       return -1;
+}
+
+int mobile_prim_intf_req(struct mobile_prim_intf *intf, struct osmo_prim_hdr 
*hdr)
+{
+       switch (OSMO_PRIM_HDR(hdr)) {
+       case OSMO_PRIM(PRIM_MOB_TIMER, PRIM_OP_REQUEST):
+               return create_timer(intf, (struct mobile_timer_prim *)hdr);
+               break;
+       case OSMO_PRIM(PRIM_MOB_TIMER_CANCEL, PRIM_OP_REQUEST):
+               return cancel_timer(intf, (struct mobile_timer_prim *)hdr);
+               break;
+       default:
+               LOGP(DPRIM, LOGL_ERROR, "Unknown primitive: %d\n", 
OSMO_PRIM_HDR(hdr));
+               break;
+       }
+
+       return 0;
+}

-- 
To view, visit https://gerrit.osmocom.org/4771
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id2456b7fae35546553c4805f12a40c0812d9255c
Gerrit-PatchSet: 2
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <hol...@freyther.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Holger Freyther <hol...@freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: neels <nhofm...@sysmocom.de>

Reply via email to