aboutsummaryrefslogtreecommitdiff
path: root/plugins/wavecom
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-04-03 17:49:20 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-05-06 15:34:13 +0200
commit3885bb365daa9bd377df34b74fbfeb04f44b87a8 (patch)
tree30b9355d3901ead11b203903a6ff4fdd226424cb /plugins/wavecom
parent1447dfee3c6b62f0f3ac68d76637cc7deff04a1e (diff)
wavecom: implement setting allowed/preferred modes
Diffstat (limited to 'plugins/wavecom')
-rw-r--r--plugins/wavecom/mm-broadband-modem-wavecom.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/plugins/wavecom/mm-broadband-modem-wavecom.c b/plugins/wavecom/mm-broadband-modem-wavecom.c
index f1783aa1..d91ecb21 100644
--- a/plugins/wavecom/mm-broadband-modem-wavecom.c
+++ b/plugins/wavecom/mm-broadband-modem-wavecom.c
@@ -343,6 +343,152 @@ load_allowed_modes (MMIfaceModem *self,
}
/*****************************************************************************/
+/* Set allowed modes (Modem interface) */
+
+typedef struct {
+ MMBroadbandModemWavecom *self;
+ GSimpleAsyncResult *result;
+ MMModemMode allowed;
+ MMModemMode preferred;
+ gchar *cgclass_command;
+ gchar *wwsm_command;
+} SetAllowedModesContext;
+
+static void
+set_allowed_modes_context_complete_and_free (SetAllowedModesContext *ctx)
+{
+ g_simple_async_result_complete_in_idle (ctx->result);
+ g_object_unref (ctx->result);
+ g_object_unref (ctx->self);
+ g_free (ctx->cgclass_command);
+ g_free (ctx->wwsm_command);
+ g_free (ctx);
+}
+
+static gboolean
+set_allowed_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+wwsm_update_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ SetAllowedModesContext *ctx)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (error)
+ /* Let the error be critical. */
+ g_simple_async_result_take_error (ctx->result, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+
+ set_allowed_modes_context_complete_and_free (ctx);
+}
+
+static void
+cgclass_update_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ SetAllowedModesContext *ctx)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (error) {
+ /* Let the error be critical. */
+ g_simple_async_result_take_error (ctx->result, error);
+ set_allowed_modes_context_complete_and_free (ctx);
+ return;
+ }
+
+ if (!ctx->wwsm_command) {
+ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+ set_allowed_modes_context_complete_and_free (ctx);
+ return;
+ }
+
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ ctx->wwsm_command,
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)wwsm_update_ready,
+ ctx);
+}
+
+static void
+set_allowed_modes (MMIfaceModem *self,
+ MMModemMode allowed,
+ MMModemMode preferred,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ SetAllowedModesContext *ctx;
+
+ ctx = g_new (SetAllowedModesContext, 1);
+ ctx->self = g_object_ref (self);
+ ctx->result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ set_allowed_modes);
+ ctx->allowed = allowed;
+ ctx->preferred = preferred;
+
+ if (allowed == MM_MODEM_MODE_CS)
+ ctx->cgclass_command = g_strdup ("+CGCLASS=" WAVECOM_MS_CLASS_CC_IDSTR);
+ else if (allowed == MM_MODEM_MODE_2G)
+ ctx->cgclass_command = g_strdup ("+CGCLASS=" WAVECOM_MS_CLASS_CG_IDSTR);
+ else if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_CS) &&
+ preferred == MM_MODEM_MODE_NONE)
+ ctx->cgclass_command = g_strdup ("+CGCLASS=" WAVECOM_MS_CLASS_B_IDSTR);
+ else if (allowed & MM_MODEM_MODE_3G) {
+ if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G) ||
+ allowed == (MM_MODEM_MODE_CS | MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) {
+ if (preferred == MM_MODEM_MODE_2G)
+ ctx->wwsm_command = g_strdup ("+WWSM=2,1");
+ else if (preferred == MM_MODEM_MODE_3G)
+ ctx->wwsm_command = g_strdup ("+WWSM=2,2");
+ else if (preferred == MM_MODEM_MODE_NONE)
+ ctx->wwsm_command = g_strdup ("+WWSM=2,0");
+ } else if (allowed == MM_MODEM_MODE_3G)
+ ctx->wwsm_command = g_strdup ("+WWSM=1");
+
+ if (ctx->wwsm_command)
+ ctx->cgclass_command = g_strdup ("+CGCLASS=" WAVECOM_MS_CLASS_A_IDSTR);
+ }
+
+ if (!ctx->cgclass_command) {
+ gchar *allowed_str;
+ gchar *preferred_str;
+
+ allowed_str = mm_modem_mode_build_string_from_mask (allowed);
+ preferred_str = mm_modem_mode_build_string_from_mask (preferred);
+ g_simple_async_result_set_error (ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Requested mode (allowed: '%s', preferred: '%s') not "
+ "supported by the modem.",
+ allowed_str,
+ preferred_str);
+ g_free (allowed_str);
+ g_free (preferred_str);
+
+ set_allowed_modes_context_complete_and_free (ctx);
+ return;
+ }
+
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ ctx->cgclass_command,
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)cgclass_update_ready,
+ ctx);
+}
+
+/*****************************************************************************/
/* Flow control (Modem interface) */
static gboolean
@@ -515,6 +661,8 @@ iface_modem_init (MMIfaceModem *iface)
iface->load_supported_modes_finish = load_supported_modes_finish;
iface->load_allowed_modes = load_allowed_modes;
iface->load_allowed_modes_finish = load_allowed_modes_finish;
+ iface->set_allowed_modes = set_allowed_modes;
+ iface->set_allowed_modes_finish = set_allowed_modes_finish;
iface->setup_flow_control = setup_flow_control;
iface->setup_flow_control_finish = setup_flow_control_finish;
iface->modem_power_up = modem_power_up;