changeset 301:4bb5772a05a3

AT%SPVER: new command for setting custom speech version lists The speech version list in the Bearer Capability IE tells the network which speech codecs are supported by the MS, and in which order of preference. The standard behaviour is to list all codecs that are supported by the hw+fw platform, and the standard preference order is newer over older, FR over HR. But sometimes it is desirable (for network testing) to artificially restrict which codecs the test MS will declare as supported, and/or to list them in some peculiar non-standard order of preference. Add a new private AT command, AT%SPVER, allowing the user to set and clear custom speech version lists for the Bearer Capability IE composer in CC.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 May 2023 21:43:10 +0000
parents edcb8364d45b
children d32ac4edb634
files components/comlib src/condat/com/include/cl_user_spver.h src/condat/com/src/comlib/cl_user_spver.c src/g23m-aci/aci/aci_cmh.h src/g23m-aci/aci/ati_cmd.c src/g23m-aci/aci/ati_fcmisc.c src/g23m-gsm/cc/cc_cfk.c
diffstat 7 files changed, 235 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/components/comlib	Tue Dec 13 02:44:01 2022 +0000
+++ b/components/comlib	Sun May 21 21:43:10 2023 +0000
@@ -74,3 +74,4 @@
 cfile_str2ind $SRCDIR/cl_des.c
 cfile_str2ind $SRCDIR/cl_shrd.c
 cfile_str2ind $SRCDIR/cl_list.c
