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.
This commit is contained in:
@@ -57,6 +57,7 @@ static gchar *command_str;
|
|||||||
static gboolean list_bearers_flag;
|
static gboolean list_bearers_flag;
|
||||||
static gchar *create_bearer_str;
|
static gchar *create_bearer_str;
|
||||||
static gchar *delete_bearer_str;
|
static gchar *delete_bearer_str;
|
||||||
|
static gchar *set_current_capabilities_str;
|
||||||
static gchar *set_allowed_modes_str;
|
static gchar *set_allowed_modes_str;
|
||||||
static gchar *set_preferred_mode_str;
|
static gchar *set_preferred_mode_str;
|
||||||
static gchar *set_current_bands_str;
|
static gchar *set_current_bands_str;
|
||||||
@@ -106,6 +107,10 @@ static GOptionEntry entries[] = {
|
|||||||
"Delete a data bearer from a given modem",
|
"Delete a data bearer from a given modem",
|
||||||
"[PATH]"
|
"[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", 0, 0, G_OPTION_ARG_STRING, &set_allowed_modes_str,
|
||||||
"Set allowed modes in a given modem.",
|
"Set allowed modes in a given modem.",
|
||||||
"[MODE1|MODE2...]"
|
"[MODE1|MODE2...]"
|
||||||
@@ -157,6 +162,7 @@ mmcli_modem_options_enabled (void)
|
|||||||
!!delete_bearer_str +
|
!!delete_bearer_str +
|
||||||
!!factory_reset_str +
|
!!factory_reset_str +
|
||||||
!!command_str +
|
!!command_str +
|
||||||
|
!!set_current_capabilities_str +
|
||||||
!!set_allowed_modes_str +
|
!!set_allowed_modes_str +
|
||||||
!!set_preferred_mode_str +
|
!!set_preferred_mode_str +
|
||||||
!!set_current_bands_str);
|
!!set_current_bands_str);
|
||||||
@@ -775,6 +781,47 @@ delete_bearer_ready (MMModem *modem,
|
|||||||
mmcli_async_operation_done ();
|
mmcli_async_operation_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
set_current_modes_process_reply (gboolean result,
|
set_current_modes_process_reply (gboolean result,
|
||||||
const GError *error)
|
const GError *error)
|
||||||
@@ -1048,6 +1095,19 @@ get_modem_ready (GObject *source,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Request to set current capabilities in a given modem? */
|
||||||
|
if (set_current_capabilities_str) {
|
||||||
|
MMModemCapability current_capabilities;
|
||||||
|
|
||||||
|
parse_current_capabilities (¤t_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? */
|
/* Request to set allowed modes in a given modem? */
|
||||||
if (set_allowed_modes_str) {
|
if (set_allowed_modes_str) {
|
||||||
MMModemMode allowed;
|
MMModemMode allowed;
|
||||||
@@ -1260,6 +1320,20 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Request to set capabilities in a given modem? */
|
||||||
|
if (set_current_capabilities_str) {
|
||||||
|
gboolean result;
|
||||||
|
MMModemCapability current_capabilities;
|
||||||
|
|
||||||
|
parse_current_capabilities (¤t_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? */
|
/* Request to set allowed modes in a given modem? */
|
||||||
if (set_allowed_modes_str) {
|
if (set_allowed_modes_str) {
|
||||||
MMModemMode allowed;
|
MMModemMode allowed;
|
||||||
|
@@ -194,6 +194,56 @@ mm_common_sms_storages_garray_to_variant (GArray *array)
|
|||||||
return mm_common_sms_storages_array_to_variant (NULL, 0);
|
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
|
MMModemMode
|
||||||
mm_common_get_modes_from_string (const gchar *str,
|
mm_common_get_modes_from_string (const gchar *str,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
@@ -38,6 +38,8 @@ gchar *mm_common_build_sms_storages_string (const MMSmsStorage *storages,
|
|||||||
gchar *mm_common_build_mode_combinations_string (const MMModemModeCombination *modes,
|
gchar *mm_common_build_mode_combinations_string (const MMModemModeCombination *modes,
|
||||||
guint n_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,
|
MMModemMode mm_common_get_modes_from_string (const gchar *str,
|
||||||
GError **error);
|
GError **error);
|
||||||
void mm_common_get_bands_from_string (const gchar *str,
|
void mm_common_get_bands_from_string (const gchar *str,
|
||||||
|
Reference in New Issue
Block a user