aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2023-07-25 03:23:08 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2023-07-25 04:23:12 +0700
commitf93ef0c634a78b4d783a3807683f9d714f48f543 (patch)
treef77820c3c5f8fb429b9c3db80317f1d37f1220fb
parent547a65aae20f5e152084e7a05f9d2ec1c692ec1c (diff)
gsm_08_08: define GSM0808_SCT_EXT (separately)
As per 3GPP TS 48.008, section 3.2.2.103, the "Codec Type" field may contain either a certain 3GPP Speech Codec Type directly (4 bit value), or the so called "Codec Extension" = 0xFh, in which case the real Codec Type follows in the next octet as "Extended Codec Type". CSD is such an example, the encoding is defined as follows: 8 7 6 5 4 3 2 1 +----+----+----+----+-------------------+ | -- | PI | PT | -- | 0xFh | +----+----+----+----+-------------------+ | Extended Codec Type (CSData) | +----+----+-----------------------------+ | R2 | R3 | | +----+----+-----------------------------+ CSData is coded with 0xFDh or '1111 1101' (0xfd). Let's have the "Codec Extension" value clearly defined in the header file, but intentionally separate from the other GSM0808_SCT_* values. Change-Id: Iafaa25070684d2ba400c75fa33e803651a5ce857 Related: OS#6110, OS#4393, OS#4394
-rw-r--r--include/osmocom/gsm/protocol/gsm_08_08.h6
-rw-r--r--src/gsm/gsm0808.c1
-rw-r--r--src/gsm/gsm0808_utils.c6
3 files changed, 10 insertions, 3 deletions
diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h b/include/osmocom/gsm/protocol/gsm_08_08.h
index 967e4fe5..1e211dc9 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -557,6 +557,12 @@ enum gsm0808_speech_codec_type {
GSM0808_SCT_CSD = 0xfd, /*!< CSData (see also TS 26.103) */
};
+/* Codec Extension (the real Codec Type follows in the next octet).
+ * This value is intentionally not included in gsm0808_speech_codec_type,
+ * because {enc,dec}_speech_codec() functions take care of the extended
+ * encoding internally. It shall not be used in struct gsm0808_speech_codec. */
+#define GSM0808_SCT_EXT 0x0f
+
extern const struct value_string gsm0808_speech_codec_type_names[];
static inline const char *gsm0808_speech_codec_type_name(enum gsm0808_speech_codec_type val)
{ return get_value_string(gsm0808_speech_codec_type_names, val); }
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index d115888e..6ba6ef2a 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -2478,6 +2478,7 @@ const struct value_string gsm0808_speech_codec_type_names[] = {
{ GSM0808_SCT_HR3, "HR3" },
{ GSM0808_SCT_HR4, "HR4" },
{ GSM0808_SCT_HR6, "HR6" },
+ { GSM0808_SCT_EXT, "Codec Extension" },
{ GSM0808_SCT_CSD, "CSD" },
{ 0, NULL }
};
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index b8e1ff0f..778630d6 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -255,7 +255,7 @@ static int enc_speech_codec(struct msgb *msg,
header |= (1 << 4);
if (type_extended) {
- header |= 0x0f;
+ header |= GSM0808_SCT_EXT;
msgb_put_u8(msg, header);
msgb_put_u8(msg, sc->type);
} else {
@@ -347,7 +347,7 @@ int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc,
/* An extended codec type needs at least two fields,
* bail if the input data length is not sufficient. */
- if ((header & 0x0F) == 0x0F && len < 2)
+ if ((header & 0x0F) == GSM0808_SCT_EXT && len < 2)
return -EINVAL;
elem++;
@@ -362,7 +362,7 @@ int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc,
if (header & (1 << 4))
sc->tf = true;
- if ((header & 0x0F) != 0x0F) {
+ if ((header & 0x0F) != GSM0808_SCT_EXT) {
sc->type = (header & 0x0F);
} else {
sc->type = *elem;