summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-05-29 17:50:49 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-06-05 19:15:15 +0200
commit0db920b7624337fa0b98d17d452fe7b6ecb1f076 (patch)
tree9942a8ab3fb5f570122205f91b4f605a12ed7ef5
parentda606ef572eeca18af14d04cbcb94f7e7c7eb474 (diff)
downloadModemManager-0db920b7624337fa0b98d17d452fe7b6ecb1f076.tar.gz
mmcli: new '--set-current-capabilities' command
New command to allow changing modem capabilities, if supported. The modem will power cycle automatically after having changed them.
-rw-r--r--cli/mmcli-modem.c74
-rw-r--r--libmm-glib/mm-common-helpers.c50
-rw-r--r--libmm-glib/mm-common-helpers.h2
3 files changed, 126 insertions, 0 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c
index 7ab462443..0a7f15183 100644
--- a/cli/mmcli-modem.c
+++ b/cli/mmcli-modem.c
@@ -57,6 +57,7 @@ static gchar *command_str;
static gboolean list_bearers_flag;
static gchar *create_bearer_str;
static gchar *delete_bearer_str;
+static gchar *set_current_capabilities_str;
static gchar *set_allowed_modes_str;
static gchar *set_preferred_mode_str;
static gchar *set_current_bands_str;
@@ -106,6 +107,10 @@ static GOptionEntry entries[] = {
"Delete a data bearer from a given modem",
"[PATH]"
},
+ { "set-current-capabilities", 0, 0, G_OPTION_ARG_STRING, &set_current_capabilities_str,
+ "Set current modem capabilities.",
+ "[CAPABILITY1|CAPABILITY2...]"
+ },
{ "set-allowed-modes", 0, 0, G_OPTION_ARG_STRING, &set_allowed_modes_str,
"Set allowed modes in a given modem.",
"[MODE1|MODE2...]"
@@ -157,6 +162,7 @@ mmcli_modem_options_enabled (void)
!!delete_bearer_str +
!!factory_reset_str +
!!command_str +
+ !!set_current_capabilities_str +
!!set_allowed_modes_str +
!!set_preferred_mode_str +
!!set_current_bands_str);
@@ -776,6 +782,47 @@ delete_bearer_ready (MMModem *modem,
}
static void
+set_current_capabilities_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't set current capabilities: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully set current capabilities in the modem\n");
+}
+
+static void
+set_current_capabilities_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_set_current_capabilities_finish (modem, result, &error);
+ set_current_capabilities_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+parse_current_capabilities (MMModemCapability *capabilities)
+{
+ GError *error = NULL;
+
+ *capabilities = mm_common_get_capabilities_from_string (set_current_capabilities_str,
+ &error);
+ if (error) {
+ g_printerr ("error: couldn't parse list of capabilities: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+}
+
+static void
set_current_modes_process_reply (gboolean result,
const GError *error)
{
@@ -1048,6 +1095,19 @@ get_modem_ready (GObject *source,
return;
}
+ /* Request to set current capabilities in a given modem? */
+ if (set_current_capabilities_str) {
+ MMModemCapability current_capabilities;
+
+ parse_current_capabilities (&current_capabilities);
+ mm_modem_set_current_capabilities (ctx->modem,
+ current_capabilities,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_current_capabilities_ready,
+ NULL);
+ return;
+ }
+
/* Request to set allowed modes in a given modem? */
if (set_allowed_modes_str) {
MMModemMode allowed;
@@ -1260,6 +1320,20 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
return;
}
+ /* Request to set capabilities in a given modem? */
+ if (set_current_capabilities_str) {
+ gboolean result;
+ MMModemCapability current_capabilities;
+
+ parse_current_capabilities (&current_capabilities);
+ result = mm_modem_set_current_capabilities_sync (ctx->modem,
+ current_capabilities,
+ NULL,
+ &error);
+ set_current_capabilities_process_reply (result, error);
+ return;
+ }
+
/* Request to set allowed modes in a given modem? */
if (set_allowed_modes_str) {
MMModemMode allowed;
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index 04ffe36de..838e09f65 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -194,6 +194,56 @@ mm_common_sms_storages_garray_to_variant (GArray *array)
return mm_common_sms_storages_array_to_variant (NULL, 0);
}
+MMModemCapability
+mm_common_get_capabilities_from_string (const gchar *str,
+ GError **error)
+{
+ GError *inner_error = NULL;
+ MMModemCapability capabilities;
+ gchar **capability_strings;
+ GFlagsClass *flags_class;
+
+ capabilities = MM_MODEM_CAPABILITY_NONE;
+
+ flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_CAPABILITY));
+ capability_strings = g_strsplit (str, "|", -1);
+
+ if (capability_strings) {
+ guint i;
+
+ for (i = 0; capability_strings[i]; i++) {
+ guint j;
+ gboolean found = FALSE;
+
+ for (j = 0; flags_class->values[j].value_nick; j++) {
+ if (!g_ascii_strcasecmp (capability_strings[i], flags_class->values[j].value_nick)) {
+ capabilities |= flags_class->values[j].value;
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (!found) {
+ inner_error = g_error_new (
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Couldn't match '%s' with a valid MMModemCapability value",
+ capability_strings[i]);
+ break;
+ }
+ }
+ }
+
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ capabilities = MM_MODEM_CAPABILITY_NONE;
+ }
+
+ g_type_class_unref (flags_class);
+ g_strfreev (capability_strings);
+ return capabilities;
+}
+
MMModemMode
mm_common_get_modes_from_string (const gchar *str,
GError **error)
diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h
index 891eb9da5..161d9030d 100644
--- a/libmm-glib/mm-common-helpers.h
+++ b/libmm-glib/mm-common-helpers.h
@@ -38,6 +38,8 @@ gchar *mm_common_build_sms_storages_string (const MMSmsStorage *storages,
gchar *mm_common_build_mode_combinations_string (const MMModemModeCombination *modes,
guint n_modes);
+MMModemCapability mm_common_get_capabilities_from_string (const gchar *str,
+ GError **error);
MMModemMode mm_common_get_modes_from_string (const gchar *str,
GError **error);
void mm_common_get_bands_from_string (const gchar *str,