ft: netdev: refactor FT-over-DS into two stages
PATCH v5 1/3 ft: netdev: refactor FT-over-DS into two stages
FT-over-DS followed the same pattern as FT-over-Air which worked, but really limited how the protocol could be used. FT-over-DS is unique in that we can authenticate to many APs by sending out FT action frames and parsing the results. Once parsed IWD can immediately Reassociate, or do so at a later time.
To take advantage of this IWD need to separate FT-over-DS into two stages: action frame and reassociation.
The initial action frame stage is started by netdev. The target BSS is sent an FT action frame and a new cache entry is created in ft.c. Once the response is received the entry is updated with all the needed data to Reassociate. To limit the record keeping on netdev each FT-over-DS entry holds a userdata pointer so netdev doesn't need to maintain its own list of data for callbacks.
Once the action response is parsed netdev will call back signalling the action frame sequence was completed (either successfully or not). At this point the 'normal' FT procedure can start using the FT-over-DS auth-proto.
--- src/ft.c | 74 ++---------------- src/ft.h | 1 - src/netdev.c | 211 ++++++++++++++++++++++++++++++++++++++++----------- src/netdev.h | 8 ++ 4 files changed, 184 insertions(+), 110 deletions(-)
v5:
* Moved timeout removal until after the frame was parsed
* Added flag to signal that the frame was parsed
* Added cleanup in netdev_reassociate and the TX functions for over-Air/DS to clean up ft_ds_info
src/ft.c +8 -66
@@ -156,40 +156,6 @@ static bool ft_parse_authentication_resp_frame(const uint8_t *data, size_t len,return true; } -static bool ft_parse_action_resp_frame (const uint8_t *frame,size_t frame_len, -const uint8_t *spa,const uint8_t *aa, -uint16_t *out_status, -const uint8_t **out_ies, -size_t *out_ies_len) -{ -uint16_t status =0 ; - -/* Category FT */ -if (frame[0 ] !=6 ) -return false; - -/* FT Action */ -if (frame[1 ] !=2 ) -return false; - -if (memcmp (frame +2 , spa,6 )) -return false; -if (memcmp (frame +8 , aa,6 )) -return false; - - status =l_get_le16 (frame +14 ); - -if (out_status) - *out_status = status; - -if (status ==0 && out_ies) { - *out_ies = frame +16 ; - *out_ies_len = frame_len -16 ; - } - -return true; -} -static bool ft_parse_associate_resp_frame (const uint8_t *frame,size_t frame_len,uint16_t *out_status,const uint8_t **rsne,const uint8_t **mde,const uint8_t **fte)
@@ -612,34 +578,6 @@ bool ft_over_ds_prepare_handshake(struct ft_ds_info *info,return true; } -static int ft_rx_action (struct auth_proto *ap,const uint8_t *frame, -size_t frame_len) -{ - struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); -uint16_t status_code =MMPDU_STATUS_CODE_UNSPECIFIED ; -const uint8_t *ies =NULL ; -size_t ies_len; -int ret; - -if (!ft_parse_action_resp_frame (frame, frame_len, ft->hs->spa, - ft->hs->aa, &status_code, - &ies, &ies_len)) -return -EBADMSG ; - -/* AP Rejected the authenticate / associate */ -if (status_code !=0 ) - goto auth_error; - - ret =ft_process_ies (ft->hs, ies, ies_len); -if (ret <0 ) - goto auth_error; - -return ft_tx_reassociate (ft); - -auth_error: -return (int )status_code; -} -void ft_ds_info_free (struct ft_ds_info *info) { __typeof__(info->free) destroy = info->free;
@@ -827,6 +765,13 @@ static void ft_sm_free(struct auth_proto *ap)l_free (ft); } +static bool ft_over_ds_start (struct auth_proto *ap) +{ + struct ft_sm *ft = l_container_of(ap, struct ft_sm, ap); + +return ft_tx_reassociate (ft) ==0 ; +} +bool ft_build_authenticate_ies (struct handshake_state *hs,const uint8_t *new_snonce,uint8_t *buf,size_t *len)
@@ -938,20 +883,17 @@ struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs, }struct auth_proto *ft_over_ds_sm_new (struct handshake_state *hs, -ft_tx_authenticate_func_t tx_auth,ft_tx_associate_func_t tx_assoc,void *user_data) { struct ft_sm *ft = l_new(struct ft_sm, 1); ft->tx_assoc = tx_assoc; - ft->tx_auth = tx_auth; ft->hs = hs; ft->user_data = user_data; - ft->ap.rx_authenticate = ft_rx_action; ft->ap.rx_associate = ft_rx_associate; - ft->ap.start = ft_start; + ft->ap.start = ft_over_ds_start; ft->ap.free = ft_sm_free;return &ft->ap;
src/ft.h +0 -1
@@ -57,7 +57,6 @@ struct auth_proto *ft_over_air_sm_new(struct handshake_state *hs, void *user_data);struct auth_proto *ft_over_ds_sm_new (struct handshake_state *hs, -ft_tx_authenticate_func_t tx_auth,ft_tx_associate_func_t tx_assoc,void *user_data);
src/netdev.c +168 -43
296 lines not on this page · raw message
src/netdev.h +8 -0
@@ -125,6 +125,10 @@ typedef void (*netdev_get_station_cb_t)(const char *netdev_iftype_to_string (uint32_t iftype); +typedef void (*netdev_ft_over_ds_cb_t )(struct netdev *netdev, +uint16_t status,const uint8_t *bssid, +void *user_data); +struct wiphy *netdev_get_wiphy (struct netdev *netdev);const uint8_t *netdev_get_address (struct netdev *netdev);uint32_t netdev_get_ifindex (struct netdev *netdev);
@@ -158,6 +162,10 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss, netdev_connect_cb_t cb, void *user_data);int netdev_fast_transition (struct netdev *netdev,struct scan_bss *target_bss,netdev_connect_cb_t cb); +int netdev_fast_transition_over_ds_action (struct netdev *netdev, +const struct scan_bss *target_bss, +netdev_ft_over_ds_cb_t cb, +void *user_data);int netdev_fast_transition_over_ds (struct netdev *netdev,struct scan_bss *target_bss,netdev_connect_cb_t cb);
Signature · 1 line
2.26.2
PATCH v5 2/3 station: separate FT-over-DS stages
FT-over-DS was refactored to separate the FT action frame and reassociation. From stations standpoint IWD needs to call netdev_fast_transition_over_ds_action prior to actually roaming. For now these two stages are being combined and the action roam happens immediately after the action response callback.
--- src/station.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-)
v5:
* Fixed up comment
src/station.c +53 -4
@@ -113,6 +113,7 @@ struct station { bool ap_directed_roaming : 1; bool scanning : 1; bool autoconnect : 1; + bool ft_over_ds : 1; };struct anqp_entry {
@@ -1587,10 +1588,18 @@ static void station_roam_failed(struct station *station)l_debug ("%u" ,netdev_get_ifindex (station->netdev));/* -* If we attempted a reassociation or a fast transition, and ended up -* here then we are now disconnected. +* If we attempted a reassociation or a fast transition and ended up +* here then we are now disconnected. This is special cased here to +* handle the action frame portion of FT-over-DS which can fail without +* resulting in a full disconnection as it has not yet commited to +* Auth/Assoc yet. */ if (station->state ==STATION_STATE_ROAMING ) { +if (station->ft_over_ds) { +station_enter_state (station,STATION_STATE_CONNECTED ); + goto delayed_retry; + } +station_disassociated (station);return ; }
@@ -1628,6 +1637,7 @@ delayed_retry: station->preparing_roam = false; station->roam_scan_full = false; station->ap_directed_roaming = false; + station->ft_over_ds = false;if (station->signal_low)station_roam_timeout_rearm (station, roam_retry_interval);
@@ -1713,6 +1723,41 @@ static bool bss_match_bssid(const void *a, const void *b)return !memcmp (bss->addr, bssid,sizeof (bss->addr)); } +static void station_fast_transition_ds_cb (struct netdev *netdev, +uint16_t status,const uint8_t *bssid, +void *user_data) +{ +struct station *station = user_data; +struct scan_bss *bss; + +if (status !=0 ) + goto failed; + +/* +* TODO: In the future it may be desired to start sending out these +* FT-over-DS action frames at the time of connecting then be able to +* roam immediately when required. If this is being done we can simply +* bail out now as ft already caches the entires. But since this was +* initiated due to a need to roam, do so now. +*/ + +/* Make sure we still have our BSS */ + bss =l_queue_find (station->bss_list, bss_match_bssid, bssid); +if (!bss) + goto failed; + +l_debug ("Starting FT-over-DS roam" ); + +if (netdev_fast_transition_over_ds (station->netdev, bss, + station_fast_transition_cb) <0 ) + goto failed; + +return ; + +failed: +station_roam_failed (station); +} +static void station_preauthenticate_cb (struct netdev *netdev,enum netdev_result result,const uint8_t *pmk,void *user_data)
@@ -1810,8 +1855,12 @@ static void station_transition_start(struct station *station,/* FT-over-DS can be better suited for these situations */ if ((hs->mde[4 ] &1 ) && (station->ap_directed_roaming || station->signal_low)) { -if (netdev_fast_transition_over_ds (station->netdev, bss, - station_fast_transition_cb) <0 ) { + station->ft_over_ds = true; + +if (netdev_fast_transition_over_ds_action ( + station->netdev, bss, + station_fast_transition_ds_cb, + station) <0 ) {station_roam_failed (station);return ; }
Signature · 1 line
2.26.2
Re: [PATCH v5 2/3] station: separate FT-over-DS stages
Hi James,
Quoted 30 lines · James Prestwood
FT-over-DS was refactored to separate the FT action frame and reassociation. From stations standpoint IWD needs to call
netdev_fast_transition_over_ds_actionprior to actually roaming. For now these two stages are being combined and the action roam happens immediately after the action response callback.--- src/station.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-)v5:
* Fixed up commentsrc/station.c +1
-2@@ -113,6 +113,7 @@ struct station { bool ap_directed_roaming : 1; bool scanning : 1; bool autoconnect : 1; + bool ft_over_ds : 1; };struct anqp_entry {@@ -1587,10 +1588,18 @@ static void station_roam_failed(struct station *station)l_debug ("%u" ,netdev_get_ifindex (station->netdev));/* -* If we attempted a reassociation or a fast transition, and ended up -* here then we are now disconnected.
src/station.c static void station_roam_failed(struct station *station) · line 1600
Quoted 10 lines
src/station.c +8
-0+* If we attempted a reassociation or a fast transition and ended up +* here then we are now disconnected. This is special cased here to +* handle the action frame portion of FT-over-DS which can fail without +* resulting in a full disconnection as it has not yet commited to +* Auth/Assoc yet. */ if (station->state ==STATION_STATE_ROAMING ) { +if (station->ft_over_ds) { +station_enter_state (station,STATION_STATE_CONNECTED ); + goto delayed_retry;
Why not just introduce station_roam_retry()
src/station.c delayed_retry: · line 1640
Quoted 10 lines
src/station.c +3
-0+ } +station_disassociated (station);return ; }@@ -1628,6 +1637,7 @@ delayed_retry: station->preparing_roam = false; station->roam_scan_full = false; station->ap_directed_roaming = false; + station->ft_over_ds = false;
so as to avoid this book-keeping variable entirely.
Quoted 6 lines
src/station.c +0
-0if (station->signal_low)station_roam_timeout_rearm (station, roam_retry_interval);@@ -1713,6 +1723,41 @@ static bool bss_match_bssid(const void *a, const void *b)return !memcmp (bss->addr, bssid,sizeof (bss->addr)); }
src/station.c static bool bss_match_bssid(const void *a, const void *b) · line 1734
Quoted 10 lines
src/station.c +9
-0+static void station_fast_transition_ds_cb (struct netdev *netdev, +uint16_t status,const uint8_t *bssid, +void *user_data) +{ +struct station *station = user_data; +struct scan_bss *bss; + +if (status !=0 ) + goto failed;
The question is really whether we should go straight into FT-over-Air instead at this point or disable FT-over-DS for the next attempt. But we can handle this later.
Quoted 14 lines
src/station.c +14
-0+ +/* +* TODO: In the future it may be desired to start sending out these +* FT-over-DS action frames at the time of connecting then be able to +* roam immediately when required. If this is being done we can simply +* bail out now as ft already caches the entires. But since this was +* initiated due to a need to roam, do so now. +*/ + +/* Make sure we still have our BSS */ + bss =l_queue_find (station->bss_list, bss_match_bssid, bssid); +if (!bss) + goto failed; +
src/station.c static bool bss_match_bssid(const void *a, const void *b) · line 1758
Quoted 10 lines
src/station.c +10
-0+l_debug ("Starting FT-over-DS roam" ); + +if (netdev_fast_transition_over_ds (station->netdev, bss, + station_fast_transition_cb) <0 ) + goto failed; + +return ; + +failed: +station_roam_failed (station);
and then just call station_roam_retry() here instead?
src/station.c static void station_transition_start(struct station *station, · line 1858
Quoted 12 lines
src/station.c +3
-2+} +static void station_preauthenticate_cb (struct netdev *netdev,enum netdev_result result,const uint8_t *pmk,void *user_data)@@ -1810,8 +1855,12 @@ static void station_transition_start(struct station *station,/* FT-over-DS can be better suited for these situations */ if ((hs->mde[4 ] &1 ) && (station->ap_directed_roaming || station->signal_low)) { -if (netdev_fast_transition_over_ds (station->netdev, bss, - station_fast_transition_cb) <0 ) { + station->ft_over_ds = true;
also, in theory you can avoid entering the ROAMING state until after the Action phase has succeeded successfully...
src/station.c static void station_transition_start(struct station *station, · line 1866
Quoted 9 lines
src/station.c +5
-0+ +if (netdev_fast_transition_over_ds_action ( + station->netdev, bss, + station_fast_transition_ds_cb, + station) <0 ) {station_roam_failed (station);return ; }
Regards,
-Denis
PATCH v5 3/3 ft: netdev: add return value to tx_associate
In reply to James PrestwoodPrior to this, an error sending the FT Reassociation was treated as fatal, which is correct for FT-over-Air but not for FT-over-DS. If the actual l_genl_family_send call fails for FT-over-DS the existing connection can be maintained and there is no need to call netdev_connect_failed.
Adding a return to the tx_associate function works for both FT types. In the FT-over-Air case this return will ultimately get sent back up to auth_proto_rx_authenticate in which case will call netdev_connect_failed. For FT-over-DS tx_associate is actually called from the 'start' operation which can fail and still maintain the existing connection.
--- src/ft.c | 4 +--- src/ft.h | 2 +- src/netdev.c | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-)
src/ft.c +1 -3
@@ -287,9 +287,7 @@ static int ft_tx_reassociate(struct ft_sm *ft) iov_elems +=1 ; } - ft->tx_assoc (iov, iov_elems, ft->user_data); - -return 0 ; +return ft->tx_assoc (iov, iov_elems, ft->user_data); error:return -EINVAL ;
src/ft.h +1 -1
@@ -24,7 +24,7 @@ struct handshake_state;typedef void (*ft_tx_authenticate_func_t )(struct iovec *iov,size_t iov_len,void *user_data); -typedef void (*ft_tx_associate_func_t )(struct iovec *ie_iov,size_t iov_len, +typedef int (*ft_tx_associate_func_t )(struct iovec *ie_iov,size_t iov_len,void *user_data);typedef void (*ft_ds_free_func_t )(void *user_data);
src/netdev.c +4 -4
@@ -3651,7 +3651,7 @@ restore_snonce: MMPDU_STATUS_CODE_UNSPECIFIED); } -static void netdev_ft_tx_associate (struct iovec *ie_iov,size_t iov_len, +static int netdev_ft_tx_associate (struct iovec *ie_iov,size_t iov_len,void *user_data) {struct netdev *netdev = user_data;
@@ -3669,9 +3669,7 @@ static void netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,if (!netdev->connect_cmd_id) {l_genl_msg_unref (msg); -netdev_connect_failed (netdev,NETDEV_RESULT_ASSOCIATION_FAILED , -MMPDU_STATUS_CODE_UNSPECIFIED ); -return ; +return -EIO ; }/* No need to keep this around at this point */
@@ -3679,6 +3677,8 @@ static void netdev_ft_tx_associate(struct iovec *ie_iov, size_t iov_len,ft_ds_info_free (&netdev->ft_ds_info->super); netdev->ft_ds_info =NULL ; } + +return 0 ; }static void prepare_ft (struct netdev *netdev,struct scan_bss *target_bss)
Signature · 1 line
2.26.2