[PATCH 2/3] ipa, gsup: file rename to prepare for refactoring

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Neels Hofmeyr nhofmeyr at sysmocom.de
Thu Sep 24 11:44:07 UTC 2015


Rename gprs_gsup_client.* to ipa_client.*.

To ease diff reading for the upcoming commit, this commit performs a file
rename only.

Background: currently, GSUP is the only protocol spoken on the IPA wire. We
will now add OAP, a new protocol to register the SGSN with a MAP proxy. What
has been only the GSUP client will mostly become the general IPA client.

Sponsored-by: On-Waves ehf
---
 openbsc/include/openbsc/Makefile.am        |   2 +-
 openbsc/include/openbsc/gprs_gsup_client.h |  54 ------
 openbsc/include/openbsc/ipa_client.h       |  54 ++++++
 openbsc/src/gprs/Makefile.am               |   2 +-
 openbsc/src/gprs/gprs_gsup_client.c        | 288 -----------------------------
 openbsc/src/gprs/gprs_subscriber.c         |   2 +-
 openbsc/src/gprs/ipa_client.c              | 288 +++++++++++++++++++++++++++++
 openbsc/src/gprs/sgsn_vty.c                |   2 +-
 openbsc/tests/sgsn/Makefile.am             |   2 +-
 openbsc/tests/sgsn/sgsn_test.c             |   2 +-
 10 files changed, 348 insertions(+), 348 deletions(-)
 delete mode 100644 openbsc/include/openbsc/gprs_gsup_client.h
 create mode 100644 openbsc/include/openbsc/ipa_client.h
 delete mode 100644 openbsc/src/gprs/gprs_gsup_client.c
 create mode 100644 openbsc/src/gprs/ipa_client.c

diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am
index 254f43d..7bc9d95 100644
--- a/openbsc/include/openbsc/Makefile.am
+++ b/openbsc/include/openbsc/Makefile.am
@@ -16,7 +16,7 @@ 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
+		 ipa_client.h bsc_msg_filter.h
 
 openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
 openbscdir = $(includedir)/openbsc
diff --git a/openbsc/include/openbsc/gprs_gsup_client.h b/openbsc/include/openbsc/gprs_gsup_client.h
deleted file mode 100644
index 9537db4..0000000
--- a/openbsc/include/openbsc/gprs_gsup_client.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* GPRS Subscriber Update Protocol client */
-
-/* (C) 2014 by Sysmocom s.f.m.c. GmbH
- * All Rights Reserved
- *
- * Author: Jacob Erlbeck
- *
- * 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 <osmocom/core/timer.h>
-
-#define GPRS_GSUP_RECONNECT_INTERVAL 10
-#define GPRS_GSUP_PING_INTERVAL 20
-
-struct msgb;
-struct ipa_client_conn;
-struct gprs_gsup_client;
-
-/* Expects message in msg->l2h */
-typedef int (*gprs_gsup_read_cb_t)(struct gprs_gsup_client *gsupc, struct msgb *msg);
-
-struct gprs_gsup_client {
-	struct ipa_client_conn	*link;
-	gprs_gsup_read_cb_t	read_cb;
-	void			*data;
-
-	struct osmo_timer_list	ping_timer;
-	struct osmo_timer_list	connect_timer;
-	int			is_connected;
-	int			got_ipa_pong;
-};
-
-struct gprs_gsup_client *gprs_gsup_client_create(const char *ip_addr,
-						 unsigned int tcp_port,
-						 gprs_gsup_read_cb_t read_cb);
-
-void gprs_gsup_client_destroy(struct gprs_gsup_client *gsupc);
-int gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg);
-struct msgb *gprs_gsup_msgb_alloc(void);
-
diff --git a/openbsc/include/openbsc/ipa_client.h b/openbsc/include/openbsc/ipa_client.h
new file mode 100644
index 0000000..9537db4
--- /dev/null
+++ b/openbsc/include/openbsc/ipa_client.h
@@ -0,0 +1,54 @@
+/* GPRS Subscriber Update Protocol client */
+
+/* (C) 2014 by Sysmocom s.f.m.c. GmbH
+ * All Rights Reserved
+ *
+ * Author: Jacob Erlbeck
+ *
+ * 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 <osmocom/core/timer.h>
+
+#define GPRS_GSUP_RECONNECT_INTERVAL 10
+#define GPRS_GSUP_PING_INTERVAL 20
+
+struct msgb;
+struct ipa_client_conn;
+struct gprs_gsup_client;
+
+/* Expects message in msg->l2h */
+typedef int (*gprs_gsup_read_cb_t)(struct gprs_gsup_client *gsupc, struct msgb *msg);
+
+struct gprs_gsup_client {
+	struct ipa_client_conn	*link;
+	gprs_gsup_read_cb_t	read_cb;
+	void			*data;
+
+	struct osmo_timer_list	ping_timer;
+	struct osmo_timer_list	connect_timer;
+	int			is_connected;
+	int			got_ipa_pong;
+};
+
+struct gprs_gsup_client *gprs_gsup_client_create(const char *ip_addr,
+						 unsigned int tcp_port,
+						 gprs_gsup_read_cb_t read_cb);
+
+void gprs_gsup_client_destroy(struct gprs_gsup_client *gsupc);
+int gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg);
+struct msgb *gprs_gsup_msgb_alloc(void);
+
diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am
index f46a402..b9c3070 100644
--- a/openbsc/src/gprs/Makefile.am
+++ b/openbsc/src/gprs/Makefile.am
@@ -26,7 +26,7 @@ osmo_sgsn_SOURCES =	gprs_gmm.c gprs_sgsn.c gprs_sndcp.c gprs_sndcp_vty.c \
 			sgsn_main.c sgsn_vty.c sgsn_libgtp.c \
 			gprs_llc.c gprs_llc_parse.c gprs_llc_vty.c crc24.c \
 			sgsn_ctrl.c sgsn_auth.c gprs_subscriber.c \
