dpp: factor out PKEX/DPP start prep into function
PATCH v2 1/5 dpp: factor out PKEX/DPP start prep into function
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(-)
src/dpp.c +36 -28
@@ -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);
Signature · 1 line
2.34.1
PATCH v2 2/5 station: add station_get_autoconnect
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(+)
src/station.c +5 -0
@@ -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));
src/station.h +1 -0
@@ -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);
Signature · 1 line
2.34.1
PATCH v2 3/5 dpp: explicitly disconnect station if enrollee is started
In reply to James PrestwoodPrior 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 | 195 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 143 insertions(+), 52 deletions(-)
src/dpp.c +143 -52
@@ -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_disconnect_started (struct dpp_sm *dpp) +{ +int ret =0 ; +struct station *station =station_find (netdev_get_ifindex (dpp->netdev)); + +/* Unusual case, but an enrollee could still be started */ +if (!station) +return false; + + 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 : + ret = false; + goto register_watch; +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 ) + goto error; + +/* fall through */ +case STATION_STATE_DISCONNECTING : +l_debug ("Delaying DPP start until after disconnect" ); + + ret = true; + goto register_watch; + } + +error: +l_warn ("failed to start disconnecting (%d)" , ret); +station_set_autoconnect (station, dpp->autoconnect); + +return ret; + +register_watch: + dpp->station_watch =station_add_state_watch (station, + dpp_station_state_watch, + dpp,NULL ); +return ret; +} +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,27 @@ 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)); +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_disconnect_started (dpp); +if (ret <0 ) { +dpp_reset (dpp); +return dbus_error_from_errno (ret, message); + }else if (ret == false) +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 +4189,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 +4442,7 @@ 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)); +int ret;l_debug ("" );
@@ -4369,9 +4450,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,8 +4462,18 @@ 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)) - goto invalid_args; + ret =dpp_disconnect_started (dpp); +if (ret <0 ) { +dpp_reset (dpp); +return dbus_error_from_errno (ret, message); + }else if (ret == false) +if (!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);
@@ -4470,6 +4558,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
Signature · 1 line
2.34.1
Re: [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started
Hi James,
Quoted 17 lines · 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 | 195 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 143 insertions(+), 52 deletions(-)
<snip>
Quoted 4 lines
src/dpp.c +0
-0@@ -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
src/dpp.c static void dpp_frame_watch(struct dpp_sm *dpp, uint16_t frame_type, · line 3750
Quoted 10 lines
src/dpp.c +3
-2-* 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 )
Is this check needed? It looks like you create the state watch after setting state and interface accordingly?
Quoted 2 lines
(quoted diff) +0
-0return;
<snip>
src/dpp.c static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs, · line 3952
Quoted 7 lines
src/dpp.c +3
-0@@ -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_disconnect_started (struct dpp_sm *dpp) +{ +int ret =0 ;
Is initialization needed?
src/dpp.c static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs, · line 3957
Quoted 5 lines
src/dpp.c +5
-0+struct station *station =station_find (netdev_get_ifindex (dpp->netdev)); + +/* Unusual case, but an enrollee could still be started */ +if (!station) +return false;
Function signature returns int, but you're returning false.
Quoted 75 lines
src/dpp.c +51
-11+ + 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 : + ret = false; + goto register_watch; +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 ) + goto error; + +/* fall through */ +case STATION_STATE_DISCONNECTING : +l_debug ("Delaying DPP start until after disconnect" ); + + ret = true; + goto register_watch; + } + +error: +l_warn ("failed to start disconnecting (%d)" , ret); +station_set_autoconnect (station, dpp->autoconnect); + +return ret; + +register_watch: + dpp->station_watch =station_add_state_watch (station, + dpp_station_state_watch, + dpp,NULL ); +return ret; +} +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,27 @@ 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)); +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 ;
src/dpp.c static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus, · line 4051
Quoted 10 lines
src/dpp.c +6
-1dpp->role =DPP_CAPABILITY_ENROLLEE ; dpp->interface =DPP_INTERFACE_DPP ; -dpp_start_enrollee (dpp); + ret =dpp_disconnect_started (dpp); +if (ret <0 ) { +dpp_reset (dpp); +return dbus_error_from_errno (ret, message); + }else if (ret == false) +dpp_start_enrollee (dpp);
I'm super confused here
src/dpp.c static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus, · line 4059
Quoted 8 lines
src/dpp.c +5
-0+ +/* +* If a disconnect was started/in progress the enrollee will start once +* that has finished +*/ dpp->pending =l_dbus_message_ref (message);
Regards,
-Denis
Re: [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started
Hi Denis,
Quoted 55 lines · Denis Kenzior
Hi James,
Quoted 17 lines · 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| 195 +++++++++++++++++++++++++++++++++++++++---------------1 file changed, 143 insertions(+), 52 deletions(-)<snip>
Quoted 7 lines
src/dpp.c +0
-1@@ -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/roamingstate.
Quoted 8 lines
+ * connecting state or enrolling and going to a roaming state.
*/
static voiddpp_station_state_watch(enum station_state state, void *user_data){
structdpp_sm*dpp =user_data;
- if (dpp->state==DPP_STATE_NOTHING)
+ if (dpp->state==DPP_STATE_NOTHING||
+dpp->interface==DPP_INTERFACE_UNBOUND)Is this check needed? It looks like you create the state watch after setting state and interface accordingly?
Quoted 1 line
return;
<snip>
src/dpp.c static void dpp_start_presence(struct dpp_sm · line 3952
Quoted 7 lines
src/dpp.c +2
-0@@ -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_disconnect_started(struct dpp_sm *dpp) +{ + int ret = 0;Is initialization needed?
Quoted 8 lines
src/dpp.c static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs, · line 3957
Quoted 6 lines
src/dpp.c +5
-0+ struct station *station =station_find (netdev_get_ifindex (dpp->netdev)); + + /* Unusual case, but an enrollee could still be started */ + if (!station) + return false;Function signature returns int, but you're returning false.
Yep this is intended.
true for a disconnect has started or is ongoing. false for already disconnected
< 0 for a fatal error (i.e. station_disconnect() failed)
If this isn't desirable we could do:
-EALREADY for a disconnect is started/ongoing
0 for already disconnected
< 0 for a fatal error
We do a somewhat similar technique with wiphy_radio_work_is_running. But if we want to keep the return strictly integers/error codes I'm fine with that.
Quoted 101 lines
Quoted 79 lines
src/dpp.c +50
-0+ + 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: + ret = false; + goto register_watch; + 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) + goto error; + + /* fall through */ + case STATION_STATE_DISCONNECTING: + l_debug("Delaying DPP start until after disconnect"); + + ret = true; + goto register_watch; + } + +error: + l_warn("failed to start disconnecting (%d)", ret); + station_set_autoconnect(station, dpp->autoconnect); + + return ret; + +register_watch: + dpp->station_watch = station_add_state_watch(station, + dpp_station_state_watch, + dpp, NULL); + return ret; +} + static void dpp_start_enrollee(struct dpp_sm *dpp){
uint32_tfreq =band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);src/dpp.c +1
-1@@ -3955,27 +4033,27 @@ 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)); + int ret;if (
dpp->state!=DPP_STATE_NOTHING||dpp->interface!=DPP_INTERFACE_UNBOUND) returndbus_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");
- returndbus_error_busy(message);
- } else if (!station)
-l_debug("No station device, continuing anyways..."); -
dpp->state=DPP_STATE_PRESENCE;
dpp->role=DPP_CAPABILITY_ENROLLEE;Quoted 8 lines
dpp->interface=DPP_INTERFACE_DPP;
-dpp_start_enrollee(dpp);
+ ret =dpp_disconnect_started(dpp);
+ if (ret < 0) {
+dpp_reset(dpp);
+ returndbus_error_from_errno(ret, message); + } else if (ret == false)
+dpp_start_enrollee(dpp);I'm super confused here
Quoted 7 lines
+
+ /*
+ * If a disconnect was started/in progress the enrollee will start once
+ * that has finished
+ */
dpp->pending=l_dbus_message_ref(message);Regards,
-Denis
Re: [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started
Hi James,
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
+ /* Unusual case, but an enrollee could still be started */ + if (!station)
+ return false;
Quoted 8 lines
Quoted 1 line
Function signature returns int, but you're returning false.
Yep this is intended.
true for a disconnect has started or is ongoing. false for already disconnected
< 0 for a fatal error (i.e.station_disconnect()failed)
The typical convention is:
-errno -> error
0 - > success
You can extend this to mean that 0...INT_MAX is a success and return value simultaneously. Mixing integers and bools is not what vast majority of people would expect and should be avoided.
Quoted 5 lines
If this isn't desirable we could do:
-EALREADYfor a disconnect is started/ongoing
0 for already disconnected
< 0 for a fatal error
That would be better. Another alternative is:
int dpp_try_disconnect_station(struct dpp_sm *dpp, bool *out_disconnect_started);
Regards,
-Denis
Re: [PATCH v2 3/5] dpp: explicitly disconnect station if enrollee is started
Hi Denis,
Quoted 23 lines · Denis Kenzior
Hi James,
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
+ /* Unusual case, but an enrollee could still be started */ + if (!station)
+ return false;Quoted 8 lines
Quoted 1 line
Function signature returns int, but you're returning false.
Yep this is intended.
true for a disconnect has started or is ongoing. false for already disconnected
< 0 for a fatal error (i.e.station_disconnect()failed)The typical convention is:
-errno -> error
0 - > successYou can extend this to mean that 0...INT_MAX is a success and return value simultaneously. Mixing integers and bools is not what vast majority of people would expect and should be avoided.
Quoted 2 lines
If this isn't desirable we could do:
Quoted 7 lines
Quoted 3 lines
-EALREADYfor a disconnect is started/ongoing
0 for already disconnected
< 0 for a fatal errorThat would be better. Another alternative is:
int
dpp_try_disconnect_station(struct dpp_sm *dpp, bool *out_disconnect_started);
Ok, I'll do one of these instead.
Quoted 3 lines
Regards,
-Denis
PATCH v2 4/5 auto-t: add DPP tests for state change checks
In reply to 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
autotests/testDPP/pkex_test.py +19 -1
@@ -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')
autotests/testDPP/state_change_test.py new file +107 -0
108 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 5/5 auto-t: fix several DPP tests after station state changes
In reply to James PrestwoodAfter 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(-)
autotests/testDPP/connection_test.py +2 -4
@@ -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)
autotests/testDPP/pkex_test.py +6 -9
@@ -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)
Signature · 1 line
2.34.1