From 47d83f020ae3d2f4eddb701860e24bb39e1fb029 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 4 Oct 2015 13:39:50 +0200 Subject: wds: new 'WDS Set Autoconnect Setting' command support --- src/qmicli/qmicli-helpers.c | 43 ++++++++++++++++++ src/qmicli/qmicli-helpers.h | 43 ++++++++++-------- src/qmicli/qmicli-wds.c | 108 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 19 deletions(-) (limited to 'src/qmicli') diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c index 478307a..d5e9eee 100644 --- a/src/qmicli/qmicli-helpers.c +++ b/src/qmicli/qmicli-helpers.c @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * + * Copyright (C) 2015 Velocloud Inc. * Copyright (C) 2012-2015 Aleksander Morgado */ @@ -367,6 +368,48 @@ qmicli_read_link_layer_protocol_from_string (const gchar *str, return !!enum_value; } +gboolean +qmicli_read_autoconnect_setting_from_string (const gchar *str, + QmiWdsAutoconnectSetting *out) +{ + GType type; + GEnumClass *enum_class; + GEnumValue *enum_value; + + type = qmi_wds_autoconnect_setting_get_type (); + enum_class = G_ENUM_CLASS (g_type_class_ref (type)); + enum_value = g_enum_get_value_by_nick (enum_class, str); + + if (enum_value) + *out = (QmiWdsAutoconnectSetting)enum_value->value; + else + g_printerr ("error: invalid autoconnect setting value given: '%s'\n", str); + + g_type_class_unref (enum_class); + return !!enum_value; +} + +gboolean +qmicli_read_autoconnect_setting_roaming_from_string (const gchar *str, + QmiWdsAutoconnectSettingRoaming *out) +{ + GType type; + GEnumClass *enum_class; + GEnumValue *enum_value; + + type = qmi_wds_autoconnect_setting_roaming_get_type (); + enum_class = G_ENUM_CLASS (g_type_class_ref (type)); + enum_value = g_enum_get_value_by_nick (enum_class, str); + + if (enum_value) + *out = (QmiWdsAutoconnectSettingRoaming)enum_value->value; + else + g_printerr ("error: invalid autoconnect setting roaming value given: '%s'\n", str); + + g_type_class_unref (enum_class); + return !!enum_value; +} + gboolean qmicli_read_uint_from_string (const gchar *str, guint *out) diff --git a/src/qmicli/qmicli-helpers.h b/src/qmicli/qmicli-helpers.h index 3245207..0e6d567 100644 --- a/src/qmicli/qmicli-helpers.h +++ b/src/qmicli/qmicli-helpers.h @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * + * Copyright (C) 2015 Velocloud Inc. * Copyright (C) 2012-2015 Aleksander Morgado */ @@ -29,25 +30,29 @@ gchar *qmicli_get_raw_data_printable (const GArray *data, gsize max_line_length, const gchar *new_line_prefix); -gboolean qmicli_read_pin_id_from_string (const gchar *str, - QmiDmsUimPinId *out); -gboolean qmicli_read_operating_mode_from_string (const gchar *str, - QmiDmsOperatingMode *out); -gboolean qmicli_read_rat_mode_pref_from_string (const gchar *str, - QmiNasRatModePreference *out); -gboolean qmicli_read_facility_from_string (const gchar *str, - QmiDmsUimFacility *out); -gboolean qmicli_read_enable_disable_from_string (const gchar *str, - gboolean *out); -gboolean qmicli_read_firmware_id_from_string (const gchar *str, - QmiDmsFirmwareImageType *out_type, - guint *out_index); -gboolean qmicli_read_radio_interface_from_string (const gchar *str, - QmiNasRadioInterface *out); -gboolean qmicli_read_net_open_flags_from_string (const gchar *str, - QmiDeviceOpenFlags *out); -gboolean qmicli_read_link_layer_protocol_from_string (const gchar *str, - QmiWdaLinkLayerProtocol *out); +gboolean qmicli_read_pin_id_from_string (const gchar *str, + QmiDmsUimPinId *out); +gboolean qmicli_read_operating_mode_from_string (const gchar *str, + QmiDmsOperatingMode *out); +gboolean qmicli_read_rat_mode_pref_from_string (const gchar *str, + QmiNasRatModePreference *out); +gboolean qmicli_read_facility_from_string (const gchar *str, + QmiDmsUimFacility *out); +gboolean qmicli_read_enable_disable_from_string (const gchar *str, + gboolean *out); +gboolean qmicli_read_firmware_id_from_string (const gchar *str, + QmiDmsFirmwareImageType *out_type, + guint *out_index); +gboolean qmicli_read_radio_interface_from_string (const gchar *str, + QmiNasRadioInterface *out); +gboolean qmicli_read_net_open_flags_from_string (const gchar *str, + QmiDeviceOpenFlags *out); +gboolean qmicli_read_link_layer_protocol_from_string (const gchar *str, + QmiWdaLinkLayerProtocol *out); +gboolean qmicli_read_autoconnect_setting_from_string (const gchar *str, + QmiWdsAutoconnectSetting *out); +gboolean qmicli_read_autoconnect_setting_roaming_from_string (const gchar *str, + QmiWdsAutoconnectSettingRoaming *out); gboolean qmicli_read_non_empty_string (const gchar *str, const gchar *description, diff --git a/src/qmicli/qmicli-wds.c b/src/qmicli/qmicli-wds.c index 0905160..5e90b4a 100644 --- a/src/qmicli/qmicli-wds.c +++ b/src/qmicli/qmicli-wds.c @@ -60,6 +60,7 @@ static gboolean get_current_data_bearer_technology_flag; static gchar *get_profile_list_str; static gchar *get_default_settings_str; static gboolean get_autoconnect_settings_flag; +static gchar *set_autoconnect_settings_str; static gboolean get_supported_messages_flag; static gboolean reset_flag; static gboolean noop_flag; @@ -109,6 +110,10 @@ static GOptionEntry entries[] = { "Get autoconnect settings", NULL }, + { "wds-set-autoconnect-settings", 0, 0, G_OPTION_ARG_STRING, &set_autoconnect_settings_str, + "Set autoconnect settings (roaming settings optional)", + "[(enabled|disabled|paused)[,(roaming-allowed|home-only)]]" + }, { "wds-get-supported-messages", 0, 0, G_OPTION_ARG_NONE, &get_supported_messages_flag, "Get supported messages", NULL @@ -158,6 +163,7 @@ qmicli_wds_options_enabled (void) !!get_profile_list_str + !!get_default_settings_str + get_autoconnect_settings_flag + + !!set_autoconnect_settings_str + get_supported_messages_flag + reset_flag + noop_flag); @@ -1049,6 +1055,87 @@ get_autoconnect_settings_ready (QmiClientWds *client, operation_shutdown (TRUE); } +static QmiMessageWdsSetAutoconnectSettingsInput * +set_autoconnect_settings_input_create (const gchar *str) +{ + QmiMessageWdsSetAutoconnectSettingsInput *input = NULL; + gchar **split; + QmiWdsAutoconnectSetting status; + QmiWdsAutoconnectSettingRoaming roaming; + GError *error = NULL; + + split = g_strsplit (str, ",", -1); + input = qmi_message_wds_set_autoconnect_settings_input_new (); + + if (g_strv_length (split) != 2 && g_strv_length (split) != 1) { + g_printerr ("error: expected 1 or 2 options in autoconnect settings\n"); + goto error_out; + } + + g_strstrip (split[0]); + if (!qmicli_read_autoconnect_setting_from_string (split[0], &status)) { + g_printerr ("error: failed to parse autoconnect setting\n"); + goto error_out; + } + if (!qmi_message_wds_set_autoconnect_settings_input_set_status (input, status, &error)) { + g_printerr ("error: couldn't create input data bundle: '%s'\n", + error->message); + goto error_out; + } + + if (g_strv_length (split) == 2) { + g_strstrip (split[1]); + if (!qmicli_read_autoconnect_setting_roaming_from_string (g_str_equal (split[1], "roaming-allowed") ? "allowed" : split[1], &roaming)) { + g_printerr ("error: failed to parse autoconnect roaming setting\n"); + goto error_out; + } + if (!qmi_message_wds_set_autoconnect_settings_input_set_roaming (input, roaming, &error)) { + g_printerr ("error: couldn't create input data bundle: '%s'\n", + error->message); + goto error_out; + } + } + + g_strfreev (split); + return input; + +error_out: + if (error) + g_error_free (error); + g_strfreev (split); + qmi_message_wds_set_autoconnect_settings_input_unref (input); + return NULL; +} + +static void +set_autoconnect_settings_ready (QmiClientWds *client, + GAsyncResult *res) +{ + QmiMessageWdsSetAutoconnectSettingsOutput *output; + GError *error = NULL; + + output = qmi_client_wds_set_autoconnect_settings_finish (client, res, &error); + if (!output) { + g_printerr ("error: operation failed: %s\n", error->message); + g_error_free (error); + operation_shutdown (FALSE); + return; + } + + if (!qmi_message_wds_set_autoconnect_settings_output_get_result (output, &error)) { + g_printerr ("error: couldn't set autoconnect settings: %s\n", + error->message); + g_error_free (error); + qmi_message_wds_set_autoconnect_settings_output_unref (output); + operation_shutdown (FALSE); + return; + } + + g_print ("Autoconnect settings updated\n"); + qmi_message_wds_set_autoconnect_settings_output_unref (output); + operation_shutdown (TRUE); +} + static void get_supported_messages_ready (QmiClientWds *client, GAsyncResult *res) @@ -1368,6 +1455,27 @@ qmicli_wds_run (QmiDevice *device, return; } + /* Request to print autoconnect settings? */ + if (set_autoconnect_settings_str) { + QmiMessageWdsSetAutoconnectSettingsInput *input; + + input = set_autoconnect_settings_input_create (set_autoconnect_settings_str); + if (!input) { + operation_shutdown (FALSE); + return; + } + + g_debug ("Asynchronously set autoconnect settings..."); + qmi_client_wds_set_autoconnect_settings (ctx->client, + input, + 10, + ctx->cancellable, + (GAsyncReadyCallback)set_autoconnect_settings_ready, + NULL); + qmi_message_wds_set_autoconnect_settings_input_unref (input); + return; + } + /* Request to list supported messages? */ if (get_supported_messages_flag) { g_debug ("Asynchronously getting supported WDS messages..."); -- cgit v1.2.3