aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-04-03 15:39:02 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-05-06 15:34:13 +0200
commitc3cc8f84104d14a1c5281312fb033644f4709329 (patch)
tree2ca20431a7a5851e8460b82b631d1bfa2b8e4730
parent8ce1e26e1b37e2cf3bc652872a707b493ed657dc (diff)
wavecom: implement custom power up sequence
-rw-r--r--plugins/wavecom/mm-broadband-modem-wavecom.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/plugins/wavecom/mm-broadband-modem-wavecom.c b/plugins/wavecom/mm-broadband-modem-wavecom.c
index 6227502b..1cc0fe8d 100644
--- a/plugins/wavecom/mm-broadband-modem-wavecom.c
+++ b/plugins/wavecom/mm-broadband-modem-wavecom.c
@@ -27,6 +27,7 @@
#include "ModemManager.h"
#include "mm-log.h"
+#include "mm-modem-helpers.h"
#include "mm-iface-modem.h"
#include "mm-base-modem-at.h"
#include "mm-broadband-modem-wavecom.h"
@@ -62,6 +63,98 @@ setup_flow_control (MMIfaceModem *self,
}
/*****************************************************************************/
+/* Modem power up (Modem interface) */
+
+static gboolean
+modem_power_up_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+full_functionality_status_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error))
+ g_simple_async_result_take_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+get_current_functionality_status_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ const gchar *response;
+ GError *error = NULL;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ mm_warn ("Failed checking if power-up command is needed: '%s'. "
+ "Will assume it isn't.",
+ error->message);
+ g_error_free (error);
+ /* On error, just assume we don't need the power-up command */
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ response = mm_strip_tag (response, "+CFUN:");
+ if (response && *response == '1') {
+ /* If reported functionality status is '1', then we do not need to
+ * issue the power-up command. Otherwise, do it. */
+ mm_dbg ("Already in full functionality status, skipping power-up command");
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ mm_warn ("Not in full functionality status, power-up command is needed. "
+ "Note that it may reboot the modem.");
+
+ /* Try to go to full functionality mode without rebooting the system.
+ * Works well if we previously switched off the power with CFUN=4
+ */
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ "+CFUN=1,0",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)full_functionality_status_ready,
+ simple);
+}
+
+static void
+modem_power_up (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_power_up);
+
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ "+CFUN?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)get_current_functionality_status_ready,
+ result);
+}
+
+/*****************************************************************************/
/* Modem power down (Modem interface) */
static gboolean
@@ -115,6 +208,8 @@ iface_modem_init (MMIfaceModem *iface)
{
iface->setup_flow_control = setup_flow_control;
iface->setup_flow_control_finish = setup_flow_control_finish;
+ iface->modem_power_up = modem_power_up;
+ iface->modem_power_up_finish = modem_power_up_finish;
iface->modem_power_down = modem_power_down;
iface->modem_power_down_finish = modem_power_down_finish;
}