pespin submitted this change.

View Change

Approvals: daniel: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve
mtp: Implement already defined osmo_mtp_prim_name()

Implement osmo_mtp_prim_name(), which was defined in a header
file but didn't exist so far.

Create a mtp_sap.c file as a counterpart of mtp_sap.h header, and move
there all primitive/SAP related code, to make it easier to spot where
the inter-layer communication happens. This way we also have the same
disposition as with sccp_sap/sccp_user.

This is a preparation commit, follow-up commits will use the
osmo_mtp_prim_name() API and clean up and move more APIs to mtp_sap.c.

Change-Id: Ifa21c26ceaa079435a2d157f99813e06cfc12e71
---
M include/osmocom/sigtran/mtp_sap.h
M src/Makefile.am
A src/mtp_sap.c
3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/include/osmocom/sigtran/mtp_sap.h b/include/osmocom/sigtran/mtp_sap.h
index f13d6f1..590e0ab 100644
--- a/include/osmocom/sigtran/mtp_sap.h
+++ b/include/osmocom/sigtran/mtp_sap.h
@@ -30,6 +30,11 @@
OSMO_MTP_PRIM_RESUME,
OSMO_MTP_PRIM_STATUS,
};
+extern const struct value_string osmo_mtp_prim_type_names[];
+static inline const char *osmo_mtp_prim_type_name(enum osmo_mtp_prim_type val)
+{
+ return get_value_string(osmo_mtp_prim_type_names, val);
+}

/* ITU Q.704 14.2 Service information octet. See enum mtp_si_ni00 in mtp.h. */
#define MTP_SIO(service, net_ind) ((((net_ind) & 0x3) << 6) | ((service) & 0xF))
@@ -66,4 +71,4 @@

#define msgb_mtp_prim(msg) ((struct osmo_mtp_prim *)(msg)->l1h)

-char *osmo_mtp_prim_name(struct osmo_prim_hdr *oph);
+char *osmo_mtp_prim_name(const struct osmo_prim_hdr *oph);
diff --git a/src/Makefile.am b/src/Makefile.am
index 62c7e9d..de3d02e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,6 +46,7 @@
libosmo_sigtran_la_SOURCES = \
ipa.c \
m3ua.c \
+ mtp_sap.c \
sccp2sua.c \
sccp_connection.c \
sccp_helpers.c \
diff --git a/src/mtp_sap.c b/src/mtp_sap.c
new file mode 100644
index 0000000..b6b6eeb
--- /dev/null
+++ b/src/mtp_sap.c
@@ -0,0 +1,59 @@
+/* (C) 2025 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/prim.h>
+#include <osmocom/sigtran/osmo_ss7.h>
+#include <osmocom/sigtran/mtp_sap.h>
+
+const struct value_string osmo_mtp_prim_type_names[] = {
+ { OSMO_MTP_PRIM_TRANSFER, "MTP-TRANSFER" },
+ { OSMO_MTP_PRIM_PAUSE, "MTP-PAUSE" },
+ { OSMO_MTP_PRIM_RESUME, "MTP-RESUME" },
+ { OSMO_MTP_PRIM_STATUS, "MTP-STATUS" },
+ { 0, NULL }
+};
+
+static char prim_name_buf[128];
+
+static int mtp_prim_hdr_name_buf(char *buf, size_t buflen, const struct osmo_prim_hdr *oph)
+{
+ struct osmo_strbuf sb = { .buf = buf, .len = buflen };
+
+ if (!oph) {
+ OSMO_STRBUF_PRINTF(sb, "null");
+ return sb.chars_needed;
+ }
+
+ OSMO_STRBUF_PRINTF(sb, "%s.%s",
+ osmo_mtp_prim_type_name(oph->primitive),
+ osmo_prim_operation_name(oph->operation));
+ return sb.chars_needed;
+}
+
+char *osmo_mtp_prim_name(const struct osmo_prim_hdr *oph)
+{
+ mtp_prim_hdr_name_buf(prim_name_buf, sizeof(prim_name_buf), oph);
+ return prim_name_buf;
+}

To view, visit change 41416. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Ifa21c26ceaa079435a2d157f99813e06cfc12e71
Gerrit-Change-Number: 41416
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>