[MERGED] libosmocore[master]: add gsm0808 channel enum to IE val conversion functions

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
Tue May 8 20:32:56 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: add gsm0808 channel enum to IE val conversion functions
......................................................................


add gsm0808 channel enum to IE val conversion functions

Add:
- gsm0808_current_channel_type_1()
- gsm0808_permitted_speech()
- gsm0808_chosen_channel()
- gsm0808_channel_type_name()

gsm0808_permitted_speech() is moved from osmo-bsc's bssap_speech_from_lchan();
gsm0808_chosen_channel() is moved from osmo-bsc's lchan_to_chosen_channel();

Rationale: will be re-used by inter-BSC handover, makes sense to keep with the
other gsm0808 utils.

Related: OS#2283 (inter-BSC handover, BSC side)
Change-Id: I8a3cc5d4548e9a78d945d54c69ccced251edcec9
---
M include/osmocom/gsm/gsm0808_utils.h
M src/gsm/gsm0808_utils.c
M src/gsm/libosmogsm.map
3 files changed, 117 insertions(+), 0 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 8cdb74b..24c139a 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -26,7 +26,9 @@
 struct sockaddr_storage;
 
 #include <osmocom/gsm/protocol/gsm_08_08.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
 #include <osmocom/gsm/gsm23003.h>
+#include <osmocom/gsm/gsm_utils.h>
 
  /*! (225-1)/2 is the maximum number of elements in a cell identifier list. */
 #define GSM0808_CELL_ID_LIST2_MAXLEN		127
@@ -102,4 +104,109 @@
 int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc,
 					uint8_t perm_spch);
 
+/*! Return 3GPP TS 48.008 3.2.2.49 Current Channel Type 1 from enum gsm_chan_t. */
+static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
+{
+	switch (type) {
+	default:
+		return 0;
+	case GSM_LCHAN_SDCCH:
+		return 0x01;
+	case GSM_LCHAN_TCH_F:
+		return 0x18;
+	case GSM_LCHAN_TCH_H:
+		return 0x19;
+	}
+}
+
+/*! Return 3GPP TS 48.008 3.2.2.51 Speech Version aka permitted speech version indication in 3.2.2.11
+ * Channel Type. */
+static inline enum gsm0808_permitted_speech gsm0808_permitted_speech(enum gsm_chan_t type,
+								     enum gsm48_chan_mode mode)
+{
+	switch (mode) {
+	case GSM48_CMODE_SPEECH_V1:
+		switch (type) {
+		case GSM_LCHAN_TCH_F:
+			return GSM0808_PERM_FR1;
+		case GSM_LCHAN_TCH_H:
+			return GSM0808_PERM_HR1;
+		default:
+			return 0;
+		}
+	case GSM48_CMODE_SPEECH_EFR:
+		switch (type) {
+		case GSM_LCHAN_TCH_F:
+			return GSM0808_PERM_FR2;
+		case GSM_LCHAN_TCH_H:
+			return GSM0808_PERM_HR2;
+		default:
+			return 0;
+		}
+	case GSM48_CMODE_SPEECH_AMR:
+		switch (type) {
+		case GSM_LCHAN_TCH_F:
+			return GSM0808_PERM_HR3;
+		case GSM_LCHAN_TCH_H:
+			return GSM0808_PERM_HR3;
+		default:
+			return 0;
+		}
+	default:
+		return 0;
+	}
+}
+
+/*! Return 3GPP TS 48.008 3.2.2.33 Chosen Channel. */
+static inline uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode)
+{
+	uint8_t channel_mode = 0, channel = 0;
+
+	switch (mode) {
+	case GSM48_CMODE_SPEECH_V1:
+	case GSM48_CMODE_SPEECH_EFR:
+	case GSM48_CMODE_SPEECH_AMR:
+		channel_mode = 0x9;
+		break;
+	case GSM48_CMODE_SIGN:
+		channel_mode = 0x8;
+		break;
+	case GSM48_CMODE_DATA_14k5:
+		channel_mode = 0xe;
+		break;
+	case GSM48_CMODE_DATA_12k0:
+		channel_mode = 0xb;
+		break;
+	case GSM48_CMODE_DATA_6k0:
+		channel_mode = 0xc;
+		break;
+	case GSM48_CMODE_DATA_3k6:
+		channel_mode = 0xd;
+		break;
+	default:
+		return 0;
+	}
+
+	switch (type) {
+	case GSM_LCHAN_NONE:
+		channel = 0x0;
+		break;
+	case GSM_LCHAN_SDCCH:
+		channel = 0x1;
+		break;
+	case GSM_LCHAN_TCH_F:
+		channel = 0x8;
+		break;
+	case GSM_LCHAN_TCH_H:
+		channel = 0x9;
+		break;
+	default:
+		return 0;
+	}
+
+	return channel_mode << 4 | channel;
+}
+
+const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct);
+
 /*! @} */
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 8ef8e24..2c659bb 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -1273,4 +1273,13 @@
 #undef APPEND_STR
 #undef APPEND_CELL_ID_U
 
+const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct)
+{
+	static char buf[128];
+	snprintf(buf, sizeof(buf), "ch_indctr=0x%x ch_rate_type=0x%x perm_spch=%s",
+		 ct->ch_indctr, ct->ch_rate_type,
+		 osmo_hexdump(ct->perm_spch, ct->perm_spch_len));
+	return buf;
+}
+
 /*! @} */
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index f04fd58..8c64020 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -188,6 +188,7 @@
 gsm0808_chan_type_to_speech_codec;
 gsm0808_speech_codec_from_chan_type;
 gsm0808_speech_codec_type_names;
+gsm0808_channel_type_name;
 
 gsm0858_rsl_ul_meas_enc;
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8a3cc5d4548e9a78d945d54c69ccced251edcec9
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list