<p>Vadim Yanitskiy has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/11105">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">(WIP) libosmogsm: introduce message definition and verification helpers<br><br>Change-Id: Idef83b0c53b17503a64d7ab7422184ca4b60be57<br>---<br>M include/Makefile.am<br>A include/osmocom/gsm/tlv_msg_def.h<br>M src/gsm/Makefile.am<br>A src/gsm/tlv_msg_def.c<br>M tests/Makefile.am<br>M tests/testsuite.at<br>A tests/tlv/tlv_msg_def_test.c<br>A tests/tlv/tlv_msg_def_test.ok<br>8 files changed, 323 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/05/11105/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/Makefile.am b/include/Makefile.am</span><br><span>index 19695d1..ec56054 100644</span><br><span>--- a/include/Makefile.am</span><br><span>+++ b/include/Makefile.am</span><br><span>@@ -121,6 +121,7 @@</span><br><span> osmocom/gsm/rxlev_stat.h \</span><br><span> osmocom/gsm/sysinfo.h \</span><br><span> osmocom/gsm/tlv.h \</span><br><span style="color: hsl(120, 100%, 40%);">+ osmocom/gsm/tlv_msg_def.h \</span><br><span> osmocom/sim/class_tables.h \</span><br><span> osmocom/sim/sim.h</span><br><span> </span><br><span>diff --git a/include/osmocom/gsm/tlv_msg_def.h b/include/osmocom/gsm/tlv_msg_def.h</span><br><span>new file mode 100644</span><br><span>index 0000000..b0c108e</span><br><span>--- /dev/null</span><br><span>+++ b/include/osmocom/gsm/tlv_msg_def.h</span><br><span>@@ -0,0 +1,41 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \addtogroup tlv</span><br><span style="color: hsl(120, 100%, 40%);">+ * @{</span><br><span style="color: hsl(120, 100%, 40%);">+ * \file tlv_msg_def.h */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Marks IE as optional / conditional */</span><br><span style="color: hsl(120, 100%, 40%);">+#define TLV_IE_FLAG_OPTIONAL (1 << 0)</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Marks IE as exclusive (i.e. this IE shall not repeat within a message) */</span><br><span style="color: hsl(120, 100%, 40%);">+#define TLV_IE_FLAG_EXCLUSIVE (1 << 1)</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Marks IE as complex (i.e. this IE may contain TLV-based payload itself) */</span><br><span style="color: hsl(120, 100%, 40%);">+#define TLV_IE_FLAG_COMPLEX (1 << 2)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Definition of a single IE (Information Element) */</span><br><span style="color: hsl(120, 100%, 40%);">+struct tlv_ie_def {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Unique IE identifier */</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t iei;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! TLV type (e.g. T, TV, TvLV) */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct tlv_def tlv_def;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Meta info (see \ref TLV_IE_FLAG_*) */</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t flags;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Definition of a message group */</span><br><span style="color: hsl(120, 100%, 40%);">+struct tlv_msg_group_def {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Human-readable name of a message group definition */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The \ref value-string list of all possible message types */</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct value_string *msg_names;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The \ref value-string list of all possible IEs */</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct value_string *iei_names;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! List of expected (mandatory and optional) IEs */</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct tlv_ie_def *ie_defs[256];</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! @} */</span><br><span>diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am</span><br><span>index 29299a6..25a7d5c 100644</span><br><span>--- a/src/gsm/Makefile.am</span><br><span>+++ b/src/gsm/Makefile.am</span><br><span>@@ -30,7 +30,8 @@</span><br><span> milenage/aes-internal.c milenage/aes-internal-enc.c \</span><br><span> milenage/milenage.c gan.c ipa.c gsm0341.c apn.c \</span><br><span> gsup.c gprs_gea.c gsm0503_conv.c oap.c gsm0808_utils.c \</span><br><span style="color: hsl(0, 100%, 40%);">- gsm23003.c mncc.c bts_features.c oap_client.c</span><br><span style="color: hsl(120, 100%, 40%);">+ gsm23003.c mncc.c bts_features.c oap_client.c \</span><br><span style="color: hsl(120, 100%, 40%);">+ tlv_msg_def.c</span><br><span> libgsmint_la_LDFLAGS = -no-undefined</span><br><span> libgsmint_la_LIBADD = $(top_builddir)/src/libosmocore.la</span><br><span> </span><br><span>diff --git a/src/gsm/tlv_msg_def.c b/src/gsm/tlv_msg_def.c</span><br><span>new file mode 100644</span><br><span>index 0000000..1eae99c</span><br><span>--- /dev/null</span><br><span>+++ b/src/gsm/tlv_msg_def.c</span><br><span>@@ -0,0 +1,50 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \file tlv_msg_def.c</span><br><span style="color: hsl(120, 100%, 40%);">+ * Message definition and verification helpers */</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2018 by Vadim Yanitskiy <axilirator@gmail.com></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * SPDX-License-Identifier: GPL-2.0+</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program. If not, see <http://www.gnu.org/licenses/>.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <errno.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv_msg_def.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \addtogroup tlv</span><br><span style="color: hsl(120, 100%, 40%);">+ * @{</span><br><span style="color: hsl(120, 100%, 40%);">+ * Osmocom message definition and verification helpers</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * In almost all of the TLV based protocols we deal with (OML, RSL,</span><br><span style="color: hsl(120, 100%, 40%);">+ * BSSAP, RR/CC/MM/...) the specification of the individual messages</span><br><span style="color: hsl(120, 100%, 40%);">+ * always includes a statement on which IEs are mandatory, which are</span><br><span style="color: hsl(120, 100%, 40%);">+ * conditional, and which are optional.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This module provides the message definition helpers, which can be</span><br><span style="color: hsl(120, 100%, 40%);">+ * used to implicitly describe and verify the structure of TLV-based</span><br><span style="color: hsl(120, 100%, 40%);">+ * messages.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \file tlv_msg_def.c */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! @} */</span><br><span>diff --git a/tests/Makefile.am b/tests/Makefile.am</span><br><span>index 18d4bb4..201b2d4 100644</span><br><span>--- a/tests/Makefile.am</span><br><span>+++ b/tests/Makefile.am</span><br><span>@@ -26,6 +26,7 @@</span><br><span> codec/codec_ecu_fr_test timer/clk_override_test \</span><br><span> oap/oap_client_test \</span><br><span> logging/logging_vty_test \</span><br><span style="color: hsl(120, 100%, 40%);">+ tlv/tlv_msg_def_test \</span><br><span> $(NULL)</span><br><span> </span><br><span> if ENABLE_MSGFILE</span><br><span>@@ -179,6 +180,9 @@</span><br><span> tlv_tlv_test_SOURCES = tlv/tlv_test.c</span><br><span> tlv_tlv_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+tlv_tlv_msg_def_test_SOURCES = tlv/tlv_msg_def_test.c</span><br><span style="color: hsl(120, 100%, 40%);">+tlv_tlv_msg_def_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> gsup_gsup_test_SOURCES = gsup/gsup_test.c</span><br><span> gsup_gsup_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la</span><br><span> </span><br><span>@@ -274,7 +278,8 @@</span><br><span> sercomm/sercomm_test.ok prbs/prbs_test.ok \</span><br><span> gsm23003/gsm23003_test.ok \</span><br><span> timer/clk_override_test.ok \</span><br><span style="color: hsl(0, 100%, 40%);">- oap/oap_client_test.ok oap/oap_client_test.err</span><br><span style="color: hsl(120, 100%, 40%);">+ oap/oap_client_test.ok oap/oap_client_test.err \</span><br><span style="color: hsl(120, 100%, 40%);">+ tlv/tlv_msg_def_test.ok</span><br><span> </span><br><span> DISTCLEANFILES = atconfig atlocal conv/gsm0503_test_vectors.c</span><br><span> BUILT_SOURCES = conv/gsm0503_test_vectors.c</span><br><span>diff --git a/tests/testsuite.at b/tests/testsuite.at</span><br><span>index a1cf98a..1a5b96a 100644</span><br><span>--- a/tests/testsuite.at</span><br><span>+++ b/tests/testsuite.at</span><br><span>@@ -253,6 +253,12 @@</span><br><span> AT_CHECK([$abs_top_builddir/tests/tlv/tlv_test], [0], [expout], [ignore])</span><br><span> AT_CLEANUP</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AT_SETUP([tlv_msg_def])</span><br><span style="color: hsl(120, 100%, 40%);">+AT_KEYWORDS([tlv_msg_def])</span><br><span style="color: hsl(120, 100%, 40%);">+cat $abs_srcdir/tlv/tlv_msg_def_test.ok > expout</span><br><span style="color: hsl(120, 100%, 40%);">+AT_CHECK([$abs_top_builddir/tests/tlv/tlv_msg_def_test], [0], [expout], [ignore])</span><br><span style="color: hsl(120, 100%, 40%);">+AT_CLEANUP</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> AT_SETUP([gsup])</span><br><span> AT_KEYWORDS([gsup])</span><br><span> cat $abs_srcdir/gsup/gsup_test.ok > expout</span><br><span>diff --git a/tests/tlv/tlv_msg_def_test.c b/tests/tlv/tlv_msg_def_test.c</span><br><span>new file mode 100644</span><br><span>index 0000000..f16d1cd</span><br><span>--- /dev/null</span><br><span>+++ b/tests/tlv/tlv_msg_def_test.c</span><br><span>@@ -0,0 +1,216 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdio.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv_msg_def.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define TEST_MSG_ITEM(msg) msg, sizeof(msg)</span><br><span style="color: hsl(120, 100%, 40%);">+#define MSGT_IES_ITEM(msgt, ies) [msgt] = (ies)</span><br><span style="color: hsl(120, 100%, 40%);">+#define TEST_MSGT_GEN(type, sub_type) ((type << 2) | sub_type)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Inspired by 3GPP TS 29.002, chapter 12 */</span><br><span style="color: hsl(120, 100%, 40%);">+enum test_msg_type {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_REQ = TEST_MSGT_GEN(0x01, 1),</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_RES = TEST_MSGT_GEN(0x01, 2),</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_ERR = TEST_MSGT_GEN(0x01, 3),</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct value_string test_msgt_names[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSGT_MAP_SRI_FOR_SM_REQ),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSGT_MAP_SRI_FOR_SM_RES),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSGT_MAP_SRI_FOR_SM_ERR),</span><br><span style="color: hsl(120, 100%, 40%);">+ { 0, NULL }</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum test_msg_ies {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SMSC_ADDR_IE = 0x01,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_NODE_ADDR_IE = 0x02,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SM_RP_RPI_IE = 0x03,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_MSISDN_IE = 0x04,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_IMSI_IE = 0x05,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_CAUSE_IE = 0x06,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct value_string test_msg_iei_names[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSG_SMSC_ADDR_IE),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSG_NODE_ADDR_IE),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSG_SM_RP_RPI_IE),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSG_MSISDN_IE),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSG_IMSI_IE),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(TEST_MSG_CAUSE_IE),</span><br><span style="color: hsl(120, 100%, 40%);">+ { 0, NULL }</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* IE definitions */</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct tlv_ie_def map_sriForSM_req_ies[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_MSISDN_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TLV },</span><br><span style="color: hsl(120, 100%, 40%);">+ .flags = TLV_IE_FLAG_EXCLUSIVE,</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_SM_RP_RPI_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TV },</span><br><span style="color: hsl(120, 100%, 40%);">+ .flags = TLV_IE_FLAG_EXCLUSIVE,</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_SMSC_ADDR_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TLV },</span><br><span style="color: hsl(120, 100%, 40%);">+ .flags = TLV_IE_FLAG_EXCLUSIVE,</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_IMSI_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TLV },</span><br><span style="color: hsl(120, 100%, 40%);">+ .flags = (TLV_IE_FLAG_EXCLUSIVE | TLV_IE_FLAG_OPTIONAL),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct tlv_ie_def map_sriForSM_res_ies[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_IMSI_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TLV },</span><br><span style="color: hsl(120, 100%, 40%);">+ .flags = TLV_IE_FLAG_EXCLUSIVE,</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_NODE_ADDR_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TLV },</span><br><span style="color: hsl(120, 100%, 40%);">+ .flags = TLV_IE_FLAG_EXCLUSIVE,</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct tlv_ie_def map_sriForSM_err_ies[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei = TEST_MSG_CAUSE_IE,</span><br><span style="color: hsl(120, 100%, 40%);">+ .tlv_def = { TLV_TYPE_TLV },</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* "SRI-FOR-SM" message group (REQ, RES, ERR) definition */</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct tlv_msg_group_def map_sriForSM_def = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "MAP-MO-ForwardSM",</span><br><span style="color: hsl(120, 100%, 40%);">+ .msg_names = test_msgt_names,</span><br><span style="color: hsl(120, 100%, 40%);">+ .iei_names = test_msg_iei_names,</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* IEs according to section 12.1 */</span><br><span style="color: hsl(120, 100%, 40%);">+ .ie_defs = {</span><br><span style="color: hsl(120, 100%, 40%);">+ MSGT_IES_ITEM(TEST_MSGT_MAP_SRI_FOR_SM_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+ map_sriForSM_req_ies),</span><br><span style="color: hsl(120, 100%, 40%);">+ MSGT_IES_ITEM(TEST_MSGT_MAP_SRI_FOR_SM_RES,</span><br><span style="color: hsl(120, 100%, 40%);">+ map_sriForSM_res_ies),</span><br><span style="color: hsl(120, 100%, 40%);">+ MSGT_IES_ITEM(TEST_MSGT_MAP_SRI_FOR_SM_ERR,</span><br><span style="color: hsl(120, 100%, 40%);">+ map_sriForSM_err_ies),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* A valid test set of hand-crafted messages */</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_req_valid[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_MSISDN_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x65, 0x75, 0x03, 0x28, 0x25,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SMSC_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x89, 0x00, 0x00, 0x10,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SM_RP_RPI_IE, 0x00, /* TV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_res_valid[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_RES,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_IMSI_IE, 0x08, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x46, 0x00, 0x44, 0x31, 0x60, 0x13, 0x03, 0xf5,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_NODE_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x15, 0x08, 0x00, 0x40,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_err_valid[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_ERR,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_CAUSE_IE, 0x04, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0xde, 0xad, 0xbe, 0xef,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Unknown and optional IEs */</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_req_valid_optional[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_MSISDN_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x65, 0x75, 0x03, 0x28, 0x25,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_IMSI_IE, 0x08, /* TLV, O (optional) */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x46, 0x00, 0x44, 0x31, 0x60, 0x13, 0x03, 0xf5,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SMSC_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x89, 0x00, 0x00, 0x10,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SM_RP_RPI_IE, 0x00, /* TV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_res_valid_unknown[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_RES,</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x99, 0x03, /* Unknown IE (considered as TLV) */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0xff, 0xff, 0xff,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_IMSI_IE, 0x08, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x46, 0x00, 0x44, 0x31, 0x60, 0x13, 0x03, 0xf5,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_NODE_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x15, 0x08, 0x00, 0x40,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Missing mandatory IE(s) */</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_req_invalid_miss[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_MSISDN_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x65, 0x75, 0x03, 0x28, 0x25,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SMSC_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x89, 0x00, 0x00, 0x10,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_res_invalid_miss[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_RES,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_NODE_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x15, 0x08, 0x00, 0x40,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* TLV vs TV mismatch */</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t map_sriForSM_enc_req_invalid_tv_vs_tlv[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSGT_MAP_SRI_FOR_SM_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_MSISDN_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x65, 0x75, 0x03, 0x28, 0x25,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SMSC_ADDR_IE, 0x07, /* TLV, M */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0x91, 0x52, 0x75, 0x89, 0x00, 0x00, 0x10,</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_SM_RP_RPI_IE, 0x04, /* TLV, M (incorrect) */</span><br><span style="color: hsl(120, 100%, 40%);">+ 0xde, 0xad, 0xbe, 0xef,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Complete test set of hand-crafted messages */</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct test_msg_def {</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+ const uint8_t *data;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t data_len;</span><br><span style="color: hsl(120, 100%, 40%);">+} map_sriForSM_enc_test_set[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Request (valid, mandatory IEs only)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_req_valid),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Response (valid, mandatory IEs only)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_res_valid),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Error (valid, mandatory IEs only)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_err_valid),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Request (valid, optional IEs)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_req_valid_optional),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Response (valid, unknown IEs)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_res_valid_unknown),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Request (invalid, missing mandatory IEs)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_req_invalid_miss),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Response (invalid, missing mandatory IEs)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_res_invalid_miss),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* FIXME: how it supposed to be detected??? decoding failure? */</span><br><span style="color: hsl(120, 100%, 40%);">+ "MAP-SRI-FOR-SM Request (invalid, TV vs TLV mismatch)",</span><br><span style="color: hsl(120, 100%, 40%);">+ TEST_MSG_ITEM(map_sriForSM_enc_req_invalid_tv_vs_tlv),</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int main(int argc, char **argv)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ printf("Done.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/tests/tlv/tlv_msg_def_test.ok b/tests/tlv/tlv_msg_def_test.ok</span><br><span>new file mode 100644</span><br><span>index 0000000..619c561</span><br><span>--- /dev/null</span><br><span>+++ b/tests/tlv/tlv_msg_def_test.ok</span><br><span>@@ -0,0 +1 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Done.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/11105">change 11105</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/11105"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Idef83b0c53b17503a64d7ab7422184ca4b60be57 </div>
<div style="display:none"> Gerrit-Change-Number: 11105 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <axilirator@gmail.com> </div>