Change in libosmocore[master]: LCLS: enc/dec entire parameter set instead of GCR

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Dec 23 10:20:06 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/12371 )

Change subject: LCLS: enc/dec entire parameter set instead of GCR
......................................................................

LCLS: enc/dec entire parameter set instead of GCR

In 3GPP TS 48.008 the Global Call Reference IE is only used in HANDOVER
REQUEST (§3.2.1.8) and ASSIGNMENT REQUEST (§3.2.1.1) messages which
also include LCLS Config and CSC parameters. Hence, there's no point in
using GCR encode/decode functions alone.

Introduce gsm0808_dec_lcls() and gsm0808_enc_lcls() as trivial wrappers
on top of GCR enc/dec routines which are made static. Adjust tests
accordingly. Test output intentionally left unchanged.

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

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 22050b5..4a2233e 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -84,8 +84,8 @@
 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 osmo_gcr_parsed *g);
-int gsm0808_dec_gcr(struct osmo_gcr_parsed *g, const struct tlv_parsed *tp);
+uint8_t gsm0808_enc_lcls(struct msgb *msg, const struct osmo_lcls *lcls);
+int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp);
 
 uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
 				 const struct gsm0808_speech_codec *sc);
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index 69da57d..485e063 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -488,23 +488,8 @@
 	if (kc)
 		msgb_tv_fixed_put(msg, GSM0808_IE_KC_128, 16, kc);
 
-	if (lcls) {
-		/* LCLS: §3.2.2.115 Global Call Reference */
-		if (lcls->gcr)
-			gsm0808_enc_gcr(msg, lcls->gcr);
-
-		/* LCLS: §3.2.2.116 Configuration */
-		if (lcls->config != GSM0808_LCLS_CFG_NA)
-			msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, lcls->config);
-
-		/* LCLS: §3.2.2.117 Connection Status Control */
-		if (lcls->control != GSM0808_LCLS_CSC_NA)
-			msgb_tv_put(msg, GSM0808_IE_LCLS_CONN_STATUS_CTRL, lcls->control);
-
-		/* LCLS: §3.2.2.118 Correlation-Not-Needed */
-		if (!lcls->corr_needed)
-			msgb_v_put(msg, GSM0808_IE_LCLS_CORR_NOT_NEEDED);
-	}
+	if (lcls)
+		gsm0808_enc_lcls(msg, lcls);
 
 	/* push the bssmap header */
 	msg->l3h =
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index aa0d3d7..2a458c3 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -512,7 +512,7 @@
  *  \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 osmo_gcr_parsed *g)
