aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-02-01 09:59:53 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:59 +0100
commit9079d660a52744f1d53a2d50d96d057775a4f86c (patch)
treedc1b559d2aed15915a0faaa2c1f0ddd26df18221 /src
parent21b1de678d3c457716fd4caffe1b179cb3212a2f (diff)
broadband-modem: default implementation of SMS format setting
Diffstat (limited to 'src')
-rw-r--r--src/mm-broadband-modem.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index 1088152e..1fd4ca23 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -152,6 +152,9 @@ struct _MMBroadbandModemPrivate {
/* Properties */
GObject *modem_messaging_dbus_skeleton;
MMBearerList *modem_messaging_sms_list;
+ /* Implementation helpers */
+ gboolean sms_use_pdu_mode;
+ gboolean sms_supported_modes_checked;
};
/*****************************************************************************/
@@ -3446,6 +3449,118 @@ modem_messaging_check_support (MMIfaceModemMessaging *self,
}
/*****************************************************************************/
+/* Setup SMS format (Messaging interface) */
+
+static gboolean
+modem_messaging_setup_sms_format_finish (MMIfaceModemMessaging *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+cmgf_set_ready (MMBroadbandModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (error) {
+ mm_dbg ("Failed to set preferred SMS mode: '%s'; assuming text mode'",
+ error->message);
+ g_error_free (error);
+ self->priv->sms_use_pdu_mode = FALSE;
+ } else
+ mm_info ("Successfully set preferred SMS mode: '%s'",
+ self->priv->sms_use_pdu_mode ? "PDU" : "text");
+
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+set_preferred_sms_format (MMBroadbandModem *self,
+ GSimpleAsyncResult *result)
+{
+ gchar *cmd;
+
+ cmd = g_strdup_printf ("+CMGF=%s",
+ self->priv->sms_use_pdu_mode ? "0" : "1");
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ cmd,
+ 3,
+ TRUE,
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)cmgf_set_ready,
+ result);
+ g_free (cmd);
+}
+
+static void
+cmgf_format_check_ready (MMBroadbandModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+ const gchar *response;
+ gboolean sms_pdu_supported = FALSE;
+ gboolean sms_text_supported = FALSE;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (error ||
+ !mm_3gpp_parse_cmgf_format_response (response,
+ &sms_pdu_supported,
+ &sms_text_supported,
+ &error)) {
+ mm_dbg ("Failed to query supported SMS modes: '%s'",
+ error->message);
+ g_error_free (error);
+ self->priv->sms_use_pdu_mode = FALSE;
+ } else
+ /* If the modem only supports PDU mode, use PDUs; otherwise try text mode.
+ * FIXME: when the PDU code is more robust, default to PDU if the
+ * modem supports it.
+ */
+ self->priv->sms_use_pdu_mode = (sms_pdu_supported && !sms_text_supported);
+
+ self->priv->sms_supported_modes_checked = TRUE;
+
+ set_preferred_sms_format (self, simple);
+}
+
+static void
+modem_messaging_setup_sms_format (MMIfaceModemMessaging *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_messaging_setup_sms_format);
+
+ /* If we already checked for supported SMS types, go on to select the
+ * preferred format. */
+ if (MM_BROADBAND_MODEM (self)->priv->sms_supported_modes_checked) {
+ set_preferred_sms_format (MM_BROADBAND_MODEM (self), result);
+ return;
+ }
+
+ /* Check supported SMS formats */
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ "+CMGF=?",
+ 3,
+ TRUE,
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)cmgf_format_check_ready,
+ result);
+}
+
+/*****************************************************************************/
/* ESN loading (CDMA interface) */
static gchar *
@@ -5810,6 +5925,8 @@ iface_modem_messaging_init (MMIfaceModemMessaging *iface)
{
iface->check_support = modem_messaging_check_support;
iface->check_support_finish = modem_messaging_check_support_finish;
+ iface->setup_sms_format = modem_messaging_setup_sms_format;
+ iface->setup_sms_format_finish = modem_messaging_setup_sms_format_finish;
}
static void