From 244251f09a65cd056e07b036f964012677320594 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 17 Apr 2013 10:44:23 -0500 Subject: cli: impelement Set System Selection Preference --- cli/qmicli-helpers.c | 37 +++++++++++++++++ cli/qmicli-helpers.h | 2 + cli/qmicli-nas.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) diff --git a/cli/qmicli-helpers.c b/cli/qmicli-helpers.c index f041126..b3c0c90 100644 --- a/cli/qmicli-helpers.c +++ b/cli/qmicli-helpers.c @@ -147,6 +147,43 @@ qmicli_read_operating_mode_from_string (const gchar *str, return !!enum_value; } +gboolean +qmicli_read_rat_mode_pref_from_string (const gchar *str, + QmiNasRatModePreference *out) +{ + GType type; + GFlagsClass *flags_class; + GFlagsValue *flags_value; + gboolean success = TRUE, set = FALSE; + char **items, **iter; + + type = qmi_nas_rat_mode_preference_get_type (); + flags_class = G_FLAGS_CLASS (g_type_class_ref (type)); + + items = g_strsplit_set (str, "|", 0); + for (iter = items; iter && *iter && success; iter++) { + if (!*iter[0]) + continue; + + flags_value = g_flags_get_value_by_nick (flags_class, *iter); + if (flags_value) { + *out |= (QmiNasRatModePreference)flags_value->value; + set = TRUE; + } else { + g_printerr ("error: invalid rat mode pref value given: '%s'\n", *iter); + success = FALSE; + } + } + + if (!set) + g_printerr ("error: invalid rat mode pref input given: '%s'\n", str); + + if (items) + g_strfreev (items); + g_type_class_unref (flags_class); + return success && set; +} + gboolean qmicli_read_facility_from_string (const gchar *str, QmiDmsUimFacility *out) diff --git a/cli/qmicli-helpers.h b/cli/qmicli-helpers.h index 30a089a..0c88e19 100644 --- a/cli/qmicli-helpers.h +++ b/cli/qmicli-helpers.h @@ -33,6 +33,8 @@ 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, diff --git a/cli/qmicli-nas.c b/cli/qmicli-nas.c index 73e4aed..d805741 100644 --- a/cli/qmicli-nas.c +++ b/cli/qmicli-nas.c @@ -31,6 +31,7 @@ #include #include "qmicli.h" +#include "qmicli-helpers.h" /* Context */ typedef struct { @@ -48,6 +49,7 @@ static gboolean get_serving_system_flag; static gboolean get_system_info_flag; static gboolean get_technology_preference_flag; static gboolean get_system_selection_preference_flag; +static gchar *set_system_selection_preference_str; static gboolean network_scan_flag; static gboolean reset_flag; static gboolean noop_flag; @@ -81,6 +83,10 @@ static GOptionEntry entries[] = { "Get system selection preference", NULL }, + { "nas-set-system-selection-preference", 0, 0, G_OPTION_ARG_STRING, &set_system_selection_preference_str, + "Set system selection preference", + "[cdma-1x|cdma-1xevdo|gsm|umts|lte|td-scdma]" + }, { "nas-network-scan", 0, 0, G_OPTION_ARG_NONE, &network_scan_flag, "Scan networks", NULL @@ -127,6 +133,7 @@ qmicli_nas_options_enabled (void) get_system_info_flag + get_technology_preference_flag + get_system_selection_preference_flag + + !!set_system_selection_preference_str + network_scan_flag + reset_flag + noop_flag); @@ -1868,6 +1875,89 @@ get_system_selection_preference_ready (QmiClientNas *client, shutdown (TRUE); } +static QmiMessageNasSetSystemSelectionPreferenceInput * +set_system_selection_preference_input_create (const gchar *str) +{ + QmiMessageNasSetSystemSelectionPreferenceInput *input = NULL; + QmiNasRatModePreference pref; + GError *error = NULL; + + if (!qmicli_read_rat_mode_pref_from_string (str, &pref)) { + g_printerr ("error: failed to parse mode pref\n"); + return NULL; + } + + input = qmi_message_nas_set_system_selection_preference_input_new (); + if (!qmi_message_nas_set_system_selection_preference_input_set_mode_preference ( + input, + pref, + &error)) { + g_printerr ("error: couldn't create input data bundle: '%s'\n", + error->message); + g_error_free (error); + qmi_message_nas_set_system_selection_preference_input_unref (input); + return NULL; + } + + if (!qmi_message_nas_set_system_selection_preference_input_set_change_duration ( + input, + QMI_NAS_CHANGE_DURATION_PERMANENT, + &error)) { + g_printerr ("error: couldn't create input data bundle: '%s'\n", + error->message); + g_error_free (error); + qmi_message_nas_set_system_selection_preference_input_unref (input); + return NULL; + } + + if (pref & (QMI_NAS_RAT_MODE_PREFERENCE_GSM | + QMI_NAS_RAT_MODE_PREFERENCE_UMTS | + QMI_NAS_RAT_MODE_PREFERENCE_LTE)) { + if (!qmi_message_nas_set_system_selection_preference_input_set_gsm_wcdma_acquisition_order_preference ( + input, + QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC, + &error)) { + g_printerr ("error: couldn't create input data bundle: '%s'\n", + error->message); + g_error_free (error); + qmi_message_nas_set_system_selection_preference_input_unref (input); + return NULL; + } + } + + return input; +} + +static void +set_system_selection_preference_ready (QmiClientNas *client, + GAsyncResult *res) +{ + QmiMessageNasSetSystemSelectionPreferenceOutput *output = NULL; + GError *error = NULL; + + output = qmi_client_nas_set_system_selection_preference_finish (client, res, &error); + if (!output) { + g_printerr ("error: operation failed: %s\n", error->message); + g_error_free (error); + shutdown (FALSE); + return; + } + + if (!qmi_message_nas_set_system_selection_preference_output_get_result (output, &error)) { + g_printerr ("error: couldn't set operating mode: %s\n", error->message); + g_error_free (error); + qmi_message_nas_set_system_selection_preference_output_unref (output); + shutdown (FALSE); + return; + } + + g_print ("[%s] System selection preference set successfully\n", + qmi_device_get_path_display (ctx->device)); + + qmi_message_nas_set_system_selection_preference_output_unref (output); + shutdown (TRUE); +} + static void network_scan_ready (QmiClientNas *client, GAsyncResult *res) @@ -2099,6 +2189,27 @@ qmicli_nas_run (QmiDevice *device, return; } + /* Request to set system_selection preference? */ + if (set_system_selection_preference_str) { + QmiMessageNasSetSystemSelectionPreferenceInput *input; + g_debug ("Asynchronously setting system selection preference..."); + + input = set_system_selection_preference_input_create (set_system_selection_preference_str); + if (!input) { + shutdown (FALSE); + return; + } + + qmi_client_nas_set_system_selection_preference (ctx->client, + input, + 10, + ctx->cancellable, + (GAsyncReadyCallback)set_system_selection_preference_ready, + NULL); + qmi_message_nas_set_system_selection_preference_input_unref (input); + return; + } + /* Request to scan networks? */ if (network_scan_flag) { g_debug ("Asynchronously scanning networks..."); -- cgit v1.2.3