Change in libosmocore[master]: LCLS, TS 29.205: add GCR routines

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/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Fri Dec 14 13:15:40 UTC 2018


Max has submitted this change and it was merged. ( https://gerrit.osmocom.org/11827 )

Change subject: LCLS, TS 29.205: add GCR routines
......................................................................

LCLS, TS 29.205: add GCR routines

Add functions to encode and decode Global Call Reference as per
3GPP TS 29.205 Table B 2.1.9.1 add corresponding tests.

Change-Id: Iee95aa4e5c056645b6cb5667e4a067097d52dfbf
Related: OS#2487
---
M include/Makefile.am
M include/osmocom/gsm/gsm0808_utils.h
A include/osmocom/gsm/gsm29205.h
M src/gsm/Makefile.am
A src/gsm/gsm29205.c
M src/gsm/libosmogsm.map
M tests/Makefile.am
A tests/gsm29205/gsm29205_test.c
A tests/gsm29205/gsm29205_test.ok
M tests/testsuite.at
10 files changed, 263 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, but someone else must approve
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified



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

-- 
To view, visit https://gerrit.osmocom.org/11827
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iee95aa4e5c056645b6cb5667e4a067097d52dfbf
Gerrit-Change-Number: 11827
Gerrit-PatchSet: 25
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Stefan Sperling <stsp at stsp.name>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181214/3d2f58be/attachment.htm>


More information about the gerrit-log mailing list