wiphy: Add wiphy_get_supported_rates
PATCH 1/16 wiphy: Add wiphy_get_supported_rates
Add code to parse the supported data rates info from the wiphy dumps and expose it for P2P's use with a getter function.
--- src/wiphy.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/wiphy.h | 2 ++ 2 files changed, 82 insertions(+), 4 deletions(-)
src/wiphy.c +80 -4
@@ -76,6 +76,7 @@ struct wiphy {struct watchlist state_watches;uint8_t extended_capabilities[EXT_CAP_LEN +2 ];/* max bitmap size + IE header */ uint8_t *iftype_extended_capabilities[NUM_NL80211_IFTYPES ]; +uint8_t *supported_rates[NUM_NL80211_BANDS ];uint8_t rm_enabled_capabilities[7 ];/* 5 size max + header */ bool support_scheduled_scan:1;
@@ -212,6 +213,9 @@ static void wiphy_free(void *data)for (i =0 ; i <NUM_NL80211_IFTYPES ; i++)l_free (wiphy->iftype_extended_capabilities[i]); +for (i =0 ; i <NUM_NL80211_BANDS ; i++) +l_free (wiphy->supported_rates[i]); +scan_freq_set_free (wiphy->supported_freqs);watchlist_destroy (&wiphy->state_watches);l_free (wiphy->model_str);
@@ -478,6 +482,20 @@ bool wiphy_supports_iftype(struct wiphy *wiphy, uint32_t iftype)return wiphy->supported_iftypes & (1 << (iftype -1 )); } +const uint8_t *wiphy_get_supported_rates (struct wiphy *wiphy,unsigned int band, +unsigned int *out_num) +{ +if (band >=L_ARRAY_SIZE (wiphy->supported_rates)) +return NULL ; + +if (out_num) + *out_num = + (uint8_t *)rawmemchr (wiphy->supported_rates[band],0 ) - + wiphy->supported_rates[band]; + +return wiphy->supported_rates[band]; +} +uint32_t wiphy_state_watch_add (struct wiphy *wiphy,wiphy_state_watch_func_t func,void *user_data,wiphy_destroy_func_t destroy)
@@ -622,20 +640,70 @@ static void parse_supported_frequencies(struct wiphy *wiphy, } } +static uint8_t *parse_supported_rates (struct l_genl_attr *attr) +{ +uint16_t type; +uint16_t len; +const void *data; +struct l_genl_attr nested; +int count =0 ; +uint8_t *ret; + +if (!l_genl_attr_recurse (attr, &nested)) +return NULL ; + +while (l_genl_attr_next (&nested,NULL ,NULL ,NULL )) + count++; + +if (!l_genl_attr_recurse (attr, &nested)) +return NULL ; + + ret =l_malloc (count +1 ); + ret[count] =0 ; + + count =0 ; + +while (l_genl_attr_next (&nested,NULL ,NULL ,NULL )) { +struct l_genl_attr nested2; + +if (!l_genl_attr_recurse (&nested, &nested2)) { +l_free (ret); +return NULL ; + } + +while (l_genl_attr_next (&nested2, &type, &len, &data)) { +if (type !=NL80211_BITRATE_ATTR_RATE || len !=4 ) +continue ; + +/* +* Convert from the 100kb/s units reported by the +* kernel to the 500kb/s used in 802.11 IEs. +*/ + ret[count++] = *(const uint32_t *) data /5 ; + } + } + +return ret; +} +static void parse_supported_bands (struct wiphy *wiphy,struct l_genl_attr *bands) { -uint16_t type, len; -const void *data; +uint16_t type;struct l_genl_attr attr;l_debug ("" ); -while (l_genl_attr_next (bands,NULL ,NULL ,NULL )) { +while (l_genl_attr_next (bands, &type,NULL ,NULL )) { +enum nl80211_band band = type; + +if (band !=NL80211_BAND_2GHZ && band !=NL80211_BAND_5GHZ ) +continue ; +if (!l_genl_attr_recurse (bands, &attr))continue ; -while (l_genl_attr_next (&attr, &type, &len, &data)) { +while (l_genl_attr_next (&attr, &type,NULL ,NULL )) {struct l_genl_attr freqs;switch (type) {
@@ -645,6 +713,14 @@ static void parse_supported_bands(struct wiphy *wiphy,parse_supported_frequencies (wiphy, &freqs);break ; + +case NL80211_BAND_ATTR_RATES : +if (wiphy->supported_rates[band]) +continue ; + + wiphy->supported_rates[band] = +parse_supported_rates (&attr); +break ; } } }
src/wiphy.h +2 -0
@@ -66,6 +66,8 @@ bool wiphy_has_ext_feature(struct wiphy *wiphy, uint32_t feature);uint8_t wiphy_get_max_num_ssids_per_scan (struct wiphy *wiphy);uint32_t wiphy_get_max_roc_duration (struct wiphy *wiphy);bool wiphy_supports_iftype (struct wiphy *wiphy,uint32_t iftype); +const uint8_t *wiphy_get_supported_rates (struct wiphy *wiphy,unsigned int band, +unsigned int *out_num);bool wiphy_supports_adhoc_rsn (struct wiphy *wiphy);bool wiphy_can_offchannel_tx (struct wiphy *wiphy);bool wiphy_supports_qos_set_map (struct wiphy *wiphy);
Signature · 1 line
2.20.1
PATCH 2/16 scan: Hide CCK rates if no_cck_rates set
no_cck_rates is set in the scan parameters generally to make sure that the Probe Request frames are not sent at any of the 802.11b rates during active scans. With this patch we also omit those rates from the Supported Rates IEs, which is required by the p2p spec and also matches our flag's name.
--- src/scan.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
src/scan.c +34 -1
@@ -347,10 +347,43 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,if (flags)l_genl_msg_append_attr (msg,NL80211_ATTR_SCAN_FLAGS ,4 , &flags); -if (params->no_cck_rates) +if (params->no_cck_rates) { +static const uint8_t b_rates[] = {2 ,4 ,11 ,22 }; +uint8_t *scan_rates; +const uint8_t *supported; +unsigned int num_supported; +unsigned int count; +l_genl_msg_append_attr (msg,NL80211_ATTR_TX_NO_CCK_RATE ,0 ,NULL ); +/* +* Assume if we're sending the probe requests at OFDM bit +* rates we don't want to advertise support for 802.11b rates. +*/ + supported =wiphy_get_supported_rates (sc->wiphy, +NL80211_BAND_2GHZ , + &num_supported); +if (!supported) { +L_WARN_ON (true); +return msg; + } + + scan_rates =l_malloc (num_supported); + +for (count =0 ; *supported; supported++) +if (!memchr (b_rates, *supported,L_ARRAY_SIZE (b_rates))) + scan_rates[count++] = *supported; + +L_WARN_ON (!count); + +l_genl_msg_enter_nested (msg,NL80211_ATTR_SCAN_SUPP_RATES ); +l_genl_msg_append_attr (msg,NL80211_BAND_2GHZ , count, + scan_rates); +l_genl_msg_leave_nested (msg); +l_free (scan_rates); + } +return msg; }
Signature · 1 line
2.20.1
Re: [PATCH 02/16] scan: Hide CCK rates if no_cck_rates set
Hi Andrew,
Quoted 27 lines · Andrew Zaborowski
no_cck_ratesis set in the scan parameters generally to make sure that the Probe Request frames are not sent at any of the 802.11b rates during active scans. With this patch we also omit those rates from the Supported Rates IEs, which is required by the p2p spec and also matches our flag's name.--- src/scan.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)src/scan.c +7
-1@@ -347,10 +347,43 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,if (flags)l_genl_msg_append_attr (msg,NL80211_ATTR_SCAN_FLAGS ,4 , &flags); -if (params->no_cck_rates) +if (params->no_cck_rates) { +static const uint8_t b_rates[] = {2 ,4 ,11 ,22 }; +uint8_t *scan_rates; +const uint8_t *supported; +unsigned int num_supported; +unsigned int count; +l_genl_msg_append_attr (msg,NL80211_ATTR_TX_NO_CCK_RATE ,0 ,NULL );
src/scan.c static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, · line 368
Quoted 10 lines
src/scan.c +9
-0+/* +* Assume if we're sending the probe requests at OFDM bit +* rates we don't want to advertise support for 802.11b rates. +*/ + supported =wiphy_get_supported_rates (sc->wiphy, +NL80211_BAND_2GHZ , + &num_supported); +if (!supported) { +L_WARN_ON (true);
So I will nag you not to do this, its just not very useful. You really want the warning to convey as much info as possible. Getting a message like "Warning: condition true failed" is pretty useless.
Also, L_WARN_ON can be used in an if statement, FYI.
Quoted 5 lines
src/scan.c +5
-0+return msg; + } + + scan_rates =l_malloc (num_supported); +
src/scan.c static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, · line 383
Quoted 10 lines
src/scan.c +10
-0+for (count =0 ; *supported; supported++) +if (!memchr (b_rates, *supported,L_ARRAY_SIZE (b_rates))) + scan_rates[count++] = *supported; + +L_WARN_ON (!count); + +l_genl_msg_enter_nested (msg,NL80211_ATTR_SCAN_SUPP_RATES ); +l_genl_msg_append_attr (msg,NL80211_BAND_2GHZ , count, + scan_rates); +l_genl_msg_leave_nested (msg);
Why are we bothering to send an empty attribute?
src/scan.c static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, · line 389
Quoted 7 lines
src/scan.c +3
-0+l_free (scan_rates); + } +return msg; }
Anyhow, I made some mods to this commit and pushed it out. Please review.
Regards,
-Denis
Re: [PATCH 02/16] scan: Hide CCK rates if no_cck_rates set
Hi Denis,
Quoted 43 lines · Denis Kenzior
Quoted 27 lines · Andrew Zaborowski
no_cck_ratesis set in the scan parameters generally to make sure that the Probe Request frames are not sent at any of the 802.11b rates during active scans. With this patch we also omit those rates from the Supported Rates IEs, which is required by the p2p spec and also matches our flag's name.--- src/scan.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)src/scan.c +7
-1@@ -347,10 +347,43 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,if (flags)l_genl_msg_append_attr (msg,NL80211_ATTR_SCAN_FLAGS ,4 , &flags); -if (params->no_cck_rates) +if (params->no_cck_rates) { +static const uint8_t b_rates[] = {2 ,4 ,11 ,22 }; +uint8_t *scan_rates; +const uint8_t *supported; +unsigned int num_supported; +unsigned int count; +l_genl_msg_append_attr (msg,NL80211_ATTR_TX_NO_CCK_RATE ,0 ,NULL );src/scan.c static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, · line 368
Quoted 10 lines
src/scan.c +9
-0+/* +* Assume if we're sending the probe requests at OFDM bit +* rates we don't want to advertise support for 802.11b rates. +*/ + supported =wiphy_get_supported_rates (sc->wiphy, +NL80211_BAND_2GHZ , + &num_supported); +if (!supported) { +L_WARN_ON (true);So I will nag you not to do this, its just not very useful. You really want the warning to convey as much info as possible. Getting a message like "Warning: condition true failed" is pretty useless.
Quoted 1 line
Also,
L_WARN_ONcan be used in an if statement, FYI.
Ok, that should also work. In the end you'll need to look at the stack trace though.
Quoted 10 lines
Quoted 10 lines
src/scan.c +9
-0+return msg; + } + + scan_rates =l_malloc (num_supported); + +for (count =0 ; *supported; supported++) +if (!memchr (b_rates, *supported,L_ARRAY_SIZE (b_rates))) + scan_rates[count++] = *supported; +
Quoted 8 lines
src/scan.c static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, · line 383
Quoted 6 lines
src/scan.c +6
-0+L_WARN_ON (!count); + +l_genl_msg_enter_nested (msg,NL80211_ATTR_SCAN_SUPP_RATES ); +l_genl_msg_append_attr (msg,NL80211_BAND_2GHZ , count, + scan_rates); +l_genl_msg_leave_nested (msg);Why are we bothering to send an empty attribute?
We aren't except if something's broken in our code.
Quoted 10 lines
src/scan.c static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, · line 389
Quoted 8 lines
src/scan.c +3
-0+l_free (scan_rates); + } +return msg; }Anyhow, I made some mods to this commit and pushed it out. Please review.
Thanks, this new version should also work.
Best regards
PATCH 3/16 scan: Parse P2P IEs according to frame type
In reply to Andrew ZaborowskiSave the source frame type in struct scan_bss as it may affect how some of the data in the struct should be parsed. Also replace the P2P IE payload data in that struct with a union containing pre-parsed p2p attributes corresponding to the frame type.
This means users don't have to call the parsers in p2putil.c on that data, which wouldn't have worked anyway because we those parsers were assuming the raw concatenated P2P IEs as a parameter instead of the payload extracted with ie_tlv_extract_p2p_payload.
--- src/scan.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++------- src/scan.h | 17 ++++++++++-- 2 files changed, 84 insertions(+), 12 deletions(-)
src/scan.c +69 -10
@@ -45,6 +45,7 @@#include "src/nl80211cmd.h" #include "src/nl80211util.h" #include "src/util.h" +#include "src/p2putil.h" #include "src/scan.h" #define SCAN_MAX_INTERVAL 320
@@ -987,6 +988,38 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, } } + bss->wsc =ie_tlv_extract_wsc_payload (data, len, &bss->wsc_size); + +switch (bss->source_frame) { +case SCAN_BSS_PROBE_RESP : + { +struct p2p_probe_resp info; + +if (p2p_parse_probe_resp (data, len, &info) ==0 ) + bss->p2p_probe_resp_info =l_memdup (&info,sizeof (info)); + +break ; + } +case SCAN_BSS_PROBE_REQ : + { +struct p2p_probe_req info; + +if (p2p_parse_probe_req (data, len, &info) ==0 ) + bss->p2p_probe_req_info =l_memdup (&info,sizeof (info)); + +break ; + } +case SCAN_BSS_BEACON : + { +struct p2p_beacon info; + +if (p2p_parse_beacon (data, len, &info) ==0 ) + bss->p2p_beacon_info =l_memdup (&info,sizeof (info)); + +break ; + } + } +return have_ssid; }
@@ -995,9 +1028,12 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr)uint16_t type, len;const void *data;struct scan_bss *bss; +const uint8_t *ies =NULL ; +size_t ies_len; bss = l_new(struct scan_bss, 1); bss->utilization =127 ; + bss->source_frame =SCAN_BSS_BEACON ;while (l_genl_attr_next (attr, &type, &len, &data)) {switch (type) {
@@ -1025,20 +1061,19 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr) bss->signal_strength = *((int32_t *) data);break ; +case NL80211_BSS_PRESP_DATA : + bss->source_frame =SCAN_BSS_PROBE_RESP ; +break ;case NL80211_BSS_INFORMATION_ELEMENTS : -if (!scan_parse_bss_information_elements (bss, - data, len)) - goto fail; - - bss->wsc =ie_tlv_extract_wsc_payload (data, len, - &bss->wsc_size); - bss->p2p =ie_tlv_extract_p2p_payload (data, len, - &bss->p2p_size); - + ies = data; + ies_len = len;break ; } } +if (ies && !scan_parse_bss_information_elements (bss, ies, ies_len)) + goto fail; +return bss; fail:
@@ -1198,9 +1233,33 @@ void scan_bss_free(struct scan_bss *bss)l_free (bss->rsne);l_free (bss->wpa);l_free (bss->wsc); -l_free (bss->p2p);l_free (bss->osen);l_free (bss->rc_ie); + +switch (bss->source_frame) { +case SCAN_BSS_PROBE_RESP : +if (!bss->p2p_probe_resp_info) +break ; + +p2p_free_probe_resp (bss->p2p_probe_resp_info); +l_free (bss->p2p_probe_resp_info); +break ; +case SCAN_BSS_PROBE_REQ : +if (!bss->p2p_probe_req_info) +break ; + +p2p_free_probe_req (bss->p2p_probe_req_info); +l_free (bss->p2p_probe_req_info); +break ; +case SCAN_BSS_BEACON : +if (!bss->p2p_beacon_info) +break ; + +p2p_free_beacon (bss->p2p_beacon_info); +l_free (bss->p2p_beacon_info); +break ; + } +l_free (bss); }
src/scan.h +15 -2
@@ -40,6 +40,15 @@ typedef void (*scan_freq_set_func_t)(uint32_t freq, void *userdata);struct scan_freq_set ;struct ie_rsn_info ; +struct p2p_probe_resp ; +struct p2p_probe_req ; +struct p2p_beacon ; + +enum scan_bss_frame_type { +SCAN_BSS_PROBE_RESP , +SCAN_BSS_PROBE_REQ , +SCAN_BSS_BEACON , +};struct scan_bss {uint8_t addr[6 ];
@@ -51,8 +60,12 @@ struct scan_bss {uint8_t *osen;uint8_t *wsc;/* Concatenated WSC IEs */ ssize_t wsc_size;/* Size of Concatenated WSC IEs */ -uint8_t *p2p;/* Concatenated P2P IEs */ -ssize_t p2p_size;/* Size of Concatenated P2P IEs */ +enum scan_bss_frame_type source_frame; +union { +struct p2p_probe_resp *p2p_probe_resp_info; +struct p2p_probe_req *p2p_probe_req_info; +struct p2p_beacon *p2p_beacon_info; + };uint8_t mde[3 ];uint8_t ssid[32 ];uint8_t ssid_len;
Signature · 1 line
2.20.1
Re: [PATCH 03/16] scan: Parse P2P IEs according to frame type
Hi Andrew,
Quoted 7 lines · Andrew Zaborowski
Save the source frame type in struct
scan_bssas it may affect how some of the data in the struct should be parsed. Also replace the P2P IE payload data in that struct with a union containing pre-parsed p2p attributes corresponding to the frame type.This means users don't have to call the parsers in
p2putil.con that data, which wouldn't have worked anyway because we those parsers were
This sentence doesn't parse
Quoted 22 lines
assuming the raw concatenated P2P IEs as a parameter instead of the payload extracted with
ie_tlv_extract_p2p_payload.--- src/scan.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++------- src/scan.h | 17 ++++++++++-- 2 files changed, 84 insertions(+), 12 deletions(-)src/scan.c +1
-0@@ -45,6 +45,7 @@#include "src/nl80211cmd.h" #include "src/nl80211util.h" #include "src/util.h" +#include "src/p2putil.h" #include "src/scan.h" #define SCAN_MAX_INTERVAL 320@@ -987,6 +988,38 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, } }
src/scan.c static bool scan_parse_bss_information_elements(struct scan_bss *bss, · line 999
Quoted 10 lines
src/scan.c +9
-0+ bss->wsc =ie_tlv_extract_wsc_payload (data, len, &bss->wsc_size); + +switch (bss->source_frame) { +case SCAN_BSS_PROBE_RESP : + { +struct p2p_probe_resp info; + +if (p2p_parse_probe_resp (data, len, &info) ==0 ) + bss->p2p_probe_resp_info =l_memdup (&info,sizeof (info));
So I don't like this l_memdup at all. There has to be a better way.
Also, how is it that you're passing data and len directly to p2p_parse_probe_resp? Are these not wrapped in IEs somehow?
src/scan.c static bool scan_parse_bss_information_elements(struct scan_bss *bss, · line 1003
Quoted 4 lines
src/scan.c +4
-0+ +break ; + } +case SCAN_BSS_PROBE_REQ :
How do you even get here? And why should scan.c even care? I think you're hacking stuff together here. I doubt this belongs on the scan API at all.
Quoted 23 lines
src/scan.c +19
-0+ { +struct p2p_probe_req info; + +if (p2p_parse_probe_req (data, len, &info) ==0 ) + bss->p2p_probe_req_info =l_memdup (&info,sizeof (info)); + +break ; + } +case SCAN_BSS_BEACON : + { +struct p2p_beacon info; + +if (p2p_parse_beacon (data, len, &info) ==0 ) + bss->p2p_beacon_info =l_memdup (&info,sizeof (info)); + +break ; + } + } +return have_ssid; }
src/scan.c static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr) · line 1036
Quoted 9 lines
src/scan.c +3
-0@@ -995,9 +1028,12 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr)uint16_t type, len;const void *data;struct scan_bss *bss; +const uint8_t *ies =NULL ; +size_t ies_len; bss = l_new(struct scan_bss, 1); bss->utilization =127 ; + bss->source_frame =SCAN_BSS_BEACON ;
So I don't think it is that simple. Looks like the kernel guys really made a mess here. We need to be looking at NL80211_BSS_BEACON_IES as well and applying 'heuristics' if the PRESP_DATA attribute isn't present.
Quoted 44 lines
src/scan.c +13
-10while (l_genl_attr_next (attr, &type, &len, &data)) {switch (type) {@@ -1025,20 +1061,19 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr) bss->signal_strength = *((int32_t *) data);break ; +case NL80211_BSS_PRESP_DATA : + bss->source_frame =SCAN_BSS_PROBE_RESP ; +break ;case NL80211_BSS_INFORMATION_ELEMENTS : -if (!scan_parse_bss_information_elements (bss, - data, len)) - goto fail; - - bss->wsc =ie_tlv_extract_wsc_payload (data, len, - &bss->wsc_size); - bss->p2p =ie_tlv_extract_p2p_payload (data, len, - &bss->p2p_size); - + ies = data; + ies_len = len;break ; } } +if (ies && !scan_parse_bss_information_elements (bss, ies, ies_len)) + goto fail; +return bss; fail:@@ -1198,9 +1233,33 @@ void scan_bss_free(struct scan_bss *bss)l_free (bss->rsne);l_free (bss->wpa);l_free (bss->wsc); -l_free (bss->p2p);l_free (bss->osen);l_free (bss->rc_ie); + +switch (bss->source_frame) { +case SCAN_BSS_PROBE_RESP : +if (!bss->p2p_probe_resp_info) +break ;
src/scan.c void scan_bss_free(struct scan_bss *bss) · line 1252
Quoted 10 lines
src/scan.c +10
-0+ +p2p_free_probe_resp (bss->p2p_probe_resp_info); +l_free (bss->p2p_probe_resp_info); +break ; +case SCAN_BSS_PROBE_REQ : +if (!bss->p2p_probe_req_info) +break ; + +p2p_free_probe_req (bss->p2p_probe_req_info); +l_free (bss->p2p_probe_req_info);
The naming needs some work. Whenever I see _free in the name I assume it calls l_free on the passed in structure. But here you have to free the structure separately. And the _free should really be last per our naming conventions.
Quoted 35 lines
src/scan.c +10
-0+break ; +case SCAN_BSS_BEACON : +if (!bss->p2p_beacon_info) +break ; + +p2p_free_beacon (bss->p2p_beacon_info); +l_free (bss->p2p_beacon_info); +break ; + } +l_free (bss); }src/scan.h +9
-0@@ -40,6 +40,15 @@ typedef void (*scan_freq_set_func_t)(uint32_t freq, void *userdata);struct scan_freq_set ;struct ie_rsn_info ; +struct p2p_probe_resp ; +struct p2p_probe_req ; +struct p2p_beacon ; + +enum scan_bss_frame_type { +SCAN_BSS_PROBE_RESP , +SCAN_BSS_PROBE_REQ , +SCAN_BSS_BEACON , +};struct scan_bss {uint8_t addr[6 ];@@ -51,8 +60,12 @@ struct scan_bss {uint8_t *osen;
src/scan.h struct scan_bss { · line 68
Quoted 10 lines
src/scan.h +6
-2uint8_t *wsc;/* Concatenated WSC IEs */ ssize_t wsc_size;/* Size of Concatenated WSC IEs */ -uint8_t *p2p;/* Concatenated P2P IEs */ -ssize_t p2p_size;/* Size of Concatenated P2P IEs */ +enum scan_bss_frame_type source_frame; +union { +struct p2p_probe_resp *p2p_probe_resp_info; +struct p2p_probe_req *p2p_probe_req_info; +struct p2p_beacon *p2p_beacon_info; + };
a union of 3 pointers is rather pointless, no? :)
src/scan.h struct scan_bss { · line 71
Quoted 4 lines
src/scan.h +0
-0uint8_t mde[3 ];uint8_t ssid[32 ];uint8_t ssid_len;
Regards,
-Denis
Re: [PATCH 03/16] scan: Parse P2P IEs according to frame type
Quoted 10 lines · Denis Kenzior
Quoted 7 lines · Andrew Zaborowski
Save the source frame type in struct
scan_bssas it may affect how some of the data in the struct should be parsed. Also replace the P2P IE payload data in that struct with a union containing pre-parsed p2p attributes corresponding to the frame type.This means users don't have to call the parsers in
p2putil.con that data, which wouldn't have worked anyway because we those parsers wereThis sentence doesn't parse
Oops, will fix.
Quoted 24 lines
Quoted 24 lines
assuming the raw concatenated P2P IEs as a parameter instead of the payload extracted with
ie_tlv_extract_p2p_payload.--- src/scan.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++------- src/scan.h | 17 ++++++++++-- 2 files changed, 84 insertions(+), 12 deletions(-)src/scan.c +1
-0@@ -45,6 +45,7 @@#include "src/nl80211cmd.h" #include "src/nl80211util.h" #include "src/util.h" +#include "src/p2putil.h" #include "src/scan.h" #define SCAN_MAX_INTERVAL 320@@ -987,6 +988,38 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, } }
Quoted 11 lines
src/scan.c static bool scan_parse_bss_information_elements(struct scan_bss *bss, · line 999
Quoted 9 lines
src/scan.c +9
-0+ bss->wsc =ie_tlv_extract_wsc_payload (data, len, &bss->wsc_size); + +switch (bss->source_frame) { +case SCAN_BSS_PROBE_RESP : + { +struct p2p_probe_resp info; + +if (p2p_parse_probe_resp (data, len, &info) ==0 ) + bss->p2p_probe_resp_info =l_memdup (&info,sizeof (info));So I don't like this
l_memdupat all. There has to be a better way.
The other way is to alloc memory at bss->p2p_probe_resp_info and l_free it on error, let me do that instead.
Quoted 3 lines
Also, how is it that you're passing data and len directly to
p2p_parse_probe_resp? Are these not wrapped in IEs somehow?
Yes, but the p2p_parse_* functions expect that wrapped data actually, and will unwrap internally.
Quoted 9 lines
src/scan.c static bool scan_parse_bss_information_elements(struct scan_bss *bss, · line 1003
Quoted 5 lines
src/scan.c +4
-0+ +break ; + } +case SCAN_BSS_PROBE_REQ :How do you even get here? And why should
scan.ceven care? I think you're hacking stuff together here. I doubt this belongs on the scan API at all.
We get here through the scan_bss_new_from_probe_req call I submitted before. This is called from outside of scan.c, in p2p.c, so you could argue it doesn't belong here but actually what p2p.c is doing is technically scanning, too.
There's also so much common code that it would just be annoying to not re-use it... or to have to split it into a separate common file.
Quoted 30 lines
Quoted 30 lines
src/scan.c +21
-0+ { +struct p2p_probe_req info; + +if (p2p_parse_probe_req (data, len, &info) ==0 ) + bss->p2p_probe_req_info =l_memdup (&info,sizeof (info)); + +break ; + } +case SCAN_BSS_BEACON : + { +struct p2p_beacon info; + +if (p2p_parse_beacon (data, len, &info) ==0 ) + bss->p2p_beacon_info =l_memdup (&info,sizeof (info)); + +break ; + } + } +return have_ssid; }@@ -995,9 +1028,12 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr)uint16_t type, len;const void *data;struct scan_bss *bss; +const uint8_t *ies =NULL ; +size_t ies_len;
Quoted 7 lines
src/scan.c static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr) · line 1036
Quoted 3 lines
src/scan.c +1
-0bss = l_new(struct scan_bss, 1); bss->utilization =127 ; + bss->source_frame =SCAN_BSS_BEACON ;So I don't think it is that simple. Looks like the kernel guys really made a mess here. We need to be looking at
NL80211_BSS_BEACON_IESas well and applying 'heuristics' if thePRESP_DATAattribute isn't present.
I'll try to make sure I understand exactly how this works and add an explanation in a comment somewhere.
Quoted 52 lines
Quoted 52 lines
src/scan.c +20
-10while (l_genl_attr_next (attr, &type, &len, &data)) {switch (type) {@@ -1025,20 +1061,19 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr) bss->signal_strength = *((int32_t *) data);break ; +case NL80211_BSS_PRESP_DATA : + bss->source_frame =SCAN_BSS_PROBE_RESP ; +break ;case NL80211_BSS_INFORMATION_ELEMENTS : -if (!scan_parse_bss_information_elements (bss, - data, len)) - goto fail; - - bss->wsc =ie_tlv_extract_wsc_payload (data, len, - &bss->wsc_size); - bss->p2p =ie_tlv_extract_p2p_payload (data, len, - &bss->p2p_size); - + ies = data; + ies_len = len;break ; } } +if (ies && !scan_parse_bss_information_elements (bss, ies, ies_len)) + goto fail; +return bss; fail:@@ -1198,9 +1233,33 @@ void scan_bss_free(struct scan_bss *bss)l_free (bss->rsne);l_free (bss->wpa);l_free (bss->wsc); -l_free (bss->p2p);l_free (bss->osen);l_free (bss->rc_ie); + +switch (bss->source_frame) { +case SCAN_BSS_PROBE_RESP : +if (!bss->p2p_probe_resp_info) +break ; + +p2p_free_probe_resp (bss->p2p_probe_resp_info); +l_free (bss->p2p_probe_resp_info); +break ; +case SCAN_BSS_PROBE_REQ : +if (!bss->p2p_probe_req_info) +break ;
Quoted 8 lines
src/scan.c void scan_bss_free(struct scan_bss *bss) · line 1252
Quoted 3 lines
src/scan.c +3
-0+ +p2p_free_probe_req (bss->p2p_probe_req_info); +l_free (bss->p2p_probe_req_info);The naming needs some work. Whenever I see
_freein the name I assume it callsl_freeon the passed in structure. But here you have to free the structure separately. And the_freeshould really be last per our naming conventions.
How about _clear_? I'd rather keep it in the middle of the name to be consistent with the _parse_ and _build_ function names, but I'll move it to the end if you really prefer.
Quoted 32 lines
Quoted 32 lines
src/scan.c +10
-0+break ; +case SCAN_BSS_BEACON : +if (!bss->p2p_beacon_info) +break ; + +p2p_free_beacon (bss->p2p_beacon_info); +l_free (bss->p2p_beacon_info); +break ; + } +l_free (bss); }src/scan.h +9
-0@@ -40,6 +40,15 @@ typedef void (*scan_freq_set_func_t)(uint32_t freq, void *userdata);struct scan_freq_set ;struct ie_rsn_info ; +struct p2p_probe_resp ; +struct p2p_probe_req ; +struct p2p_beacon ; + +enum scan_bss_frame_type { +SCAN_BSS_PROBE_RESP , +SCAN_BSS_PROBE_REQ , +SCAN_BSS_BEACON , +};
Quoted 16 lines
Quoted 4 lines
src/scan.h +0
-0struct scan_bss {uint8_t addr[6 ];@@ -51,8 +60,12 @@ struct scan_bss {uint8_t *osen;src/scan.h struct scan_bss { · line 68
Quoted 10 lines
src/scan.h +6
-2uint8_t *wsc;/* Concatenated WSC IEs */ ssize_t wsc_size;/* Size of Concatenated WSC IEs */ -uint8_t *p2p;/* Concatenated P2P IEs */ -ssize_t p2p_size;/* Size of Concatenated P2P IEs */ +enum scan_bss_frame_type source_frame; +union { +struct p2p_probe_resp *p2p_probe_resp_info; +struct p2p_probe_req *p2p_probe_req_info; +struct p2p_beacon *p2p_beacon_info; + };a union of 3 pointers is rather pointless, no? :)
Only if you think non-void pointers are pointless ;) But, we could do void * if you want.
Best regards
PATCH 4/16 scan: Add scan_bss_new_from_probe_req
In reply to Andrew Zaborowski--- src/scan.c | 27 +++++++++++++++++++++++++++ src/scan.h | 6 ++++++ 2 files changed, 33 insertions(+)
src/scan.c +27 -0
@@ -46,6 +46,7 @@#include "src/nl80211util.h" #include "src/util.h" #include "src/p2putil.h" +#include "src/mpdu.h" #include "src/scan.h" #define SCAN_MAX_INTERVAL 320
@@ -1227,6 +1228,32 @@ static void scan_bss_compute_rank(struct scan_bss *bss) bss->rank = irank; } +struct scan_bss *scan_bss_new_from_probe_req (const struct mmpdu_header *mpdu, +const uint8_t *body, +size_t body_len, +uint32_t frequency,int rssi) + +{ +struct scan_bss *bss; + + bss = l_new(struct scan_bss, 1); +memcpy (bss->addr, mpdu->address_2,6 ); + bss->utilization =127 ; + bss->source_frame =SCAN_BSS_PROBE_REQ ; + bss->frequency = frequency; + bss->signal_strength = rssi; + +if (!scan_parse_bss_information_elements (bss, body, body_len)) + goto fail; + +scan_bss_compute_rank (bss); +return bss; + +fail: +scan_bss_free (bss); +return NULL ; +} +void scan_bss_free (struct scan_bss *bss) {l_free (bss->ext_supp_rates_ie);
src/scan.h +6 -0
@@ -43,6 +43,7 @@ struct ie_rsn_info;struct p2p_probe_resp ;struct p2p_probe_req ;struct p2p_beacon ; +struct mmpdu_header ;enum scan_bss_frame_type {SCAN_BSS_PROBE_RESP ,
@@ -134,6 +135,11 @@ int scan_bss_rank_compare(const void *a, const void *b, void *user);int scan_bss_get_rsn_info (const struct scan_bss *bss,struct ie_rsn_info *info); +struct scan_bss *scan_bss_new_from_probe_req (const struct mmpdu_header *mpdu, +const uint8_t *body, +size_t body_len, +uint32_t frequency,int rssi); +uint8_t scan_freq_to_channel (uint32_t freq,enum scan_band *out_band);uint32_t scan_channel_to_freq (uint8_t channel,enum scan_band band); enum scan_band scan_oper_class_to_band(const uint8_t *country,
Signature · 1 line
2.20.1
PATCH 5/16 handshake: Convert handshake event callbacks variadic functions
In reply to Andrew ZaborowskiConvert the handshake event callback type to use variable argument list to allow for more flexibility in event-specific arguments passed to the callbacks.
--- src/adhoc.c | 2 +- src/ap.c | 9 +++++++-- src/handshake.c | 7 ------- src/handshake.h | 13 +++++++++---- src/station.c | 9 +++++++-- src/wsc.c | 11 +++++++++-- 6 files changed, 33 insertions(+), 18 deletions(-)
src/adhoc.c +1 -1
@@ -159,7 +159,7 @@ static bool ap_sta_match_addr(const void *a, const void *b) }static void adhoc_handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data,void *user_data) +enum handshake_event event,void *user_data, ...) {struct sta_state *sta = user_data;struct adhoc_state *adhoc = sta->adhoc;
src/ap.c +7 -2
@@ -382,16 +382,19 @@ static uint32_t ap_send_mgmt_frame(struct ap_state *ap, }static void ap_handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data,void *user_data) +enum handshake_event event,void *user_data, ...) {struct sta_state *sta = user_data; +va_list args; + +va_start (args, user_data);switch (event) {case HANDSHAKE_EVENT_COMPLETE :ap_new_rsna (sta);break ;case HANDSHAKE_EVENT_FAILED : -netdev_handshake_failed (hs,l_get_u16 (event_data)); + netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *)));/* fall through */ case HANDSHAKE_EVENT_SETTING_KEYS_FAILED : sta->sm =NULL ;
@@ -399,6 +402,8 @@ static void ap_handshake_event(struct handshake_state *hs,default :break ; } + +va_end (args); }static void ap_start_rsna (struct sta_state *sta,const uint8_t *gtk_rsc)
src/handshake.c +0 -7
@@ -912,10 +912,3 @@ bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,return true; } - -void handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data) -{ -if (hs->event_func) - hs->event_func (hs, event, event_data, hs->user_data); -}
src/handshake.h +9 -4
@@ -54,7 +54,7 @@ enum handshake_event {typedef void (*handshake_event_func_t )(struct handshake_state *hs,enum handshake_event event, -void *event_data,void *user_data); +void *user_data, ...);typedef bool (*handshake_get_nonce_func_t )(uint8_t nonce[]); typedef void (*handshake_install_tk_func_t)(struct handshake_state *hs,
@@ -130,6 +130,14 @@ struct handshake_state {handshake_event_func_t event_func; }; +#define handshake_event (hs, event, ...) \ + do { \ + if (!(hs)->event_func) \ + break; \ + \ + (hs)->event_func(hs, event, (hs)->user_data, ##__VA_ARGS__); \ + } while (0) +void handshake_state_free (struct handshake_state *s); void handshake_state_set_supplicant_address(struct handshake_state *s,
@@ -216,6 +224,3 @@ const uint8_t *handshake_util_find_pmkid_kde(const uint8_t *data, size_t data_len);void handshake_util_build_gtk_kde (enum crypto_cipher cipher,const uint8_t *key,unsigned int key_index,uint8_t *to); - -void handshake_event (struct handshake_state *hs,enum handshake_event event, -void *event_data);
src/station.c +7 -2
@@ -650,10 +650,13 @@ static void station_reconnect(struct station *station);static void station_handshake_event (struct handshake_state *hs,enum handshake_event event, -void *event_data,void *user_data) +void *user_data, ...) {struct station *station = user_data;struct network *network = station->connected_network; +va_list args; + +va_start (args, user_data);switch (event) {case HANDSHAKE_EVENT_STARTED :
@@ -666,7 +669,7 @@ static void station_handshake_event(struct handshake_state *hs,network_sync_psk (network);break ;case HANDSHAKE_EVENT_FAILED : -netdev_handshake_failed (hs,l_get_u16 (event_data)); + netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *)));break ;case HANDSHAKE_EVENT_REKEY_FAILED :station_reconnect (station);
@@ -680,6 +683,8 @@ static void station_handshake_event(struct handshake_state *hs,*/ break ; } + +va_end (args); }static bool station_has_erp_identity (struct network *network)
src/wsc.c +9 -2
@@ -402,15 +402,22 @@ static void wsc_netdev_event(struct netdev *netdev, enum netdev_event event, }static void wsc_handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data,void *user_data) +enum handshake_event event,void *user_data, + ...) { +va_list args; + +va_start (args, user_data); +switch (event) {case HANDSHAKE_EVENT_FAILED : -netdev_handshake_failed (hs,l_get_u16 (event_data)); + netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *)));break ;default :break ; } + +va_end (args); }static inline enum wsc_rf_band freq_to_rf_band (uint32_t freq)
Signature · 1 line
2.20.1
Re: [PATCH 05/16] handshake: Convert handshake event callbacks variadic functions
Hi Andrew,
Quoted 38 lines · Andrew Zaborowski
Convert the handshake event callback type to use variable argument list to allow for more flexibility in event-specific arguments passed to the callbacks.
--- src/adhoc.c | 2 +- src/ap.c | 9 +++++++-- src/handshake.c | 7 ------- src/handshake.h | 13 +++++++++---- src/station.c | 9 +++++++-- src/wsc.c | 11 +++++++++-- 6 files changed, 33 insertions(+), 18 deletions(-)src/adhoc.c +1
-1@@ -159,7 +159,7 @@ static bool ap_sta_match_addr(const void *a, const void *b) }static void adhoc_handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data,void *user_data) +enum handshake_event event,void *user_data, ...) {struct sta_state *sta = user_data;struct adhoc_state *adhoc = sta->adhoc;src/ap.c +2
-1@@ -382,16 +382,19 @@ static uint32_t ap_send_mgmt_frame(struct ap_state *ap, }static void ap_handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data,void *user_data) +enum handshake_event event,void *user_data, ...) {struct sta_state *sta = user_data; +va_list args;
src/ap.c static uint32_t ap_send_mgmt_frame(struct ap_state *ap, · line 397
Quoted 10 lines
src/ap.c +3
-1+ +va_start (args, user_data);switch (event) {case HANDSHAKE_EVENT_COMPLETE :ap_new_rsna (sta);break ;case HANDSHAKE_EVENT_FAILED : -netdev_handshake_failed (hs,l_get_u16 (event_data)); + netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *)));
So since you make the caller extract arguments via va_arg, I wonder if it would be cleaner to pass unsigned/int to va_arg directly instead of using void pointers?
So do something like handshake_event(hs,HANDSHAKE_EVENT_FAILED, reason_code);
Quoted 41 lines
src/ap.c +2
-0/* fall through */ case HANDSHAKE_EVENT_SETTING_KEYS_FAILED : sta->sm =NULL ;@@ -399,6 +402,8 @@ static void ap_handshake_event(struct handshake_state *hs,default :break ; } + +va_end (args); }static void ap_start_rsna (struct sta_state *sta,const uint8_t *gtk_rsc)src/handshake.c +0
-7@@ -912,10 +912,3 @@ bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,return true; } - -void handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data) -{ -if (hs->event_func) - hs->event_func (hs, event, event_data, hs->user_data); -}src/handshake.h +1
-1@@ -54,7 +54,7 @@ enum handshake_event {typedef void (*handshake_event_func_t )(struct handshake_state *hs,enum handshake_event event, -void *event_data,void *user_data); +void *user_data, ...);typedef bool (*handshake_get_nonce_func_t )(uint8_t nonce[]); typedef void (*handshake_install_tk_func_t)(struct handshake_state *hs,
src/handshake.h struct handshake_state { · line 138
Quoted 9 lines
src/handshake.h +6
-0@@ -130,6 +130,14 @@ struct handshake_state {handshake_event_func_t event_func; }; +#define handshake_event (hs, event, ...) \ + do { \ + if (!(hs)->event_func) \ + break; \ + \ + (hs)->event_func(hs, event, (hs)->user_data, ##__VA_ARGS__); \
second hs is not in ()s here?
src/handshake.h struct handshake_state { · line 143
Quoted 5 lines
src/handshake.h +2
-0+ }while (0 ) + void handshake_state_free(struct handshake_state *s); void handshake_state_set_supplicant_address(struct handshake_state *s,
Regards,
-Denis
Re: [PATCH 05/16] handshake: Convert handshake event callbacks variadic functions
Quoted 11 lines · Denis Kenzior
Review
Quoted 3 lines · Andrew Zaborowski
case
HANDSHAKE_EVENT_FAILED:(quoted diff) +1
-1- netdev_handshake_failed(hs, l_get_u16(event_data)); + netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *)));So since you make the caller extract arguments via
va_arg, I wonder if it would be cleaner to pass unsigned/int tova_argdirectly instead of using void pointers?So do something like handshake_event(hs,
HANDSHAKE_EVENT_FAILED,reason_code);
Done in the other patch ;)
Quoted 45 lines
Quoted 45 lines
/* fall through */ case HANDSHAKE_EVENT_SETTING_KEYS_FAILED: sta->sm = NULL;src/ap.c +2
-0@@ -399,6 +402,8 @@ static void ap_handshake_event(struct handshake_state *hs,default :break ; } + +va_end (args); }static void ap_start_rsna (struct sta_state *sta,const uint8_t *gtk_rsc)src/handshake.c +0
-7@@ -912,10 +912,3 @@ bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,return true; } - -void handshake_event (struct handshake_state *hs, -enum handshake_event event,void *event_data) -{ -if (hs->event_func) - hs->event_func (hs, event, event_data, hs->user_data); -}src/handshake.h +1
-1@@ -54,7 +54,7 @@ enum handshake_event {typedef void (*handshake_event_func_t )(struct handshake_state *hs,enum handshake_event event, -void *event_data,void *user_data); +void *user_data, ...);typedef bool (*handshake_get_nonce_func_t )(uint8_t nonce[]); typedef void (*handshake_install_tk_func_t)(struct handshake_state *hs,@@ -130,6 +130,14 @@ struct handshake_state {handshake_event_func_t event_func; };
Quoted 7 lines
src/handshake.h struct handshake_state { · line 138
Quoted 6 lines
src/handshake.h +6
-0+#define handshake_event (hs, event, ...) \ + do { \ + if (!(hs)->event_func) \ + break; \ + \ + (hs)->event_func(hs, event, (hs)->user_data, ##__VA_ARGS__); \second hs is not in ()s here?
Since it's surrounded by a ( and a , can this ever be a problem? For the record event isn't surrounded by ()s and the event-specific arguments aren't either.
This reminds me I was gonna comment on that I intended to make sure each argument is evaluated exactly once when using the handshake_event macro, same as if it was a C function. But there was no way to do this for the event-specific arguments so I gave up and left the responsibilty for this to the few callers, this may need a comment in the code though.
Best regards
PATCH 6/16 handshake: Convert HANDSHAKE_EVENT_FAILED data to int
In reply to Andrew ZaborowskiNote the uint16_t reason code is promoted to an int when using variable arguments so va_arg(args, int) has to be used.
--- src/ap.c | 2 +- src/eapol.c | 2 +- src/station.c | 2 +- src/wsc.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
src/ap.c +1 -1
@@ -394,7 +394,7 @@ static void ap_handshake_event(struct handshake_state *hs,ap_new_rsna (sta);break ;case HANDSHAKE_EVENT_FAILED : - netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *))); +netdev_handshake_failed (hs,va_arg (args, int));/* fall through */ case HANDSHAKE_EVENT_SETTING_KEYS_FAILED : sta->sm =NULL ;
src/eapol.c +1 -1
@@ -915,7 +915,7 @@ static void eapol_sm_write(struct eapol_sm *sm, const struct eapol_frame *ef,static inline void handshake_failed (struct eapol_sm *sm,uint16_t reason_code) { -handshake_event (sm->handshake,HANDSHAKE_EVENT_FAILED , &reason_code); +handshake_event (sm->handshake,HANDSHAKE_EVENT_FAILED , reason_code);eapol_sm_free (sm); }
src/station.c +1 -1
@@ -669,7 +669,7 @@ static void station_handshake_event(struct handshake_state *hs,network_sync_psk (network);break ;case HANDSHAKE_EVENT_FAILED : - netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *))); +netdev_handshake_failed (hs,va_arg (args, int));break ;case HANDSHAKE_EVENT_REKEY_FAILED :station_reconnect (station);
src/wsc.c +1 -1
@@ -411,7 +411,7 @@ static void wsc_handshake_event(struct handshake_state *hs,switch (event) {case HANDSHAKE_EVENT_FAILED : - netdev_handshake_failed(hs, l_get_u16(va_arg(args, void *))); +netdev_handshake_failed (hs,va_arg (args, int));break ;default :break ;
Signature · 1 line
2.20.1
Re: [PATCH 06/16] handshake: Convert HANDSHAKE_EVENT_FAILED data to int
Quoted 9 lines · Andrew Zaborowski
Note the
uint16_treason code is promoted to an int when using variable arguments sova_arg(args, int)has to be used.--- src/ap.c | 2 +- src/eapol.c | 2 +- src/station.c | 2 +- src/wsc.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
Ah, you did this part as a separate patch. Should have looked again.
I squashed patchees 5, 6, and 7 together and applied.
Regards,
-Denis
PATCH 7/16 handshake: Drop NULL event params passed to handshake_event
In reply to Andrew Zaborowski--- src/eapol.c | 4 ++-- src/handshake.c | 2 +- src/netdev.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
src/eapol.c +2 -2
@@ -970,7 +970,7 @@ static void __send_eapol_start(struct eapol_sm *sm, bool noencrypt)uint8_t buf[sizeof (struct eapol_frame )];struct eapol_frame *frame = (struct eapol_frame *) buf; -handshake_event (sm->handshake,HANDSHAKE_EVENT_STARTED ,NULL ); +handshake_event (sm->handshake,HANDSHAKE_EVENT_STARTED ); frame->header.protocol_version =EAPOL_PROTOCOL_VERSION_2001 ; frame->header.packet_type =1 ;
@@ -1181,7 +1181,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,* layers that we need to do a full reauth */ handshake_event (sm->handshake, -HANDSHAKE_EVENT_REKEY_FAILED ,NULL ); +HANDSHAKE_EVENT_REKEY_FAILED );return ; }
src/handshake.c +1 -1
@@ -558,7 +558,7 @@ void handshake_state_install_ptk(struct handshake_state *s)uint32_t cipher =ie_rsn_cipher_suite_to_cipher ( s->pairwise_cipher); -handshake_event (s,HANDSHAKE_EVENT_SETTING_KEYS ,NULL ); +handshake_event (s,HANDSHAKE_EVENT_SETTING_KEYS );install_tk (s,handshake_get_tk (s), cipher); }
src/netdev.c +2 -2
@@ -1094,7 +1094,7 @@ static void try_handshake_complete(struct netdev_handshake_state *nhs)if (nhs->ptk_installed && nhs->gtk_installed && nhs->igtk_installed && !nhs->complete) { nhs->complete = true; -handshake_event (&nhs->super,HANDSHAKE_EVENT_COMPLETE ,NULL ); +handshake_event (&nhs->super,HANDSHAKE_EVENT_COMPLETE );netdev_connect_ok (nhs->netdev); }
@@ -1388,7 +1388,7 @@ static void netdev_group_timeout_cb(struct l_timeout *timeout, void *user_data) nhs->netdev->index); nhs->complete = true; -handshake_event (&nhs->super,HANDSHAKE_EVENT_COMPLETE ,NULL ); +handshake_event (&nhs->super,HANDSHAKE_EVENT_COMPLETE );netdev_connect_ok (nhs->netdev); }
Signature · 1 line
2.20.1
PATCH 8/16 eapol: Move the EAP events to handshake event handler
In reply to Andrew ZaborowskiOn EAP events, call the handshake_event handler with the new event type HANDSHAKE_EVENT_EAP_NOTIFY isntead of the eapol_event callback.
This allows the handler to be set before calling netdev_connect/netdev_connect_wsc. It's also in theory more type-safe because we don't need the cast in netdev_connect_wsc anymore.
--- src/eapol.c | 6 ++---- src/handshake.h | 1 + src/station.c | 1 + src/wsc.c | 27 +++++++++++++++++---------- 4 files changed, 21 insertions(+), 14 deletions(-)
src/eapol.c +2 -4
@@ -2167,10 +2167,8 @@ static void eapol_eap_event_cb(unsigned int event, {struct eapol_sm *sm = user_data; -if (!sm->event_func) -return ; - - sm->event_func (event, event_data, sm->user_data); +handshake_event (sm->handshake,HANDSHAKE_EVENT_EAP_NOTIFY , event, + event_data); }void eapol_sm_set_use_eapol_start (struct eapol_sm *sm,bool enabled)
src/handshake.h +1 -0
@@ -50,6 +50,7 @@ enum handshake_event {HANDSHAKE_EVENT_COMPLETE ,HANDSHAKE_EVENT_FAILED ,HANDSHAKE_EVENT_REKEY_FAILED , + HANDSHAKE_EVENT_EAP_NOTIFY, }; typedef void (*handshake_event_func_t)(struct handshake_state *hs,
src/station.c +1 -0
@@ -676,6 +676,7 @@ static void station_handshake_event(struct handshake_state *hs,break ;case HANDSHAKE_EVENT_COMPLETE :case HANDSHAKE_EVENT_SETTING_KEYS_FAILED : +case HANDSHAKE_EVENT_EAP_NOTIFY :/* * currently we dont care about any other events. The * netdev_connect_cb will notify us when the connection is
src/wsc.c +17 -10
@@ -363,16 +363,7 @@ static void wsc_credential_obtained(struct wsc *wsc,static void wsc_eapol_event (uint32_t event,const void *event_data,void *user_data) { -struct wsc *wsc = user_data; - -switch (event) { -case EAP_WSC_EVENT_CREDENTIAL_OBTAINED : -wsc_credential_obtained (wsc, - (const struct wsc_credential *) event_data); -break ; -default : -l_debug ("Got event: %d" , event); - } +l_debug ("Got event: %d" , event); } static void wsc_netdev_event(struct netdev *netdev, enum netdev_event event,
@@ -405,6 +396,7 @@ static void wsc_handshake_event(struct handshake_state *hs, enum handshake_event event, void *user_data, ...) { + struct wsc *wsc = user_data;va_list args;va_start (args, user_data);
@@ -413,6 +405,21 @@ static void wsc_handshake_event(struct handshake_state *hs,case HANDSHAKE_EVENT_FAILED :netdev_handshake_failed (hs,va_arg (args, int));break ; +case HANDSHAKE_EVENT_EAP_NOTIFY : + { + unsigned int eap_event = va_arg(args, unsigned int); + +switch (eap_event) { +case EAP_WSC_EVENT_CREDENTIAL_OBTAINED : +wsc_credential_obtained (wsc, + va_arg(args, const struct wsc_credential *)); +break ; +default : +l_debug ("Got event: %d" , eap_event); + } + +break ; + }default :break ; }
Signature · 1 line
2.20.1
Re: [PATCH 08/16] eapol: Move the EAP events to handshake event handler
Hi Andrew,
Quoted 6 lines · Andrew Zaborowski
On EAP events, call the
handshake_eventhandler with the new event typeHANDSHAKE_EVENT_EAP_NOTIFYisntead of theeapol_eventcallback.This allows the handler to be set before calling netdev_connect/netdev_connect_wsc. It's also in theory more type-safe because we don't need the cast in
netdev_connect_wscanymore.
Quoted 7 lines
--- src/eapol.c | 6 ++---- src/handshake.h | 1 + src/station.c | 1 + src/wsc.c | 27 +++++++++++++++++---------- 4 files changed, 21 insertions(+), 14 deletions(-)
Patch 8 and 9 applied, thanks.
Regards,
-Denis
PATCH 9/16 unit: Update event handler in WSC, eapol tests
In reply to Andrew Zaborowski--- unit/test-eapol.c | 2 +- unit/test-wsc.c | 42 +++++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 24 deletions(-)
unit/test-eapol.c +1 -1
@@ -2871,7 +2871,7 @@ static void eapol_sm_test_tls_test_disconnected(enum l_tls_alert_desc reason,static void test_handshake_event (struct handshake_state *hs,enum handshake_event event, -void *event_data,void *user_data) +void *user_data, ...) {struct test_handshake_state *ths = l_container_of(hs, struct test_handshake_state, super);
unit/test-wsc.c +19 -23
73 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 10/16 wsc: Replace netdev_connect_wsc with netdev_connect usage
In reply to Andrew Zaborowskinetdev_connect can achieve the same effect as netdev_connect_wsc but is more flexible as it allows us to supply additional association IEs. We will need this capability to make P2P connections. This way we're also moving the WSC-specific bits to wsc.c from the crowded netdev.c.
--- src/netdev.c | 2 +- src/wsc.c | 46 +++++++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 14 deletions(-)
src/netdev.c +1 -1
@@ -2502,7 +2502,7 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,if (!cmd_connect)return -EINVAL ; -if (is_rsn) +if (is_rsn || hs->settings_8021x) sm =eapol_sm_new (hs); }
src/wsc.c +33 -13
67 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 10/16] wsc: Replace netdev_connect_wsc with netdev_connect usage
Hi Andrew,
Quoted 9 lines · Andrew Zaborowski
netdev_connectcan achieve the same effect asnetdev_connect_wscbut is more flexible as it allows us to supply additional association IEs. We will need this capability to make P2P connections. This way we're also moving the WSC-specific bits towsc.cfrom the crowdednetdev.c.--- src/netdev.c | 2 +- src/wsc.c | 46 +++++++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 14 deletions(-)
Patch 10 & 12 applied, thanks.
Regards,
-Denis
PATCH 11/16 eapol: Drop unused eapol_sm_set_event_func
In reply to Andrew Zaborowski--- src/eapol.c | 6 ------ src/eapol.h | 1 - src/netdev.c | 2 -- 3 files changed, 9 deletions(-)
src/eapol.c +0 -6
@@ -823,7 +823,6 @@ struct eapol_sm {struct handshake_state *handshake;enum eapol_protocol_version protocol_version;uint64_t replay_counter; -eapol_sm_event_func_t event_func;void *user_data;struct l_timeout *timeout;struct l_timeout *eapol_start_timeout;
@@ -901,11 +900,6 @@ void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data) sm->user_data = user_data; } -void eapol_sm_set_event_func (struct eapol_sm *sm,eapol_sm_event_func_t func) -{ - sm->event_func = func; -} -static void eapol_sm_write (struct eapol_sm *sm,const struct eapol_frame *ef,bool noencrypt) {
src/eapol.h +0 -1
@@ -117,7 +117,6 @@ void eapol_sm_set_use_eapol_start(struct eapol_sm *sm, bool enabled);void eapol_sm_set_require_handshake (struct eapol_sm *sm,bool enabled);void eapol_sm_set_listen_interval (struct eapol_sm *sm,uint16_t interval);void eapol_sm_set_user_data (struct eapol_sm *sm,void *user_data); -void eapol_sm_set_event_func (struct eapol_sm *sm,eapol_sm_event_func_t func);void eapol_register (struct eapol_sm *sm);bool eapol_start (struct eapol_sm *sm);
src/netdev.c +0 -2
@@ -2553,8 +2553,6 @@ int netdev_connect_wsc(struct netdev *netdev, struct scan_bss *bss,l_free (ie); sm =eapol_sm_new (hs); -eapol_sm_set_user_data (sm, user_data); -eapol_sm_set_event_func (sm, eapol_cb);return netdev_connect_common (netdev, cmd_connect, bss, hs, sm, event_filter, cb, user_data);
Signature · 1 line
2.20.1
Denis Kenzior
AppliedRe: [PATCH 11/16] eapol: Drop unused eapol_sm_set_event_func
Hi Andrew,
Quoted 6 lines · Andrew Zaborowski
--- src/eapol.c | 6 ------ src/eapol.h | 1 - src/netdev.c | 2 -- 3 files changed, 9 deletions(-)
Applied, thanks.
Regards,
-Denis
PATCH 12/16 netdev: Drop unused netdev_connect_wsc
In reply to Andrew Zaborowski--- src/netdev.c | 53 ---------------------------------------------------- src/netdev.h | 9 --------- 2 files changed, 62 deletions(-)
src/netdev.c +0 -53
@@ -52,7 +52,6 @@#include "src/device.h" #include "src/scan.h" #include "src/netdev.h" -#include "src/wscutil.h" #include "src/ft.h" #include "src/util.h" #include "src/watchlist.h"
@@ -2510,58 +2509,6 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss, event_filter, cb, user_data); } -int netdev_connect_wsc (struct netdev *netdev,struct scan_bss *bss, -struct handshake_state *hs, -netdev_event_func_t event_filter, -netdev_connect_cb_t cb, -netdev_eapol_event_func_t eapol_cb, -void *user_data) -{ -struct l_genl_msg *cmd_connect; -struct wsc_association_request request; -uint8_t *pdu; -size_t pdu_len; -void *ie; -size_t ie_len; -struct eapol_sm *sm; - -if (netdev->type !=NL80211_IFTYPE_STATION && - netdev->type !=NL80211_IFTYPE_P2P_CLIENT ) -return -ENOTSUP ; - -if (netdev->connected) -return -EISCONN ; - - cmd_connect =netdev_build_cmd_connect (netdev, bss, hs,NULL ,NULL ,0 ); -if (!cmd_connect) -return -EINVAL ; - - request.version2 = true; - request.request_type =WSC_REQUEST_TYPE_ENROLLEE_OPEN_8021X ; - - pdu =wsc_build_association_request (&request, &pdu_len); -if (!pdu) - goto error; - - ie =ie_tlv_encapsulate_wsc_payload (pdu, pdu_len, &ie_len); -l_free (pdu); - -if (!ie) - goto error; - -l_genl_msg_append_attr (cmd_connect,NL80211_ATTR_IE , ie_len, ie); -l_free (ie); - - sm =eapol_sm_new (hs); - -return netdev_connect_common (netdev, cmd_connect, bss, hs, sm, - event_filter, cb, user_data); - -error: -l_genl_msg_unref (cmd_connect); -return -ENOMEM ; -} -int netdev_disconnect (struct netdev *netdev,netdev_disconnect_cb_t cb,void *user_data) {
src/netdev.h +0 -9
@@ -107,9 +107,6 @@ typedef void (*netdev_watch_func_t)(struct netdev *netdev,enum netdev_watch_event event, void *user_data);typedef void (*netdev_destroy_func_t )(void *user_data); -typedef void (*netdev_eapol_event_func_t )(unsigned int event, -const void *event_data, -void *user_data);typedef void (*netdev_neighbor_report_cb_t )(struct netdev *netdev,int err,const uint8_t *reports,size_t reports_len,void *user_data);
@@ -150,12 +147,6 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,size_t num_vendor_ies, netdev_event_func_t event_filter, netdev_connect_cb_t cb, void *user_data); -int netdev_connect_wsc (struct netdev *netdev,struct scan_bss *bss, -struct handshake_state *hs, -netdev_event_func_t event_filter, -netdev_connect_cb_t cb, -netdev_eapol_event_func_t eapol_cb, -void *user_data);int netdev_disconnect (struct netdev *netdev,netdev_disconnect_cb_t cb,void *user_data); int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
Signature · 1 line
2.20.1
PATCH 13/16 wsc: Declare the credentials structure in wsc.h
In reply to Andrew Zaborowski--- Makefile.am | 2 +- src/wsc.c | 12 ++---------- src/wsc.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 src/wsc.h
Makefile.am +1 -1
@@ -202,7 +202,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \ src/agent.h src/agent.c \ src/storage.h src/storage.c \ src/network.h src/network.c \ - src/wsc.c \ + src/wsc.h src/wsc.c \ src/backtrace.h src/backtrace.c \ src/knownnetworks.h \ src/knownnetworks.c \
src/wsc.c +2 -10
@@ -44,6 +44,7 @@#include "src/storage.h" #include "src/iwd.h" #include "src/network.h" +#include "src/wsc.h" #define WALK_TIME 120
@@ -60,16 +61,7 @@ struct wsc {uint32_t scan_id;struct scan_bss *target;uint32_t station_state_watch; -struct { -char ssid[33 ]; -enum security security; -union { -uint8_t psk[32 ]; -char passphrase[64 ]; - }; -uint8_t addr[6 ]; -bool has_passphrase; - } creds[3 ]; +struct wsc_credentials_info creds[3 ];uint32_t n_creds;struct l_settings *eap_settings;
src/wsc.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* +* Wireless daemon for Linux +* +* Copyright (C) 2019 Intel Corporation. All rights reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +struct wsc_credentials_info { +char ssid[33 ]; +enum security security; +union { +uint8_t psk[32 ]; +char passphrase[64 ]; + }; +uint8_t addr[6 ]; +bool has_passphrase; +};
Signature · 1 line
2.20.1
PATCH 14/16 wsc: Refactor to separate DBus-specific code
In reply to Andrew ZaborowskiSplit the DBus-specific logic out of the core WSC logic. The core WSC code is the part that we can re-use for P2P and doesn't include the scanning for the target BSS or the attempt to make a station mode connection.
--- src/wsc.c | 141 ++++++++++++++++++++++++++++++++++++++---------------- src/wsc.h | 3 ++ 2 files changed, 103 insertions(+), 41 deletions(-)
src/wsc.c +100 -41
@@ -64,6 +64,11 @@ struct wsc {struct wsc_credentials_info creds[3 ];uint32_t n_creds;struct l_settings *eap_settings; +char *pin; + +wsc_done_cb_t done_cb; +void *done_data; +uint16_t config_method; bool wsc_association : 1; };
@@ -152,15 +157,12 @@ static void wsc_try_credentials(struct wsc *wsc)l_dbus_message_unref (wsc->pending); wsc->pending =NULL ; - goto done; +return ; }dbus_pending_reply (&wsc->pending,wsc_error_not_reachable (wsc->pending));station_set_autoconnect (wsc->station, true); -done: -memset (wsc->creds,0 ,sizeof (wsc->creds)); - wsc->n_creds =0 ; }static void wsc_store_credentials (struct wsc *wsc)
@@ -216,6 +218,22 @@ static void wsc_disconnect_cb(struct netdev *netdev, bool success,station_set_autoconnect (wsc->station, true); } +static void wsc_connect_cleanup (struct wsc *wsc) +{ + wsc->wsc_association = false; + +l_settings_free (wsc->eap_settings); + wsc->eap_settings =NULL ; + +if (wsc->pin) { +explicit_bzero (wsc->pin,strlen (wsc->pin)); +l_free (wsc->pin); + wsc->pin =NULL ; + } + + wsc->target =NULL ; +} +static void wsc_connect_cb (struct netdev *netdev,enum netdev_result result,void *event_data,void *user_data) {
@@ -223,33 +241,34 @@ static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result,l_debug ("%d, result: %d" ,netdev_get_ifindex (wsc->netdev), result); - wsc->wsc_association = false; - -l_settings_free (wsc->eap_settings); - wsc->eap_settings =NULL ; +wsc_connect_cleanup (wsc);if (result ==NETDEV_RESULT_HANDSHAKE_FAILED && wsc->n_creds >0 ) { -wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +struct wsc_credentials_info creds[L_ARRAY_SIZE (wsc->creds)]; +uint32_t n_creds = wsc->n_creds; + +memcpy (creds, wsc->creds,sizeof (creds)); +explicit_bzero (wsc->creds,sizeof (creds)); + wsc->n_creds =0 ; + wsc->done_cb (0 , creds, n_creds, wsc->done_data); +explicit_bzero (creds,sizeof (creds));return ; }switch (result) {case NETDEV_RESULT_ABORTED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); + wsc->done_cb (-ECANCELED ,NULL ,0 , wsc->done_data);return ;case NETDEV_RESULT_HANDSHAKE_FAILED : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); + wsc->done_cb (-ENOKEY ,NULL ,0 , wsc->done_data);break ;default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); + wsc->done_cb (-EIO ,NULL ,0 , wsc->done_data);break ; } -station_set_autoconnect (wsc->station, true); +if (wsc->station) +station_set_autoconnect (wsc->station, true); } static void wsc_credential_obtained(struct wsc *wsc,
@@ -451,30 +470,24 @@ static void wsc_connect(struct wsc *wsc)l_settings_set_uint (settings,"WSC" ,"RFBand" ,freq_to_rf_band (bss->frequency));l_settings_set_uint (settings,"WSC" ,"ConfigurationMethods" , -WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN | -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON | -WSC_CONFIGURATION_METHOD_KEYPAD ); + wsc->config_method);l_settings_set_string (settings,"WSC" ,"PrimaryDeviceType" ,"0-00000000-0" );l_settings_set_string (settings,"WSC" ,"EnrolleeMAC" ,util_address_to_string (netdev_get_address (wsc->netdev))); -if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { -const char *pin; - -if (l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) { -enum wsc_device_password_id dpid; +if (wsc->config_method ==WSC_CONFIGURATION_METHOD_KEYPAD ) { +enum wsc_device_password_id dpid; -if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) - dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; -else - dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; +if (strlen (wsc->pin) ==4 || +wsc_pin_is_checksum_valid (wsc->pin)) + dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; +else + dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; -l_settings_set_uint (settings,"WSC" , -"DevicePasswordId" , dpid); -l_settings_set_string (settings,"WSC" , -"DevicePassword" , pin); - } +l_settings_set_uint (settings,"WSC" ,"DevicePasswordId" , dpid); +l_settings_set_string (settings,"WSC" ,"DevicePassword" , + wsc->pin); }handshake_state_set_event_func (hs, wsc_handshake_event, wsc);
@@ -510,8 +523,41 @@ static void wsc_connect(struct wsc *wsc)return ; error:handshake_state_free (hs); -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); +wsc_connect_cleanup (wsc); + wsc->done_cb (r,NULL ,0 , wsc->done_data); +} + +/* Done callback for when WSC is triggered by DBus methods */ +static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data) +{ +struct wsc *wsc = user_data; + +l_debug ("err=%i" , err); + +switch (err) { +case 0 : +break ; +case -ECANCELED : +dbus_pending_reply (&wsc->pending, +dbus_error_aborted (wsc->pending)); +return ; +case -ENOKEY : +dbus_pending_reply (&wsc->pending, +wsc_error_no_credentials (wsc->pending)); +return ; +case -EBUSY : +dbus_pending_reply (&wsc->pending, +dbus_error_busy (wsc->pending)); +return ; +default : +dbus_pending_reply (&wsc->pending, +dbus_error_failed (wsc->pending)); +return ; + } + +wsc_store_credentials (wsc); +wsc_try_credentials (wsc); }static void station_state_watch (enum station_state state,void *userdata)
@@ -540,6 +586,22 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target) wsc->target = target;station_set_autoconnect (wsc->station, false); +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { +char *pin; + + wsc->config_method =WSC_CONFIGURATION_METHOD_KEYPAD ; + +if (!l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) + goto error; + + wsc->pin =l_strdup (pin); + }else + wsc->config_method = +WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; + + wsc->done_cb = wsc_dbus_done_cb; + wsc->done_data = wsc; +switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED :wsc_connect (wsc);
@@ -563,7 +625,7 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target)break ; } error: - wsc->target =NULL ; +wsc_connect_cleanup (wsc);dbus_pending_reply (&wsc->pending,dbus_error_failed (wsc->pending)); }
@@ -1073,12 +1135,12 @@ static void wsc_free(void *userdata)struct wsc *wsc = userdata;wsc_cancel_scan (wsc); +wsc_connect_cleanup (wsc);if (wsc->station_state_watch) {station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; - wsc->target =NULL ; }if (wsc->pending)
@@ -1089,9 +1151,6 @@ static void wsc_free(void *userdata)dbus_pending_reply (&wsc->pending_cancel,dbus_error_aborted (wsc->pending_cancel)); -if (wsc->eap_settings) -l_settings_free (wsc->eap_settings); -l_free (wsc); }
src/wsc.h +3 -0
@@ -30,3 +30,6 @@ struct wsc_credentials_info {uint8_t addr[6 ];bool has_passphrase; }; + +typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data);
Signature · 1 line
2.20.1
Re: [PATCH 14/16] wsc: Refactor to separate DBus-specific code
Hi Andrew,
Quoted 9 lines · Andrew Zaborowski
Split the DBus-specific logic out of the core WSC logic. The core WSC code is the part that we can re-use for P2P and doesn't include the scanning for the target BSS or the attempt to make a station mode connection.
--- src/wsc.c | 141 ++++++++++++++++++++++++++++++++++++++---------------- src/wsc.h | 3 ++ 2 files changed, 103 insertions(+), 41 deletions(-)
<snip>
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 473
Quoted 8 lines
src/wsc.c +1
-3@@ -451,30 +470,24 @@ static void wsc_connect(struct wsc *wsc)l_settings_set_uint (settings,"WSC" ,"RFBand" ,freq_to_rf_band (bss->frequency));l_settings_set_uint (settings,"WSC" ,"ConfigurationMethods" , -WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN | -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON | -WSC_CONFIGURATION_METHOD_KEYPAD ); + wsc->config_method);
So this is somewhat non-obvious that you're messing with the advertised config method in this patch. Just setting METHOD_KEYPAD (and using that as a selector) is not flexible enough and most likely against what the WSC spec recommends anyway. Can't we explicitly track what 'high-level' method type we're using? i.e. PIN vs PushButton?
Otherwise, I'm mostly okay with this patch.
One thing to think about though is to make wsc an explicit state machine. Right now wsc only registers to the station ifindex and thus only exists if the station interface exists.
How are you dealing with the fact that you need to run P2P transactions on the P2P_CLIENT interface and what happens if there's no station iftype registered at all?
Regards,
-Denis
PATCH 15/16 wsc: Add wsc_new_p2p_enrollee
In reply to Andrew ZaborowskiUntil now WSC could only be triggered by calling a DBus method and success and error paths would end with a reply to the DBus method. Instead use a wsc done callback pointer so that the WSC connection logic can be triggered through DBus or a C API.
Export a function that adds a new entry point to start the WSC connection for the P2P provisioning phase. The function doesn't have anything specific to P2P at this point.
--- src/wsc.c | 31 +++++++++++++++++++++++++++++++ src/wsc.h | 9 +++++++++ 2 files changed, 40 insertions(+)
src/wsc.c +31 -0
@@ -1197,6 +1197,37 @@ static void wsc_netdev_watch(struct netdev *netdev, } } +struct wsc *wsc_new_p2p_enrollee (struct netdev *netdev,struct scan_bss *target, +char *pin,wsc_done_cb_t done_cb, +void *user_data) +{ +struct wsc *wsc; + + wsc = l_new(struct wsc, 1); + wsc->netdev = netdev; + wsc->target = target; + wsc->config_method = pin ?WSC_CONFIGURATION_METHOD_KEYPAD : +WSC_CONFIGURATION_METHOD_PUSH_BUTTON ; + wsc->done_cb = done_cb; + wsc->done_data = user_data; + wsc->pin =l_strdup (pin); + +wsc_connect (wsc); + +/* +* Wsc objects created this way are not handled in wsc_remove_interface, +* the caller is expected to watch interfaces going away and there's no +* need to handle the event in both places. +*/ + +return wsc; +} + +void wsc_destroy (struct wsc *wsc) +{ +wsc_free (wsc); +} +static int wsc_init (void ) {l_debug ("" );
src/wsc.h +9 -0
@@ -20,6 +20,10 @@* */ +struct wsc ; +struct netdev ; +struct scan_bss ; +struct wsc_credentials_info {char ssid[33 ];enum security security;
@@ -33,3 +37,8 @@ struct wsc_credentials_info {typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds,unsigned int n_creds,void *user_data); + +struct wsc *wsc_new_p2p_enrollee (struct netdev *netdev,struct scan_bss *target, +char *pin,wsc_done_cb_t done_cb, +void *user_data); +void wsc_destroy (struct wsc *wsc);
Signature · 1 line
2.20.1
PATCH 16/16 wsc: Accept extra IEs in wsc_new_p2p_enrollee
In reply to Andrew Zaborowski--- src/wsc.c | 30 +++++++++++++++++------------- src/wsc.h | 6 ++++-- 2 files changed, 21 insertions(+), 15 deletions(-)
src/wsc.c +17 -13
@@ -448,7 +448,8 @@ static inline enum wsc_rf_band freq_to_rf_band(uint32_t freq)return WSC_RF_BAND_2_4_GHZ ; } -static void wsc_connect (struct wsc *wsc) +static void wsc_connect (struct wsc *wsc,struct iovec *ies, +unsigned int ies_num) {struct handshake_state *hs;struct l_settings *settings =l_settings_new ();
@@ -457,7 +458,7 @@ static void wsc_connect(struct wsc *wsc)struct wsc_association_request request;uint8_t *pdu;size_t pdu_len; -struct iovec ie_iov; +struct iovec ie_iov[1 + ies_num]; wsc->target =NULL ;
@@ -503,18 +504,20 @@ static void wsc_connect(struct wsc *wsc) goto error; } - ie_iov.iov_base =ie_tlv_encapsulate_wsc_payload (pdu, pdu_len, - &ie_iov.iov_len); + ie_iov[0 ].iov_base =ie_tlv_encapsulate_wsc_payload (pdu, pdu_len, + &ie_iov[0 ].iov_len);l_free (pdu); -if (!ie_iov.iov_base) { +if (!ie_iov[0 ].iov_base) { r = -ENOMEM ; goto error; } - r =netdev_connect (wsc->netdev, bss, hs, &ie_iov,1 , wsc_netdev_event, - wsc_connect_cb, wsc); -l_free (ie_iov.iov_base); +memcpy (ie_iov +1 , ies,sizeof (struct iovec ) * ies_num); + + r =netdev_connect (wsc->netdev, bss, hs, ie_iov,1 + ies_num, + wsc_netdev_event, wsc_connect_cb, wsc); +l_free (ie_iov[0 ].iov_base);if (r <0 ) goto error;
@@ -572,7 +575,7 @@ static void station_state_watch(enum station_state state, void *userdata)station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; -wsc_connect (wsc); +wsc_connect (wsc,NULL ,0 ); }static void wsc_check_can_connect (struct wsc *wsc,struct scan_bss *target)
@@ -604,7 +607,7 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target)switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED : -wsc_connect (wsc); +wsc_connect (wsc,NULL ,0 );return ;case STATION_STATE_CONNECTING :case STATION_STATE_CONNECTED :
@@ -1198,8 +1201,9 @@ static void wsc_netdev_watch(struct netdev *netdev, }struct wsc *wsc_new_p2p_enrollee (struct netdev *netdev,struct scan_bss *target, -char *pin,wsc_done_cb_t done_cb, -void *user_data) +char *pin, +struct iovec *ies,unsigned int ies_num, +wsc_done_cb_t done_cb,void *user_data) {struct wsc *wsc;
@@ -1212,7 +1216,7 @@ struct wsc *wsc_new_p2p_enrollee(struct netdev *netdev, struct scan_bss *target, wsc->done_data = user_data; wsc->pin =l_strdup (pin); -wsc_connect (wsc); +wsc_connect (wsc, ies, ies_num);/* * Wsc objects created this way are not handled in wsc_remove_interface,
src/wsc.h +4 -2
@@ -23,6 +23,7 @@struct wsc ;struct netdev ;struct scan_bss ; +struct iovec ;struct wsc_credentials_info {char ssid[33 ];
@@ -39,6 +40,7 @@ typedef void (*wsc_done_cb_t)(int err, struct wsc_credentials_info *creds, unsigned int n_creds, void *user_data);struct wsc *wsc_new_p2p_enrollee (struct netdev *netdev,struct scan_bss *target, -char *pin,wsc_done_cb_t done_cb, -void *user_data); +char *pin, +struct iovec *ies,unsigned int ies_num, +wsc_done_cb_t done_cb,void *user_data);void wsc_destroy (struct wsc *wsc);
Signature · 1 line
2.20.1
Denis Kenzior
AppliedHi Andrew,
Quoted 7 lines · Andrew Zaborowski
Add code to parse the supported data rates info from the wiphy dumps and expose it for P2P's use with a getter function.
--- src/wiphy.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/wiphy.h | 2 ++ 2 files changed, 82 insertions(+), 4 deletions(-)
Applied, thanks.
Regards,
-Denis