cinterion: add support for mode setting using SXRAT
The previously used COPS command to set to LTE-only mode did not work for an ELS81 modem. Now ^SXRAT is used to switch modes instead of COPS, if SXRAT is supported by the modem.
This commit is contained in:

committed by
Aleksander Morgado

parent
fcd393a6c2
commit
a25b45f795
@@ -1743,6 +1743,187 @@ test_sgauth_response (void)
|
||||
g_assert (!result);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test ^SXRAT responses */
|
||||
|
||||
static void
|
||||
common_test_sxrat (const gchar *response,
|
||||
const GArray *expected_rat,
|
||||
const GArray *expected_pref1,
|
||||
const GArray *expected_pref2)
|
||||
{
|
||||
GArray *supported_rat = NULL;
|
||||
GArray *supported_pref1 = NULL;
|
||||
GArray *supported_pref2 = NULL;
|
||||
GError *error = NULL;
|
||||
gboolean res;
|
||||
|
||||
g_assert (expected_rat != NULL);
|
||||
g_assert (expected_pref1 != NULL);
|
||||
|
||||
res = mm_cinterion_parse_sxrat_test (response,
|
||||
&supported_rat,
|
||||
&supported_pref1,
|
||||
&supported_pref2,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (res == TRUE);
|
||||
g_assert (supported_rat != NULL);
|
||||
g_assert (supported_pref1 != NULL);
|
||||
if (expected_pref2)
|
||||
g_assert (supported_pref2 != NULL);
|
||||
else
|
||||
g_assert (supported_pref2 == NULL);
|
||||
|
||||
compare_arrays (supported_rat, expected_rat);
|
||||
compare_arrays (supported_pref1, expected_pref1);
|
||||
if (expected_pref2)
|
||||
compare_arrays (supported_pref2, expected_pref2);
|
||||
|
||||
g_array_unref (supported_rat);
|
||||
g_array_unref (supported_pref1);
|
||||
if (supported_pref2)
|
||||
g_array_unref (supported_pref2);
|
||||
}
|
||||
|
||||
static void
|
||||
test_sxrat_response_els61 (void)
|
||||
{
|
||||
GArray *expected_rat;
|
||||
GArray *expected_pref1;
|
||||
GArray *expected_pref2;
|
||||
guint val;
|
||||
const gchar *response =
|
||||
"^SXRAT: (0-6),(0,2,3),(0,2,3)\r\n"
|
||||
"\r\n";
|
||||
|
||||
expected_rat = g_array_sized_new (FALSE, FALSE, sizeof (guint), 7);
|
||||
val = 0, g_array_append_val (expected_rat, val);
|
||||
val = 1, g_array_append_val (expected_rat, val);
|
||||
val = 2, g_array_append_val (expected_rat, val);
|
||||
val = 3, g_array_append_val (expected_rat, val);
|
||||
val = 4, g_array_append_val (expected_rat, val);
|
||||
val = 5, g_array_append_val (expected_rat, val);
|
||||
val = 6, g_array_append_val (expected_rat, val);
|
||||
|
||||
expected_pref1 = g_array_sized_new (FALSE, FALSE, sizeof (guint), 3);
|
||||
val = 0, g_array_append_val (expected_pref1, val);
|
||||
val = 2, g_array_append_val (expected_pref1, val);
|
||||
val = 3, g_array_append_val (expected_pref1, val);
|
||||
|
||||
expected_pref2 = g_array_sized_new (FALSE, FALSE, sizeof (guint), 3);
|
||||
val = 0, g_array_append_val (expected_pref2, val);
|
||||
val = 2, g_array_append_val (expected_pref2, val);
|
||||
val = 3, g_array_append_val (expected_pref2, val);
|
||||
|
||||
common_test_sxrat (response,
|
||||
expected_rat,
|
||||
expected_pref1,
|
||||
expected_pref2);
|
||||
|
||||
g_array_unref (expected_rat);
|
||||
g_array_unref (expected_pref1);
|
||||
g_array_unref (expected_pref2);
|
||||
}
|
||||
|
||||
static void
|
||||
test_sxrat_response_other (void)
|
||||
{
|
||||
GArray *expected_rat;
|
||||
GArray *expected_pref1;
|
||||
GArray *expected_pref2 = NULL;
|
||||
guint val;
|
||||
const gchar *response =
|
||||
"^SXRAT: (0-2),(0,2)\r\n"
|
||||
"\r\n";
|
||||
|
||||
expected_rat = g_array_sized_new (FALSE, FALSE, sizeof (guint), 3);
|
||||
val = 0, g_array_append_val (expected_rat, val);
|
||||
val = 1, g_array_append_val (expected_rat, val);
|
||||
val = 2, g_array_append_val (expected_rat, val);
|
||||
|
||||
expected_pref1 = g_array_sized_new (FALSE, FALSE, sizeof (guint), 3);
|
||||
val = 0, g_array_append_val (expected_pref1, val);
|
||||
val = 2, g_array_append_val (expected_pref1, val);
|
||||
|
||||
common_test_sxrat (response,
|
||||
expected_rat,
|
||||
expected_pref1,
|
||||
expected_pref2);
|
||||
|
||||
g_array_unref (expected_rat);
|
||||
g_array_unref (expected_pref1);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const gchar *str;
|
||||
MMModemMode allowed;
|
||||
MMModemMode preferred;
|
||||
gboolean success;
|
||||
} SxratBuildTest;
|
||||
|
||||
static const SxratBuildTest sxrat_build_tests[] = {
|
||||
{
|
||||
.str = "^SXRAT=0",
|
||||
.allowed = MM_MODEM_MODE_2G,
|
||||
.preferred = MM_MODEM_MODE_NONE,
|
||||
.success = TRUE,
|
||||
},
|
||||
{
|
||||
.str = "^SXRAT=3",
|
||||
.allowed = MM_MODEM_MODE_4G,
|
||||
.preferred = MM_MODEM_MODE_NONE,
|
||||
.success = TRUE,
|
||||
},
|
||||
{
|
||||
.str = "^SXRAT=1,2",
|
||||
.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G,
|
||||
.preferred = MM_MODEM_MODE_3G,
|
||||
.success = TRUE,
|
||||
},
|
||||
{
|
||||
.str = "^SXRAT=6,3",
|
||||
.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G,
|
||||
.preferred = MM_MODEM_MODE_4G,
|
||||
.success = TRUE,
|
||||
},
|
||||
{
|
||||
.str = NULL,
|
||||
.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G,
|
||||
.preferred = MM_MODEM_MODE_3G | MM_MODEM_MODE_4G,
|
||||
.success = FALSE,
|
||||
},
|
||||
{
|
||||
.str = NULL,
|
||||
.allowed = MM_MODEM_MODE_5G,
|
||||
.preferred = MM_MODEM_MODE_NONE,
|
||||
.success = FALSE,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
static void
|
||||
test_sxrat (void)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (sxrat_build_tests); i++) {
|
||||
GError *error = NULL;
|
||||
gchar* result;
|
||||
|
||||
result = mm_cinterion_build_sxrat_set_command (sxrat_build_tests[i].allowed,
|
||||
sxrat_build_tests[i].preferred,
|
||||
&error);
|
||||
if (sxrat_build_tests[i].success) {
|
||||
g_assert_no_error (error);
|
||||
g_assert (result);
|
||||
g_assert_cmpstr (result, ==, sxrat_build_tests[i].str);
|
||||
} else {
|
||||
g_assert (error);
|
||||
g_assert (!result);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
int main (int argc, char **argv)
|
||||
@@ -1778,6 +1959,9 @@ int main (int argc, char **argv)
|
||||
g_test_add_func ("/MM/cinterion/smoni/query_response_to_signal", test_smoni_response_to_signal);
|
||||
g_test_add_func ("/MM/cinterion/scfg/provcfg", test_provcfg_response);
|
||||
g_test_add_func ("/MM/cinterion/sgauth", test_sgauth_response);
|
||||
g_test_add_func ("/MM/cinterion/sxrat", test_sxrat);
|
||||
g_test_add_func ("/MM/cinterion/sxrat/response/els61", test_sxrat_response_els61);
|
||||
g_test_add_func ("/MM/cinterion/sxrat/response/other", test_sxrat_response_other);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user