aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/ublox/mm-broadband-modem-ublox.c40
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.c63
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.h8
-rw-r--r--plugins/ublox/tests/test-modem-helpers-ublox.c79
4 files changed, 171 insertions, 19 deletions
diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c
index 7d392faa..09c9797c 100644
--- a/plugins/ublox/mm-broadband-modem-ublox.c
+++ b/plugins/ublox/mm-broadband-modem-ublox.c
@@ -46,6 +46,44 @@ struct _MMBroadbandModemUbloxPrivate {
};
/*****************************************************************************/
+/* Load supported modes (Modem interface) */
+
+static GArray *
+load_supported_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ const gchar *response;
+ GArray *combinations;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
+ if (!response)
+ return FALSE;
+
+ if (!(combinations = mm_ublox_parse_urat_test_response (response, error)))
+ return FALSE;
+
+ if (!(combinations = mm_ublox_filter_supported_modes (mm_iface_modem_get_model (self), combinations, error)))
+ return FALSE;
+
+ return combinations;
+}
+
+static void
+load_supported_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "+URAT=?",
+ 3,
+ TRUE,
+ callback,
+ user_data);
+}
+
+/*****************************************************************************/
/* Create Bearer (Modem interface) */
typedef enum {
@@ -324,6 +362,8 @@ iface_modem_init (MMIfaceModem *iface)
{
iface->create_bearer = modem_create_bearer;
iface->create_bearer_finish = modem_create_bearer_finish;
+ iface->load_supported_modes = load_supported_modes;
+ iface->load_supported_modes_finish = load_supported_modes_finish;
}
static void
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index b20381ff..f0e3b73d 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -363,3 +363,66 @@ out:
return combinations;
}
+
+/*****************************************************************************/
+
+static MMModemMode
+supported_modes_per_model (const gchar *model)
+{
+ MMModemMode all = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G);
+
+ if (model) {
+ /* Some TOBY-L2/MPCI-L2 devices don't support 2G */
+ if (g_str_equal (model, "TOBY-L201") || g_str_equal (model, "TOBY-L220") || g_str_equal (model, "MPCI-L201"))
+ all &= ~MM_MODEM_MODE_2G;
+ /* None of the LISA-U or SARA-U devices support 4G */
+ else if (g_str_has_prefix (model, "LISA-U") || g_str_has_prefix (model, "SARA-U")) {
+ all &= ~MM_MODEM_MODE_4G;
+ /* Some SARA devices don't support 2G */
+ if (g_str_equal (model, "SARA-U270-53S") || g_str_equal (model, "SARA-U280"))
+ all &= ~MM_MODEM_MODE_2G;
+ }
+ }
+
+ return all;
+}
+
+GArray *
+mm_ublox_filter_supported_modes (const gchar *model,
+ GArray *combinations,
+ GError **error)
+{
+ MMModemModeCombination mode;
+ GArray *all;
+ GArray *filtered;
+
+ /* Model not specified? */
+ if (!model)
+ return combinations;
+
+ /* AT+URAT=? lies; we need an extra per-device filtering, thanks u-blox.
+ * Don't know all PIDs for all devices, so model string based filtering... */
+
+ mode.allowed = supported_modes_per_model (model);
+ mode.preferred = MM_MODEM_MODE_NONE;
+
+ /* Nothing filtered? */
+ if (mode.allowed == supported_modes_per_model (NULL))
+ return combinations;
+
+ all = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 1);
+ g_array_append_val (all, mode);
+ filtered = mm_filter_supported_modes (all, combinations);
+ g_array_unref (all);
+ g_array_unref (combinations);
+
+ /* Error if nothing left */
+ if (filtered->len == 0) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "No valid mode combinations built after filtering (model %s)", model);
+ g_array_unref (filtered);
+ return NULL;
+ }
+
+ return filtered;
+}
diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h
index 2e25a10e..631bbf99 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.h
+++ b/plugins/ublox/mm-modem-helpers-ublox.h
@@ -63,4 +63,12 @@ gboolean mm_ublox_parse_uipaddr_response (const gchar *response,
GArray *mm_ublox_parse_urat_test_response (const gchar *response,
GError **error);
+/*****************************************************************************/
+/* Model-based supported modes filtering */
+
+GArray *mm_ublox_filter_supported_modes (const gchar *model,
+ GArray *combinations,
+ GError **error);
+
+
#endif /* MM_MODEM_HELPERS_UBLOX_H */
diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c
index 814e3811..5da9b374 100644
--- a/plugins/ublox/tests/test-modem-helpers-ublox.c
+++ b/plugins/ublox/tests/test-modem-helpers-ublox.c
@@ -182,10 +182,11 @@ test_uipaddr_response (void)
}
/*****************************************************************************/
-/* Test URAT=? responses */
+/* Test URAT=? responses and model based filtering */
static void
compare_combinations (const gchar *response,
+ const gchar *model,
const MMModemModeCombination *expected_combinations,
guint n_expected_combinations)
{
@@ -197,6 +198,10 @@ compare_combinations (const gchar *response,
g_assert_no_error (error);
g_assert (combinations);
+ combinations = mm_ublox_filter_supported_modes (model, combinations, &error);
+ g_assert_no_error (error);
+ g_assert (combinations);
+
g_assert_cmpuint (combinations->len, ==, n_expected_combinations);
for (i = 0; i < combinations->len; i++) {
@@ -221,10 +226,10 @@ test_urat_test_response_2g (void)
{ MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE }
};
- compare_combinations ("+URAT: 0", expected_combinations, G_N_ELEMENTS (expected_combinations));
- compare_combinations ("+URAT: 0,0", expected_combinations, G_N_ELEMENTS (expected_combinations));
- compare_combinations ("+URAT: (0)", expected_combinations, G_N_ELEMENTS (expected_combinations));
- compare_combinations ("+URAT: (0),(0)", expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: 0", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: 0,0", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: (0)", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: (0),(0)", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
}
static void
@@ -238,8 +243,8 @@ test_urat_test_response_2g3g (void)
{ MM_MODEM_MODE_2G | MM_MODEM_MODE_3G, MM_MODEM_MODE_3G },
};
- compare_combinations ("+URAT: (0,1,2),(0,2)", expected_combinations, G_N_ELEMENTS (expected_combinations));
- compare_combinations ("+URAT: (0-2),(0,2)", expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: (0,1,2),(0,2)", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: (0-2),(0,2)", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
}
static void
@@ -268,8 +273,48 @@ test_urat_test_response_2g3g4g (void)
{ MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G, MM_MODEM_MODE_4G },
};
- compare_combinations ("+URAT: (0,1,2,3,4,5,6),(0,2,3)", expected_combinations, G_N_ELEMENTS (expected_combinations));
- compare_combinations ("+URAT: (0-6),(0,2,3)", expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: (0,1,2,3,4,5,6),(0,2,3)", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
+ compare_combinations ("+URAT: (0-6),(0,2,3)", NULL, expected_combinations, G_N_ELEMENTS (expected_combinations));
+}
+
+static void
+test_mode_filtering_toby_l201 (void)
+{
+ static const MMModemModeCombination expected_combinations[] = {
+ { MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE },
+ { MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE },
+
+ { MM_MODEM_MODE_3G | MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE },
+ { MM_MODEM_MODE_3G | MM_MODEM_MODE_4G, MM_MODEM_MODE_3G },
+ { MM_MODEM_MODE_3G | MM_MODEM_MODE_4G, MM_MODEM_MODE_4G },
+ };
+
+ compare_combinations ("+URAT: (0-6),(0,2,3)", "TOBY-L201", expected_combinations, G_N_ELEMENTS (expected_combinations));
+}
+
+static void
+test_mode_filtering_lisa_u200 (void)
+{
+ static const MMModemModeCombination expected_combinations[] = {
+ { MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE },
+ { MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE },
+
+ { MM_MODEM_MODE_2G | MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE },
+ { MM_MODEM_MODE_2G | MM_MODEM_MODE_3G, MM_MODEM_MODE_2G },
+ { MM_MODEM_MODE_2G | MM_MODEM_MODE_3G, MM_MODEM_MODE_3G },
+ };
+
+ compare_combinations ("+URAT: (0-6),(0,2,3)", "LISA-U200", expected_combinations, G_N_ELEMENTS (expected_combinations));
+}
+
+static void
+test_mode_filtering_sara_u280 (void)
+{
+ static const MMModemModeCombination expected_combinations[] = {
+ { MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE },
+ };
+
+ compare_combinations ("+URAT: (0-6),(0,2,3)", "SARA-U280", expected_combinations, G_N_ELEMENTS (expected_combinations));
}
/*****************************************************************************/
@@ -301,19 +346,15 @@ int main (int argc, char **argv)
g_type_init ();
g_test_init (&argc, &argv, NULL);
-<<<<<<< HEAD
g_test_add_func ("/MM/ublox/uusbconf/response", test_uusbconf_response);
g_test_add_func ("/MM/ublox/ubmconf/response", test_ubmconf_response);
g_test_add_func ("/MM/ublox/uipaddr/response", test_uipaddr_response);
-=======
- g_test_add_func ("/MM/ublox/uusbconf/response", test_uusbconf_response);
- g_test_add_func ("/MM/ublox/ubmconf/response", test_ubmconf_response);
- g_test_add_func ("/MM/ublox/uipaddr/response", test_uipaddr_response);
- g_test_add_func ("/MM/ublox/cgcontrdp/response", test_cgcontrdp_response);
- g_test_add_func ("/MM/ublox/urat/test/response/2g", test_urat_test_response_2g);
- g_test_add_func ("/MM/ublox/urat/test/response/2g3g", test_urat_test_response_2g3g);
- g_test_add_func ("/MM/ublox/urat/test/response/2g3g4g", test_urat_test_response_2g3g4g);
->>>>>>> 759a486... ublox: new +URAT=? response parser
+ g_test_add_func ("/MM/ublox/urat/test/response/2g", test_urat_test_response_2g);
+ g_test_add_func ("/MM/ublox/urat/test/response/2g3g", test_urat_test_response_2g3g);
+ g_test_add_func ("/MM/ublox/urat/test/response/2g3g4g", test_urat_test_response_2g3g4g);
+ g_test_add_func ("/MM/ublox/urat/test/response/toby-l201", test_mode_filtering_toby_l201);
+ g_test_add_func ("/MM/ublox/urat/test/response/lisa-u200", test_mode_filtering_lisa_u200);
+ g_test_add_func ("/MM/ublox/urat/test/response/sara-u280", test_mode_filtering_sara_u280);
return g_test_run ();
}