[PATCH] libosmo-sccp[master]: Add sccp_helpers.[hc] moved from osmo-iuh, 1:1 at first

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon Feb 13 03:09:20 UTC 2017


Review at  https://gerrit.osmocom.org/1798

Add sccp_helpers.[hc] moved from osmo-iuh, 1:1 at first

Move here unchanged first, so we're able to see the modifications in diffs.
Pending changes will follow in subsequent patches.

Moved from osmo-iuh 3da8608b6ad014fc74536dbb49019704fd425b8c, which was before
the rename of osmo_sua_link and osmo_sua_user to osmo_sccp_link and
osmo_sccp_user, so this will not compile.

Change-Id: Iae0c58c5f1eb00a685de70add0d5257e4316c6d5
---
M include/osmocom/sigtran/Makefile.am
A include/osmocom/sigtran/sccp_helpers.h
M src/Makefile.am
A src/sccp_helpers.c
4 files changed, 172 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/98/1798/1

diff --git a/include/osmocom/sigtran/Makefile.am b/include/osmocom/sigtran/Makefile.am
index adb0997..e168256 100644
--- a/include/osmocom/sigtran/Makefile.am
+++ b/include/osmocom/sigtran/Makefile.am
@@ -1,4 +1,6 @@
-sigtran_HEADERS = m3ua_types.h xua_types.h xua_msg.h m2ua_types.h sccp_sap.h sua.h sigtran_sap.h
+sigtran_HEADERS = m3ua_types.h xua_types.h xua_msg.h m2ua_types.h sccp_sap.h \
+		  sua.h sigtran_sap.h sccp_helpers.h
+
 sigtrandir = $(includedir)/osmocom/sigtran
 
 sigtran_prot_HEADERS = protocol/sua.h
diff --git a/include/osmocom/sigtran/sccp_helpers.h b/include/osmocom/sigtran/sccp_helpers.h
new file mode 100644
index 0000000..089d69a
--- /dev/null
+++ b/include/osmocom/sigtran/sccp_helpers.h
@@ -0,0 +1,33 @@
+#pragma once
+#include <unistd.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/sigtran/sccp_sap.h>
+#include <osmocom/sigtran/sua.h>
+
+int sccp_tx_unitdata(struct osmo_sua_link *link,
+		     const struct osmo_sccp_addr *calling_addr,
+		     const struct osmo_sccp_addr *called_addr,
+		     uint8_t *data, unsigned int len);
+
+int sccp_tx_unitdata_msg(struct osmo_sua_link *link,
+			 const struct osmo_sccp_addr *calling_addr,
+			 const struct osmo_sccp_addr *called_addr,
+			 struct msgb *msg);
+
+void sccp_make_addr_pc_ssn(struct osmo_sccp_addr *addr, uint32_t pc, uint32_t ssn);
+
+int sccp_tx_conn_req(struct osmo_sua_link *link, uint32_t conn_id,
+		     const struct osmo_sccp_addr *calling_addr,
+		     const struct osmo_sccp_addr *called_addr,
+		     uint8_t *data, unsigned int len);
+
+int sccp_tx_conn_req_msg(struct osmo_sua_link *link, uint32_t conn_id,
+			 const struct osmo_sccp_addr *calling_addr,
+			 const struct osmo_sccp_addr *called_addr,
+			 struct msgb *msg);
+
+int sccp_tx_data(struct osmo_sua_link *link, uint32_t conn_id,
+		 uint8_t *data, unsigned int len);
+
+int sccp_tx_data_msg(struct osmo_sua_link *link, uint32_t conn_id,
+		     struct msgb *msg);
diff --git a/src/Makefile.am b/src/Makefile.am
index 238a840..26482a0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,6 @@
 # documentation before making any modification
 LIBVERSION=0:0:0
 
-libosmo_sigtran_la_SOURCES = sccp_sap.c sua.c xua_msg.c
+libosmo_sigtran_la_SOURCES = sccp_sap.c sua.c xua_msg.c sccp_helpers.c
 libosmo_sigtran_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined -export-symbols-regex '^osmo_'
 libosmo_sigtran_la_LIBADD = $(LIBOSMOCORE_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS)