-			gprs_gsup_messages.c gprs_utils.c gprs_gsup_client.c \
+			gprs_gsup_messages.c gprs_utils.c ipa_client.c \
 			gsm_04_08_gprs.c sgsn_cdr.c sgsn_ares.c
 osmo_sgsn_LDADD = 	\
 			$(top_builddir)/src/libcommon/libcommon.a \
diff --git a/openbsc/src/gprs/gprs_gsup_client.c b/openbsc/src/gprs/gprs_gsup_client.c
deleted file mode 100644
index 807b0c1..0000000
--- a/openbsc/src/gprs/gprs_gsup_client.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/* GPRS Subscriber Update Protocol client */
-
-/* (C) 2014 by Sysmocom s.f.m.c. GmbH
- * All Rights Reserved
- *
- * Author: Jacob Erlbeck
- *
- * 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 <openbsc/gprs_gsup_client.h>
-
-#include <osmocom/abis/ipa.h>
-#include <osmocom/gsm/protocol/ipaccess.h>
-#include <osmocom/core/msgb.h>
-
-#include <openbsc/debug.h>
-
-#include <errno.h>
-#include <string.h>
-
-extern void *tall_bsc_ctx;
-
-static void start_test_procedure(struct gprs_gsup_client *gsupc);
-
-static void gsup_client_send_ping(struct gprs_gsup_client *gsupc)
-{
-	struct msgb *msg = gprs_gsup_msgb_alloc();
-
-	msg->l2h = msgb_put(msg, 1);
-	msg->l2h[0] = IPAC_MSGT_PING;
-	ipa_msg_push_header(msg, IPAC_PROTO_IPACCESS);
-	ipa_client_conn_send(gsupc->link, msg);
-}
-
-static int gsup_client_connect(struct gprs_gsup_client *gsupc)
-{
-	int rc;
-
-	if (gsupc->is_connected)
-		return 0;
-
-	if (osmo_timer_pending(&gsupc->connect_timer)) {
-		LOGP(DLINP, LOGL_DEBUG,
-		     "GSUP connect: connect timer already running\n");
-		osmo_timer_del(&gsupc->connect_timer);
-	}
-
-	if (osmo_timer_pending(&gsupc->ping_timer)) {
-		LOGP(DLINP, LOGL_DEBUG,
-		     "GSUP connect: ping timer already running\n");
-		osmo_timer_del(&gsupc->ping_timer);
-	}
-
-	if (ipa_client_conn_clear_queue(gsupc->link) > 0)
-		LOGP(DLINP, LOGL_DEBUG, "GSUP connect: discarded stored messages\n");
-
-	rc = ipa_client_conn_open(gsupc->link);
-
-	if (rc >= 0) {
-		LOGP(DGPRS, LOGL_INFO, "GSUP connecting to %s:%d\n",
-		     gsupc->link->addr, gsupc->link->port);
-		return 0;
-	}
-
-	LOGP(DGPRS, LOGL_INFO, "GSUP failed to connect to %s:%d: %s\n",
-	     gsupc->link->addr, gsupc->link->port, strerror(-rc));
-
-	if (rc == -EBADF || rc == -ENOTSOCK || rc == -EAFNOSUPPORT ||
-	    rc == -EINVAL)
-		return rc;
-
-	osmo_timer_schedule(&gsupc->connect_timer, GPRS_GSUP_RECONNECT_INTERVAL, 0);
-
-	LOGP(DGPRS, LOGL_INFO, "Scheduled timer to retry GSUP connect to %s:%d\n",
-	     gsupc->link->addr, gsupc->link->port);
-
-	return 0;
-}
-
-static void connect_timer_cb(void *gsupc_)
-{
-	struct gprs_gsup_client *gsupc = gsupc_;
-
-	if (gsupc->is_connected)
-		return;
-
-	gsup_client_connect(gsupc);
-}
-
-static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
-{
-	struct gprs_gsup_client *gsupc = link->data;
-
-	LOGP(DGPRS, LOGL_INFO, "GSUP link to %s:%d %s\n",
-		     link->addr, link->port, up ? "UP" : "DOWN");
-
-	gsupc->is_connected = up;
-
-	if (up) {
-		start_test_procedure(gsupc);
-
-		osmo_timer_del(&gsupc->connect_timer);
-	} else {
-		osmo_timer_del(&gsupc->ping_timer);
-
-		osmo_timer_schedule(&gsupc->connect_timer,
-				    GPRS_GSUP_RECONNECT_INTERVAL, 0);
-	}
-}
-
-static int gsup_client_read_cb(struct ipa_client_conn *link, struct msgb *msg)
-{
-	struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
-	struct ipaccess_head_ext *he = (struct ipaccess_head_ext *) msgb_l2(msg);
-	struct gprs_gsup_client *gsupc = (struct gprs_gsup_client *)link->data;
-	int rc;
-	static struct ipaccess_unit ipa_dev = {
-		.unit_name = "SGSN"
-	};
-
-	msg->l2h = &hh->data[0];
-
-	rc = ipaccess_bts_handle_ccm(link, &ipa_dev, msg);
-
-	if (rc < 0) {
-		LOGP(DGPRS, LOGL_NOTICE,
-		     "GSUP received an invalid IPA/CCM message from %s:%d\n",
-		     link->addr, link->port);
-		/* Link has been closed */
-		gsupc->is_connected = 0;
-		msgb_free(msg);
-		return -1;
-	}
-
-	if (rc == 1) {
-		uint8_t msg_type = *(msg->l2h);
-		/* CCM message */
-		if (msg_type == IPAC_MSGT_PONG) {
-			LOGP(DGPRS, LOGL_DEBUG, "GSUP receiving PONG\n");
-			gsupc->got_ipa_pong = 1;
-		}
-
-		msgb_free(msg);
-		return 0;
-	}
-
-	if (hh->proto != IPAC_PROTO_OSMO)
-		goto invalid;
-
-	if (!he || msgb_l2len(msg) < sizeof(*he) ||
-	    he->proto != IPAC_PROTO_EXT_GSUP)
-		goto invalid;
-
-	msg->l2h = &he->data[0];
-
-	OSMO_ASSERT(gsupc->read_cb != NULL);
-	gsupc->read_cb(gsupc, msg);
-
-	/* Not freeing msg here, because that must be done by the read_cb. */
-	return 0;
-
-invalid:
-	LOGP(DGPRS, LOGL_NOTICE,
-	     "GSUP received an invalid IPA message from %s:%d, size = %d\n",
-	     link->addr, link->port, msgb_length(msg));
-
-	msgb_free(msg);
-	return -1;
-}
-
-static void ping_timer_cb(void *gsupc_)
-{
-	struct gprs_gsup_client *gsupc = gsupc_;
-
-	LOGP(DGPRS, LOGL_INFO, "GSUP ping callback (%s, %s PONG)\n",
-	     gsupc->is_connected ? "connected" : "not connected",
-	     gsupc->got_ipa_pong ? "got" : "didn't get");
-
-	if (gsupc->got_ipa_pong) {
-		start_test_procedure(gsupc);
-		return;
-	}
-
-	LOGP(DGPRS, LOGL_NOTICE, "GSUP ping timed out, reconnecting\n");
-	ipa_client_conn_close(gsupc->link);
-	gsupc->is_connected = 0;
-
-	gsup_client_connect(gsupc);
-}
-
-static void start_test_procedure(struct gprs_gsup_client *gsupc)
-{
-	gsupc->ping_timer.data = gsupc;
-	gsupc->ping_timer.cb = &ping_timer_cb;
-
-	gsupc->got_ipa_pong = 0;
-	osmo_timer_schedule(&gsupc->ping_timer, GPRS_GSUP_PING_INTERVAL, 0);
-	LOGP(DGPRS, LOGL_DEBUG, "GSUP sending PING\n");
-	gsup_client_send_ping(gsupc);
-}
-
-struct gprs_gsup_client *gprs_gsup_client_create(const char *ip_addr,
-						 unsigned int tcp_port,
-						 gprs_gsup_read_cb_t read_cb)
-{
-	struct gprs_gsup_client *gsupc;
-	int rc;
-
-	gsupc = talloc_zero(tall_bsc_ctx, struct gprs_gsup_client);
-	OSMO_ASSERT(gsupc);
-
-	gsupc->link = ipa_client_conn_create(gsupc,
-					     /* no e1inp */ NULL,
-					     0,
-					     ip_addr, tcp_port,
-					     gsup_client_updown_cb,
-					     gsup_client_read_cb,
-					     /* default write_cb */ NULL,
-					     gsupc);
-	if (!gsupc->link)
-		goto failed;
-
-	gsupc->connect_timer.data = gsupc;
-	gsupc->connect_timer.cb = &connect_timer_cb;
-
-	rc = gsup_client_connect(gsupc);
-
-	if (rc < 0)
-		goto failed;
-
-	gsupc->read_cb = read_cb;
-
-	return gsupc;
-
-failed:
-	gprs_gsup_client_destroy(gsupc);
-	return NULL;
-}
-
-void gprs_gsup_client_destroy(struct gprs_gsup_client *gsupc)
-{
-	osmo_timer_del(&gsupc->connect_timer);
-	osmo_timer_del(&gsupc->ping_timer);
-
-	if (gsupc->link) {
-		ipa_client_conn_close(gsupc->link);
-		ipa_client_conn_destroy(gsupc->link);
-		gsupc->link = NULL;
-	}
-	talloc_free(gsupc);
-}
-
-int gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg)
-{
-	if (!gsupc) {
-		msgb_free(msg);
-		return -ENOTCONN;
-	}
-
-	if (!gsupc->is_connected) {
-		msgb_free(msg);
-		return -EAGAIN;
-	}
-
-	ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_GSUP);
-	ipa_msg_push_header(msg, IPAC_PROTO_OSMO);
-	ipa_client_conn_send(gsupc->link, msg);
-
-	return 0;
-}
-
-struct msgb *gprs_gsup_msgb_alloc(void)
-{
-	return msgb_alloc_headroom(4000, 64, __func__);
-}
diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c
index 8231e8c..0a3fe19 100644
--- a/openbsc/src/gprs/gprs_subscriber.c
+++ b/openbsc/src/gprs/gprs_subscriber.c
@@ -21,7 +21,7 @@
  */
 
 #include <openbsc/gsm_subscriber.h>
