netdev: downgrade L_WARN_ON for ensure_eapol_registered
PATCH 1/10 netdev: downgrade L_WARN_ON for ensure_eapol_registered
This warning is guaranteed to happen for SAE networks where there are multiple netdev_authenticate_events. This should just be a check so we don't register eapol twice, not a warning.
--- src/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/netdev.c +1 -1
@@ -2898,7 +2898,7 @@ static bool kernel_will_retry_auth(uint16_t status_code,static void netdev_ensure_eapol_registered (struct netdev *netdev) { -if (L_WARN_ON (netdev->sm)) +if (netdev->sm)return ; netdev->sm =eapol_sm_new (netdev->handshake);
Signature · 1 line
2.34.1
PATCH 2/10 nl80211util: add ATTR_SURVEY_INFO to parse_attrs
--- src/nl80211util.c | 1 + 1 file changed, 1 insertion(+)
src/nl80211util.c +1 -0
@@ -181,6 +181,7 @@ static attr_handler handler_for_type(enum nl80211_attrs type)case NL80211_ATTR_FRAME :return extract_iovec;case NL80211_ATTR_WIPHY_BANDS : +case NL80211_ATTR_SURVEY_INFO :return extract_nested;case NL80211_ATTR_KEY_IDX :return extract_u8;
Signature · 1 line
2.34.1
PATCH 3/10 nl80211util: refactor nl80211_parse_attrs for nested variant
In reply to James PrestwoodTo prep for adding a _nested() variant of this function refactor this to act on an l_genl_attr object rather than the message itself. In addition a handler specific to the attribute being parsed is now passed in, with the current "handler_for_type" being renamed to "handler_for_nl80211" that corresponds to root level attributes.
--- src/nl80211util.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
src/nl80211util.c +25 -13
@@ -37,6 +37,7 @@#include "src/util.h" typedef bool (*attr_handler )(const void *data,uint16_t len,void *o); +typedef attr_handler (*handler_for_type )(int type);static bool extract_ifindex (const void *data,uint16_t len,void *o) {
@@ -150,7 +151,7 @@ static bool extract_u8(const void *data, uint16_t len, void *o)return true; } -static attr_handler handler_for_type (enum nl80211_attrs type) +static attr_handler handler_for_nl80211 (int type) {switch (type) {case NL80211_ATTR_IFINDEX :
@@ -199,10 +200,9 @@ struct attr_entry { bool present : 1; }; -int nl80211_parse_attrs (struct l_genl_msg *msg,int tag, ...) +static int parse_attrs (struct l_genl_attr *attr,handler_for_type handler, +int tag,va_list args) { -struct l_genl_attr attr; -va_list args;struct l_queue *entries;const struct l_queue_entry *e;struct attr_entry *entry;
@@ -211,10 +211,6 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)const void *data;int ret; -if (!l_genl_attr_init (&attr, msg)) -return -EINVAL ; - -va_start (args, tag); entries =l_queue_new (); ret = -ENOSYS ;
@@ -223,7 +219,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) entry->type = tag; entry->data = va_arg(args, void *); - entry->handler =handler_for_type (tag); + entry->handler =handler (tag);l_queue_push_tail (entries, entry);if (!entry->handler)
@@ -232,9 +228,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...) tag = va_arg(args, enum nl80211_attrs); } -va_end (args); - -while (l_genl_attr_next (&attr, &type, &len, &data)) { +while (l_genl_attr_next (attr, &type, &len, &data)) {for (e =l_queue_get_entries (entries); e; e = e->next) { entry = e->data;
@@ -252,7 +246,7 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)/* For nested attributes use the outer attribute as data */ if (entry->handler == extract_nested) - data = &attr; + data = attr;if (!entry->handler (data, len, entry->data)) { ret = -EINVAL ;
@@ -285,6 +279,24 @@ done:return ret; } +int nl80211_parse_attrs (struct l_genl_msg *msg,int tag, ...) +{ +struct l_genl_attr attr; +va_list args; +int ret; + +if (!l_genl_attr_init (&attr, msg)) +return -EINVAL ; + +va_start (args, tag); + + ret =parse_attrs (&attr, handler_for_nl80211, tag, args); + +va_end (args); + +return ret; +} +struct l_genl_msg *nl80211_build_deauthenticate (uint32_t ifindex,const uint8_t addr[static 6 ],uint16_t reason_code)
Signature · 1 line
2.34.1
PATCH 4/10 nl80211util: add nl80211_parse_nested
In reply to James PrestwoodAdd a nested attribute parser. For the first supported attribute add NL80211_ATTR_SURVEY_INFO.
This allows parsing of nested attributes in the same convenient way as nl80211_parse_attrs but allows for support of any level of nested attributes provided that a handler is added for each.
--- src/nl80211util.c | 37 +++++++++++++++++++++++++++++++++++++ src/nl80211util.h | 1 + 2 files changed, 38 insertions(+)
src/nl80211util.c +37 -0
@@ -193,6 +193,20 @@ static attr_handler handler_for_nl80211(int type)return NULL ; } +static attr_handler handler_for_survey_info (int type) +{ +switch (type) { +case NL80211_SURVEY_INFO_NOISE : +return extract_u8; +case NL80211_SURVEY_INFO_FREQUENCY : +return extract_uint32; +default : +break ; + } + +return NULL ; +} +struct attr_entry {uint16_t type;void *data;
@@ -297,6 +311,29 @@ int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)return ret; } +int nl80211_parse_nested (struct l_genl_attr *attr,int type,int tag, ...) +{ +handler_for_type handler; +va_list args; +int ret; + +switch (type) { +case NL80211_ATTR_SURVEY_INFO : + handler = handler_for_survey_info; +break ; +default : +return -ENOTSUP ; + } + +va_start (args, tag); + + ret =parse_attrs (attr, handler, tag, args); + +va_end (args); + +return ret; +} +struct l_genl_msg *nl80211_build_deauthenticate (uint32_t ifindex,const uint8_t addr[static 6 ],uint16_t reason_code)
src/nl80211util.h +1 -0
@@ -28,6 +28,7 @@ struct band_freq_attrs;struct handshake_state ;int nl80211_parse_attrs (struct l_genl_msg *msg,int tag, ...); +int nl80211_parse_nested (struct l_genl_attr *attr,int type,int tag, ...); struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex, const uint8_t addr[static 6],
Signature · 1 line
2.34.1
PATCH 5/10 nl80211util: add ATTR_SCAN_FLAGS
In reply to James Prestwood--- src/nl80211util.c | 1 + 1 file changed, 1 insertion(+)
src/nl80211util.c +1 -0
@@ -159,6 +159,7 @@ static attr_handler handler_for_nl80211(int type)case NL80211_ATTR_WIPHY :case NL80211_ATTR_IFTYPE :case NL80211_ATTR_KEY_TYPE : +case NL80211_ATTR_SCAN_FLAGS :return extract_uint32;case NL80211_ATTR_WDEV :case NL80211_ATTR_COOKIE :
Signature · 1 line
2.34.1
PATCH 6/10 scan: fixed flush flag parsing
In reply to James PrestwoodParsing the flush flag for external scans was not done correctly as it was not parsing the ATTR_SCAN_FLAGS but instead the flag bitmap. Fix this by parsing the flags attribute, then checking if the bit is set.
--- src/scan.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
src/scan.c +5 -7
@@ -2021,16 +2021,14 @@ static struct scan_context *scan_context_new(uint64_t wdev_id)static bool scan_parse_flush_flag_from_msg (struct l_genl_msg *msg) { -struct l_genl_attr attr; -uint16_t type, len; -const void *data; +uint32_t flags; -if (!l_genl_attr_init (&attr, msg)) +if (nl80211_parse_attrs (msg,NL80211_ATTR_SCAN_FLAGS , &flags, +NL80211_ATTR_UNSPEC ) <0 )return false; -while (l_genl_attr_next (&attr, &type, &len, &data)) -if (type ==NL80211_SCAN_FLAG_FLUSH ) -return true; +if (flags &NL80211_SCAN_FLAG_FLUSH ) +return true;return false; }
Signature · 1 line
2.34.1
PATCH 7/10 unit: add simple test for nl80211util
In reply to James Prestwood--- Makefile.am | 9 +++++- unit/test-nl80211util.c | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 unit/test-nl80211util.c
Makefile.am +8 -1
@@ -433,7 +433,7 @@ unit_tests += unit/test-cmac-aes \ unit/test-ie unit/test-util unit/test-ssid-security \ unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \ unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \ - unit/test-dpp unit/test-json + unit/test-dpp unit/test-json unit/test-nl80211util endif if CLIENT
@@ -582,6 +582,13 @@ unit_test_dpp_LDADD = $(ell_ldadd) unit_test_json_SOURCES = unit/test-json.c src/json.h src/json.c shared/jsmn.h unit_test_json_LDADD = $(ell_ldadd) + +unit_test_nl80211util_SOURCES = unit/test-nl80211util.c \ + src/nl80211util.h src/nl80211util.c \ + src/band.h src/band.c \ + src/ie.h src/ie.c \ + src/util.h src/util.c +unit_test_nl80211util_LDADD = $(ell_ldadd) endif if CLIENT
unit/test-nl80211util.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 8/10 scan: use GET_SURVEY for SNR calculation in ranking
In reply to James PrestwoodThis issues a GET_SURVEY dump after scan results are available and populates the survey information within the scan results. Currently the only value obtained is the noise for a given frequency but the survey results structure was created if in the future more values need to be added.
From the noise, the SNR can be calculated. This is then used in the ranking calculation to help lower BSS ranks that are on high noise channels.
--- src/scan.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/scan.h | 2 + 2 files changed, 151 insertions(+), 7 deletions(-)
src/scan.c +149 -7
@@ -132,6 +132,18 @@ struct scan_context {*/ unsigned int get_fw_scan_cmd_id;struct wiphy *wiphy; + +unsigned int get_survey_cmd_id; +}; + +struct scan_survey { +int8_t noise; +}; + +struct scan_survey_results { +struct scan_survey survey_2_4[14 ]; +struct scan_survey survey_5[196 ]; +struct scan_survey survey_6[233 ]; };struct scan_results {
@@ -140,6 +152,9 @@ struct scan_results {uint64_t time_stamp;struct scan_request *sr;struct scan_freq_set *freqs; +struct scan_survey_results survey; + + bool survey_parsed : 1; };static bool start_next_scan_request (struct wiphy_radio_work_item *item);
@@ -217,6 +232,9 @@ static void scan_context_free(struct scan_context *sc)if (sc->get_fw_scan_cmd_id && nl80211)l_genl_family_cancel (nl80211, sc->get_fw_scan_cmd_id); +if (sc->get_survey_cmd_id && nl80211) +l_genl_family_cancel (nl80211, sc->get_survey_cmd_id); +wiphy_state_watch_remove (sc->wiphy, sc->wiphy_watch_id);l_free (sc);
@@ -1663,6 +1681,8 @@ static void scan_bss_compute_rank(struct scan_bss *bss) {static const double RANK_HIGH_UTILIZATION_FACTOR =0.8 ;static const double RANK_LOW_UTILIZATION_FACTOR =1.2 ; +static const double RANK_HIGH_SNR_FACTOR =1.2 ; +static const double RANK_LOW_SNR_FACTOR =0.8 ;double rank;uint32_t irank;/*
@@ -1689,6 +1709,13 @@ static void scan_bss_compute_rank(struct scan_bss *bss)else if (bss->utilization <=63 ) rank *=RANK_LOW_UTILIZATION_FACTOR ; +if (bss->have_snr) { +if (bss->snr <=15 ) + rank *=RANK_LOW_SNR_FACTOR ; +else if (bss->snr >=30 ) + rank *=RANK_HIGH_SNR_FACTOR ; + } + irank = rank;if (irank >USHRT_MAX )
@@ -1824,6 +1851,41 @@ int scan_bss_rank_compare(const void *a, const void *b, void *user_data)return (bss->rank > new_bss->rank) ?1 :-1 ; } +static bool scan_survey_get_snr (struct scan_results *results, +uint32_t freq,int32_t signal, +int8_t *snr) +{ +uint8_t channel; +enum band_freq band; +int8_t noise =0 ; + +if (!results->survey_parsed) +return false; + + channel =band_freq_to_channel (freq, &band); +if (L_WARN_ON (!channel)) +return false; + +switch (band) { +case BAND_FREQ_2_4_GHZ : + noise = results->survey.survey_2_4[channel].noise; +break ; +case BAND_FREQ_5_GHZ : + noise = results->survey.survey_5[channel].noise; +break ; +case BAND_FREQ_6_GHZ : + noise = results->survey.survey_6[channel].noise; +break ; + } + +if (noise) { + *snr = signal - noise; +return true; + } + +return false; +} +static void get_scan_callback (struct l_genl_msg *msg,void *user_data) {struct scan_results *results = user_data;
@@ -1849,6 +1911,10 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data) bss->time_stamp = results->time_stamp - seen_ms_ago *L_USEC_PER_MSEC ; + bss->have_snr =scan_survey_get_snr (results, bss->frequency, + bss->signal_strength /100 , + &bss->snr); +scan_bss_compute_rank (bss);l_queue_insert (results->bss_list, bss, scan_bss_rank_compare,NULL ); }
@@ -1925,11 +1991,88 @@ static void get_scan_done(void *user)l_free (results); } +static void get_survey_callback (struct l_genl_msg *msg,void *user_data) +{ +struct scan_results *results = user_data; +struct scan_survey_results *survey = &results->survey; +struct l_genl_attr attr; +uint32_t freq; +int8_t noise; +uint8_t channel; +enum band_freq band; + +if (nl80211_parse_attrs (msg,NL80211_ATTR_SURVEY_INFO , &attr, +NL80211_ATTR_UNSPEC ) <0 ) +return ; + +if (nl80211_parse_nested (&attr,NL80211_ATTR_SURVEY_INFO , +NL80211_SURVEY_INFO_FREQUENCY , &freq, +NL80211_SURVEY_INFO_NOISE , &noise, +NL80211_ATTR_UNSPEC ) <0 ) +return ; + + channel =band_freq_to_channel (freq, &band); +if (!channel) +return ; + +/* At least one frequency was surveyed */ + results->survey_parsed = true; + +switch (band) { +case BAND_FREQ_2_4_GHZ : + survey->survey_2_4[channel].noise = noise; +break ; +case BAND_FREQ_5_GHZ : + survey->survey_5[channel].noise = noise; +break ; +case BAND_FREQ_6_GHZ : + survey->survey_6[channel].noise = noise; +break ; + } +} + +static void get_results (struct scan_results *results) +{ +struct l_genl_msg *scan_msg; + + scan_msg =l_genl_msg_new_sized (NL80211_CMD_GET_SCAN ,8 ); + +l_genl_msg_append_attr (scan_msg,NL80211_ATTR_WDEV ,8 , + &results->sc->wdev_id); + results->sc->get_scan_cmd_id =l_genl_family_dump (nl80211, scan_msg, + get_scan_callback, + results, get_scan_done); +} + +static void get_survey_done (void *user_data) +{ +struct scan_results *results = user_data; +struct scan_context *sc = results->sc; + + sc->get_survey_cmd_id =0 ; + +get_results (results); +} + +static bool scan_survey (struct scan_results *results) +{ +struct scan_context *sc = results->sc; +struct l_genl_msg *survey_msg; + + survey_msg =l_genl_msg_new (NL80211_CMD_GET_SURVEY ); +l_genl_msg_append_attr (survey_msg,NL80211_ATTR_WDEV ,8 , + &sc->wdev_id); + sc->get_survey_cmd_id =l_genl_family_dump (nl80211, survey_msg, + get_survey_callback, results, + get_survey_done); + +return sc->get_survey_cmd_id !=0 ; +} +static void scan_get_results (struct scan_context *sc,struct scan_request *sr,struct scan_freq_set *freqs) {struct scan_results *results; -struct l_genl_msg *scan_msg; results = l_new(struct scan_results, 1); results->sc = sc;
@@ -1938,13 +2081,12 @@ static void scan_get_results(struct scan_context *sc, struct scan_request *sr, results->bss_list =l_queue_new (); results->freqs = freqs; - scan_msg =l_genl_msg_new_sized (NL80211_CMD_GET_SCAN ,8 ); +if (scan_survey (results)) +return ; +else +l_warn ("failed to start a scan survey" ); -l_genl_msg_append_attr (scan_msg,NL80211_ATTR_WDEV ,8 , - &sc->wdev_id); - sc->get_scan_cmd_id =l_genl_family_dump (nl80211, scan_msg, - get_scan_callback, - results, get_scan_done); +get_results (results); } static void scan_wiphy_watch(struct wiphy *wiphy,
src/scan.h +2 -0
@@ -75,6 +75,7 @@ struct scan_bss {uint64_t parent_tsf;uint8_t *wfd;/* Concatenated WFD IEs */ ssize_t wfd_size;/* Size of Concatenated WFD IEs */ +int8_t snr; bool mde_present : 1; bool cc_present : 1; bool cap_rm_neighbor_report : 1;
@@ -89,6 +90,7 @@ struct scan_bss { bool dpp_configurator : 1; bool sae_pw_id_used : 1; bool sae_pw_id_exclusive : 1; + bool have_snr : 1; };struct scan_parameters {
Signature · 1 line
2.34.1
PATCH 9/10 scan: add flag if BSS load was advertised
In reply to James PrestwoodFor ranking purposes the utilization was defaulted to a valid (127) which would not change the rank if that IE was not found in the scan results. Historically this was printed (debug) as part of the scan results but that was removed as it was somewhat confusing. i.e. did the AP _really_ have a utilization of 127? or was the IE not found?
Since it is useful to see the BSS load if that is advertised add a flag to the scan_bss struct to indicate if the IE was present which can be checked.
--- src/scan.c | 14 ++++++++------ src/scan.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-)
src/scan.c +8 -6
@@ -1344,6 +1344,8 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, NULL) < 0)l_warn ("Unable to parse BSS Load IE for " MAC ,MAC_STR (bss->addr)); + else + bss->have_utilization = true;break ;case IE_TYPE_VENDOR_SPECIFIC :
@@ -1533,7 +1535,6 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr,size_t beacon_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)) {
@@ -1704,10 +1705,12 @@ static void scan_bss_compute_rank(struct scan_bss *bss) rank *=RANK_6G_FACTOR ;/* Rank loaded APs lower and lightly loaded APs higher */ -if (bss->utilization >=192 ) - rank *=RANK_HIGH_UTILIZATION_FACTOR ; -else if (bss->utilization <=63 ) - rank *=RANK_LOW_UTILIZATION_FACTOR ; +if (bss->have_utilization) { +if (bss->utilization >=192 ) + rank *=RANK_HIGH_UTILIZATION_FACTOR ; +else if (bss->utilization <=63 ) + rank *=RANK_LOW_UTILIZATION_FACTOR ; + }if (bss->have_snr) {if (bss->snr <=15 )
@@ -1734,7 +1737,6 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu, 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;
src/scan.h +1 -0
@@ -91,6 +91,7 @@ struct scan_bss { bool sae_pw_id_used : 1; bool sae_pw_id_exclusive : 1; bool have_snr : 1; + bool have_utilization : 1; };struct scan_parameters {
Signature · 1 line
2.34.1
PATCH 10/10 station: refactor the printing of scan results, print SNR/load
In reply to James PrestwoodThere are a few values which are nice to see in debug logs. Namely the BSS load and SNR. Both of these values may not be available either due to the AP or local hardware limiations. Rather than print dummy values for these refactor the print so append the values only if they are set in the scan result.
--- src/station.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-)
src/station.c +23 -14
@@ -402,6 +402,27 @@ static int bss_signal_strength_compare(const void *a, const void *b, void *user)return (bss->signal_strength > new_bss->signal_strength) ?1 :-1 ; } +static void station_print_scan_bss (const struct scan_bss *bss) +{ +uint32_t kbps100 =DIV_ROUND_CLOSEST (bss->data_rate,100000 ); +char optional[64 ] = {0 }; +char *ptr = optional; + +if (bss->have_snr) + ptr +=sprintf (ptr,", snr: %d" , bss->snr); + +if (bss->have_utilization) + ptr +=sprintf (ptr,", load: %u/255" , bss->utilization); + +l_debug ("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, " +"strength: %i, data_rate: %u.%u%s" , +util_address_to_string (bss->addr), +util_ssid_to_utf8 (bss->ssid_len, bss->ssid), + bss->frequency, bss->rank, bss->signal_strength, + kbps100 /10 , kbps100 %10 , + optional); +} +/* * Returns the network object the BSS was added to or NULL if ignored. */
@@ -412,14 +433,8 @@ static struct network *station_add_seen_bss(struct station *station,enum security security;const char *path;char ssid[33 ]; -uint32_t kbps100 =DIV_ROUND_CLOSEST (bss->data_rate,100000 ); -l_debug ("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u, " -"strength: %i, data_rate: %u.%u" , -util_address_to_string (bss->addr), -util_ssid_to_utf8 (bss->ssid_len, bss->ssid), - bss->frequency, bss->rank, bss->signal_strength, - kbps100 /10 , kbps100 %10 ); +station_print_scan_bss (bss);if (util_ssid_is_hidden (bss->ssid_len, bss->ssid)) {l_debug ("BSS has hidden SSID" );
@@ -2655,15 +2670,9 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,while ((bss =l_queue_pop_head (bss_list))) {double rank; -uint32_t kbps100 =DIV_ROUND_CLOSEST (bss->data_rate,100000 );struct roam_bss *rbss; -l_debug ("Processing BSS '%s' with SSID: %s, freq: %u, rank: %u," -" strength: %i, data_rate: %u.%u" , -util_address_to_string (bss->addr), -util_ssid_to_utf8 (bss->ssid_len, bss->ssid), - bss->frequency, bss->rank, bss->signal_strength, - kbps100 /10 , kbps100 %10 ); +station_print_scan_bss (bss);/* Skip the BSS we are connected to */ if (!memcmp (bss->addr, station->connected_bss->addr,6 ))
Signature · 1 line
2.34.1
Hi James,
Quoted 7 lines · James Prestwood
This warning is guaranteed to happen for SAE networks where there are multiple
netdev_authenticate_events. This should just be a check so we don't register eapol twice, not a warning.--- src/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
All applied, thanks.
Regards,
-Denis