aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-12-12 16:59:41 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-01-09 21:57:13 +0100
commit50131c125e2298cc4f71fa2b69881f6a40a7000a (patch)
tree959d9c63902ae8e57b9562445cdc250933a29002
parent5a03e129a633637d0a6b57b3b5aa6d6596b938fe (diff)
sysmobts: Begin with calib control from the sysmobts manager
In the long run we will connect to GPSD and wait for a fix and then run the calibration. The first step is to open (and re-open) the control connection to the BTS. As the connection is on localhost there should not be a computation overhead to always have the connection open. When connecting assume that the ASYNC connect worked directly as otherwise we get no notification of the failure. This looks like a "bug" of libosmo-abis that should check if the socket has been connected or not.
-rw-r--r--src/osmo-bts-sysmo/Makefile.am5
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr.c9
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr.h13
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr_calib.c128
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c2
5 files changed, 155 insertions, 2 deletions
diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am
index e36593a..2cad5c0 100644
--- a/src/osmo-bts-sysmo/Makefile.am
+++ b/src/osmo-bts-sysmo/Makefile.am
@@ -1,5 +1,5 @@
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
-AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS)
+AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOABIS_CFLAGS)
COMMON_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) -lortp
EXTRA_DIST = misc/sysmobts_mgr.h misc/sysmobts_misc.h misc/sysmobts_par.h \
@@ -27,8 +27,9 @@ sysmobts_mgr_SOURCES = \
misc/sysmobts_mgr_vty.c \
misc/sysmobts_mgr_nl.c \
misc/sysmobts_mgr_temp.c \
+ misc/sysmobts_mgr_calib.c \
eeprom.c
-sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
+sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOGSM_LIBS) $(top_builddir)/src/common/libbts.a
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c eeprom.c
sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS)
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
index ea83fb6..fce375b 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
@@ -224,6 +224,12 @@ static struct log_info_cat mgr_log_info_cat[] = {
.color = "\033[1;37m",
.enabled = 1, .loglevel = LOGL_INFO,
},
+ [DCALIB] = {
+ .name = "DCALIB",
+ .description = "Calibration handling",
+ .color = "\033[1;37m",
+ .enabled = 1, .loglevel = LOGL_INFO,
+ },
};
static const struct log_info mgr_log_info = {
@@ -292,6 +298,9 @@ int main(int argc, char **argv)
/* Initialize the temperature control */
sysmobts_mgr_temp_init(&manager);
+ if (sysmobts_mgr_calib_init(&manager) != 0)
+ exit(3);
+
if (daemonize) {
rc = osmo_daemonize();
if (rc < 0) {
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
index 0a32c28..21b442e 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
@@ -4,10 +4,13 @@
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
+#include <osmocom/core/timer.h>
+
enum {
DTEMP,
DFW,
DFIND,
+ DCALIB,
};
@@ -74,12 +77,22 @@ struct sysmobts_mgr_instance {
int action_crit;
enum sysmobts_temp_state state;
+
+ struct {
+ int is_up;
+ struct osmo_timer_list recon_timer;
+ struct ipa_client_conn *bts_conn;
+ } calib;
};
int sysmobts_mgr_vty_init(void);
int sysmobts_mgr_parse_config(struct sysmobts_mgr_instance *mgr);
int sysmobts_mgr_nl_init(void);
int sysmobts_mgr_temp_init(struct sysmobts_mgr_instance *mgr);
+int sysmobts_mgr_calib_init(struct sysmobts_mgr_instance *mgr);
const char *sysmobts_mgr_temp_get_state(enum sysmobts_temp_state state);
+
+extern void *tall_mgr_ctx;
+
#endif
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr_calib.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr_calib.c
new file mode 100644
index 0000000..4313e68
--- /dev/null
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_calib.c
@@ -0,0 +1,128 @@
+/* OCXO/TCXO calibration control for SysmoBTS management daemon */
+
+/*
+ * (C) 2014 by Holger Hans Peter Freyther
+ * (C) 2014 by Harald Welte for the IPA code from the oml router
+ *
+ * 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 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/licenses/>.
+ *
+ */
+
+#include "misc/sysmobts_mgr.h"
+#include "osmo-bts/msg_utils.h"
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/select.h>
+
+#include <osmocom/gsm/ipa.h>
+#include <osmocom/gsm/protocol/ipaccess.h>
+
+#include <osmocom/abis/abis.h>
+#include <osmocom/abis/e1_input.h>
+#include <osmocom/abis/ipa.h>
+
+static void bts_updown_cb(struct ipa_client_conn *link, int up);
+
+/* Schedule a connect towards the BTS */
+static void schedule_bts_connect(struct sysmobts_mgr_instance *mgr)
+{
+ DEBUGP(DLCTRL, "Scheduling BTS connect\n");
+ osmo_timer_schedule(&mgr->calib.recon_timer, 1, 0);
+}
+
+/* BTS re-connect timer call-back */
+static void bts_recon_timer_cb(void *data)
+{
+ int rc;
+ struct sysmobts_mgr_instance *mgr = data;
+
+ /* The connection failures are to be expected during boot */
+ mgr->calib.bts_conn->ofd->when |= BSC_FD_WRITE;
+ rc = ipa_client_conn_open(mgr->calib.bts_conn);
+ if (rc < 0) {
+ LOGP(DLCTRL, LOGL_NOTICE, "Failed to connect to BTS.\n");
+ schedule_bts_connect(mgr);
+ }
+}
+
+static int bts_read_cb(struct ipa_client_conn *link, struct msgb *msg)
+{
+ int rc;
+ struct ipaccess_head *hh = (struct ipaccess_head *) msgb_l1(msg);
+
+ DEBUGP(DLCTRL, "Received data from BTS: %s\n",
+ osmo_hexdump(msgb_data(msg), msgb_length(msg)));
+
+ /* regular message handling */
+ rc = msg_verify_ipa_structure(msg);
+ if (rc < 0) {
+ LOGP(DLCTRL, LOGL_ERROR,
+ "Invalid IPA message from BTS (rc=%d)\n", rc);
+ goto err;
+ }
+
+ switch (hh->proto) {
+ case IPAC_PROTO_IPACCESS:
+ /* handle the core IPA CCM messages in libosmoabis */
+ ipa_ccm_rcvmsg_bts_base(msg, link->ofd);
+ msgb_free(msg);
+ break;
+ default:
+ LOGP(DLCTRL, LOGL_NOTICE,
+ "Unhandled stream ID %u from BTS\n", hh->proto);
+ msgb_free(msg);
+ break;
+ }
+
+ return 0;
+err:
+ msgb_free(msg);
+ return -1;
+}
+
+/* link to BSC has gone up or down */
+static void bts_updown_cb(struct ipa_client_conn *link, int up)
+{
+ struct sysmobts_mgr_instance *mgr = link->data;
+
+ LOGP(DLCTRL, LOGL_INFO, "BTS connection %s\n", up ? "up" : "down");
+
+ if (up) {
+ mgr->calib.is_up = 1;
+ } else {
+ mgr->calib.is_up = 0;
+ schedule_bts_connect(mgr);
+ }
+}
+
+int sysmobts_mgr_calib_init(struct sysmobts_mgr_instance *mgr)
+{
+ mgr->calib.bts_conn = ipa_client_conn_create(tall_mgr_ctx, NULL, 0,
+ "localhost", 4238,
+ bts_updown_cb, bts_read_cb,
+ NULL, mgr);
+ if (!mgr) {
+ LOGP(DCALIB, LOGL_ERROR,
+ "Failed to create IPA connection\n");
+ return -1;
+ }
+
+ mgr->calib.recon_timer.cb = bts_recon_timer_cb;
+ mgr->calib.recon_timer.data = mgr;
+ schedule_bts_connect(mgr);
+
+ return 0;
+}
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
index 7df3b05..2144377 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
@@ -375,6 +375,8 @@ DEFUN(cfg_no_action_slave_off, cfg_no_action_slave_off_cmd,
DEFUN(show_mgr, show_mgr_cmd, "show manager",
SHOW_STR "Display information about the manager")
{
+ vty_out(vty, "BTS Control Interface: %s%s",
+ s_mgr->calib.is_up ? "connected" : "disconnected", VTY_NEWLINE);
vty_out(vty, "Temperature control state: %s%s",
sysmobts_mgr_temp_get_state(s_mgr->state), VTY_NEWLINE);
vty_out(vty, "Current Temperatures%s", VTY_NEWLINE);