Change in libosmocore[master]: LCLS, TS 48.008: add GCR IE encoding/decoding

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
Thu Nov 29 22:47:40 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/12020


Change subject: LCLS, TS 48.008: add GCR IE encoding/decoding
......................................................................

LCLS, TS 48.008: add GCR IE encoding/decoding

* add functions to encode Global Call. Ref. from TS 29.205 as 3GPP TS
  48.008 §3.2.2.115 information element
* add corresponding tests

Change-Id: I82ce0207dc8de50689a8806c6471ad7fbae6219d
---
M include/osmocom/gsm/gsm0808_utils.h
M src/gsm/gsm0808_utils.c
M src/gsm/libosmogsm.map
M tests/gsm0808/gsm0808_test.c
M tests/gsm0808/gsm0808_test.ok
5 files changed, 103 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/20/12020/1

diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 57aa6ea..5de0d9d 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -81,6 +81,10 @@
 				    const struct sockaddr_storage *ss);
 int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss,
 				const uint8_t *elem, uint8_t len);
+
+uint8_t gsm0808_enc_gcr(struct msgb *msg,  const struct gsm29205_gcr *g);
+int gsm0808_dec_gcr(struct gsm29205_gcr *g, struct tlv_parsed *tp);
+
 uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
 				 const struct gsm0808_speech_codec *sc);
 int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc,
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index c58d828..9f7ec7e 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -482,6 +482,42 @@
 	return (int)(elem - old_elem);
 }
 
+/*! Create BSSMAP Global Call Reference, 3GPP TS 48.008 §3.2.2.115
+ *  \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 or 0 on error */
+uint8_t gsm0808_enc_gcr(struct msgb *msg, const struct gsm29205_gcr *g)
+{
+	uint8_t enc, *len;
+
+	len = msgb_v_put(msg, GSM0808_IE_GLOBAL_CALL_REF);
+
+	/* reserve space for length */
+	msgb_v_put(msg, 0); /* len points to this reserved space already */
+
+	enc = gsm29205_enc_gcr(msg, g);
+	if (enc) {
+		len[0] = enc;
+		return enc + 2; /* type (1 byte) + length (1 byte) */
+	}
+
+	return 0;
+}
+
+/*! Decode BSSMAP 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 gsm0808_dec_gcr(struct gsm29205_gcr *gcr, struct tlv_parsed *tp)
+{
+	const uint8_t *buf = TLVP_VAL_MINLEN(tp, GSM0808_IE_GLOBAL_CALL_REF, OSMO_GCR_MIN_LEN);
+	if (!buf)
+		return -EINVAL;
+
+	return 2 + gsm29205_dec_gcr(gcr, buf, TLVP_LEN(tp, GSM0808_IE_GLOBAL_CALL_REF));
+}
+
 /*! Encode TS 08.08 Encryption Information IE
  *  \param[out] msg Message Buffer to which IE is to be appended
  *  \param[in] ei Encryption Information to be encoded
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index e1012b2..390b546 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -146,6 +146,8 @@
 
 gsm29205_enc_gcr;
 gsm29205_dec_gcr;
+gsm0808_enc_gcr;
+gsm0808_dec_gcr;
 
 gsm0808_att_tlvdef;
 gsm0808_bssap_name;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 197ec06..e428970 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -569,6 +569,61 @@
 	msgb_free(in_msg);
 }
 
+static void test_enc_dec_gcr()
+{
+	static const uint8_t res[] = {
+		GSM0808_IE_GLOBAL_CALL_REF,
+		0x0d, /* GCR length */
+		0x03, /* .net_len */
+		0x4f, 0x4f, 0x4f, /* .net */
+		0x02, /* .node length */
+		0xde, 0xad, /* .node */
+		0x05, /* length of Call. Ref. */
+		0x4e, 0x4e, 0x4e, 0x4e, 0x4e /* .cr - Call. Ref. */
+	};
+	uint8_t len;
+	struct msgb *msg;
+	struct gsm29205_gcr g = { .net_len = 3, .node = 0xDEAD }, p = { 0 };
+	int rc;
+	struct tlv_parsed tp;
+	msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "global call reference");
+	if (!msg)
+		return;
+
+	memset(g.cr, 'N', sizeof(g.cr));
+	memset(g.net, 'O', g.net_len);
+
+	len = gsm0808_enc_gcr(msg, &g);
+	printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: %s\n",
+	       len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
+
+	if (!msgb_cmpr(__func__, __LINE__, msg, res, ARRAY_SIZE(res), true))
+		abort();
+
+	rc = osmo_bssap_tlv_parse(&tp, msgb_data(msg), msgb_length(msg));
+	if (rc < 0)
+		printf("parsing failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
+
+	rc = gsm0808_dec_gcr(&p, &tp);
+	if (rc < 0)
+		printf("decoding failed: %s [%s]\n", strerror(-rc), msgb_hexdump(msg));
+
+	if (p.net_len != g.net_len)
+		printf("Network ID length parsed wrong: %u != %u\n", p.net_len, g.net_len);
+
+	if (p.node != g.node)
+		printf("Node ID parsed wrong: 0x%X != 0x%X\n", p.node, g.node);
+
+	if (memcmp(p.net, g.net, g.net_len) != 0)
+		printf("Network ID parsed wrong: %s\n", osmo_hexdump(p.net, p.net_len));
+
+	if (memcmp(p.cr, g.cr, 5) != 0)
+		printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(p.cr, 5));
+
+	printf("\tdecoded %d bytes: %s\n", rc, rc == len ? "OK" : "FAIL");
+	msgb_free(msg);
+}
+
 static void test_enc_dec_aoip_trasp_addr_v4()
 {
 	struct sockaddr_storage enc_addr;
@@ -1791,6 +1846,9 @@
 	test_create_paging();
 	test_create_dtap();
 	test_prepend_dtap();
+
+	test_enc_dec_gcr();
+
 	test_enc_dec_aoip_trasp_addr_v4();
 	test_enc_dec_aoip_trasp_addr_v6();
 	test_gsm0808_enc_dec_speech_codec();
diff --git a/tests/gsm0808/gsm0808_test.ok b/tests/gsm0808/gsm0808_test.ok
index a48cf1d..f38dac3 100644
--- a/tests/gsm0808/gsm0808_test.ok
+++ b/tests/gsm0808/gsm0808_test.ok
@@ -20,6 +20,9 @@
 Testing creating Paging Request
 Testing creating DTAP
 Testing prepend DTAP
+Testing Global Call Reference IE encoder...
+	15 bytes added: OK
+	decoded 15 bytes: OK
 test_gsm0808_enc_dec_cell_id_list_lac: encoded: 1a 07 05 01 24 ab cd 56 78 (rc = 9)
 ------- test_cell_id_list_add
      cell_id_list == CGI[0]:{}

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82ce0207dc8de50689a8806c6471ad7fbae6219d
Gerrit-Change-Number: 12020
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181129/7ac38027/attachment.htm>


More information about the gerrit-log mailing list