-#include <openbsc/gprs_gsup_client.h>
+#include <openbsc/ipa_client.h>
 
 #include <openbsc/sgsn.h>
 #include <openbsc/gprs_sgsn.h>
diff --git a/openbsc/src/gprs/ipa_client.c b/openbsc/src/gprs/ipa_client.c
new file mode 100644
index 0000000..bec33c4
--- /dev/null
+++ b/openbsc/src/gprs/ipa_client.c
@@ -0,0 +1,288 @@
+/* GPRS Subscriber Update Protocol client */
+
+/* (C) 2014 by Sysmocom s.f.m.c. GmbH
+ * All Rights Reserved
+ *
+ * Author: Jacob Erlbeck
+ *
+ * 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 <openbsc/ipa_client.h>
+
+#include <osmocom/abis/ipa.h>
+#include <osmocom/gsm/protocol/ipaccess.h>
+#include <osmocom/core/msgb.h>
+
+#include <openbsc/debug.h>
+
+#include <errno.h>
+#include <string.h>
+
+extern void *tall_bsc_ctx;
+
+static void start_test_procedure(struct gprs_gsup_client *gsupc);
+
+static void gsup_client_send_ping(struct gprs_gsup_client *gsupc)
+{
+	struct msgb *msg = gprs_gsup_msgb_alloc();
+
+	msg->l2h = msgb_put(msg, 1);
+	msg->l2h[0] = IPAC_MSGT_PING;
+	ipa_msg_push_header(msg, IPAC_PROTO_IPACCESS);
+	ipa_client_conn_send(gsupc->link, msg);
+}
+
+static int gsup_client_connect(struct gprs_gsup_client *gsupc)
+{
+	int rc;
+
+	if (gsupc->is_connected)
+		return 0;
+
+	if (osmo_timer_pending(&gsupc->connect_timer)) {
+		LOGP(DLINP, LOGL_DEBUG,
+		     "GSUP connect: connect timer already running\n");
+		osmo_timer_del(&gsupc->connect_timer);
+	}
+
+	if (osmo_timer_pending(&gsupc->ping_timer)) {
+		LOGP(DLINP, LOGL_DEBUG,
+		     "GSUP connect: ping timer already running\n");
+		osmo_timer_del(&gsupc->ping_timer);
+	}
+
+	if (ipa_client_conn_clear_queue(gsupc->link) > 0)
+		LOGP(DLINP, LOGL_DEBUG, "GSUP connect: discarded stored messages\n");
+
+	rc = ipa_client_conn_open(gsupc->link);
+
+	if (rc >= 0) {
+		LOGP(DGPRS, LOGL_INFO, "GSUP connecting to %s:%d\n",
+		     gsupc->link->addr, gsupc->link->port);
+		return 0;
+	}
+
+	LOGP(DGPRS, LOGL_INFO, "GSUP failed to connect to %s:%d: %s\n",
+	     gsupc->link->addr, gsupc->link->port, strerror(-rc));
+
+	if (rc == -EBADF || rc == -ENOTSOCK || rc == -EAFNOSUPPORT ||
+	    rc == -EINVAL)
+		return rc;
+
+	osmo_timer_schedule(&gsupc->connect_timer, GPRS_GSUP_RECONNECT_INTERVAL, 0);
+
+	LOGP(DGPRS, LOGL_INFO, "Scheduled timer to retry GSUP connect to %s:%d\n",
+	     gsupc->link->addr, gsupc->link->port);
+
+	return 0;
+}
+
+static void connect_timer_cb(void *gsupc_)
+{
+	struct gprs_gsup_client *gsupc = gsupc_;
+
+	if (gsupc->is_connected)
+		return;
+
+	gsup_client_connect(gsupc);
+}
+
+static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
+{
+	struct gprs_gsup_client *gsupc = link->data;
+
+	LOGP(DGPRS, LOGL_INFO, "GSUP link to %s:%d %s\n",
+		     link->addr, link->port, up ? "UP" : "DOWN");
+
+	gsupc->is_connected = up;
+
+	if (up) {
+		start_test_procedure(gsupc);
+
+		osmo_timer_del(&gsupc->connect_timer);
+	} else {
+		osmo_timer_del(&gsupc->ping_timer);
+
+		osmo_timer_schedule(&gsupc->connect_timer,
+				    GPRS_GSUP_RECONNECT_INTERVAL, 0);
+	}
+}
+
+static int gsup_client_read_cb(struct ipa_client_conn *link, struct msgb *msg)
+{
+	struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
+	struct ipaccess_head_ext *he = (struct ipaccess_head_ext *) msgb_l2(msg);
+	struct gprs_gsup_client *gsupc = (struct gprs_gsup_client *)link->data;
+	int rc;
+	static struct ipaccess_unit ipa_dev = {
+		.unit_name = "SGSN"
+	};
+
+	msg->l2h = &hh->data[0];
+
+	rc = ipaccess_bts_handle_ccm(link, &ipa_dev, msg);
+
+	if (rc < 0) {
+		LOGP(DGPRS, LOGL_NOTICE,
+		     "GSUP received an invalid IPA/CCM message from %s:%d\n",
+		     link->addr, link->port);
+		/* Link has been closed */
+		gsupc->is_connected = 0;
+		msgb_free(msg);
+		return -1;
+	}
+
+	if (rc == 1) {
+		uint8_t msg_type = *(msg->l2h);
+		/* CCM message */
+		if (msg_type == IPAC_MSGT_PONG) {
+			LOGP(DGPRS, LOGL_DEBUG, "GSUP receiving PONG\n");
+			gsupc->got_ipa_pong = 1;
+		}
+
+		msgb_free(msg);
+		return 0;
+	}
+
+	if (hh->proto != IPAC_PROTO_OSMO)
+		goto invalid;
+
+	if (!he || msgb_l2len(msg) < sizeof(*he) ||
+	    he->proto != IPAC_PROTO_EXT_GSUP)
+		goto invalid;
+
+	msg->l2h = &he->data[0];
+
+	OSMO_ASSERT(gsupc->read_cb != NULL);
+	gsupc->read_cb(gsupc, msg);
+
+	/* Not freeing msg here, because that must be done by the read_cb. */
+	return 0;
+
+invalid:
+	LOGP(DGPRS, LOGL_NOTICE,
+	     "GSUP received an invalid IPA message from %s:%d, size = %d\n",
+	     link->addr, link->port, msgb_length(msg));
+
+	msgb_free(msg);
+	return -1;
+}
+
+static void ping_timer_cb(void *gsupc_)
+{
+	struct gprs_gsup_client *gsupc = gsupc_;
+
+	LOGP(DGPRS, LOGL_INFO, "GSUP ping callback (%s, %s PONG)\n",
+	     gsupc->is_connected ? "connected" : "not connected",
+	     gsupc->got_ipa_pong ? "got" : "didn't get");
+
+	if (gsupc->got_ipa_pong) {
+		start_test_procedure(gsupc);
+		return;
+	}
+
+	LOGP(DGPRS, LOGL_NOTICE, "GSUP ping timed out, reconnecting\n");
+	ipa_client_conn_close(gsupc->link);
+	gsupc->is_connected = 0;
+
+	gsup_client_connect(gsupc);
+}
+
+static void start_test_procedure(struct gprs_gsup_client *gsupc)
+{
+	gsupc->ping_timer.data = gsupc;
+	gsupc->ping_timer.cb = &ping_timer_cb;
+
+	gsupc->got_ipa_pong = 0;
+	osmo_timer_schedule(&gsupc->ping_timer, GPRS_GSUP_PING_INTERVAL, 0);
+	LOGP(DGPRS, LOGL_DEBUG, "GSUP sending PING\n");
+	gsup_client_send_ping(gsupc);
+}
+
+struct gprs_gsup_client *gprs_gsup_client_create(const char *ip_addr,
+						 unsigned int tcp_port,
+						 gprs_gsup_read_cb_t read_cb)
+{
+	struct gprs_gsup_client *gsupc;
+	int rc;
+
+	gsupc = talloc_zero(tall_bsc_ctx, struct gprs_gsup_client);
+	OSMO_ASSERT(gsupc);
+
+	gsupc->link = ipa_client_conn_create(gsupc,
+					     /* no e1inp */ NULL,
+					     0,
+					     ip_addr, tcp_port,
+					     gsup_client_updown_cb,
+					     gsup_client_read_cb,
+					     /* default write_cb */ NULL,
+					     gsupc);
+	if (!gsupc->link)
+		goto failed;
+
+	gsupc->connect_timer.data = gsupc;
+	gsupc->connect_timer.cb = &connect_timer_cb;
+
+	rc = gsup_client_connect(gsupc);
+
+	if (rc < 0)
+		goto failed;
+
+	gsupc->read_cb = read_cb;
+
+	return gsupc;
+
+failed:
+	gprs_gsup_client_destroy(gsupc);
+	return NULL;
+}
+
+void gprs_gsup_client_destroy(struct gprs_gsup_client *gsupc)
+{
+	osmo_timer_del(&gsupc->connect_timer);
+	osmo_timer_del(&gsupc->ping_timer);
+
+	if (gsupc->link) {
+		ipa_client_conn_close(gsupc->link);
+		ipa_client_conn_destroy(gsupc->link);
+		gsupc->link = NULL;
+	}
+	talloc_free(gsupc);
+}
+
+int gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg)
+{
+	if (!gsupc) {
+		msgb_free(msg);
+		return -ENOTCONN;
+	}
+
+	if (!gsupc->is_connected) {
+		msgb_free(msg);
+		return -EAGAIN;
+	}
+
+	ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_GSUP);
+	ipa_msg_push_header(msg, IPAC_PROTO_OSMO);
+	ipa_client_conn_send(gsupc->link, msg);
+
+	return 0;
+}
+
+struct msgb *gprs_gsup_msgb_alloc(void)
+{
+	return msgb_alloc_headroom(4000, 64, __func__);
+}
diff --git a/openbsc/src/gprs/sgsn_vty.c b/openbsc/src/gprs/sgsn_vty.c
index b74d01a..00a930f 100644
--- a/openbsc/src/gprs/sgsn_vty.c
+++ b/openbsc/src/gprs/sgsn_vty.c
@@ -34,7 +34,7 @@
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/vty.h>
 #include <openbsc/gsm_04_08_gprs.h>
