From b05d72d21b8cc91126cf45525f9010df6142e1c2 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 25 May 2014 14:43:03 +0200 Subject: sysmobts: Begin with an OML router that will be used by the manager Begin with the basics of a OML Router. This is currently only capable of accepting a connection and read messages but it will evolve into a router in multiple stages. The first usage will be by the sysmobts-mgr. An OML Error Indication will be sent by the sysmobts-mgr and it will be forwarded to the BSC. In the second step we will set a relative power reduction from the sysmobts-mgr. In the long-term this code will be used to communicate with a second TRX. --- src/osmo-bts-sysmo/Makefile.am | 4 +- src/osmo-bts-sysmo/main.c | 8 +++ src/osmo-bts-sysmo/oml_router.c | 115 ++++++++++++++++++++++++++++++++++++++++ src/osmo-bts-sysmo/oml_router.h | 13 +++++ 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/osmo-bts-sysmo/oml_router.c create mode 100644 src/osmo-bts-sysmo/oml_router.h diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3a..a213759e 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -4,12 +4,12 @@ COMMON_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOS EXTRA_DIST = misc/sysmobts_mgr.h misc/sysmobts_misc.h misc/sysmobts_par.h \ misc/sysmobts_eeprom.h misc/sysmobts_nl.h femtobts.h hw_misc.h \ - l1_fwd.h l1_if.h l1_transp.h eeprom.h utils.h + l1_fwd.h l1_if.h l1_transp.h eeprom.h utils.h oml_router.h bin_PROGRAMS = sysmobts sysmobts-remote l1fwd-proxy sysmobts-mgr sysmobts-util COMMON_SOURCES = main.c femtobts.c l1_if.c oml.c sysmobts_vty.c tch.c hw_misc.c calib_file.c \ - eeprom.c calib_fixup.c utils.c misc/sysmobts_par.c + eeprom.c calib_fixup.c utils.c misc/sysmobts_par.c oml_router.c sysmobts_SOURCES = $(COMMON_SOURCES) l1_transp_hw.c sysmobts_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD) diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c index fac45d9c..60a4a7ff 100644 --- a/src/osmo-bts-sysmo/main.c +++ b/src/osmo-bts-sysmo/main.c @@ -52,6 +52,7 @@ #include "eeprom.h" #include "l1_if.h" #include "hw_misc.h" +#include "oml_router.h" /* FIXME: read from real hardware */ const uint8_t abis_mac[6] = { 0,1,2,3,4,5 }; @@ -300,6 +301,7 @@ int main(int argc, char **argv) struct gsm_bts_role_bts *btsb; struct e1inp_line *line; void *tall_msgb_ctx; + struct osmo_fd accept_fd, read_fd; int rc; tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context"); @@ -367,6 +369,12 @@ int main(int argc, char **argv) signal(SIGUSR2, &signal_handler); osmo_init_ignore_signals(); + rc = oml_router_init(bts, &accept_fd, &read_fd); + if (rc < 0) { + perror("Error creating the OML router\n"); + exit(1); + } + if (!btsb->bsc_oml_host) { fprintf(stderr, "Cannot start BTS without knowing BSC OML IP\n"); exit(1); diff --git a/src/osmo-bts-sysmo/oml_router.c b/src/osmo-bts-sysmo/oml_router.c new file mode 100644 index 00000000..64b36840 --- /dev/null +++ b/src/osmo-bts-sysmo/oml_router.c @@ -0,0 +1,115 @@ +/* Beginnings of an OML router */ + +/* (C) 2014 by sysmocom s.f.m.c. GmbH + * + * 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 . + * + */ + +#include "oml_router.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + +static int oml_router_read_cb(struct osmo_fd *fd, unsigned int what) +{ + struct msgb *msg; + int rc; + + msg = oml_msgb_alloc(); + if (!msg) { + LOGP(DL1C, LOGL_ERROR, "Failed to allocate oml msgb.\n"); + return -1; + } + + rc = recv(fd->fd, msg->tail, msg->data_len, 0); + if (rc <= 0) { + close(fd->fd); + osmo_fd_unregister(fd); + fd->fd = -1; + goto err; + } + + msgb_put(msg, rc); + + /* todo analyze and dispatch message */ + +err: + msgb_free(msg); + return -1; +} + +static int oml_router_accept_cb(struct osmo_fd *accept_fd, unsigned int what) +{ + int fd; + struct osmo_fd *read_fd = (struct osmo_fd *) accept_fd->data; + + /* Accept only one connection at a time. De-register it */ + if (read_fd->fd > -1) { + LOGP(DL1C, LOGL_NOTICE, + "New OML router connection. Closing old one.\n"); + close(read_fd->fd); + osmo_fd_unregister(read_fd); + read_fd->fd = -1; + } + + fd = accept(accept_fd->fd, NULL, NULL); + if (fd < 0) { + LOGP(DL1C, LOGL_ERROR, "Failed to accept. errno: %s.\n", + strerror(errno)); + return -1; + } + + read_fd->fd = fd; + if (osmo_fd_register(read_fd) != 0) { + LOGP(DL1C, LOGL_ERROR, "Registering the read fd failed.\n"); + close(fd); + read_fd->fd = -1; + return -1; + } + + return 0; +} + +int oml_router_init(struct gsm_bts *bts, + struct osmo_fd *accept_fd, struct osmo_fd *read_fd) +{ + int rc; + + memset(accept_fd, 0, sizeof(*accept_fd)); + memset(read_fd, 0, sizeof(*read_fd)); + + accept_fd->cb = oml_router_accept_cb; + accept_fd->data = read_fd; + + read_fd->cb = oml_router_read_cb; + read_fd->data = bts; + read_fd->when = BSC_FD_READ; + read_fd->fd = -1; + + rc = osmo_sock_unix_init_ofd(accept_fd, SOCK_SEQPACKET, 0, + OML_ROUTER_PATH, + OSMO_SOCK_F_BIND | OSMO_SOCK_F_NONBLOCK); + return rc; +} diff --git a/src/osmo-bts-sysmo/oml_router.h b/src/osmo-bts-sysmo/oml_router.h new file mode 100644 index 00000000..f8fe4c95 --- /dev/null +++ b/src/osmo-bts-sysmo/oml_router.h @@ -0,0 +1,13 @@ +#pragma once + +struct gsm_bts; +struct osmo_fd; + +/** + * The default path sysmobts will listen for incoming + * registrations for OML routing and sending. + */ +#define OML_ROUTER_PATH "/var/run/sysmobts/oml_router" + + +int oml_router_init(struct gsm_bts *bts, struct osmo_fd *accept, struct osmo_fd *read); -- cgit v1.2.3