+cfile_str2ind $SRCDIR/cl_user_spver.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/condat/com/include/cl_user_spver.h	Sun May 21 21:43:10 2023 +0000
@@ -0,0 +1,48 @@
+/*
+ * This header file is a FreeCalypso addition; it is part of the mechanism
+ * for setting a user-defined list of accepted speech versions in the Bearer
+ * Capability IE for speech calls, with a user-defined order of preference,
+ * overriding the standard SV list based on hw+fw platform capabilities
+ * and the standard order of preference.
+ */
+
+#ifndef CL_USER_SPVER_H
+#define CL_USER_SPVER_H
+
+/*
+ * This function sets (establishes for use) a user-defined SV list.
+ * The input is an array of 5 bytes, giving the list of speech versions
+ * in the user-preferred order; if fewer than all 5 possible SVs are listed,
+ * the remaining array elements shall be filled with 0xFF.  At least FRv1
+ * (GSM full rate speech version 1) must always be included in the list;
+ * a corollary of this requirement is that an empty list is not a valid input.
+ */
+extern UBYTE cl_user_spver_set(const UBYTE *spver_list);
+
+/* cl_user_spver_set() return codes */
+#define	CL_USER_SPVER_SET_OK		0
+#define	CL_USER_SPVER_SET_ERROR		1
+
+/*
+ * This function resets (clears) the user-defined SV list, returning to
+ * standard operation of accepting all speech versions supported by the
+ * platform with the standard order of preference.
+ */
+extern void cl_user_spver_reset(void);
+
+/*
+ * This function checks to see if a user-defined speech version list is set.
+ * If no such list is set, the function returns CL_USER_SPVER_IS_NOT_SET
+ * and leaves *spver_list and *rad_chan_req untouched.  If a user-defined
+ * SV list is set, the function returns CL_USER_SPVER_IS_SET, writes the list
+ * into the *spver_list output array (all 5 bytes are always written,
+ * with 0xFF padding as needed), and writes the corresponding radio channel
+ * requirement code into *rad_chan_req.
+ */
+extern UBYTE cl_user_spver_get(UBYTE *spver_list, UBYTE *rad_chan_req);
+
+/* cl_user_spver_get() return codes */
+#define	CL_USER_SPVER_IS_NOT_SET	0
+#define	CL_USER_SPVER_IS_SET		1
+
+#endif	/* include guard */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/condat/com/src/comlib/cl_user_spver.c	Sun May 21 21:43:10 2023 +0000
@@ -0,0 +1,119 @@
+/*
+ * This C module is a FreeCalypso addition; it is part of the mechanism
+ * for setting a user-defined list of accepted speech versions in the Bearer
+ * Capability IE for speech calls, with a user-defined order of preference,
+ * overriding the standard SV list based on hw+fw platform capabilities
+ * and the standard order of preference.
+ */
+
+#include <string.h>
+#include "typedefs.h"
+#include "vsi.h"
+#include "gsm.h"
+#include "cl_user_spver.h"
+#include "m_cc.val"
+
+/*
+ * State variable: it is packed into a single 32-bit word so it can be
+ * updated atomically; it is declared as volatile so that each set/reset/get
+ * function will access it exactly once as written in the code, and it is
+ * made global so it will appear in the linker map file for debugging -
+ * so we can read it via fc-tmsh r32.
+ *
+ * Packing format:
+ *
+ * bits [31:24] = number of SVs in user-defined list
+ * bits [23:20] = rad_chan_req
+ * bits [19:16] = spver_list[0]
+ * bits [15:12] = spver_list[1]
+ * bits [11: 8] = spver_list[2]
+ * bits [ 7: 4] = spver_list[3]
+ * bits [ 3: 0] = spver_list[4]
+ */
+volatile U32 cl_user_spver_state_var;
+
+UBYTE cl_user_spver_set(const UBYTE *spver_list)
+{
+	UBYTE n, sv;
+	UBYTE pos_fr = 0, pos_hr = 0, pos_efr = 0;
+	UBYTE pos_amr_fr = 0, pos_amr_hr = 0;
+	UBYTE rad_chan_req;
+	U32 new_word;
+
+	for (n = 0; n < 5; n++) {
+		sv = spver_list[n];
+		if (sv == NOT_PRESENT_8BIT)
+			break;
+		switch (sv) {
+		case M_CC_SPEECH_VERS_FR:
+			if (pos_fr)
+				return CL_USER_SPVER_SET_ERROR;
+			pos_fr = n + 1;
+			break;
+		case M_CC_SPEECH_VERS_HR:
+			if (pos_hr)
+				return CL_USER_SPVER_SET_ERROR;
+			pos_hr = n + 1;
+			break;
+		case M_CC_SPEECH_VERS_EFR:
+			if (pos_efr)
+				return CL_USER_SPVER_SET_ERROR;
+			pos_efr = n + 1;
+			break;
+		case M_CC_SPEECH_VERS_AMR_FR:
+			if (pos_amr_fr)
+				return CL_USER_SPVER_SET_ERROR;
+			pos_amr_fr = n + 1;
+			break;
+		case M_CC_SPEECH_VERS_AMR_HR:
+			if (pos_amr_hr)
+				return CL_USER_SPVER_SET_ERROR;
+			pos_amr_hr = n + 1;
+			break;
+		default:
+			return CL_USER_SPVER_SET_ERROR;
+		}
+	}
+	if (!n || !pos_fr)
+		return CL_USER_SPVER_SET_ERROR;
+	if (!pos_hr)
+		rad_chan_req = M_CC_RCR_FULL_ONLY;
+	else if (pos_hr < pos_fr)
+		rad_chan_req = M_CC_RCR_HALF_PREF;
+	else
+		rad_chan_req = M_CC_RCR_FULL_PREF;
+	new_word = n << 24;
+	new_word |= rad_chan_req << 20;
+	new_word |= (spver_list[0] & 0xF) << 16;
+	new_word |= (spver_list[1] & 0xF) << 12;
+	new_word |= (spver_list[2] & 0xF) << 8;
+	new_word |= (spver_list[3] & 0xF) << 4;
+	new_word |= (spver_list[4] & 0xF) << 0;
+	cl_user_spver_state_var = new_word;
+	return CL_USER_SPVER_SET_OK;
+}
+
+void cl_user_spver_reset(void)
+{
+	cl_user_spver_state_var = 0;
+}
+
+UBYTE cl_user_spver_get(UBYTE *spver_list, UBYTE *rad_chan_req)
+{
+	U32 conf;
+	UBYTE num, n;
+
+	conf = cl_user_spver_state_var;
+	num = conf >> 24;
+	if (num < 1 || num > 5)
+		return CL_USER_SPVER_IS_NOT_SET;
+	spver_list[0] = (conf >> 16) & 0xF;
+	spver_list[1] = (conf >> 12) & 0xF;
+	spver_list[2] = (conf >> 8) & 0xF;
+	spver_list[3] = (conf >> 4) & 0xF;
+	spver_list[4] = conf & 0xF;
+	for (n = num; n < 5; n++)
+		spver_list[n] = NOT_PRESENT_8BIT;
+	*rad_chan_req = (conf >> 20) & 0xF;
+	return CL_USER_SPVER_IS_SET;
+}
--- a/src/g23m-aci/aci/aci_cmh.h	Tue Dec 13 02:44:01 2022 +0000
+++ b/src/g23m-aci/aci/aci_cmh.h	Sun May 21 21:43:10 2023 +0000
@@ -552,6 +552,7 @@
   AT_CMD_AT_BZSTOP,
   AT_CMD_AT_VIBR,
   AT_CMD_AT_VIBS,
+  AT_CMD_P_SPVER,
   /* terminator */
   AT_CMD_MAX,                  /* maximum command id */
   AT_CMD_BIGGEST = 0x0000ffff  /* To avoid the lint warning 650 */
--- a/src/g23m-aci/aci/ati_cmd.c	Tue Dec 13 02:44:01 2022 +0000
+++ b/src/g23m-aci/aci/ati_cmd.c	Sun May 21 21:43:10 2023 +0000
@@ -790,6 +790,8 @@
 EXTERN T_ATI_RSLT atAtVIBR (char *cl, UBYTE srcId);
 EXTERN T_ATI_RSLT atAtVIBS (char *cl, UBYTE srcId);
 #endif
