aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.c32
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.h7
-rw-r--r--plugins/ublox/tests/test-modem-helpers-ublox.c38
3 files changed, 77 insertions, 0 deletions
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index 54e09667..b82b2d0c 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -242,6 +242,38 @@ out:
}
/*****************************************************************************/
+/* CFUN? response parser */
+
+gboolean
+mm_ublox_parse_cfun_response (const gchar *response,
+ MMModemPowerState *out_state,
+ GError **error)
+{
+ guint state;
+
+ if (!mm_3gpp_parse_cfun_query_response (response, &state, error))
+ return FALSE;
+
+ switch (state) {
+ case 1:
+ *out_state = MM_MODEM_POWER_STATE_ON;
+ return TRUE;
+ case 0:
+ /* minimum functionality */
+ case 4:
+ /* airplane mode */
+ case 19:
+ /* minimum functionality with SIM deactivated */
+ *out_state = MM_MODEM_POWER_STATE_LOW;
+ return TRUE;
+ default:
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Unknown +CFUN state: %u", state);
+ return FALSE;
+ }
+}
+
+/*****************************************************************************/
/* URAT=? response parser */
/* Index of the array is the ublox-specific value */
diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h
index ae633070..a0ee611c 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.h
+++ b/plugins/ublox/mm-modem-helpers-ublox.h
@@ -59,6 +59,13 @@ gboolean mm_ublox_parse_uipaddr_response (const gchar *response,
GError **error);
/*****************************************************************************/
+/* CFUN? response parser */
+
+gboolean mm_ublox_parse_cfun_response (const gchar *response,
+ MMModemPowerState *out_state,
+ GError **error);
+
+/*****************************************************************************/
/* URAT=? response parser */
GArray *mm_ublox_parse_urat_test_response (const gchar *response,
diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c
index cd333477..2c0d1bb2 100644
--- a/plugins/ublox/tests/test-modem-helpers-ublox.c
+++ b/plugins/ublox/tests/test-modem-helpers-ublox.c
@@ -182,6 +182,42 @@ test_uipaddr_response (void)
}
/*****************************************************************************/
+/* Test CFUN? response */
+
+typedef struct {
+ const gchar *str;
+ MMModemPowerState state;
+} CfunQueryTest;
+
+static const CfunQueryTest cfun_query_tests[] = {
+ { "+CFUN: 1", MM_MODEM_POWER_STATE_ON },
+ { "+CFUN: 1,0", MM_MODEM_POWER_STATE_ON },
+ { "+CFUN: 0", MM_MODEM_POWER_STATE_LOW },
+ { "+CFUN: 0,0", MM_MODEM_POWER_STATE_LOW },
+ { "+CFUN: 4", MM_MODEM_POWER_STATE_LOW },
+ { "+CFUN: 4,0", MM_MODEM_POWER_STATE_LOW },
+ { "+CFUN: 19", MM_MODEM_POWER_STATE_LOW },
+ { "+CFUN: 19,0", MM_MODEM_POWER_STATE_LOW },
+};
+
+static void
+test_cfun_response (void)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (cfun_query_tests); i++) {
+ GError *error = NULL;
+ gboolean success;
+ MMModemPowerState state = MM_MODEM_POWER_STATE_UNKNOWN;
+
+ success = mm_ublox_parse_cfun_response (cfun_query_tests[i].str, &state, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_cmpuint (cfun_query_tests[i].state, ==, state);
+ }
+}
+
+/*****************************************************************************/
/* Test URAT=? responses and model based filtering */
static void
@@ -398,9 +434,11 @@ int main (int argc, char **argv)
g_type_init ();
g_test_init (&argc, &argv, NULL);
+
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/cfun/response", test_cfun_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);