diff --git a/src/sccp_helpers.c b/src/sccp_helpers.c
new file mode 100644
index 0000000..cdb26e7
--- /dev/null
+++ b/src/sccp_helpers.c
@@ -0,0 +1,135 @@
+/* SCCP User SAP helper functions (move to libosmo-sigtran?) */
+
+/* (C) 2015 by Harald Welte <laforge at gnumonks.org>
+ * 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 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 <osmocom/sigtran/sccp_sap.h>
+#include <osmocom/sigtran/sua.h>
+
+#include "sccp_helpers.h"
+
+void sccp_make_addr_pc_ssn(struct osmo_sccp_addr *addr, uint32_t pc, uint32_t ssn)
+{
+	addr->presence = OSMO_SCCP_ADDR_T_SSN | OSMO_SCCP_ADDR_T_PC;
+	addr->ssn = ssn;
+	addr->pc = pc;
+}
+
+int sccp_tx_unitdata(struct osmo_sua_link *link,
+		     const struct osmo_sccp_addr *calling_addr,
+		     const struct osmo_sccp_addr *called_addr,
+		     uint8_t *data, unsigned int len)
+{
+	struct msgb *msg = msgb_alloc(1024, "sccp_tx_unitdata");
+	struct osmo_scu_prim *prim;
+	struct osmo_scu_unitdata_param *param;
+
+	prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
+	param = &prim->u.unitdata;
+	sccp_make_addr_pc_ssn(&param->calling_addr, 1, OSMO_SCCP_SSN_RANAP);
+	sccp_make_addr_pc_ssn(&param->called_addr, 2, OSMO_SCCP_SSN_RANAP);
+	osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_REQUEST, msg);
+
+	msg->l2h = msgb_put(msg, len);
+	memcpy(msg->l2h, data, len);
+
+	return osmo_sua_user_link_down(link, &prim->oph);
+}
+
+int sccp_tx_unitdata_msg(struct osmo_sua_link *link,
+			 const struct osmo_sccp_addr *calling_addr,
+			 const struct osmo_sccp_addr *called_addr,
+			 struct msgb *msg)
+{
+	int rc;
+
+	rc = sccp_tx_unitdata(link, calling_addr, called_addr,
+			      msg->data, msgb_length(msg));
+	msgb_free(msg);
+
+	return rc;
+}
+
+int sccp_tx_conn_req(struct osmo_sua_link *link, uint32_t conn_id,
+		     const struct osmo_sccp_addr *calling_addr,
+		     const struct osmo_sccp_addr *called_addr,
+		     uint8_t *data, unsigned int len)
+{
+	struct msgb *msg = msgb_alloc(1024, "sccp_tx_conn_req");
+	struct osmo_scu_prim *prim;
+
+	prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
+	osmo_prim_init(&prim->oph, SCCP_SAP_USER,
+			OSMO_SCU_PRIM_N_CONNECT,
+			PRIM_OP_REQUEST, msg);
+	sccp_make_addr_pc_ssn(&prim->u.connect.calling_addr, 1, OSMO_SCCP_SSN_RANAP);
+	prim->u.connect.sccp_class = 2;
+	prim->u.connect.conn_id = conn_id;
+
+	if (data && len) {
+		msg->l2h = msgb_put(msg, len);
+		memcpy(msg->l2h, data, len);
+	}
+
+	return osmo_sua_user_link_down(link, &prim->oph);
+}
+
+int sccp_tx_conn_req_msg(struct osmo_sua_link *link, uint32_t conn_id,
+			 const struct osmo_sccp_addr *calling_addr,
+			 const struct osmo_sccp_addr *called_addr,
+			 struct msgb *msg)
+{
+	int rc;
+
+	rc = sccp_tx_conn_req(link, conn_id, calling_addr, called_addr,
+			      msg->data, msgb_length(msg));
+	msgb_free(msg);
+
+	return rc;
+}
+
+int sccp_tx_data(struct osmo_sua_link *link, uint32_t conn_id,
+		 uint8_t *data, unsigned int len)
+{
+	struct msgb *msg = msgb_alloc(1024, "sccp_tx_data");
+	struct osmo_scu_prim *prim;
+
+	prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
+	osmo_prim_init(&prim->oph, SCCP_SAP_USER,
+			OSMO_SCU_PRIM_N_DATA,
+			PRIM_OP_REQUEST, msg);
+	prim->u.data.conn_id = conn_id;
+
+	msg->l2h = msgb_put(msg, len);
+	memcpy(msg->l2h, data, len);
+
+	return osmo_sua_user_link_down(link, &prim->oph);
+}
+
+int sccp_tx_data_msg(struct osmo_sua_link *link, uint32_t conn_id,
+		     struct msgb *msg)
+{
+	int rc;
+
+	rc = sccp_tx_data(link, conn_id, msg->data, msgb_length(msg));
+	msgb_free(msg);
+
+	return rc;
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae0c58c5f1eb00a685de70add0d5257e4316c6d5
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list