@@ -16,7 +16,8 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
arfcn_range_encode.h nat_rewrite_trie.h bsc_nat_callstats.h \
osmux.h mgcp_transcode.h gprs_utils.h \
gprs_gb_parse.h smpp.h meas_feed.h gprs_gsup_messages.h \
- gprs_gsup_client.h bsc_msg_filter.h
+ gprs_gsup_client.h bsc_msg_filter.h \
+ gtphub.h
openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
openbscdir = $(includedir)/openbsc
new file mode 100644
@@ -0,0 +1,96 @@
+/* GTP Hub Implementation */
+
+/* (C) 2015 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * All Rights Reserved
+ *
+ * Author: Neels Hofmeyr
+ *
+ * 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/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <sys/socket.h>
+
+#include <osmocom/core/select.h>
+
+
+/* general */
+
+enum gtphub_port_idx {
+ GTPH_PORT_CONTROL = 0,
+ GTPH_PORT_USER = 1,
+ GTPH_PORT_N
+};
+
+extern const char* const gtphub_port_idx_names[GTPH_PORT_N];
+
+
+/* config */
+
+struct gtphub_cfg_addr {
+ const char *addr_str;
+ uint16_t port;
+};
+
+struct gtphub_cfg_bind {
+ struct gtphub_cfg_addr bind;
+};
+
+struct gtphub_cfg {
+ struct gtphub_cfg_bind to_sgsns[GTPH_PORT_N];
+ struct gtphub_cfg_bind to_ggsns[GTPH_PORT_N];
+};
+
+
+/* state */
+
+struct gtphub_addr {
+ struct sockaddr_storage a;
+ socklen_t l;
+};
+
+struct gtphub_peer {
+ struct llist_head entry;
+
+ struct gtphub_addr addr;
+};
+
+struct gtphub_bind {
+ struct osmo_fd ofd;
+
+ /* list of struct gtphub_peer */
+ struct llist_head peers;
+};
+
+struct gtphub {
+ struct gtphub_bind to_sgsns[GTPH_PORT_N];
+ struct gtphub_bind to_ggsns[GTPH_PORT_N];
+};
+
+
+/* api */
+
+void gtphub_zero(struct gtphub *hub);
+int gtphub_init(struct gtphub *hub, struct gtphub_cfg *cfg);
+
+/* Create a new gtphub_peer instance added to peers_list.
+ * Initialize to all-zero. Return a pointer to the new instance, or NULL on
+ * error. */
+struct gtphub_peer *gtphub_peer_new(struct gtphub_bind *bind);
+
+/* Remove a gtphub_peer from its list and free it. */
+void gtphub_peer_del(struct gtphub_peer *peer);
+
@@ -34,5 +34,5 @@ osmo_sgsn_LDADD = \
-lgtp $(OSMO_LIBS) $(LIBOSMOABIS_LIBS) $(LIBCARES_LIBS) \
$(LIBCRYPTO_LIBS) -lrt
-osmo_gtphub_SOURCES = gtphub_main.c
+osmo_gtphub_SOURCES = gtphub_main.c gtphub.c
osmo_gtphub_LDADD = $(LIBOSMOCORE_LIBS) -lrt
new file mode 100644
@@ -0,0 +1,45 @@
+/* GTP Hub Implementation */
+
+/* (C) 2015 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * All Rights Reserved
+ *
+ * Author: Neels Hofmeyr
+ *
+ * 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/licenses/>.
+ */
+
+#include <string.h>
+
+#include <openbsc/gtphub.h>
+#include <openbsc/debug.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/logging.h>
+
+void *osmo_gtphub_ctx;
+
+#define LOGERR(fmt, args...) \
+ LOGP(DGTPHUB, LOGL_ERROR, fmt, ##args)
+
+void gtphub_zero(struct gtphub *hub)
+{
+ memset(hub, '\0', sizeof(*hub));
+}
+
+int gtphub_init(struct gtphub *hub, struct gtphub_cfg *cfg)
+{
+ LOGERR("%s not implemented\n", __func__);
+ return -1;
+}
+