+EXTERN T_ATI_RSLT atPercentSPVER (char *cl, UBYTE srcId);
+EXTERN T_ATI_RSLT queatPercentSPVER (char *cl, UBYTE srcId);
 
 LOCAL const ATCommand_bas cmds_bas[] =
 {
@@ -1273,6 +1275,8 @@
     {"@VIBR",	AT_CMD_AT_VIBR,  atAtVIBR,	0,	0,	0},
     {"@VIBS",	AT_CMD_AT_VIBS,  atAtVIBS,	0,	0,	0},
 #endif
+    {"%SPVER",	AT_CMD_P_SPVER,  atPercentSPVER, test_gen, queatPercentSPVER,
+				"%s: (0,1),(0-5),(0-5),(0-5),(0-5),(0-5)"},
     /* terminator */
     {NULL,AT_CMD_NONE,NULL,NULL,NULL,NULL}
 };
--- a/src/g23m-aci/aci/ati_fcmisc.c	Tue Dec 13 02:44:01 2022 +0000
+++ b/src/g23m-aci/aci/ati_fcmisc.c	Sun May 21 21:43:10 2023 +0000
@@ -56,6 +56,8 @@
 
 #endif /*FF_ATI_BAT*/
 
+#include "cl_user_spver.h"
+
 #include "rv/rv_defined_swe.h"     /* for RVM_BUZM_SWE and RVM_VIBR_SWE */
 #include "main/sys_types.h"
 #include "fc-target.h"
@@ -105,6 +107,56 @@
 	return (ATI_CMPL);
 }
 
+/* AT%SPVER - set custom speech version list */
+GLOBAL T_ATI_RSLT atPercentSPVER (char *cl, UBYTE srcId)
+{
+	UBYTE spver_set;
+	UBYTE spver_list[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+	UBYTE spver_rc;
+
+	TRACE_FUNCTION("atPercentSPVER()");
+
+	cl = parse(cl, "Xxxxxx", &spver_set, &spver_list[0], &spver_list[1],
+		   &spver_list[2], &spver_list[3], &spver_list[4]);
+	if (!cl)
+		return (ATI_FAIL);
+	switch (spver_set) {
+	case CL_USER_SPVER_IS_NOT_SET:
+		cl_user_spver_reset();
+		return (ATI_CMPL);
+	case CL_USER_SPVER_IS_SET:
+		spver_rc = cl_user_spver_set(spver_list);
+		if (spver_rc == CL_USER_SPVER_SET_OK)
+			return (ATI_CMPL);
+		else
+			return (ATI_FAIL);
+	default:
+		return (ATI_FAIL);
+	}
+}
+
+GLOBAL T_ATI_RSLT queatPercentSPVER (char *cl, UBYTE srcId)
+{
+	UBYTE spver_set, rad_chan_req;
+	UBYTE spver_list[5], n, sv;
+	char *me="%SPVER: ";
+	char add[5];
+
+	spver_set = cl_user_spver_get(spver_list, &rad_chan_req);
+	sprintf(g_sa, "%s%u", me, spver_set);
+	if (spver_set == CL_USER_SPVER_IS_SET) {
+		for (n = 0; n < 5; n++) {
+			sv = spver_list[n];
+			if (sv == NOT_PRESENT_8BIT)
+				break;
+			sprintf(add, ",%u", sv);
+			strcat(g_sa, add);
+		}
+	}
+	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
+	return (ATI_CMPL);
+}
+
 #ifdef TARGET_HAS_LPG
 /* AT@LPG - program LPG output */
 GLOBAL T_ATI_RSLT atAtLPG ( char *cl, UBYTE srcId )
--- a/src/g23m-gsm/cc/cc_cfk.c	Tue Dec 13 02:44:01 2022 +0000
+++ b/src/g23m-gsm/cc/cc_cfk.c	Sun May 21 21:43:10 2023 +0000
@@ -40,6 +40,9 @@
 #include "tok.h"
 #include "cc.h"
 
+/* FreeCalypso addition */
+#include "cl_user_spver.h"
+
 /*==== EXPORT =====================================================*/
 
 /*==== PROTOTYPE ==================================================*/
@@ -610,7 +613,8 @@
   UBYTE index, prio;
   const UBYTE codec_prio[5] = {M_CC_SPEECH_VERS_AMR_FR, M_CC_SPEECH_VERS_AMR_HR, M_CC_SPEECH_VERS_EFR,
                                M_CC_SPEECH_VERS_FR, M_CC_SPEECH_VERS_HR};
-        UBYTE codec_val[5]  = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+  UBYTE codec_val[5]  = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+  UBYTE user_spver_set, user_spver_rcr;
 
   TRACE_FUNCTION ("cc_set_radio_channel_requirement()");
 
@@ -687,6 +691,11 @@
           } /* switch (codec_prio[prio])*/
         } /* for */
 
+	/* FreeCalypso addition: user override of codec priority list */
+	user_spver_set = cl_user_spver_get(codec_val, &user_spver_rcr);
+	if (user_spver_set == CL_USER_SPVER_IS_SET)
+		bearer_cap->rad_chan_req = user_spver_rcr;
+
         if (bcpara->bearer_serv EQ MNCC_BEARER_SERV_SPEECH_CTM OR
             bcpara->bearer_serv EQ MNCC_BEARER_SERV_AUX_SPEECH_CTM)
         {