summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2018-09-25 15:57:49 +0200
committerHarald Welte <laforge@gnumonks.org>2018-09-25 15:32:29 +0000
commit8515d035ae09edf3ad4d6e0dcbe526eee8bce3eb (patch)
tree7d2aa142f40d85f6ae1766de11ccd04153c8a214
parentb066305016141606e7f031065dc71c2002a6af0a (diff)
gsm0808: add function to convert AMR S15-S0 to gsm0408 settings
Add a function to convert S0-S15 bits to struct gsm48_multi_rate_conf, which hold the codec settings for AMR. Change-Id: I973736273c236eee84decf15868190e339c3fed4 Related: OS#3548
-rw-r--r--include/osmocom/gsm/gsm0808_utils.h1
-rw-r--r--src/gsm/gsm0808_utils.c41
-rw-r--r--src/gsm/libosmogsm.map1
-rw-r--r--tests/gsm0808/gsm0808_test.c57
-rw-r--r--tests/gsm0808/gsm0808_test.ok133
5 files changed, 233 insertions, 0 deletions
diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 8746ceba..f70dbdb6 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -105,6 +105,7 @@ int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch);
int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc,
uint8_t perm_spch);
uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cfg, bool fr);
+void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0);
/*! 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)
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 0d6938ef..886f546a 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -1204,6 +1204,47 @@ uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cf
return s15_s0;
}
+/*! Determine a GSM 04.08 AMR configuration struct from a set of speech codec
+ * configuration bits (S0-S15)
+ * \param[out] cfg AMR configuration in GSM 04.08 format.
+ * \param[in] s15_s0 configuration bits (S0-S15). */
+void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg,
+ uint16_t s15_s0)
+{
+ memset(cfg, 0, sizeof(*cfg));
+
+ /* Strip option bits */
+ s15_s0 &= 0x00ff;
+
+ /* Rate 5,15k must always be present */
+ cfg->m5_15 = 1;
+
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_4_75 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_4_75 & 0xff))
+ cfg->m4_75 = 1;
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_5_90 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_5_90 & 0xff))
+ cfg->m5_90 = 1;
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_6_70 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_6_70 & 0xff))
+ cfg->m6_70 = 1;
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_7_40 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_7_40 & 0xff))
+ cfg->m7_40 = 1;
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_7_95 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_7_95 & 0xff))
+ cfg->m7_95 = 1;
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_10_2 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_10_2 & 0xff))
+ cfg->m10_2 = 1;
+ if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_12_2 & 0xff) ==
+ (GSM0808_SC_CFG_DEFAULT_AMR_12_2 & 0xff))
+ cfg->m12_2 = 1;
+
+ cfg->ver = 1;
+ cfg->icmi = 1;
+}
+
/*! Print a human readable name of the cell identifier to the char buffer.
* This is useful both for struct gsm0808_cell_id and struct gsm0808_cell_id_list2.
* See also gsm0808_cell_id_name() and gsm0808_cell_id_list_name().
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 3d08232c..dcc491d7 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -206,6 +206,7 @@ gsm0808_cell_id_u_name;
gsm0808_chan_type_to_speech_codec;
gsm0808_speech_codec_from_chan_type;
gsm0808_sc_cfg_from_gsm48_mr_cfg;
+gsm48_mr_cfg_from_gsm0808_sc_cfg;
gsm0808_speech_codec_type_names;
gsm0808_permitted_speech_names;
gsm0808_chosen_enc_alg_names;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 6faa6890..8cf1cf4c 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -1640,6 +1640,62 @@ static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
}
+static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
+{
+ struct gsm48_multi_rate_conf cfg;
+
+ printf("Input:\n");
+ printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
+ OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
+
+ gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
+
+ printf("Output:\n");
+ printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
+ printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
+ printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
+ printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
+ printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
+ printf(" m7_95= %u\n", cfg.m7_95);
+ printf(" m10_2= %u\n", cfg.m10_2);
+ printf(" m12_2= %u\n", cfg.m12_2);
+
+ printf("\n");
+}
+
+void test_gsm48_mr_cfg_from_gsm0808_sc_cfg()
+{
+ printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
+
+ /* Only one codec per setting */
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_4_75);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_5_15);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_5_90);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_6_70);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_7_40);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_7_95);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_10_2);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_12_2);
+
+ /* Combinations */
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_4_75 | GSM0808_SC_CFG_DEFAULT_AMR_6_70 |
+ GSM0808_SC_CFG_DEFAULT_AMR_10_2);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_10_2 | GSM0808_SC_CFG_DEFAULT_AMR_12_2 |
+ GSM0808_SC_CFG_DEFAULT_AMR_7_40);
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
+ (GSM0808_SC_CFG_DEFAULT_AMR_7_95 | GSM0808_SC_CFG_DEFAULT_AMR_12_2);
+}
+
int main(int argc, char **argv)
{
printf("Testing generation of GSM0808 messages\n");
@@ -1692,6 +1748,7 @@ int main(int argc, char **argv)
test_gsm0808_enc_dec_cell_id_global();
test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
+ test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
printf("Done\n");
return EXIT_SUCCESS;
diff --git a/tests/gsm0808/gsm0808_test.ok b/tests/gsm0808/gsm0808_test.ok
index dc1debac..58bc5099 100644
--- a/tests/gsm0808/gsm0808_test.ok
+++ b/tests/gsm0808/gsm0808_test.ok
@@ -299,4 +299,137 @@ Result (fr):
Result (hr):
S15-S0 = 073f = 0b0000011100111111
+Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():
+Input:
+ S15-S0 = ff03 = 0b1111111100000011
+Output:
+ m4_75= 1 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 0
+ m12_2= 0
+
+Input:
+ S15-S0 = 0000 = 0b0000000000000000
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 0
+ m12_2= 0
+
+Input:
+ S15-S0 = ff06 = 0b1111111100000110
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 1 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 0
+ m12_2= 0
+
+Input:
+ S15-S0 = 3e08 = 0b0011111000001000
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 1 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 0
+ m12_2= 0
+
+Input:
+ S15-S0 = 0c12 = 0b0000110000010010
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 1 ver= 1
+ m7_95= 0
+ m10_2= 0
+ m12_2= 0
+
+Input:
+ S15-S0 = c020 = 0b1100000000100000
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 1
+ m10_2= 0
+ m12_2= 0
+
+Input:
+ S15-S0 = 3040 = 0b0011000001000000
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 1
+ m12_2= 0
+
+Input:
+ S15-S0 = c082 = 0b1100000010000010
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 0
+ m12_2= 1
+
+Input:
+ S15-S0 = ff4b = 0b1111111101001011
+Output:
+ m4_75= 1 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 1 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 0
+ m10_2= 1
+ m12_2= 0
+
+Input:
+ S15-S0 = fcd2 = 0b1111110011010010
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 1 ver= 1
+ m7_95= 0
+ m10_2= 1
+ m12_2= 1
+
+Input:
+ S15-S0 = c0a2 = 0b1100000010100010
+Output:
+ m4_75= 0 smod= 0
+ m5_15= 1 spare= 0
+ m5_90= 0 icmi= 1
+ m6_70= 0 nscb= 0
+ m7_40= 0 ver= 1
+ m7_95= 1
+ m10_2= 0
+ m12_2= 1
+
Done