[PATCH] libosmocore[master]: gsm0808: Add utils for Channel Type

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

dexter gerrit-no-reply at lists.osmocom.org
Thu Mar 30 16:44:53 UTC 2017


Review at  https://gerrit.osmocom.org/2179

gsm0808: Add utils for Channel Type

The planned support for true A over IP requires the encoding of
the a Channel Type element (see also ASSIGNMENT REQUEST).

This commt adds encoding/decoding functionality and tests for
the element mentioned above, however, it is not yet actively used.

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


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/79/2179/1

diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 4049a2f..6a2259f 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -43,3 +43,10 @@
 /* Decode Speech Codec list */
 struct llist_head *gsm0808_dec_speech_codec_list(const void *ctx,
 						 struct msgb *msg);
+
+/* Encode Channel Type element */
+struct msgb *gsm0808_enc_channel_type(struct gsm0808_channel_type *ct);
+
+/* Decode Channel Type element */
+struct gsm0808_channel_type *gsm0808_dec_channel_type(const void *ctx,
+						      struct msgb *msg);
diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h b/include/osmocom/gsm/protocol/gsm_08_08.h
index ad5e633..981dda5 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -433,3 +433,12 @@
 	bool type_extended;
 	bool cfg_present;
 };
+
+/* 3GPP TS 48.008 3.2.2.11 Channel Type */
+#define CH_TYPE_PERM_SPCH_MAXLEN 9
+struct gsm0808_channel_type {
+	uint8_t ch_indctr;
+	uint8_t ch_rate_type;
+	uint8_t perm_spch[CH_TYPE_PERM_SPCH_MAXLEN];
+	unsigned int perm_spch_len;
+};
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 202f1ac..54b8a70 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -32,6 +32,8 @@
 #define IP_V6_ADDR_LEN 16
 #define IP_PORT_LEN 2
 
+#define CHANNEL_TYPE_ELEMENT_MAXLEN 11
+#define CHANNEL_TYPE_ELEMENT_MINLEN 3
 
 /* Encode AoIP transport address element */
 struct msgb *gsm0808_enc_aoip_trasp_addr(struct sockaddr_storage *ss)
@@ -287,3 +289,70 @@
 
 	return scl;
 }
+
+/* Encode Channel Type element */
+struct msgb *gsm0808_enc_channel_type(struct gsm0808_channel_type *ct)
+{
+	struct msgb *msg;
+	unsigned int i;
+	uint8_t byte;
+
+	OSMO_ASSERT(ct);
+	OSMO_ASSERT(ct->perm_spch_len <= CHANNEL_TYPE_ELEMENT_MAXLEN-2);
+
+	/* FIXME: Implement encoding support for Data
+	 * and Speech + CTM Text Telephony */
+	if ((ct->ch_indctr & 0x0f) != GSM0808_CHAN_SPEECH
+	    && (ct->ch_indctr & 0x0f) != GSM0808_CHAN_SIGN)
+		return NULL;
+
+	msg = msgb_alloc(ELEMENT_MSGB_MAXLEN, "Channel Type Element");
+	if (!msg)
+		return NULL;
+
+	msgb_put_u8(msg, ct->ch_indctr & 0x0f);
+	msgb_put_u8(msg, ct->ch_rate_type);
+
+	for (i = 0; i < ct->perm_spch_len; i++) {
+		byte = ct->perm_spch[i];
+
+		if (i < ct->perm_spch_len - 1)
+			byte |= 0x80;
+		msgb_put_u8(msg, byte);
+	}
+
+	return msg;
+}
+
+/* Decode Channel Type element */
+struct gsm0808_channel_type *gsm0808_dec_channel_type(const void *ctx,
+						      struct msgb *msg)
+{
+	struct gsm0808_channel_type *ct;
+	unsigned int i;
+	uint8_t byte;
+
+	if (!msg)
+		return NULL;
+
+	/* Malformed element */
+	if (msg->len < CHANNEL_TYPE_ELEMENT_MINLEN)
+		return NULL;
+
+	ct = talloc_zero(ctx, struct gsm0808_channel_type);
+	if (!ct)
+		return NULL;
+
+	ct->ch_indctr = msgb_pull_u8(msg) & 0x0f;
+	ct->ch_rate_type = msgb_pull_u8(msg) & 0x0f;
+
+	for (i = 0; i < ARRAY_SIZE(ct->perm_spch); i++) {
+		byte = msgb_pull_u8(msg);
+		ct->perm_spch[i] = byte & 0x7f;
+		if ((byte & 0x80) == 0x00)
+			break;
+	}
+	ct->perm_spch_len = i + 1;
+
+	return ct;
+}
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 3c23ed8..60cc742 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -146,6 +146,8 @@
 gsm0808_dec_speech_codec;
 gsm0808_enc_speech_codec_list;
 gsm0808_dec_speech_codec_list;
+gsm0808_enc_channel_type;
+gsm0808_dec_channel_type;
 
 gsm0858_rsl_ul_meas_enc;
 
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 6cfcf34..51edce2 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -592,6 +592,33 @@
 	msgb_free(msg);
 }
 
+static void test_gsm0808_enc_dec_channel_type(const void *ctx)
+{
+	struct gsm0808_channel_type ct;
+	struct msgb *ct_enc;
+	uint8_t ct_enc_expected[] = {0x01, 0x0b, 0xa1, 0x25};
+	struct gsm0808_channel_type *ct_dec;
+
+	memset(&ct,0,sizeof(ct));
+	ct.ch_indctr = GSM0808_CHAN_SPEECH;
+	ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
+	ct.perm_spch[0] = GSM0808_PERM_FR3;
+	ct.perm_spch[1] = GSM0808_PERM_HR3;
+	ct.perm_spch_len = 2;
+
+	ct_enc = gsm0808_enc_channel_type(&ct);
+	OSMO_ASSERT(ct_enc);
+	OSMO_ASSERT(memcmp(ct_enc_expected,ct_enc->data,ct_enc->len) == 0);
+
+	ct_dec = gsm0808_dec_channel_type(ctx, ct_enc);
+	OSMO_ASSERT(ct_dec);
+	OSMO_ASSERT(ct_enc->len == 0);
+	OSMO_ASSERT(memcmp(&ct,ct_dec,sizeof(ct)) == 0);
+
+	talloc_free(ct_dec);
+	msgb_free(ct_enc);
+}
+
 int main(int argc, char **argv)
 {
 	void *ctx;
@@ -621,6 +648,7 @@
 	test_gsm0808_enc_dec_speech_codec_ext(ctx);
 	test_gsm0808_enc_dec_speech_codec_ext_with_cfg(ctx);
 	test_gsm0808_enc_dec_speech_codec_list(ctx);
+	test_gsm0808_enc_dec_channel_type(ctx);
 
 	printf("Done\n");
 

-- 
To view, visit https://gerrit.osmocom.org/2179
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id0e2164d84b8cbcc6fe6a090fc7f40a1251421d7
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>



More information about the gerrit-log mailing list