gsm0808_utils: fix gsm48 multirate to S-bit converter

The function gsm0808_sc_cfg_from_gsm48_mr_cfg() is used to convert a
gsm48 multirate struct into a set of S-bits (S0 to S15). However, the
conversion function currently does not take into account that bit S1
actually stands for four rates at once (Config-NB-Code = 1). Lets make
sure that S1 is only set when the multirate configuration permits all
four required rates.

Change-Id: I6ad531d4e70c2252e32e2bbaca8e14a7ec6d9840
Related: SYS#4470
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 2552c08..e0cdaaf 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -1340,6 +1340,16 @@
 	else
 		s15_s0 &= GSM0808_SC_CFG_DEFAULT_HR_AMR;
 
+	/* The mode that is encoded by S1 (Config-NB-Code = 1), takes a special
+	 * role as it does not stand for a single rate, but for up to four rates
+	 * at once (12.2, 7.4, 5.9, 4.75). We must check if the supplied cfg
+	 * covers this mode. If not, we need to make sure that the related
+	 * bit is removed. (See also 3GPP TS 28.062, Table 7.11.3.1.3-2) */
+	if (!(cfg->m12_2 && cfg->m7_40 && cfg->m5_90 && cfg->m4_75) && fr)
+		s15_s0 &= ~GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20;
+	else if (!(cfg->m7_40 && cfg->m5_90 && cfg->m4_75))
+		s15_s0 &= ~GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20;
+
 	return s15_s0;
 }