diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2015-10-10 14:20:40 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2015-10-12 14:04:26 +0200 |
commit | 5b6752d37dbd82c7f244b2c54de0376f245b305a (patch) | |
tree | fedd37d4a5b9148f02aa854576378b88577289a9 /src | |
parent | fe0d1020bfc3f7b931b250eaf89b02e200d2c8f3 (diff) | |
download | external_libqmi-5b6752d37dbd82c7f244b2c54de0376f245b305a.zip external_libqmi-5b6752d37dbd82c7f244b2c54de0376f245b305a.tar.gz external_libqmi-5b6752d37dbd82c7f244b2c54de0376f245b305a.tar.bz2 |
qmicli,wds: allow autoconnect settings in Start/Stop Network commands
Diffstat (limited to 'src')
-rw-r--r-- | src/qmicli/qmicli-helpers.c | 23 | ||||
-rw-r--r-- | src/qmicli/qmicli-helpers.h | 2 | ||||
-rw-r--r-- | src/qmicli/qmicli-wds.c | 70 |
3 files changed, 75 insertions, 20 deletions
diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c index 3b62358..a2ca5d3 100644 --- a/src/qmicli/qmicli-helpers.c +++ b/src/qmicli/qmicli-helpers.c @@ -230,6 +230,29 @@ qmicli_read_enable_disable_from_string (const gchar *str, } gboolean +qmicli_read_yes_no_from_string (const gchar *str, + gboolean *out) +{ + if (!str || str[0] == '\0') { + g_printerr ("error: expected 'true', 'false', 'yes' or 'no', got: none\n"); + return FALSE; + } + + if ((g_strcasecmp (str, "yes") == 0) || (g_strcasecmp (str, "true") == 0)) { + *out = TRUE; + return TRUE; + } + + if ((g_strcasecmp (str, "no") == 0) || (g_strcasecmp (str, "false") == 0)) { + *out = FALSE; + return TRUE; + } + + g_printerr ("error: expected 'true', 'false', 'yes' or 'no', got: %s\n", str); + return FALSE; +} + +gboolean qmicli_read_non_empty_string (const gchar *str, const gchar *description, gchar **out) diff --git a/src/qmicli/qmicli-helpers.h b/src/qmicli/qmicli-helpers.h index 6b19827..975b507 100644 --- a/src/qmicli/qmicli-helpers.h +++ b/src/qmicli/qmicli-helpers.h @@ -61,6 +61,8 @@ gboolean qmicli_read_non_empty_string (const gchar *str, gchar **out); gboolean qmicli_read_uint_from_string (const gchar *str, guint *out); +gboolean qmicli_read_yes_no_from_string (const gchar *str, + gboolean *out); gchar *qmicli_get_supported_messages_list (const guint8 *data, gsize len); diff --git a/src/qmicli/qmicli-wds.c b/src/qmicli/qmicli-wds.c index 77b01cb..5e6979d 100644 --- a/src/qmicli/qmicli-wds.c +++ b/src/qmicli/qmicli-wds.c @@ -67,7 +67,7 @@ static gboolean noop_flag; static GOptionEntry entries[] = { { "wds-start-network", 0, 0, G_OPTION_ARG_STRING, &start_network_str, - "Start network (allowed keys: apn, auth (PAP|CHAP|BOTH), username, password)", + "Start network (allowed keys: apn, auth (PAP|CHAP|BOTH), username, password, autoconnect=yes)", "[\"key=value,...\"]" }, { "wds-follow-network", 0, 0, G_OPTION_ARG_NONE, &follow_network_flag, @@ -76,7 +76,7 @@ static GOptionEntry entries[] = { }, { "wds-stop-network", 0, 0, G_OPTION_ARG_STRING, &stop_network_str, "Stop network", - "[Packet data handle]" + "[Packet data handle] OR [disable-autoconnect]", }, { "wds-get-current-settings", 0, 0, G_OPTION_ARG_NONE, &get_current_settings_flag, "Get current settings", @@ -241,12 +241,15 @@ stop_network_ready (QmiClientWds *client, static void internal_stop_network (GCancellable *cancellable, - guint32 packet_data_handle) + guint32 packet_data_handle, + gboolean disable_autoconnect) { QmiMessageWdsStopNetworkInput *input; input = qmi_message_wds_stop_network_input_new (); qmi_message_wds_stop_network_input_set_packet_data_handle (input, packet_data_handle, NULL); + if (disable_autoconnect) + qmi_message_wds_stop_network_input_set_disable_autoconnect (input, TRUE, NULL); g_print ("Network cancelled... releasing resources\n"); qmi_client_wds_stop_network (ctx->client, @@ -270,7 +273,7 @@ network_cancelled (GCancellable *cancellable) } g_print ("Network cancelled... releasing resources\n"); - internal_stop_network (cancellable, ctx->packet_data_handle); + internal_stop_network (cancellable, ctx->packet_data_handle, FALSE); } static void @@ -310,7 +313,7 @@ timeout_get_packet_service_status_ready (QmiClientWds *client, if (status != QMI_WDS_CONNECTION_STATUS_CONNECTED) { g_print ("[%s] Stopping after detecting disconnection\n", qmi_device_get_path_display (ctx->device)); - internal_stop_network (NULL, ctx->packet_data_handle); + internal_stop_network (NULL, ctx->packet_data_handle, FALSE); } } @@ -333,6 +336,8 @@ typedef struct { gboolean auth_set; gchar *username; gchar *password; + gboolean autoconnect; + gboolean autoconnect_set; } StartNetworkProperties; static gboolean @@ -380,6 +385,19 @@ start_network_properties_handle (const gchar *key, return TRUE; } + if (g_ascii_strcasecmp (key, "autoconnect") == 0 && !props->autoconnect_set) { + if (!qmicli_read_yes_no_from_string (value, &(props->autoconnect))) { + g_set_error (error, + QMI_CORE_ERROR, + QMI_CORE_ERROR_FAILED, + "unknown autoconnect setup '%s'", + value); + return FALSE; + } + props->autoconnect_set = TRUE; + return TRUE; + } + g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED, @@ -461,11 +479,16 @@ start_network_input_create (const gchar *str) if (props.password && props.password[0]) qmi_message_wds_start_network_input_set_password (input, props.password, NULL); - g_debug ("Network start parameters set (apn: '%s', auth: '%s', username: '%s', password: '%s')", - props.apn ? props.apn : "unspecified", - aux_auth_str ? aux_auth_str : "unspecified", - (props.username && props.username[0]) ? props.username : "unspecified", - (props.password && props.password[0]) ? props.password : "unspecified"); + /* Set autoconnect */ + if (props.autoconnect_set) + qmi_message_wds_start_network_input_set_enable_autoconnect (input, props.autoconnect, NULL); + + g_debug ("Network start parameters set (apn: '%s', auth: '%s', username: '%s', password: '%s', autoconnect: '%s')", + props.apn ? props.apn : "unspecified", + aux_auth_str ? aux_auth_str : "unspecified", + (props.username && props.username[0]) ? props.username : "unspecified", + (props.password && props.password[0]) ? props.password : "unspecified", + props.autoconnect_set ? (props.autoconnect ? "yes" : "no") : "unspecified"); out: g_strfreev (split); @@ -1395,20 +1418,27 @@ qmicli_wds_run (QmiDevice *device, /* Request to stop network? */ if (stop_network_str) { gulong packet_data_handle; + gboolean disable_autoconnect; - if (g_str_has_prefix (stop_network_str, "0x")) - packet_data_handle = strtoul (stop_network_str, NULL, 16); - else - packet_data_handle = strtoul (stop_network_str, NULL, 10); - if (!packet_data_handle || packet_data_handle > G_MAXUINT32) { - g_printerr ("error: invalid packet data handle given '%s'\n", - stop_network_str); - operation_shutdown (FALSE); - return; + if (g_str_equal (stop_network_str, "disable-autoconnect")) { + packet_data_handle = 0xFFFFFFFF; + disable_autoconnect = TRUE; + } else { + disable_autoconnect = FALSE; + if (g_str_has_prefix (stop_network_str, "0x")) + packet_data_handle = strtoul (stop_network_str, NULL, 16); + else + packet_data_handle = strtoul (stop_network_str, NULL, 10); + if (!packet_data_handle || packet_data_handle > G_MAXUINT32) { + g_printerr ("error: invalid packet data handle given '%s'\n", + stop_network_str); + operation_shutdown (FALSE); + return; + } } g_debug ("Asynchronously stopping network (%lu)...", packet_data_handle); - internal_stop_network (ctx->cancellable, (guint32)packet_data_handle); + internal_stop_network (ctx->cancellable, (guint32)packet_data_handle, disable_autoconnect); return; } |