+static uint8_t gsm0808_enc_gcr(struct msgb *msg, const struct osmo_gcr_parsed *g)
 {
 	uint8_t enc, *len = msgb_tl_put(msg, GSM0808_IE_GLOBAL_CALL_REF);
 
@@ -528,7 +528,7 @@
  *  \param[out] gcr Caller-provided memory to store Global Call Reference
  *  \param[in] tp IE values to be decoded
  *  \returns number of bytes parsed; negative on error */
-int gsm0808_dec_gcr(struct osmo_gcr_parsed *gcr, const struct tlv_parsed *tp)
+static int gsm0808_dec_gcr(struct osmo_gcr_parsed *gcr, const struct tlv_parsed *tp)
 {
 	int ret;
 	const uint8_t *buf = TLVP_VAL_MINLEN(tp, GSM0808_IE_GLOBAL_CALL_REF, OSMO_GCR_MIN_LEN);
@@ -542,6 +542,56 @@
 	return 2 + ret;
 }
 
+/*! Add LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
+ *  \param[out] msg Message Buffer for appending IE
+ *  \param[in] lcls LCLS-related data
+ *  \returns number of bytes added to \a msg or 0 on error */
+uint8_t gsm0808_enc_lcls(struct msgb *msg, const struct osmo_lcls *lcls)
+{
+	uint8_t enc = 0;
+
+	/* LCLS: §3.2.2.115 Global Call Reference */
+	if (lcls->gcr)
+		enc = gsm0808_enc_gcr(msg, lcls->gcr);
+
+	/* LCLS: §3.2.2.116 Configuration */
+	if (lcls->config != GSM0808_LCLS_CFG_NA) {
+		msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, lcls->config);
+		enc += 2;
+	}
+
+	/* LCLS: §3.2.2.117 Connection Status Control */
+	if (lcls->control != GSM0808_LCLS_CSC_NA) {
+		msgb_tv_put(msg, GSM0808_IE_LCLS_CONN_STATUS_CTRL, lcls->control);
+		enc += 2;
+	}
+
+	/* LCLS: §3.2.2.118 Correlation-Not-Needed */
+	if (!lcls->corr_needed) {
+		msgb_v_put(msg, GSM0808_IE_LCLS_CORR_NOT_NEEDED);
+		enc++;
+	}
+
+	return enc;
+}
+
+/*! Decode LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
+ *  \param[out] lcls Caller-provided memory to store LCLS-related data
+ *  \param[in] tp IE values to be decoded
+ *  \returns GCR size or negative on error */
+int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp)
+{
+	int ret = gsm0808_dec_gcr(lcls->gcr, tp);
+	if (ret < 0)
+		return ret;
+
+	lcls->config = tlvp_val8(tp, GSM0808_IE_LCLS_CONFIG, GSM0808_LCLS_CFG_NA);
+	lcls->control = tlvp_val8(tp, GSM0808_IE_LCLS_CONN_STATUS_CTRL, GSM0808_LCLS_CSC_NA);
+	lcls->corr_needed = TLVP_PRESENT(tp, GSM0808_IE_LCLS_CORR_NOT_NEEDED) ? false : true;
+
+	return ret;
+}
+
 /*! 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 90c2195..76b3fd0 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -220,8 +220,8 @@
 gsm0808_lcls_config_names;
 gsm0808_lcls_control_names;
 gsm0808_lcls_status_names;
-gsm0808_enc_gcr;
-gsm0808_dec_gcr;
+gsm0808_enc_lcls;
+gsm0808_dec_lcls;
 
 gsm29118_msgb_alloc;
 gsm29118_create_alert_req;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index ebdfc29..40e2b87 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -668,7 +668,7 @@
 	msgb_free(in_msg);
 }
 
-static void test_enc_dec_gcr()
+static void test_enc_dec_lcls()
 {
 	static const uint8_t res[] = {
 		GSM0808_IE_GLOBAL_CALL_REF,
@@ -690,11 +690,18 @@
 	};
 	int rc;
 	struct tlv_parsed tp;
-	msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "global call reference");
+	struct osmo_lcls lcls_out = { .gcr = &p }, lcls_in = {
+		.gcr = &g,
+		.config = GSM0808_LCLS_CFG_NA,
+		.control = GSM0808_LCLS_CSC_NA,
+		.corr_needed = true,
+	};
+
+	msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "LCLS IE");
 	if (!msg)
 		return;
 
-	len = gsm0808_enc_gcr(msg, &g);
+	len = gsm0808_enc_lcls(msg, &lcls_in);
 	printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: %s\n",
 	       len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
 
@@ -707,29 +714,29 @@
 		abort();
 	}
 
-	rc = gsm0808_dec_gcr(&p, &tp);
+	rc = gsm0808_dec_lcls(&lcls_out, &tp);
 	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);
+	if (lcls_out.gcr->net_len != g.net_len) {
+		printf("Network ID length parsed wrong: %u != %u\n", lcls_out.gcr->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);
+	if (lcls_out.gcr->node != g.node) {
+		printf("Node ID parsed wrong: 0x%X != 0x%X\n", lcls_out.gcr->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));
+	if (memcmp(lcls_out.gcr->net, g.net, g.net_len) != 0) {
+		printf("Network ID parsed wrong: %s\n", osmo_hexdump(lcls_out.gcr->net, lcls_out.gcr->net_len));
 		abort();
 	}
 
-	if (memcmp(p.cr, g.cr, 5) != 0) {
-		printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(p.cr, 5));
+	if (memcmp(lcls_out.gcr->cr, g.cr, 5) != 0) {
+		printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(lcls_out.gcr->cr, 5));
 		abort();
 	}
 
@@ -1959,7 +1966,7 @@
 	test_create_dtap();
 	test_prepend_dtap();
 
-	test_enc_dec_gcr();
+	test_enc_dec_lcls();
 
 	test_enc_dec_aoip_trasp_addr_v4();
 	test_enc_dec_aoip_trasp_addr_v6();

-- 
To view, visit https://gerrit.osmocom.org/12371
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: Icfbb2404e1a1d500243e2071173299b557369335
Gerrit-Change-Number: 12371
Gerrit-PatchSet: 6
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: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181223/ea1831a4/attachment.htm>


More information about the gerrit-log mailing list