<p>Max <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/11827">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Harald Welte: Looks good to me, but someone else must approve
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">LCLS, TS 29.205: add GCR routines<br><br>Add functions to encode and decode Global Call Reference as per<br>3GPP TS 29.205 Table B 2.1.9.1 add corresponding tests.<br><br>Change-Id: Iee95aa4e5c056645b6cb5667e4a067097d52dfbf<br>Related: OS#2487<br>---<br>M include/Makefile.am<br>M include/osmocom/gsm/gsm0808_utils.h<br>A include/osmocom/gsm/gsm29205.h<br>M src/gsm/Makefile.am<br>A src/gsm/gsm29205.c<br>M src/gsm/libosmogsm.map<br>M tests/Makefile.am<br>A tests/gsm29205/gsm29205_test.c<br>A tests/gsm29205/gsm29205_test.ok<br>M tests/testsuite.at<br>10 files changed, 263 insertions(+), 4 deletions(-)<br><br></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 366fd70..ccf9e10 100644</span><br><span>--- a/include/Makefile.am</span><br><span>+++ b/include/Makefile.am</span><br><span>@@ -86,6 +86,7 @@</span><br><span>                        osmocom/coding/gsm0503_interleaving.h \</span><br><span>                        osmocom/coding/gsm0503_coding.h \</span><br><span>                        osmocom/gsm/gsm0808.h \</span><br><span style="color: hsl(120, 100%, 40%);">+                       osmocom/gsm/gsm29205.h \</span><br><span>                        osmocom/gsm/gsm0808_utils.h \</span><br><span>                        osmocom/gsm/gsm23003.h \</span><br><span>                        osmocom/gsm/gsm29118.h \</span><br><span>diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h</span><br><span>index 90ff677..5d5803b 100644</span><br><span>--- a/include/osmocom/gsm/gsm0808_utils.h</span><br><span>+++ b/include/osmocom/gsm/gsm0808_utils.h</span><br><span>@@ -62,7 +62,7 @@</span><br><span> struct osmo_lcls {</span><br><span>     enum gsm0808_lcls_config config;   /**< §3.2.2.116 Configuration */</span><br><span>      enum gsm0808_lcls_control control; /**< §3.2.2.117 Connection Status Control */</span><br><span style="color: hsl(0, 100%, 40%);">-     struct gsm29205_gcr *gcr;          /**< §3.2.2.115 Global Call Reference */</span><br><span style="color: hsl(120, 100%, 40%);">+       struct osmo_gcr_parsed *gcr;       /**< §3.2.2.115 Global Call Reference */</span><br><span>      bool corr_needed;                  /**< §3.2.2.118 Correlation-Not-Needed */</span><br><span> };</span><br><span> </span><br><span>diff --git a/include/osmocom/gsm/gsm29205.h b/include/osmocom/gsm/gsm29205.h</span><br><span>new file mode 100644</span><br><span>index 0000000..0c3c153</span><br><span>--- /dev/null</span><br><span>+++ b/include/osmocom/gsm/gsm29205.h</span><br><span>@@ -0,0 +1,41 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \defgroup gsm29205 3GPP TS 29.205</span><br><span style="color: hsl(120, 100%, 40%);">+ *  @{</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \file gsm29205.h */</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2018 by sysmocom - s.f.m.c. GmbH</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%);">+ * 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 along</span><br><span style="color: hsl(120, 100%, 40%);">+ * with this program; if not, write to the Free Software Foundation, Inc.,</span><br><span style="color: hsl(120, 100%, 40%);">+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</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%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/msgb.h></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%);">+#define OSMO_GCR_MIN_LEN 13</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Parsed representation of Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1. */</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_gcr_parsed {</span><br><span style="color: hsl(120, 100%, 40%);">+       uint8_t net[5];  /** Network ID, ITU-T Q.1902.3 */</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t net_len; /** length (3-5 octets) of gsm29205_gcr#net */</span><br><span style="color: hsl(120, 100%, 40%);">+       uint16_t node;   /** Node ID */</span><br><span style="color: hsl(120, 100%, 40%);">+       uint8_t cr[5];   /** Call Reference ID */</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%);">+uint8_t osmo_enc_gcr(struct msgb *msg, const struct osmo_gcr_parsed *g);</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_dec_gcr(struct osmo_gcr_parsed *gcr, const uint8_t *elem, uint8_t len);</span><br><span>diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am</span><br><span>index e28ea33..ccb38ad 100644</span><br><span>--- a/src/gsm/Makefile.am</span><br><span>+++ b/src/gsm/Makefile.am</span><br><span>@@ -24,7 +24,7 @@</span><br><span>                     gsm_utils.c rsl.c gsm48.c gsm48_ie.c gsm0808.c sysinfo.c \</span><br><span>                   gprs_cipher_core.c gprs_rlc.c gsm0480.c abis_nm.c gsm0502.c \</span><br><span>                        gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c gsm0414.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                 lapd_core.c lapdm.c kasumi.c gsm_04_08_gprs.c \</span><br><span style="color: hsl(120, 100%, 40%);">+                       lapd_core.c lapdm.c kasumi.c gsm29205.c gsm_04_08_gprs.c \</span><br><span>                   auth_core.c auth_comp128v1.c auth_comp128v23.c \</span><br><span>                     auth_milenage.c milenage/aes-encblock.c gea.c \</span><br><span>                      milenage/aes-internal.c milenage/aes-internal-enc.c \</span><br><span>diff --git a/src/gsm/gsm29205.c b/src/gsm/gsm29205.c</span><br><span>new file mode 100644</span><br><span>index 0000000..0ef29b7</span><br><span>--- /dev/null</span><br><span>+++ b/src/gsm/gsm29205.c</span><br><span>@@ -0,0 +1,93 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2018 by sysmocom - s.f.m.c. GmbH</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 along</span><br><span style="color: hsl(120, 100%, 40%);">+ * with this program; if not, write to the Free Software Foundation, Inc.,</span><br><span style="color: hsl(120, 100%, 40%);">+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</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 <osmocom/gsm/protocol/gsm_08_08.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/gsm29205.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/gsm0808.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/msgb.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%);">+#include <errno.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \addtogroup gsm29205</span><br><span style="color: hsl(120, 100%, 40%);">+ *  @{</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \file gsm29205.c</span><br><span style="color: hsl(120, 100%, 40%);">+ *  Functions related to 3GPP TS 29.205, primarily message generation/encoding.</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%);">+/*! Create Global Call Reference.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[out] msg Message Buffer for appending IE</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] g Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns number of bytes added to \a msg */</span><br><span style="color: hsl(120, 100%, 40%);">+uint8_t osmo_enc_gcr(struct msgb *msg, const struct osmo_gcr_parsed *g)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t buf[2];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!g)</span><br><span style="color: hsl(120, 100%, 40%);">+               return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (g->net_len < 3 || g->net_len > 5)</span><br><span style="color: hsl(120, 100%, 40%);">+             return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   msgb_lv_put(msg, g->net_len, g->net);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_store16be(g->node, &buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ msgb_lv_put(msg, 2, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   msgb_lv_put(msg, 5, g->cr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* Length: LV(Net) + LV(Node) + LV(CRef) - see 3GPP TS §3.2.2.115 */</span><br><span style="color: hsl(120, 100%, 40%);">+ return (g->net_len + 1) + (2 + 1) + (5 + 1);</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%);">+/*! Decode Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[out] gcr Caller-provided memory to store Global Call Reference</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] elem IE value to be decoded</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] len Length of \a elem in bytes</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns number of bytes parsed; negative on error */</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_dec_gcr(struct osmo_gcr_parsed *gcr, const uint8_t *elem, uint8_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  uint16_t parsed = 1; /* account for length byte right away */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       if (len < 13)</span><br><span style="color: hsl(120, 100%, 40%);">+              return -EBADMSG;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    gcr->net_len = elem[0];</span><br><span style="color: hsl(120, 100%, 40%);">+    if (gcr->net_len < 3 || gcr->net_len > 5)</span><br><span style="color: hsl(120, 100%, 40%);">+         return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     memcpy(gcr->net, elem + parsed, gcr->net_len);</span><br><span style="color: hsl(120, 100%, 40%);">+  /* +1 for ignored Node ID length field */</span><br><span style="color: hsl(120, 100%, 40%);">+     parsed += (gcr->net_len + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    gcr->node = osmo_load16be(elem + parsed);</span><br><span style="color: hsl(120, 100%, 40%);">+  parsed += 2;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        if (elem[parsed] != 5) /* see Table B 2.1.9.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+              return -ENOENT;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     parsed++;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   memcpy(gcr->cr, elem + parsed, 5);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       return parsed + 5;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map</span><br><span>index dc4e0a6..e85ed6d 100644</span><br><span>--- a/src/gsm/libosmogsm.map</span><br><span>+++ b/src/gsm/libosmogsm.map</span><br><span>@@ -235,6 +235,9 @@</span><br><span> gsm29118_create_release_req;</span><br><span> gsm29118_create_service_abort_req;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+osmo_enc_gcr;</span><br><span style="color: hsl(120, 100%, 40%);">+osmo_dec_gcr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> gsm0858_rsl_ul_meas_enc;</span><br><span> </span><br><span> gsm338_get_sms_alphabet;</span><br><span>diff --git a/tests/Makefile.am b/tests/Makefile.am</span><br><span>index 18d4bb4..028abc2 100644</span><br><span>--- a/tests/Makefile.am</span><br><span>+++ b/tests/Makefile.am</span><br><span>@@ -24,7 +24,7 @@</span><br><span>           abis/abis_test endian/endian_test sercomm/sercomm_test \</span><br><span>             prbs/prbs_test gsm23003/gsm23003_test                  \</span><br><span>             codec/codec_ecu_fr_test timer/clk_override_test        \</span><br><span style="color: hsl(0, 100%, 40%);">-                oap/oap_client_test                                    \</span><br><span style="color: hsl(120, 100%, 40%);">+              oap/oap_client_test gsm29205/gsm29205_test             \</span><br><span>             logging/logging_vty_test                               \</span><br><span>             $(NULL)</span><br><span> </span><br><span>@@ -104,6 +104,9 @@</span><br><span> gsm0808_gsm0808_test_SOURCES = gsm0808/gsm0808_test.c</span><br><span> gsm0808_gsm0808_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+gsm29205_gsm29205_test_SOURCES = gsm29205/gsm29205_test.c</span><br><span style="color: hsl(120, 100%, 40%);">+gsm29205_gsm29205_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> gsm0408_gsm0408_test_SOURCES = gsm0408/gsm0408_test.c</span><br><span> gsm0408_gsm0408_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la</span><br><span> </span><br><span>@@ -272,7 +275,7 @@</span><br><span>              osmo-auc-gen/osmo-auc-gen_test.err                         \</span><br><span>         conv/conv_gsm0503_test.ok endian/endian_test.ok            \</span><br><span>         sercomm/sercomm_test.ok prbs/prbs_test.ok                  \</span><br><span style="color: hsl(0, 100%, 40%);">-            gsm23003/gsm23003_test.ok                                 \</span><br><span style="color: hsl(120, 100%, 40%);">+           gsm29205/gsm29205_test.ok gsm23003/gsm23003_test.ok        \</span><br><span>         timer/clk_override_test.ok                                 \</span><br><span>         oap/oap_client_test.ok oap/oap_client_test.err</span><br><span> </span><br><span>diff --git a/tests/gsm29205/gsm29205_test.c b/tests/gsm29205/gsm29205_test.c</span><br><span>new file mode 100644</span><br><span>index 0000000..5add1b1</span><br><span>--- /dev/null</span><br><span>+++ b/tests/gsm29205/gsm29205_test.c</span><br><span>@@ -0,0 +1,107 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2018 by sysmocom - s.f.m.c. GmbH</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%);">+ * 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 along</span><br><span style="color: hsl(120, 100%, 40%);">+ * with this program; if not, write to the Free Software Foundation, Inc.,</span><br><span style="color: hsl(120, 100%, 40%);">+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</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 <osmocom/gsm/gsm29205.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/msgb.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/protocol/gsm_08_08.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/gsm0808.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/logging.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/application.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdio.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdlib.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdbool.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.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%);">+static void test_gcr()</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      static const uint8_t res[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                0x03, /* .net_len */</span><br><span style="color: hsl(120, 100%, 40%);">+          0x51, 0x52, 0x53, /* .net */</span><br><span style="color: hsl(120, 100%, 40%);">+          0x02, /* .node length */</span><br><span style="color: hsl(120, 100%, 40%);">+              0xde, 0xad, /* .node */</span><br><span style="color: hsl(120, 100%, 40%);">+               0x05, /* length of Call. Ref. */</span><br><span style="color: hsl(120, 100%, 40%);">+              0x41, 0x42, 0x43, 0x44, 0x45 /* .cr - Call. Ref. */</span><br><span style="color: hsl(120, 100%, 40%);">+   };</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t len;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct msgb *msg;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct osmo_gcr_parsed p = { 0 }, g = {</span><br><span style="color: hsl(120, 100%, 40%);">+               .net_len = 3,</span><br><span style="color: hsl(120, 100%, 40%);">+         .net = { 0x51, 0x52, 0x53 },</span><br><span style="color: hsl(120, 100%, 40%);">+          .node = 0xDEAD,</span><br><span style="color: hsl(120, 100%, 40%);">+               .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 }</span><br><span style="color: hsl(120, 100%, 40%);">+        };</span><br><span style="color: hsl(120, 100%, 40%);">+    int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "global call reference");</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!msg)</span><br><span style="color: hsl(120, 100%, 40%);">+             return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     len = osmo_enc_gcr(msg, &g);</span><br><span style="color: hsl(120, 100%, 40%);">+      printf("Testing Global Call Reference encoder...\n\t%d bytes added: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+         len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!msgb_eq_data_print(msg, res, ARRAY_SIZE(res)))</span><br><span style="color: hsl(120, 100%, 40%);">+           abort();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    rc = osmo_dec_gcr(&p, msgb_data(msg), msgb_length(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+  if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printf("decoding failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+             abort();</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%);">+   if (p.net_len != g.net_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+         printf("Network ID length parsed wrong: %u != %u\n", p.net_len, g.net_len);</span><br><span style="color: hsl(120, 100%, 40%);">+         abort();</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%);">+   if (p.node != g.node) {</span><br><span style="color: hsl(120, 100%, 40%);">+               printf("Node ID parsed wrong: 0x%X != 0x%X\n", p.node, g.node);</span><br><span style="color: hsl(120, 100%, 40%);">+             abort();</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%);">+   if (memcmp(p.net, g.net, g.net_len) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+           printf("Network ID parsed wrong: %s\n", osmo_hexdump(p.net, p.net_len));</span><br><span style="color: hsl(120, 100%, 40%);">+            abort();</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%);">+   if (memcmp(p.cr, g.cr, 5) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+             printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(p.cr, 5));</span><br><span style="color: hsl(120, 100%, 40%);">+           abort();</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%);">+   printf("\tdecoded %d bytes: %s\n", rc, rc == len ? "OK" : "FAIL");</span><br><span style="color: hsl(120, 100%, 40%);">+      msgb_free(msg);</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%);">+      osmo_init_logging2(talloc_named_const(NULL, 0, "gsm29205 test"), NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   printf("Testing 3GPP TS 29.205 routines...\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   test_gcr();</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        return EXIT_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/tests/gsm29205/gsm29205_test.ok b/tests/gsm29205/gsm29205_test.ok</span><br><span>new file mode 100644</span><br><span>index 0000000..bddd88a</span><br><span>--- /dev/null</span><br><span>+++ b/tests/gsm29205/gsm29205_test.ok</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Testing 3GPP TS 29.205 routines...</span><br><span style="color: hsl(120, 100%, 40%);">+Testing Global Call Reference encoder...</span><br><span style="color: hsl(120, 100%, 40%);">+      13 bytes added: OK</span><br><span style="color: hsl(120, 100%, 40%);">+    decoded 13 bytes: OK</span><br><span style="color: hsl(120, 100%, 40%);">+Done.</span><br><span>diff --git a/tests/testsuite.at b/tests/testsuite.at</span><br><span>index a1cf98a..6aaaa78 100644</span><br><span>--- a/tests/testsuite.at</span><br><span>+++ b/tests/testsuite.at</span><br><span>@@ -132,6 +132,12 @@</span><br><span> AT_CHECK([$abs_top_builddir/tests/gsm0808/gsm0808_test], [0], [expout], [ignore])</span><br><span> AT_CLEANUP</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AT_SETUP([gsm29205])</span><br><span style="color: hsl(120, 100%, 40%);">+AT_KEYWORDS([gsm29205])</span><br><span style="color: hsl(120, 100%, 40%);">+cat $abs_srcdir/gsm29205/gsm29205_test.ok > expout</span><br><span style="color: hsl(120, 100%, 40%);">+AT_CHECK([$abs_top_builddir/tests/gsm29205/gsm29205_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([gsm0408])</span><br><span> AT_KEYWORDS([gsm0408])</span><br><span> cat $abs_srcdir/gsm0408/gsm0408_test.ok > expout</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/11827">change 11827</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/11827"/><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: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iee95aa4e5c056645b6cb5667e4a067097d52dfbf </div>
<div style="display:none"> Gerrit-Change-Number: 11827 </div>
<div style="display:none"> Gerrit-PatchSet: 25 </div>
<div style="display:none"> Gerrit-Owner: Max <msuraev@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-Reviewer: Max <msuraev@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Pau Espin Pedrol <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Stefan Sperling <stsp@stsp.name> </div>