-#include <openbsc/gprs_gsup_client.h>
+#include <openbsc/ipa_client.h>
 
 #include <osmocom/vty/command.h>
 #include <osmocom/vty/vty.h>
diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am
index 3c202dd..ea29fce 100644
--- a/openbsc/tests/sgsn/Makefile.am
+++ b/openbsc/tests/sgsn/Makefile.am
@@ -24,7 +24,7 @@ sgsn_test_LDADD = \
 	$(top_builddir)/src/gprs/sgsn_auth.o \
 	$(top_builddir)/src/gprs/sgsn_ares.o \
 	$(top_builddir)/src/gprs/gprs_gsup_messages.o \
-	$(top_builddir)/src/gprs/gprs_gsup_client.o \
+	$(top_builddir)/src/gprs/ipa_client.o \
 	$(top_builddir)/src/gprs/gprs_utils.o \
 	$(top_builddir)/src/gprs/gprs_subscriber.o \
 	$(top_builddir)/src/gprs/gsm_04_08_gprs.o \
diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c
index 7e5ab1a..251772e 100644
--- a/openbsc/tests/sgsn/sgsn_test.c
+++ b/openbsc/tests/sgsn/sgsn_test.c
@@ -25,7 +25,7 @@
 #include <openbsc/debug.h>
 #include <openbsc/gsm_subscriber.h>
 #include <openbsc/gprs_gsup_messages.h>
-#include <openbsc/gprs_gsup_client.h>
+#include <openbsc/ipa_client.h>
 #include <openbsc/gprs_utils.h>
 
 #include <osmocom/gprs/gprs_bssgp.h>
-- 
2.1.4




More information about the OpenBSC mailing list