diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-07-01 10:24:00 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2016-07-01 10:24:12 +0200 |
commit | 3f4e777e4a2af7fcf8b020accb8949d0bcd91c5b (patch) | |
tree | 613360b4501f521d4679b57f45b0686be883c1b8 | |
parent | bcf3f09df4e8a765fae9d462dc087f3de619fde4 (diff) | |
download | libmbim-3f4e777e4a2af7fcf8b020accb8949d0bcd91c5b.tar.gz |
mbimcli: allow querying IP configuration out of the connection attempt
-rw-r--r-- | src/mbimcli/mbimcli-basic-connect.c | 112 |
1 files changed, 79 insertions, 33 deletions
diff --git a/src/mbimcli/mbimcli-basic-connect.c b/src/mbimcli/mbimcli-basic-connect.c index efdd8be..260d14c 100644 --- a/src/mbimcli/mbimcli-basic-connect.c +++ b/src/mbimcli/mbimcli-basic-connect.c @@ -64,6 +64,7 @@ static gboolean set_packet_service_attach_flag; static gboolean set_packet_service_detach_flag; static gchar *query_connect_str; static gchar *set_connect_activate_str; +static gchar *query_ip_configuration_str; static gchar *set_connect_deactivate_str; static gboolean query_packet_statistics_flag; @@ -72,6 +73,11 @@ static gboolean query_connection_state_arg_parse (const char *option_name, gpointer user_data, GError **error); +static gboolean query_ip_configuration_arg_parse (const char *option_name, + const char *value, + gpointer user_data, + GError **error); + static gboolean disconnect_arg_parse (const char *option_name, const char *value, gpointer user_data, @@ -166,6 +172,10 @@ static GOptionEntry entries[] = { "Connect (allowed keys: session-id, apn, auth (PAP|CHAP|MSCHAPV2), username, password)", "[\"key=value,...\"]" }, + { "query-ip-configuration", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, G_CALLBACK (query_ip_configuration_arg_parse), + "Query IP configuration (SessionID is optional, defaults to 0)", + "[SessionID]" + }, { "disconnect", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, G_CALLBACK (disconnect_arg_parse), "Disconnect (SessionID is optional, defaults to 0)", "[SessionID]" @@ -203,6 +213,16 @@ query_connection_state_arg_parse (const char *option_name, } static gboolean +query_ip_configuration_arg_parse (const char *option_name, + const char *value, + gpointer user_data, + GError **error) +{ + query_ip_configuration_str = g_strdup (value ? value : "0"); + return TRUE; +} + +static gboolean disconnect_arg_parse (const char *option_name, const char *value, gpointer user_data, @@ -243,6 +263,7 @@ mbimcli_basic_connect_options_enabled (void) set_packet_service_detach_flag + !!query_connect_str + !!set_connect_activate_str + + !!query_ip_configuration_str + !!set_connect_deactivate_str + query_packet_statistics_flag); @@ -714,6 +735,47 @@ ip_configuration_query_ready (MbimDevice *device, } static void +ip_configuration_query (MbimDevice *device, + guint session_id) +{ + MbimMessage *message; + GError *error = NULL; + + message = (mbim_message_ip_configuration_query_new ( + session_id, + MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_NONE, /* ipv4configurationavailable */ + MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_NONE, /* ipv6configurationavailable */ + 0, /* ipv4addresscount */ + NULL, /* ipv4address */ + 0, /* ipv6addresscount */ + NULL, /* ipv6address */ + NULL, /* ipv4gateway */ + NULL, /* ipv6gateway */ + 0, /* ipv4dnsservercount */ + NULL, /* ipv4dnsserver */ + 0, /* ipv6dnsservercount */ + NULL, /* ipv6dnsserver */ + 0, /* ipv4mtu */ + 0, /* ipv6mtu */ + &error)); + if (!message) { + g_printerr ("error: couldn't create IP config request: %s\n", error->message); + g_error_free (error); + mbim_message_unref (message); + shutdown (FALSE); + return; + } + + mbim_device_command (device, + message, + 60, + NULL, + (GAsyncReadyCallback)ip_configuration_query_ready, + NULL); + mbim_message_unref (message); +} + +static void connect_ready (MbimDevice *device, GAsyncResult *res, gpointer user_data) @@ -782,39 +844,7 @@ connect_ready (MbimDevice *device, VALIDATE_UNKNOWN (mbim_nw_error_get_string (nw_error))); if (GPOINTER_TO_UINT (user_data) == CONNECT) { - MbimMessage *message; - - message = (mbim_message_ip_configuration_query_new ( - session_id, - MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_NONE, /* ipv4configurationavailable */ - MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_NONE, /* ipv6configurationavailable */ - 0, /* ipv4addresscount */ - NULL, /* ipv4address */ - 0, /* ipv6addresscount */ - NULL, /* ipv6address */ - NULL, /* ipv4gateway */ - NULL, /* ipv6gateway */ - 0, /* ipv4dnsservercount */ - NULL, /* ipv4dnsserver */ - 0, /* ipv6dnsservercount */ - NULL, /* ipv6dnsserver */ - 0, /* ipv4mtu */ - 0, /* ipv6mtu */ - &error)); - if (message) { - mbim_device_command (device, - message, - 60, - NULL, - (GAsyncReadyCallback)ip_configuration_query_ready, - NULL); - mbim_message_unref (message); - } else { - g_printerr ("error: couldn't create IP config request: %s\n", error->message); - g_error_free (error); - mbim_message_unref (message); - shutdown (FALSE); - } + ip_configuration_query (device, session_id); return; } @@ -1948,6 +1978,22 @@ mbimcli_basic_connect_run (MbimDevice *device, return; } + /* Query IP configuration? */ + if (query_ip_configuration_str) { + GError *error = NULL; + guint session_id = 0; + + if (!connect_session_id_parse (query_ip_configuration_str, TRUE, &session_id, &error)) { + g_printerr ("error: couldn't parse session ID: %s\n", error->message); + g_error_free (error); + shutdown (FALSE); + return; + } + + ip_configuration_query (ctx->device, session_id); + return; + } + /* Disconnect? */ if (set_connect_deactivate_str) { MbimMessage *request; |