From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 06/10] network: delay connect if ANQP has not completed
Date: Tue, 02 Jun 2020 10:30:17 -0700 [thread overview]
Message-ID: <20200602173021.20085-7-prestwoj@gmail.com> (raw)
In-Reply-To: <20200602173021.20085-1-prestwoj@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3948 bytes --]
Using the new station ANQP watch network can delay the connection
request until after ANQP has finished. Since station may be
autoconnecting we must also add a check in network_autoconnect
which prevents it from autoconnecting if we have a pending Connect
request.
---
src/network.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/src/network.c b/src/network.c
index c08d7e72..b2599c7c 100644
--- a/src/network.c
+++ b/src/network.c
@@ -52,6 +52,7 @@
#include "src/util.h"
static uint32_t known_networks_watch;
+static uint32_t anqp_watch;
struct network {
char ssid[33];
@@ -72,7 +73,10 @@ struct network {
bool update_psk:1; /* Whether PSK should be written to storage */
bool ask_passphrase:1; /* Whether we should force-ask agent */
bool is_hs20:1;
+ bool anqp_pending:1; /* Set if there is a pending ANQP request */
int rank;
+ /* Holds DBus Connect() message if it comes in before ANQP finishes */
+ struct l_dbus_message *connect_after_anqp;
};
static bool network_settings_load(struct network *network)
@@ -521,6 +525,10 @@ int network_autoconnect(struct network *network, struct scan_bss *bss)
bool is_rsn;
int ret;
+ /* already waiting for an ANQP response to connect */
+ if (network->connect_after_anqp)
+ return -EALREADY;
+
switch (security) {
case SECURITY_NONE:
is_rsn = false;
@@ -1102,6 +1110,11 @@ static struct l_dbus_message *network_connect_8021x(struct network *network,
goto error;
}
+ if (network->connect_after_anqp) {
+ l_dbus_message_unref(network->connect_after_anqp);
+ network->connect_after_anqp = NULL;
+ }
+
station_connect_network(station, network, bss, message);
return NULL;
@@ -1156,6 +1169,19 @@ static struct l_dbus_message *network_connect(struct l_dbus *dbus,
station_connect_network(station, network, bss, message);
return NULL;
case SECURITY_8021X:
+ /*
+ * If there is an ongoing ANQP request we must wait for that to
+ * finish. Save the message and wait for the ANQP watch to
+ * fire
+ */
+ if (network->anqp_pending) {
+ network->connect_after_anqp =
+ l_dbus_message_ref(message);
+ l_debug("Pending ANQP request, delaying connect to %s",
+ network->ssid);
+ return NULL;
+ }
+
if (!network_settings_load(network))
return dbus_error_not_configured(message);
@@ -1484,6 +1510,33 @@ static void known_networks_changed(enum known_networks_event event,
}
}
+static void anqp_watch_changed(enum station_anqp_state state,
+ struct network *network, void *user_data)
+{
+ network->anqp_pending = state == STATION_ANQP_STARTED;
+
+ if (state == STATION_ANQP_FINISHED && network->connect_after_anqp) {
+ struct l_dbus_message *reply;
+
+ l_debug("ANQP complete, resuming connect to %s", network->ssid);
+
+ if (!network_settings_load(network))
+ reply = dbus_error_not_configured(
+ network->connect_after_anqp);
+ else
+ reply = network_connect_8021x(network,
+ network_bss_select(network, true),
+ network->connect_after_anqp);
+
+ if (!reply)
+ return;
+
+ dbus_pending_reply(&network->connect_after_anqp, reply);
+
+ return;
+ }
+}
+
static void setup_network_interface(struct l_dbus_interface *interface)
{
l_dbus_interface_method(interface, "Connect", 0,
@@ -1517,6 +1570,8 @@ static int network_init(void)
known_networks_watch =
known_networks_watch_add(known_networks_changed, NULL, NULL);
+ anqp_watch = station_add_anqp_watch(anqp_watch_changed, NULL, NULL);
+
return 0;
}
@@ -1525,6 +1580,9 @@ static void network_exit(void)
known_networks_watch_remove(known_networks_watch);
known_networks_watch = 0;
+ station_remove_anqp_watch(anqp_watch);
+ anqp_watch = 0;
+
l_dbus_unregister_interface(dbus_get_bus(), IWD_NETWORK_INTERFACE);
}
--
2.21.1
next prev parent reply other threads:[~2020-06-02 17:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 17:30 [PATCH 00/10] ANQP Refactor to use frame-xchg James Prestwood
2020-06-02 17:30 ` [PATCH 01/10] frame-xchg: fix bug when starting new xchg from callback James Prestwood
2020-06-02 17:30 ` [PATCH 02/10] frame-xchg: Fix frame_watch_remove_by_handler for group 0 James Prestwood
2020-06-02 17:30 ` [PATCH 03/10] frame-xchg: Use frame_watch_group_match in frame_watch_group_get James Prestwood
2020-06-02 17:30 ` [PATCH 04/10] anqp: refactor to use frame-xchg James Prestwood
2020-06-02 17:30 ` [PATCH 05/10] station: add ANQP state watch API James Prestwood
2020-06-02 17:30 ` James Prestwood [this message]
2020-06-02 17:30 ` [PATCH 07/10] hwsim: add new 'Delay' property to Rules James Prestwood
2020-06-08 20:15 ` Denis Kenzior
2020-06-02 17:30 ` [PATCH 08/10] doc: document new 'Delay' property for hwsim Rules James Prestwood
2020-06-02 17:30 ` [PATCH 09/10] auto-t: add 'Delay' property to hwsim python module James Prestwood
2020-06-02 17:30 ` [PATCH 10/10] auto-t: add test for delayed ANQP response James Prestwood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200602173021.20085-7-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox