* [PATCH v2 2/5] station: add station_get_autoconnect
2024-07-22 18:29 James Prestwood
@ 2024-07-22 18:29 ` James Prestwood
0 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2024-07-22 18:29 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
Gets the current autoconenct setting. This is not the current
autoconnect state. Will be used in DPP to reset station's autoconnect
setting back to what it was prior to DPP, in case of failure.
---
src/station.c | 5 +++++
src/station.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/src/station.c b/src/station.c
index ca0e6a38..db069981 100644
--- a/src/station.c
+++ b/src/station.c
@@ -1726,6 +1726,11 @@ bool station_set_autoconnect(struct station *station, bool autoconnect)
return true;
}
+bool station_get_autoconnect(struct station *station)
+{
+ return station->autoconnect;
+}
+
static void station_roam_state_clear(struct station *station)
{
l_debug("%u", netdev_get_ifindex(station->netdev));
diff --git a/src/station.h b/src/station.h
index a38327e4..50f0be12 100644
--- a/src/station.h
+++ b/src/station.h
@@ -88,6 +88,7 @@ uint32_t station_add_event_watch(station_event_watch_func_t func,
void station_remove_event_watch(uint32_t id);
bool station_set_autoconnect(struct station *station, bool autoconnect);
+bool station_get_autoconnect(struct station *station);
int __station_connect_network(struct station *station, struct network *network,
struct scan_bss *bss, enum station_state state);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function
@ 2024-07-24 15:46 James Prestwood
2024-07-24 15:46 ` [PATCH v2 2/5] station: add station_get_autoconnect James Prestwood
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: James Prestwood @ 2024-07-24 15:46 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
In order to slightly rework the DPP state machine to handle
automatically disconnecting (for enrollees) functions need to be
created that isolate everything needed to start DPP/PKEX in case
a disconnect needs to be done first.
---
src/dpp.c | 64 +++++++++++++++++++++++++++++++------------------------
1 file changed, 36 insertions(+), 28 deletions(-)
diff --git a/src/dpp.c b/src/dpp.c
index 567fe8d2..6f05aae9 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -3927,12 +3927,34 @@ static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs,
dpp_start_offchannel(dpp, dpp->current_freq);
}
+static void dpp_start_enrollee(struct dpp_sm *dpp)
+{
+ uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
+
+ dpp->uri = dpp_generate_uri(dpp->own_asn1, dpp->own_asn1_len, 2,
+ netdev_get_address(dpp->netdev), &freq,
+ 1, NULL, NULL);
+
+ l_ecdh_generate_key_pair(dpp->curve, &dpp->proto_private,
+ &dpp->own_proto_public);
+
+ l_debug("DPP Start Enrollee: %s", dpp->uri);
+
+ /*
+ * Going off spec here. Select a single channel to send presence
+ * announcements on. This will be advertised in the URI. The full
+ * presence procedure can be implemented if it is ever needed.
+ */
+ dpp_start_presence(dpp, &freq, 1);
+
+ dpp_property_changed_notify(dpp);
+}
+
static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data)
{
struct dpp_sm *dpp = user_data;
- uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
if (dpp->state != DPP_STATE_NOTHING ||
@@ -3949,30 +3971,14 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
} else if (!station)
l_debug("No station device, continuing anyways...");
- dpp->uri = dpp_generate_uri(dpp->own_asn1, dpp->own_asn1_len, 2,
- netdev_get_address(dpp->netdev), &freq,
- 1, NULL, NULL);
-
dpp->state = DPP_STATE_PRESENCE;
dpp->role = DPP_CAPABILITY_ENROLLEE;
dpp->interface = DPP_INTERFACE_DPP;
- l_ecdh_generate_key_pair(dpp->curve, &dpp->proto_private,
- &dpp->own_proto_public);
-
- l_debug("DPP Start Enrollee: %s", dpp->uri);
+ dpp_start_enrollee(dpp);
dpp->pending = l_dbus_message_ref(message);
- /*
- * Going off spec here. Select a single channel to send presence
- * announcements on. This will be advertised in the URI. The full
- * presence procedure can be implemented if it is ever needed.
- */
- dpp_start_presence(dpp, &freq, 1);
-
- dpp_property_changed_notify(dpp);
-
return NULL;
}
@@ -4246,19 +4252,12 @@ static void dpp_pkex_scan_destroy(void *user_data)
dpp->pkex_scan_id = 0;
}
-static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp, const char *key,
- const char *identifier)
+static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp)
{
_auto_(l_ecc_point_free) struct l_ecc_point *qi = NULL;
- if (identifier)
- dpp->pkex_id = l_strdup(identifier);
-
- dpp->pkex_key = l_strdup(key);
memcpy(dpp->peer_addr, broadcast, 6);
- dpp->role = DPP_CAPABILITY_ENROLLEE;
- dpp->state = DPP_STATE_PKEX_EXCHANGE;
- dpp->interface = DPP_INTERFACE_PKEX;
+
/*
* In theory a driver could support a lesser duration than 200ms. This
* complicates things since we would need to tack on additional
@@ -4376,7 +4375,16 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
if (!dpp_parse_pkex_args(message, &key, &id))
goto invalid_args;
- if (!dpp_start_pkex_enrollee(dpp, key, id))
+ dpp->pkex_key = l_strdup(key);
+
+ if (id)
+ dpp->pkex_id = l_strdup(id);
+
+ dpp->role = DPP_CAPABILITY_ENROLLEE;
+ dpp->state = DPP_STATE_PKEX_EXCHANGE;
+ dpp->interface = DPP_INTERFACE_PKEX;
+
+ if (!dpp_start_pkex_enrollee(dpp))
goto invalid_args;
return l_dbus_message_new_method_return(message);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] station: add station_get_autoconnect
2024-07-24 15:46 [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function James Prestwood
@ 2024-07-24 15:46 ` James Prestwood
2024-07-24 15:46 ` [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started James Prestwood
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2024-07-24 15:46 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
Gets the current autoconenct setting. This is not the current
autoconnect state. Will be used in DPP to reset station's autoconnect
setting back to what it was prior to DPP, in case of failure.
---
src/station.c | 5 +++++
src/station.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/src/station.c b/src/station.c
index ca0e6a38..db069981 100644
--- a/src/station.c
+++ b/src/station.c
@@ -1726,6 +1726,11 @@ bool station_set_autoconnect(struct station *station, bool autoconnect)
return true;
}
+bool station_get_autoconnect(struct station *station)
+{
+ return station->autoconnect;
+}
+
static void station_roam_state_clear(struct station *station)
{
l_debug("%u", netdev_get_ifindex(station->netdev));
diff --git a/src/station.h b/src/station.h
index a38327e4..50f0be12 100644
--- a/src/station.h
+++ b/src/station.h
@@ -88,6 +88,7 @@ uint32_t station_add_event_watch(station_event_watch_func_t func,
void station_remove_event_watch(uint32_t id);
bool station_set_autoconnect(struct station *station, bool autoconnect);
+bool station_get_autoconnect(struct station *station);
int __station_connect_network(struct station *station, struct network *network,
struct scan_bss *bss, enum station_state state);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started
2024-07-24 15:46 [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function James Prestwood
2024-07-24 15:46 ` [PATCH v2 2/5] station: add station_get_autoconnect James Prestwood
@ 2024-07-24 15:46 ` James Prestwood
2024-07-24 15:46 ` [PATCH v2 4/5] auto-t: add DPP tests for state change checks James Prestwood
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2024-07-24 15:46 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
Prior to now the DPP state was required to be disconnected before
DPP would start. This is inconvenient for the user since it requires
extra state checking and/or DBus method calls. Instead model this
case like WSC and issue a disconnect to station if DPP is requested
to start.
The other conditions on stopping DPP are also preserved and no
changes to the configurator role have been made, i.e. being
disconnected while configuring still stops DPP. Similarly any
connection made during enrolling will stop DPP.
It should also be noted that station's autoconfigure setting is also
preserved and set back to its original value upon DPP completing.
---
src/dpp.c | 198 ++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 147 insertions(+), 51 deletions(-)
v2:
* Used an bool out parameter to distinguish if a disconnect is in
progress as opposed to a true/false/< 0 return
diff --git a/src/dpp.c b/src/dpp.c
index 6f05aae9..d89c3056 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -193,6 +193,7 @@ struct dpp_sm {
bool roc_started : 1;
bool channel_switch : 1;
bool mutual_auth : 1;
+ bool autoconnect : 1;
};
static const char *dpp_role_to_string(enum dpp_capability role)
@@ -469,6 +470,8 @@ static void dpp_free_auth_data(struct dpp_sm *dpp)
static void dpp_reset(struct dpp_sm *dpp)
{
+ struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+
if (dpp->uri) {
l_free(dpp->uri);
dpp->uri = NULL;
@@ -549,12 +552,19 @@ static void dpp_reset(struct dpp_sm *dpp)
dpp_property_changed_notify(dpp);
dpp->interface = DPP_INTERFACE_UNBOUND;
+
+ if (station) {
+ if (dpp->station_watch)
+ station_remove_state_watch(station, dpp->station_watch);
+
+ /* Set the old autoconnect state back to what it was */
+ if (dpp->role == DPP_CAPABILITY_ENROLLEE)
+ station_set_autoconnect(station, dpp->autoconnect);
+ }
}
static void dpp_free(struct dpp_sm *dpp)
{
- struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
-
dpp_reset(dpp);
if (dpp->own_asn1) {
@@ -572,13 +582,6 @@ static void dpp_free(struct dpp_sm *dpp)
dpp->boot_private = NULL;
}
- /*
- * Since this is called when the netdev goes down, station may already
- * be gone in which case the state watch will automatically go away.
- */
- if (station)
- station_remove_state_watch(station, dpp->station_watch);
-
known_networks_watch_remove(dpp->known_network_watch);
l_free(dpp);
@@ -3721,6 +3724,9 @@ static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type,
L_UINT_TO_PTR(frame_type), NULL);
}
+static void dpp_start_enrollee(struct dpp_sm *dpp);
+static bool dpp_start_pkex_enrollee(struct dpp_sm *dpp);
+
/*
* Station is unaware of DPP's state so we need to handle a few cases here so
* weird stuff doesn't happen:
@@ -3734,27 +3740,50 @@ static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type,
* DPP finishes.
*
* Other conditions shouldn't ever happen i.e. configuring and going into a
- * connecting state or enrolling and going to a disconnected/roaming state.
+ * connecting state or enrolling and going to a roaming state.
*/
static void dpp_station_state_watch(enum station_state state, void *user_data)
{
struct dpp_sm *dpp = user_data;
- if (dpp->state == DPP_STATE_NOTHING)
+ if (dpp->state == DPP_STATE_NOTHING ||
+ dpp->interface == DPP_INTERFACE_UNBOUND)
return;
switch (state) {
case STATION_STATE_DISCONNECTED:
+ /* DPP-initiated disconnect, the enrollee can now start */
+ if (dpp->role == DPP_CAPABILITY_ENROLLEE) {
+ l_debug("Starting enrollee after disconnect");
+
+ if (dpp->interface == DPP_INTERFACE_DPP)
+ dpp_start_enrollee(dpp);
+ else
+ dpp_start_pkex_enrollee(dpp);
+
+ return;
+ }
+
+ break;
case STATION_STATE_DISCONNECTING:
+ /* Normal part of disconnecting prior to enrolling */
+ if (dpp->role == DPP_CAPABILITY_ENROLLEE)
+ return;
+
+ /* fall through */
case STATION_STATE_ROAMING:
case STATION_STATE_FT_ROAMING:
case STATION_STATE_FW_ROAMING:
+ /*
+ * An enrollee will always be disconnected prior to starting
+ * so a roaming condition should never happen.
+ */
if (L_WARN_ON(dpp->role == DPP_CAPABILITY_ENROLLEE))
- dpp_reset(dpp);
+ goto reset;
if (dpp->role == DPP_CAPABILITY_CONFIGURATOR) {
l_debug("Disconnected while configuring, stopping DPP");
- dpp_reset(dpp);
+ goto reset;
}
break;
@@ -3762,28 +3791,22 @@ static void dpp_station_state_watch(enum station_state state, void *user_data)
case STATION_STATE_CONNECTED:
case STATION_STATE_CONNECTING_AUTO:
case STATION_STATE_NETCONFIG:
- if (L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR))
- dpp_reset(dpp);
-
- if (dpp->role == DPP_CAPABILITY_ENROLLEE) {
- l_debug("Connecting while enrolling, stopping DPP");
- dpp_reset(dpp);
- }
-
- break;
-
- /*
- * Autoconnect states are fine for enrollees. This makes it nicer for
- * the user since they don't need to explicity Disconnect() to disable
- * autoconnect, then re-enable it if DPP fails.
- */
case STATION_STATE_AUTOCONNECT_FULL:
case STATION_STATE_AUTOCONNECT_QUICK:
- if (L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR))
- dpp_reset(dpp);
+ /*
+ * The user could have issued a connection request during
+ * enrolling, in which case DPP should be canceled. We should
+ * never hit this case as a configurator as a disconnect would
+ * need to come prior.
+ */
+ L_WARN_ON(dpp->role == DPP_CAPABILITY_CONFIGURATOR);
- break;
+ goto reset;
}
+
+reset:
+ l_debug("Resetting DPP after station state change (state=%u)", state);
+ dpp_reset(dpp);
}
static void dpp_create(struct netdev *netdev)
@@ -3793,7 +3816,6 @@ static void dpp_create(struct netdev *netdev)
uint8_t dpp_conf_response_prefix[] = { 0x04, 0x0b };
uint8_t dpp_conf_request_prefix[] = { 0x04, 0x0a };
uint64_t wdev_id = netdev_get_wdev_id(netdev);
- struct station *station = station_find(netdev_get_ifindex(netdev));
dpp->netdev = netdev;
dpp->state = DPP_STATE_NOTHING;
@@ -3839,8 +3861,6 @@ static void dpp_create(struct netdev *netdev)
sizeof(dpp_conf_request_prefix),
dpp_handle_config_request_frame, dpp, NULL);
- dpp->station_watch = station_add_state_watch(station,
- dpp_station_state_watch, dpp, NULL);
dpp->known_network_watch = known_networks_watch_add(
dpp_known_network_watch, dpp, NULL);
@@ -3927,6 +3947,64 @@ static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs,
dpp_start_offchannel(dpp, dpp->current_freq);
}
+static int dpp_try_disconnect_station(struct dpp_sm *dpp,
+ bool *out_disconnect_started)
+{
+ struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+ int ret;
+ bool started = false;
+
+ /* Unusual case, but an enrollee could still be started */
+ if (!station)
+ goto done;
+
+ dpp->autoconnect = station_get_autoconnect(station);
+ station_set_autoconnect(station, false);
+
+ switch (station_get_state(station)) {
+ case STATION_STATE_AUTOCONNECT_QUICK:
+ case STATION_STATE_AUTOCONNECT_FULL:
+ /* Should never happen since we just set autoconnect false */
+ l_warn("Still in autoconnect state after setting false!");
+
+ /* fall through */
+ case STATION_STATE_DISCONNECTED:
+ break;
+ case STATION_STATE_ROAMING:
+ case STATION_STATE_FT_ROAMING:
+ case STATION_STATE_FW_ROAMING:
+ case STATION_STATE_CONNECTING:
+ case STATION_STATE_CONNECTING_AUTO:
+ case STATION_STATE_CONNECTED:
+ case STATION_STATE_NETCONFIG:
+ /*
+ * For any connected or connection in progress state, start a
+ * disconnect
+ */
+ ret = station_disconnect(station);
+ if (ret < 0) {
+ l_warn("failed to start disconnecting (%d)", ret);
+ station_set_autoconnect(station, dpp->autoconnect);
+
+ return ret;
+ }
+ /* fall through */
+ case STATION_STATE_DISCONNECTING:
+ l_debug("Delaying DPP start until after disconnect");
+ started = true;
+
+ break;
+ }
+
+ dpp->station_watch = station_add_state_watch(station,
+ dpp_station_state_watch,
+ dpp, NULL);
+done:
+ *out_disconnect_started = started;
+
+ return 0;
+}
+
static void dpp_start_enrollee(struct dpp_sm *dpp)
{
uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
@@ -3955,27 +4033,30 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
void *user_data)
{
struct dpp_sm *dpp = user_data;
- struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+ bool wait_for_disconnect;
+ int ret;
if (dpp->state != DPP_STATE_NOTHING ||
dpp->interface != DPP_INTERFACE_UNBOUND)
return dbus_error_busy(message);
- /*
- * Station isn't actually required for DPP itself, although this will
- * prevent connecting to the network once configured.
- */
- if (station && station_get_connected_network(station)) {
- l_warn("cannot be enrollee while connected, please disconnect");
- return dbus_error_busy(message);
- } else if (!station)
- l_debug("No station device, continuing anyways...");
-
dpp->state = DPP_STATE_PRESENCE;
dpp->role = DPP_CAPABILITY_ENROLLEE;
dpp->interface = DPP_INTERFACE_DPP;
- dpp_start_enrollee(dpp);
+ ret = dpp_try_disconnect_station(dpp, &wait_for_disconnect);
+ if (ret < 0) {
+ dpp_reset(dpp);
+ return dbus_error_from_errno(ret, message);
+ }
+
+ if (!wait_for_disconnect)
+ dpp_start_enrollee(dpp);
+
+ /*
+ * If a disconnect was started/in progress the enrollee will start once
+ * that has finished
+ */
dpp->pending = l_dbus_message_ref(message);
@@ -4111,6 +4192,9 @@ static struct l_dbus_message *dpp_start_configurator_common(
dpp_property_changed_notify(dpp);
+ dpp->station_watch = station_add_state_watch(station,
+ dpp_station_state_watch, dpp, NULL);
+
l_debug("DPP Start Configurator: %s", dpp->uri);
reply = l_dbus_message_new_method_return(message);
@@ -4361,7 +4445,8 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
struct dpp_sm *dpp = user_data;
const char *key;
const char *id;
- struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+ bool wait_for_disconnect;
+ int ret;
l_debug("");
@@ -4369,9 +4454,6 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
dpp->interface != DPP_INTERFACE_UNBOUND)
return dbus_error_busy(message);
- if (station && station_get_connected_network(station))
- return dbus_error_busy(message);
-
if (!dpp_parse_pkex_args(message, &key, &id))
goto invalid_args;
@@ -4384,9 +4466,20 @@ static struct l_dbus_message *dpp_dbus_pkex_start_enrollee(struct l_dbus *dbus,
dpp->state = DPP_STATE_PKEX_EXCHANGE;
dpp->interface = DPP_INTERFACE_PKEX;
- if (!dpp_start_pkex_enrollee(dpp))
+ ret = dpp_try_disconnect_station(dpp, &wait_for_disconnect);
+ if (ret < 0) {
+ dpp_reset(dpp);
+ return dbus_error_from_errno(ret, message);
+ }
+
+ if (!wait_for_disconnect && !dpp_start_pkex_enrollee(dpp))
goto invalid_args;
+ /*
+ * If a disconnect was started/in progress the PKEX enrollee will start
+ * once that has finished
+ */
+
return l_dbus_message_new_method_return(message);
invalid_args:
@@ -4470,6 +4563,9 @@ static struct l_dbus_message *dpp_start_pkex_configurator(struct dpp_sm *dpp,
dpp_reset_protocol_timer(dpp, DPP_PKEX_PROTO_TIMEOUT);
dpp_property_changed_notify(dpp);
+ dpp->station_watch = station_add_state_watch(station,
+ dpp_station_state_watch, dpp, NULL);
+
if (dpp->pkex_key)
l_debug("Starting PKEX configurator for single enrollee");
else
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] auto-t: add DPP tests for state change checks
2024-07-24 15:46 [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function James Prestwood
2024-07-24 15:46 ` [PATCH v2 2/5] station: add station_get_autoconnect James Prestwood
2024-07-24 15:46 ` [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started James Prestwood
@ 2024-07-24 15:46 ` James Prestwood
2024-07-24 15:46 ` [PATCH v2 5/5] auto-t: fix several DPP tests after station state changes James Prestwood
2024-07-24 20:27 ` [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function Denis Kenzior
4 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2024-07-24 15:46 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
---
autotests/testDPP/pkex_test.py | 20 ++++-
autotests/testDPP/state_change_test.py | 107 +++++++++++++++++++++++++
2 files changed, 126 insertions(+), 1 deletion(-)
create mode 100644 autotests/testDPP/state_change_test.py
diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py
index db355225..3d3ea6d1 100644
--- a/autotests/testDPP/pkex_test.py
+++ b/autotests/testDPP/pkex_test.py
@@ -4,7 +4,7 @@ import unittest
import sys
sys.path.append('../util')
-from iwd import IWD, SharedCodeAgent
+from iwd import IWD, SharedCodeAgent, DeviceState
from iwd import DeviceProvisioning
from wpas import Wpas
from hostapd import HostapdCLI
@@ -210,6 +210,24 @@ class Test(unittest.TestCase):
self.assertIn("SendHostname=true", settings)
+ def test_existing_incorrect_profile(self):
+ self.hapd.reload()
+ self.hapd.wait_for_event('AP-ENABLED')
+ IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidCCMP.psk")
+
+ # Start connecting
+ self.device[1].autoconnect = True
+ self.wd.wait_for_object_condition(self.device[1], 'obj.state == DeviceState.connecting')
+
+ # We should be able to start DPP despite the connecting state
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
+
+ self.start_iwd_pkex_configurator(self.device[0])
+ self.assertEqual(self.device[1].state, DeviceState.disconnected)
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(self.device[1], condition)
+
def test_existing_hidden_network(self):
self.hapd_hidden.reload()
self.hapd_hidden.wait_for_event('AP-ENABLED')
diff --git a/autotests/testDPP/state_change_test.py b/autotests/testDPP/state_change_test.py
new file mode 100644
index 00000000..d52f2b12
--- /dev/null
+++ b/autotests/testDPP/state_change_test.py
@@ -0,0 +1,107 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+from iwd import IWD, SharedCodeAgent, DeviceState
+from iwd import DeviceProvisioning
+from wpas import Wpas
+from hostapd import HostapdCLI
+from hwsim import Hwsim
+from config import ctx
+from time import time
+import os
+
+class Test(unittest.TestCase):
+ def auto_connect(self):
+ IWD.copy_to_storage('ssidCCMP.psk')
+ self.device.autoconnect = True
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ def test_configurator_stops_on_disconnect(self):
+ self.auto_connect()
+
+ self.device.dpp_start_configurator()
+
+ self.device.disconnect()
+
+ condition = 'obj.state == DeviceState.disconnected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ self.assertEqual(self.device._device_provisioning.started, False)
+
+ def test_enrollee_stops_on_connect(self):
+ # Scan to get a list of networks
+ self.device.scan()
+ self.wd.wait_for_object_condition(self.device, 'obj.scanning == True')
+ self.wd.wait_for_object_condition(self.device, 'obj.scanning == False')
+
+ self.device.dpp_start_enrollee()
+
+ network = self.device.get_ordered_network("ssidCCMP")
+ network.network_object.connect()
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ self.assertEqual(self.device._device_provisioning.started, False)
+
+ def test_enrollee_disconnects_automatically(self):
+ self.auto_connect()
+
+ self.device.dpp_start_enrollee()
+
+ condition = 'obj.state == DeviceState.disconnected'
+ self.wd.wait_for_object_condition(self.device, condition)
+
+ def test_enrollee_autoconnect_stays_on(self):
+ # Put in an autoconnecting state, no saved profile though
+ self.device.autoconnect = True
+
+ self.device.dpp_start_enrollee()
+
+ # DPP should set autoconnect false, but then re-enable after it stops
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+ self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True")
+
+ # Stop DPP
+ self.device.dpp_stop()
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == True")
+
+ def test_enrollee_autoconnect_stays_off(self):
+ # Autoconnect should be off by default
+
+ self.device.dpp_start_enrollee()
+
+ # DPP should set autoconnect false, but stay off after it stops
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+ self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True")
+
+ # Stop DPP
+ self.device.dpp_stop()
+ self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+
+ def setUp(self):
+ self.wd = IWD(True)
+ self.device = self.wd.list_devices(1)[0]
+
+ def tearDown(self):
+ self.wd.stop()
+ self.wd = None
+
+ @classmethod
+ def setUpClass(cls):
+ hapd = HostapdCLI(config="hostapd.conf")
+ hapd.reload()
+
+ hapd.wait_for_event("AP-ENABLED")
+
+ @classmethod
+ def tearDownClass(cls):
+ pass
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
\ No newline at end of file
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/5] auto-t: fix several DPP tests after station state changes
2024-07-24 15:46 [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function James Prestwood
` (2 preceding siblings ...)
2024-07-24 15:46 ` [PATCH v2 4/5] auto-t: add DPP tests for state change checks James Prestwood
@ 2024-07-24 15:46 ` James Prestwood
2024-07-24 20:27 ` [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function Denis Kenzior
4 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2024-07-24 15:46 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
After the station state changes in DPP setting autoconnect=True was
causing DPP to stop prior to being able to scan for the network.
Instead we can start autoconnect earlier so we aren't toggling the
property while DPP is running.
---
autotests/testDPP/connection_test.py | 6 ++----
autotests/testDPP/pkex_test.py | 15 ++++++---------
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/autotests/testDPP/connection_test.py b/autotests/testDPP/connection_test.py
index f72a412d..e4f07af7 100644
--- a/autotests/testDPP/connection_test.py
+++ b/autotests/testDPP/connection_test.py
@@ -38,20 +38,18 @@ class Test(unittest.TestCase):
def test_iwd_as_enrollee_scan_after(self):
self.wpas.disconnect()
+ self.device.autoconnect = True
uri = self.device.dpp_start_enrollee()
self.wpas.dpp_configurator_create(uri)
self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
- self.hapd.reload()
-
with self.assertRaises(Exception):
self.device.get_ordered_network('ssidCCMP', scan_if_needed=False)
+ self.hapd.reload()
self.hapd.wait_for_event('AP-ENABLED')
- self.device.autoconnect = True
-
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device, condition)
diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py
index 3d3ea6d1..a651c6f6 100644
--- a/autotests/testDPP/pkex_test.py
+++ b/autotests/testDPP/pkex_test.py
@@ -160,10 +160,8 @@ class Test(unittest.TestCase):
def test_pkex_iwd_to_iwd(self):
self.start_iwd_pkex_configurator(self.device[0])
-
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
-
self.device[1].autoconnect = True
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -176,10 +174,8 @@ class Test(unittest.TestCase):
def test_pkex_configurator_with_agent(self):
self.start_iwd_pkex_configurator(self.device[0], agent=True)
-
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
-
self.device[1].autoconnect = True
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -198,8 +194,8 @@ class Test(unittest.TestCase):
self.start_iwd_pkex_configurator(self.device[0])
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
self.device[1].autoconnect = False
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -240,8 +236,9 @@ class Test(unittest.TestCase):
self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk')
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
self.device[1].autoconnect = False
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
+
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
@@ -257,8 +254,8 @@ class Test(unittest.TestCase):
self.hapd_hidden.wait_for_event('AP-ENABLED')
self.start_iwd_pkex_configurator(self.device[0], profile='ssidHidden.psk')
- self.device[1].dpp_pkex_enroll('secret123', identifier="test")
self.device[1].autoconnect = False
+ self.device[1].dpp_pkex_enroll('secret123', identifier="test")
condition = 'obj.state == DeviceState.connected'
self.wd.wait_for_object_condition(self.device[1], condition)
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function
2024-07-24 15:46 [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function James Prestwood
` (3 preceding siblings ...)
2024-07-24 15:46 ` [PATCH v2 5/5] auto-t: fix several DPP tests after station state changes James Prestwood
@ 2024-07-24 20:27 ` Denis Kenzior
4 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-07-24 20:27 UTC (permalink / raw)
To: James Prestwood, iwd
Hi James,
On 7/24/24 10:46 AM, James Prestwood wrote:
> In order to slightly rework the DPP state machine to handle
> automatically disconnecting (for enrollees) functions need to be
> created that isolate everything needed to start DPP/PKEX in case
> a disconnect needs to be done first.
> ---
> src/dpp.c | 64 +++++++++++++++++++++++++++++++------------------------
> 1 file changed, 36 insertions(+), 28 deletions(-)
>
All applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-07-24 20:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24 15:46 [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function James Prestwood
2024-07-24 15:46 ` [PATCH v2 2/5] station: add station_get_autoconnect James Prestwood
2024-07-24 15:46 ` [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started James Prestwood
2024-07-24 15:46 ` [PATCH v2 4/5] auto-t: add DPP tests for state change checks James Prestwood
2024-07-24 15:46 ` [PATCH v2 5/5] auto-t: fix several DPP tests after station state changes James Prestwood
2024-07-24 20:27 ` [PATCH v2 1/5] dpp: factor out PKEX/DPP start prep into function Denis Kenzior
-- strict thread matches above, loose matches on Subject: below --
2024-07-22 18:29 James Prestwood
2024-07-22 18:29 ` [PATCH v2 2/5] station: add station_get_autoconnect James Prestwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox