eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit a35edc66175cebf056ff9f73daf884b23f8597f4
parent 3c8e058f4fe73fe33d090717a8801656c894b0ea
Author: illiliti <illiliti@protonmail.com>
Date:   Wed, 21 Dec 2022 03:24:56 +0300

Merge tag '2.1'

Release 2.1

Diffstat:
M.gitignore | 2++
MChangeLog | 6++++++
Mautotests/testPSK-roam/failed_roam_test.py | 38+-------------------------------------
Mclient/command.c | 2+-
Mconfigure.ac | 4++--
Msrc/ap.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/band.c | 2++
Msrc/band.h | 8++++++++
Msrc/ft.c | 58+++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/iwd.ap.rst | 13+++++++++++--
Msrc/iwd.config.rst | 2+-
Msrc/nl80211util.c | 22+++++++++++++++++-----
Msrc/nl80211util.h | 6++++--
Msrc/scan.c | 27+++++----------------------
Msrc/station.c | 98+++++++++++++------------------------------------------------------------------
Msrc/util.c | 22++++++++++++++++++++++
Msrc/util.h | 1+
Msrc/wiphy.c | 168+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Msrc/wiphy.h | 11++++++++++-
19 files changed, 360 insertions(+), 220 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -5,6 +5,8 @@ .deps .dirstamp .cache +.ccls-cache +compile_commands.json tags cscope.* Makefile diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,9 @@ +ver 2.1: + Fix issue with handling FT-over-DS action. + Fix issue with handling scan and 6 GHz support check. + Fix issue with handling when periodic scans get aborted. + Add support for using 5 GHz frequencies in AP mode. + ver 2.0: Fix issue with handling P2P and limiting ciphers to CCMP. Fix issue with scanning before forced roaming action. diff --git a/autotests/testPSK-roam/failed_roam_test.py b/autotests/testPSK-roam/failed_roam_test.py @@ -65,7 +65,7 @@ class Test(unittest.TestCase): device.roam(self.bss_hostapd[1].bssid) # Roam should fail... - device.wait_for_event('ft-over-air-roam-failed') + device.wait_for_event('ft-roam-failed') # ... but IWD should remain connected self.assertTrue(device.state == DeviceState.connected) @@ -80,42 +80,6 @@ class Test(unittest.TestCase): condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition) - # Network sets over-DS bit, but fails to authenticate. IWD should still be - # able to roam using FT-over-Air. - def test_fallback_to_over_air(self): - self.bss_hostapd[0].set_value('wpa_key_mgmt', 'FT-PSK') - self.bss_hostapd[0].set_value('ft_over_ds', '1') - self.bss_hostapd[0].reload() - self.bss_hostapd[0].wait_for_event("AP-ENABLED") - - self.bss_hostapd[1].set_value('wpa_key_mgmt', 'FT-PSK') - self.bss_hostapd[1].set_value('ft_over_ds', '1') - self.bss_hostapd[1].reload() - self.bss_hostapd[1].wait_for_event("AP-ENABLED") - - wd = IWD(True) - - device = wd.list_devices(1)[0] - - # Drop action frames, this will prevent FT-over-DS authentication - self.rule1.enabled = True - - self.connect(wd, device, self.bss_hostapd[0]) - - device.roam(self.bss_hostapd[1].bssid) - - self.rule1.enabled = False - - # FT-over-DS should fail, and over-Air should take over leading to a - # successful roam - device.wait_for_event('try-ft-over-air') - - self.verify_roam(wd, device, self.bss_hostapd[0], self.bss_hostapd[1]) - - self.bss_hostapd[1].deauthenticate(device.address) - condition = 'obj.state == DeviceState.disconnected' - wd.wait_for_object_condition(device, condition) - def tearDown(self): os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down') os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down') diff --git a/client/command.c b/client/command.c @@ -753,7 +753,7 @@ options_parsed: argv += optind; argc -= optind; - if (argc < 2) { + if (argc < 1) { interactive_mode = true; return false; } diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([iwd],[2.0]) +AC_INIT([iwd],[2.1]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -268,7 +268,7 @@ if (test "${enable_external_ell}" = "yes"); then test "${enable_monitor}" != "no" || test "${enable_wired}" = "yes" || test "${enable_hwsim}" = "yes"); then - ell_min_version="0.54" + ell_min_version="0.55" else ell_min_version="0.5" fi diff --git a/src/ap.c b/src/ap.c @@ -70,6 +70,7 @@ struct ap_state { char ssid[33]; char passphrase[64]; uint8_t psk[32]; + enum band_freq band; uint8_t channel; uint8_t *authorized_macs; unsigned int authorized_macs_num; @@ -985,7 +986,7 @@ static uint32_t ap_send_mgmt_frame(struct ap_state *ap, frame_xchg_cb_t callback, void *user_data) { - uint32_t ch_freq = band_channel_to_freq(ap->channel, BAND_FREQ_2_4_GHZ); + uint32_t ch_freq = band_channel_to_freq(ap->channel, ap->band); uint64_t wdev_id = netdev_get_wdev_id(ap->netdev); struct iovec iov[2]; @@ -2408,7 +2409,7 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap) uint32_t nl_akm = CRYPTO_AKM_PSK; uint32_t wpa_version = NL80211_WPA_VERSION_2; uint32_t auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; - uint32_t ch_freq = band_channel_to_freq(ap->channel, BAND_FREQ_2_4_GHZ); + uint32_t ch_freq = band_channel_to_freq(ap->channel, ap->band); uint32_t ch_width = NL80211_CHAN_WIDTH_20; unsigned int i; @@ -3170,6 +3171,33 @@ static char **ap_ciphers_to_strv(uint16_t ciphers) return list; } +static bool ap_validate_band_channel(struct ap_state *ap) +{ + struct wiphy *wiphy = netdev_get_wiphy(ap->netdev); + uint32_t freq; + const struct band_freq_attrs *attr; + + if (!(wiphy_get_supported_bands(wiphy) & ap->band)) { + l_error("AP hardware does not support band"); + return -EINVAL; + } + + freq = band_channel_to_freq(ap->channel, ap->band); + if (!freq) { + l_error("AP invalid band (%s) and channel (%u) combination", + (ap->band & BAND_FREQ_5_GHZ) ? "5Ghz" : "2.4GHz", + ap->channel); + return false; + } + + attr = wiphy_get_frequency_info(wiphy, freq); + if (!attr || attr->disabled) { + l_error("AP frequency %u disabled or unsupported", freq); + return false; + } + return true; +} + static int ap_load_config(struct ap_state *ap, const struct l_settings *config, bool *out_cck_rates) { @@ -3214,17 +3242,31 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config, unsigned int uintval; if (!l_settings_get_uint(config, "General", "Channel", - &uintval) || - !band_channel_to_freq(uintval, - BAND_FREQ_2_4_GHZ)) { + &uintval)) { l_error("AP Channel value unsupported"); return -EINVAL; } ap->channel = uintval; - } else + + /* + * 6GHz is not supported so we can use only a channel number to + * distinguish between 2.4 and 5GHz. + */ + if (ap->channel >= 36) + ap->band = BAND_FREQ_5_GHZ; + else + ap->band = BAND_FREQ_2_4_GHZ; + } else { /* TODO: Start a Get Survey to decide the channel */ ap->channel = 6; + ap->band = BAND_FREQ_2_4_GHZ; + } + + if (!ap_validate_band_channel(ap)) { + l_error("AP Band and Channel combination invalid"); + return -EINVAL; + } strval = l_settings_get_string(config, "WSC", "DeviceName"); if (strval) { @@ -3290,7 +3332,13 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config, l_strfreev(strvval); } - if (l_settings_get_value(config, "General", "NoCCKRates")) { + /* + * Since 5GHz won't ever support only CCK rates we can ignore this + * setting on that band. + */ + if (ap->band & BAND_FREQ_5_GHZ) + *out_cck_rates = false; + else if (l_settings_get_value(config, "General", "NoCCKRates")) { bool boolval; if (!l_settings_get_bool(config, "General", "NoCCKRates", @@ -3381,6 +3429,9 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config, uint64_t wdev_id = netdev_get_wdev_id(netdev); int err; bool cck_rates = true; + const uint8_t *rates; + unsigned int num_rates; + unsigned int i; if (L_WARN_ON(!config)) { if (err_out) @@ -3406,22 +3457,17 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config, wsc_uuid_from_addr(netdev_get_address(netdev), ap->wsc_uuid_r); + rates = wiphy_get_supported_rates(wiphy, ap->band, &num_rates); + if (!rates) + goto error; + ap->rates = l_uintset_new(200); - /* TODO: Pick from actual supported rates */ - if (!cck_rates) { - l_uintset_put(ap->rates, 12); /* 6 Mbps*/ - l_uintset_put(ap->rates, 18); /* 9 Mbps*/ - l_uintset_put(ap->rates, 24); /* 12 Mbps*/ - l_uintset_put(ap->rates, 36); /* 18 Mbps*/ - l_uintset_put(ap->rates, 48); /* 24 Mbps*/ - l_uintset_put(ap->rates, 72); /* 36 Mbps*/ - l_uintset_put(ap->rates, 96); /* 48 Mbps*/ - l_uintset_put(ap->rates, 108); /* 54 Mbps*/ - } else { - l_uintset_put(ap->rates, 2); /* 1 Mbps*/ - l_uintset_put(ap->rates, 11); /* 5.5 Mbps*/ - l_uintset_put(ap->rates, 22); /* 11 Mbps*/ + for (i = 0; i < num_rates; i++) { + if (cck_rates && !L_IN_SET(rates[i], 2, 4, 11, 22)) + continue; + + l_uintset_put(ap->rates, rates[i]); } if (!frame_watch_add(wdev_id, 0, 0x0000 | @@ -4080,7 +4126,7 @@ static bool ap_dbus_property_get_freq(struct l_dbus *dbus, if (!ap_if->ap || !ap_if->ap->started) return false; - freq = band_channel_to_freq(ap_if->ap->channel, BAND_FREQ_2_4_GHZ); + freq = band_channel_to_freq(ap_if->ap->channel, ap_if->ap->band); l_dbus_message_builder_append_basic(builder, 'u', &freq); diff --git a/src/band.c b/src/band.c @@ -36,6 +36,8 @@ void band_free(struct band *band) if (band->he_capabilities) l_queue_destroy(band->he_capabilities, l_free); + l_free(band->freq_attrs); + l_free(band); } diff --git a/src/band.h b/src/band.h @@ -55,8 +55,16 @@ struct band_he_capabilities { uint8_t he_mcs_set[12]; }; +struct band_freq_attrs { + bool supported : 1; + bool disabled : 1; + bool no_ir : 1; +} __attribute__ ((packed)); + struct band { enum band_freq freq; + struct band_freq_attrs *freq_attrs; + size_t freqs_len; /* Each entry is type struct band_he_capabilities */ struct l_queue *he_capabilities; uint8_t vht_mcs_set[8]; diff --git a/src/ft.c b/src/ft.c @@ -54,8 +54,12 @@ struct ft_info { uint8_t *authenticator_ie; uint8_t prev_bssid[6]; uint32_t frequency; + uint32_t ds_frequency; uint32_t offchannel_id; + struct l_timeout *timeout; + struct wiphy_radio_work_item work; + struct ie_ft_info ft_info; bool parsed : 1; @@ -830,6 +834,11 @@ void __ft_rx_action(uint32_t ifindex, const uint8_t *frame, size_t frame_len) info->parsed = true; + l_timeout_remove(info->timeout); + info->timeout = NULL; + + wiphy_radio_work_done(netdev_get_wiphy(netdev), info->work.id); + return; ft_error: @@ -868,6 +877,9 @@ static void ft_info_destroy(void *data) if (info->authenticator_ie) l_free(info->authenticator_ie); + if (info->timeout) + l_timeout_remove(info->timeout); + l_free(info); } @@ -900,19 +912,17 @@ static void ft_prepare_handshake(struct ft_info *info, handshake_state_derive_ptk(hs); } -int ft_action(uint32_t ifindex, uint32_t freq, const struct scan_bss *target) +static bool ft_send_action(struct wiphy_radio_work_item *work) { - struct netdev *netdev = netdev_find(ifindex); + struct ft_info *info = l_container_of(work, struct ft_info, work); + struct netdev *netdev = netdev_find(info->ifindex); struct handshake_state *hs = netdev_get_handshake(netdev); - struct ft_info *info; uint8_t ft_req[14]; struct iovec iov[5]; uint8_t ies[512]; size_t len; int ret = -EINVAL; - info = ft_info_new(hs, target); - ft_req[0] = 6; /* FT category */ ft_req[1] = 1; /* FT Request action */ memcpy(ft_req + 2, info->spa, 6); @@ -928,17 +938,47 @@ int ft_action(uint32_t ifindex, uint32_t freq, const struct scan_bss *target) iov[1].iov_base = ies; iov[1].iov_len = len; - ret = tx_frame(hs->ifindex, 0x00d0, freq, hs->aa, iov, 2); + ret = tx_frame(hs->ifindex, 0x00d0, info->ds_frequency, hs->aa, iov, 2); if (ret < 0) goto failed; l_queue_push_tail(info_list, info); - return 0; + return false; failed: - l_free(info); - return ret; + l_debug("FT-over-DS action failed to "MAC, MAC_STR(hs->aa)); + + ft_info_destroy(info); + return true; +} + +struct wiphy_radio_work_item_ops ft_ops = { + .do_work = ft_send_action, +}; + +static void ft_ds_timeout(struct l_timeout *timeout, void *user_data) +{ + struct ft_info *info = user_data; + struct netdev *netdev = netdev_find(info->ifindex); + + wiphy_radio_work_done(netdev_get_wiphy(netdev), info->work.id); +} + +int ft_action(uint32_t ifindex, uint32_t freq, const struct scan_bss *target) +{ + struct netdev *netdev = netdev_find(ifindex); + struct handshake_state *hs = netdev_get_handshake(netdev); + struct ft_info *info; + + info = ft_info_new(hs, target); + info->ds_frequency = freq; + info->timeout = l_timeout_create_ms(200, ft_ds_timeout, info, NULL); + + wiphy_radio_work_insert(netdev_get_wiphy(netdev), &info->work, + WIPHY_WORK_PRIORITY_FT, &ft_ops); + + return 0; } void __ft_rx_authenticate(uint32_t ifindex, const uint8_t *frame, diff --git a/src/iwd.ap.rst b/src/iwd.ap.rst @@ -55,8 +55,17 @@ The group ``[General]`` contains general AP configuration. * - Channel - Channel number - Optional channel number for the access point to operate on. Only the - 2.4GHz-band channels are currently allowed. + Optional channel number for the access point to operate on. If omitted + the channel will be chosen automatically. Channels greater than or equal + to 36 will select the 5GHz band for the AP to operate on. + + Note: Due to regulatory requirements the linux kernel does not allow or + strictly limits 5GHz use in AP mode while in world roaming. These + frequencies become available once the country is set, either via IWD's + main.conf option ``[General].Country`` (see ``man iwd.config``) or + externally (e.g. iw reg set <CC>). If you are having trouble using 5GHz + ensure the country is set, and that the desired frequency/channel is + unrestricted. Network Authentication Settings ------------------------------- diff --git a/src/iwd.config.rst b/src/iwd.config.rst @@ -232,7 +232,7 @@ The group ``[Network]`` contains network configuration related settings. Sets the global default that tells **iwd** whether it should configure IPv6 addresses and routes (either provided via static settings, - Router Advertisements or DHCPv6 protocol). This setting is disabled + Router Advertisements or DHCPv6 protocol). This setting is enabled by default. This setting can also be overridden on a per-network basis. * - NameResolvingService diff --git a/src/nl80211util.c b/src/nl80211util.c @@ -502,19 +502,21 @@ int nl80211_parse_chandef(struct l_genl_msg *msg, struct band_chandef *out) int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs, struct scan_freq_set *supported_list, - struct scan_freq_set *disabled_list) + struct band_freq_attrs *list, + size_t num_channels) { uint16_t type, len; const void *data; struct l_genl_attr attr; struct l_genl_attr nested; + uint8_t channel; if (!l_genl_attr_recurse(band_freqs, &nested)) return -EBADMSG; while (l_genl_attr_next(&nested, NULL, NULL, NULL)) { uint32_t freq = 0; - bool disabled = false; + struct band_freq_attrs freq_attr = { 0 }; if (!l_genl_attr_recurse(&nested, &attr)) continue; @@ -523,9 +525,13 @@ int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs, switch (type) { case NL80211_FREQUENCY_ATTR_FREQ: freq = *((uint32_t *) data); + freq_attr.supported = true; break; case NL80211_FREQUENCY_ATTR_DISABLED: - disabled = true; + freq_attr.disabled = true; + break; + case NL80211_FREQUENCY_ATTR_NO_IR: + freq_attr.no_ir = true; break; } } @@ -533,11 +539,17 @@ int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs, if (!freq) continue; + channel = band_freq_to_channel(freq, NULL); + if (!channel) + continue; + + if (L_WARN_ON(channel > num_channels)) + continue; + if (supported_list) scan_freq_set_add(supported_list, freq); - if (disabled && disabled_list) - scan_freq_set_add(disabled_list, freq); + list[channel] = freq_attr; } return 0; diff --git a/src/nl80211util.h b/src/nl80211util.h @@ -24,6 +24,7 @@ struct band_chandef; struct scan_freq_set; +struct band_freq_attrs; int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...); @@ -58,5 +59,6 @@ struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex, int nl80211_parse_chandef(struct l_genl_msg *msg, struct band_chandef *out); int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs, - struct scan_freq_set *supported, - struct scan_freq_set *disabled); + struct scan_freq_set *supported_list, + struct band_freq_attrs *list, + size_t num_channels); diff --git a/src/scan.c b/src/scan.c @@ -83,7 +83,6 @@ struct scan_request { bool canceled : 1; /* Is scan_cancel being called on this request? */ bool passive:1; /* Active or Passive scan? */ bool started : 1; /* Has TRIGGER_SCAN succeeded at least once? */ - bool periodic : 1; /* Started as a periodic scan? */ /* * Set to true if the TRIGGER_SCAN command at the head of the 'cmds' * queue was acked by the kernel indicating that the scan request was @@ -426,7 +425,7 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, * rates we don't want to advertise support for 802.11b rates. */ if (L_WARN_ON(!(supported = wiphy_get_supported_rates(sc->wiphy, - NL80211_BAND_2GHZ, + BAND_FREQ_2_4_GHZ, &num_supported)))) goto done; @@ -997,7 +996,6 @@ static void scan_periodic_destroy(void *user_data) static bool scan_periodic_queue(struct scan_context *sc) { struct scan_parameters params = {}; - struct scan_request *sr; if (sc->sp.needs_active_scan && known_networks_has_hidden()) { params.randomize_mac_addr_hint = true; @@ -1015,13 +1013,7 @@ static bool scan_periodic_queue(struct scan_context *sc) scan_periodic_notify, sc, scan_periodic_destroy); - if (!sc->sp.id) - return false; - - sr = l_queue_peek_tail(sc->requests); - sr->periodic = true; - - return true; + return sc->sp.id != 0; } static bool scan_periodic_is_disabled(void) @@ -1933,12 +1925,9 @@ static void scan_wiphy_watch(struct wiphy *wiphy, struct scan_freq_set *freqs_6ghz; struct scan_freq_set *allowed; bool allow_6g; - const struct scan_freq_set *supported = - wiphy_get_supported_freqs(wiphy); - /* Only care about regulatory events, and if 6GHz capable */ - if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE || - !(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ)) + /* Only care about completed regulatory dumps */ + if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE) return; if (!sc->sp.id) @@ -2242,13 +2231,7 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data) if (sr->triggered) { sr->triggered = false; - - /* If periodic scan, don't report the abort */ - if (sr->periodic) { - l_queue_remove(sc->requests, sr); - wiphy_radio_work_done(sc->wiphy, sr->work.id); - } else - scan_finished(sc, -ECANCELED, NULL, NULL, sr); + scan_finished(sc, -ECANCELED, NULL, NULL, sr); } else if (wiphy_radio_work_is_running(sc->wiphy, sr->work.id)) { /* diff --git a/src/station.c b/src/station.c @@ -1409,8 +1409,6 @@ static int station_quick_scan_trigger(struct station *station) { _auto_(scan_freq_set_free) struct scan_freq_set *known_freq_set = NULL; bool known_6ghz; - const struct scan_freq_set *disabled = wiphy_get_disabled_freqs( - station->wiphy); if (wiphy_regdom_is_updating(station->wiphy)) { l_debug("regdom is updating, delaying quick scan"); @@ -1432,9 +1430,11 @@ static int station_quick_scan_trigger(struct station *station) * this since its so limited, so return an error which will fall back to * full autoconnect. */ - if ((scan_freq_set_get_bands(disabled) & BAND_FREQ_6_GHZ) && - wiphy_country_is_unknown(station->wiphy) && - known_6ghz) + if (wiphy_get_supported_bands(station->wiphy) & BAND_FREQ_6_GHZ && + wiphy_band_is_disabled(station->wiphy, + BAND_FREQ_6_GHZ) && + wiphy_country_is_unknown(station->wiphy) && + known_6ghz) return -ENOTSUP; if (!wiphy_constrain_freq_set(station->wiphy, known_freq_set)) { @@ -1826,10 +1826,6 @@ static void parse_neighbor_report(struct station *station, struct scan_freq_set *freq_set_md, *freq_set_no_md; uint32_t current_freq = 0; struct handshake_state *hs = netdev_get_handshake(station->netdev); - const struct scan_freq_set *supported = - wiphy_get_supported_freqs(station->wiphy); - const struct scan_freq_set *disabled = - wiphy_get_disabled_freqs(station->wiphy); freq_set_md = scan_freq_set_new(); freq_set_no_md = scan_freq_set_new(); @@ -1842,6 +1838,7 @@ static void parse_neighbor_report(struct station *station, uint32_t freq; enum band_freq band; const uint8_t *cc = NULL; + const struct band_freq_attrs *attr; if (ie_tlv_iter_get_tag(&iter) != IE_TYPE_NEIGHBOR_REPORT) continue; @@ -1867,8 +1864,8 @@ static void parse_neighbor_report(struct station *station, continue; /* Skip if frequency is not supported or disabled */ - if (!scan_freq_set_contains(supported, freq) || - scan_freq_set_contains(disabled, freq)) + attr = wiphy_get_frequency_info(station->wiphy, freq); + if (!attr || attr->disabled) continue; if (!memcmp(info.addr, @@ -1987,47 +1984,6 @@ static bool station_can_fast_transition(struct handshake_state *hs, return true; } -static void station_ft_ds_action_start(struct station *station) -{ - struct handshake_state *hs = netdev_get_handshake(station->netdev); - uint16_t mdid; - const struct l_queue_entry *entry; - struct scan_bss *bss; - struct ie_rsn_info rsn_info; - - if (!station_can_fast_transition(hs, station->connected_bss) || - !(hs->mde[4] & 1)) - return; - - if (ie_parse_mobility_domain_from_data(hs->mde, hs->mde[1] + 2, - &mdid, NULL, NULL) < 0) - return; - - for (entry = network_bss_list_get_entries(station->connected_network); - entry; entry = entry->next) { - bss = entry->data; - - if (bss == station->connected_bss) - continue; - - if (mdid != l_get_le16(bss->mde)) - continue; - - if (scan_bss_get_rsn_info(bss, &rsn_info) < 0) - continue; - - if (!IE_AKM_IS_FT(rsn_info.akm_suites)) - continue; - - /* - * Fire and forget. Netdev will maintain a cache of responses - * and when the time comes these can be referenced for a roam - */ - ft_action(netdev_get_ifindex(station->netdev), - station->connected_bss->frequency, bss); - } -} - static void station_roamed(struct station *station) { station->roam_scan_full = false; @@ -2056,8 +2012,6 @@ static void station_roamed(struct station *station) l_queue_clear(station->roam_bss_list, l_free); - station_ft_ds_action_start(station); - station_enter_state(station, STATION_STATE_CONNECTED); } @@ -2311,7 +2265,7 @@ static bool station_ft_work_ready(struct wiphy_radio_work_item *item) ret = ft_associate(netdev_get_ifindex(station->netdev), bss->addr); if (ret == -ENOENT) { - station_debug_event(station, "ft-over-air-roam-failed"); + station_debug_event(station, "ft-roam-failed"); try_next: station_transition_start(station); return true; @@ -2341,7 +2295,6 @@ static bool station_fast_transition(struct station *station, const struct network_info *info = network_get_info(connected); const struct iovec *vendor_ies; size_t iov_elems = 0; - int ret; /* Rebuild handshake RSN for target AP */ if (station_build_handshake_rsn(hs, station->wiphy, @@ -2352,34 +2305,17 @@ static bool station_fast_transition(struct station *station, vendor_ies = network_info_get_extra_ies(info, bss, &iov_elems); handshake_state_set_vendor_ies(hs, vendor_ies, iov_elems); - if ((hs->mde[4] & 1)) { - ret = ft_associate(netdev_get_ifindex(station->netdev), - bss->addr); - /* No action responses from this BSS, try over air */ - if (ret == -ENOENT) { - station_debug_event(station, "try-ft-over-air"); - goto try_over_air; - } else if (ret < 0) - return false; - - station->connected_bss = bss; - station->preparing_roam = false; - station_enter_state(station, STATION_STATE_FT_ROAMING); - - return true; - } else { -try_over_air: - /* - * Send FT-Authenticate and insert a work item which will be - * gated until authentication completes - */ + /* Both ft_action/ft_authenticate will gate the associate work item */ + if ((hs->mde[4] & 1)) + ft_action(netdev_get_ifindex(station->netdev), + station->connected_bss->frequency, bss); + else ft_authenticate(netdev_get_ifindex(station->netdev), bss); - wiphy_radio_work_insert(station->wiphy, &station->ft_work, + wiphy_radio_work_insert(station->wiphy, &station->ft_work, WIPHY_WORK_PRIORITY_CONNECT, &ft_work_ops); - return true; - } + return true; } static bool station_try_next_transition(struct station *station, @@ -3131,8 +3067,6 @@ static void station_connect_ok(struct station *station) l_warn("Could not request neighbor report"); } - station_ft_ds_action_start(station); - network_connected(station->connected_network); if (station->netconfig) { diff --git a/src/util.c b/src/util.c @@ -360,6 +360,28 @@ bool scan_freq_set_add(struct scan_freq_set *freqs, uint32_t freq) return false; } +bool scan_freq_set_remove(struct scan_freq_set *freqs, uint32_t freq) +{ + enum band_freq band; + uint8_t channel; + + channel = band_freq_to_channel(freq, &band); + if (!channel) + return false; + + switch (band) { + case BAND_FREQ_2_4_GHZ: + freqs->channels_2ghz &= ~(1 << (channel - 1)); + return true; + case BAND_FREQ_5_GHZ: + return l_uintset_take(freqs->channels_5ghz, channel); + case BAND_FREQ_6_GHZ: + return l_uintset_take(freqs->channels_6ghz, channel); + } + + return false; +} + bool scan_freq_set_contains(const struct scan_freq_set *freqs, uint32_t freq) { enum band_freq band; diff --git a/src/util.h b/src/util.h @@ -111,6 +111,7 @@ typedef void (*scan_freq_set_func_t)(uint32_t freq, void *userdata); struct scan_freq_set *scan_freq_set_new(void); void scan_freq_set_free(struct scan_freq_set *freqs); bool scan_freq_set_add(struct scan_freq_set *freqs, uint32_t freq); +bool scan_freq_set_remove(struct scan_freq_set *freqs, uint32_t freq); bool scan_freq_set_contains(const struct scan_freq_set *freqs, uint32_t freq); uint32_t scan_freq_set_get_bands(const struct scan_freq_set *freqs); void scan_freq_set_foreach(const struct scan_freq_set *freqs, diff --git a/src/wiphy.c b/src/wiphy.c @@ -496,6 +496,67 @@ const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy) return wiphy->disabled_freqs; } +static struct band *wiphy_get_band(const struct wiphy *wiphy, enum band_freq band) +{ + switch (band) { + case BAND_FREQ_2_4_GHZ: + return wiphy->band_2g; + case BAND_FREQ_5_GHZ: + return wiphy->band_5g; + case BAND_FREQ_6_GHZ: + return wiphy->band_6g; + default: + return NULL; + } +} + +const struct band_freq_attrs *wiphy_get_frequency_info( + const struct wiphy *wiphy, + uint32_t freq) +{ + struct band_freq_attrs *attr; + enum band_freq band; + uint8_t channel; + struct band *bandp; + + channel = band_freq_to_channel(freq, &band); + if (!channel) + return NULL; + + bandp = wiphy_get_band(wiphy, band); + if (!bandp) + return NULL; + + attr = &bandp->freq_attrs[channel]; + if (!attr->supported) + return NULL; + + return attr; +} + +bool wiphy_band_is_disabled(const struct wiphy *wiphy, enum band_freq band) +{ + struct band_freq_attrs attr; + unsigned int i; + struct band *bandp; + + bandp = wiphy_get_band(wiphy, band); + if (!bandp) + return true; + + for (i = 0; i < bandp->freqs_len; i++) { + attr = bandp->freq_attrs[i]; + + if (!attr.supported) + continue; + + if (!attr.disabled) + return false; + } + + return true; +} + bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy) { return wiphy->ap_probe_resp_offload; @@ -745,8 +806,35 @@ void wiphy_generate_address_from_ssid(struct wiphy *wiphy, const char *ssid, bool wiphy_constrain_freq_set(const struct wiphy *wiphy, struct scan_freq_set *set) { + struct band *bands[3] = { wiphy->band_2g, + wiphy->band_5g, wiphy->band_6g }; + unsigned int b; + unsigned int i; + scan_freq_set_constrain(set, wiphy->supported_freqs); - scan_freq_set_subtract(set, wiphy->disabled_freqs); + + for (b = 0; b < L_ARRAY_SIZE(bands); b++) { + struct band *band = bands[b]; + + if (!band) + continue; + + for (i = 0; i < band->freqs_len; i++) { + uint32_t freq; + + if (!band->freq_attrs[i].supported) + continue; + + if (!band->freq_attrs[i].disabled) + continue; + + freq = band_channel_to_freq(i, band->freq); + if (!freq) + continue; + + scan_freq_set_remove(set, freq); + } + } if (!scan_freq_set_get_bands(set)) /* The set is empty. */ @@ -788,24 +876,11 @@ 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, +const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, + enum band_freq band, unsigned int *out_num) { - struct band *bandp; - - switch (band) { - case NL80211_BAND_2GHZ: - bandp = wiphy->band_2g; - break; - case NL80211_BAND_5GHZ: - bandp = wiphy->band_5g; - break; - case NL80211_BAND_6GHZ: - bandp = wiphy->band_6g; - break; - default: - return NULL; - } + struct band *bandp = wiphy_get_band(wiphy, band); if (!bandp) return NULL; @@ -863,19 +938,9 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy, if (band_freq_to_channel(bss->frequency, &band) == 0) return -ENOTSUP; - switch (band) { - case BAND_FREQ_2_4_GHZ: - bandp = wiphy->band_2g; - break; - case BAND_FREQ_5_GHZ: - bandp = wiphy->band_5g; - break; - case BAND_FREQ_6_GHZ: - bandp = wiphy->band_6g; - break; - default: + bandp = wiphy_get_band(wiphy, band); + if (!bandp) return -ENOTSUP; - } ie_tlv_iter_init(&iter, ies, ies_len); @@ -951,7 +1016,7 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy, bool wiphy_regdom_is_updating(struct wiphy *wiphy) { - return wiphy->pending_freqs != NULL; + return wiphy->dump_id || (!wiphy->self_managed && wiphy_dump_id); } uint32_t wiphy_state_watch_add(struct wiphy *wiphy, @@ -1470,19 +1535,23 @@ static void parse_supported_bands(struct wiphy *wiphy, struct band **bandp; struct band *band; enum band_freq freq; + size_t num_channels; switch (type) { case NL80211_BAND_2GHZ: bandp = &wiphy->band_2g; freq = BAND_FREQ_2_4_GHZ; + num_channels = 14; break; case NL80211_BAND_5GHZ: bandp = &wiphy->band_5g; freq = BAND_FREQ_5_GHZ; + num_channels = 196; break; case NL80211_BAND_6GHZ: bandp = &wiphy->band_6g; freq = BAND_FREQ_6_GHZ; + num_channels = 233; break; default: continue; @@ -1497,6 +1566,9 @@ static void parse_supported_bands(struct wiphy *wiphy, continue; band->freq = freq; + band->freq_attrs = l_new(struct band_freq_attrs, + num_channels); + band->freqs_len = num_channels; /* Reset iter to beginning */ if (!l_genl_attr_recurse(bands, &attr)) { @@ -1506,7 +1578,6 @@ static void parse_supported_bands(struct wiphy *wiphy, } else band = *bandp; - while (l_genl_attr_next(&attr, &type, &len, &data)) { struct l_genl_attr nested; @@ -1514,7 +1585,8 @@ static void parse_supported_bands(struct wiphy *wiphy, case NL80211_BAND_ATTR_FREQS: nl80211_parse_supported_frequencies(&attr, wiphy->supported_freqs, - wiphy->disabled_freqs); + band->freq_attrs, + band->freqs_len); break; case NL80211_BAND_ATTR_RATES: @@ -1975,6 +2047,7 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, struct l_genl_attr bands; struct l_genl_attr attr; uint16_t type; + struct band *band; if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &id, NL80211_ATTR_WIPHY_BANDS, &bands, @@ -1985,7 +2058,28 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, if (L_WARN_ON(!wiphy)) return; - while (l_genl_attr_next(&bands, NULL, NULL, NULL)) { + /* Unregistered means the wiphy is blacklisted, don't bother parsing */ + if (!wiphy->registered) + return; + + while (l_genl_attr_next(&bands, &type, NULL, NULL)) { + switch (type) { + case NL80211_BAND_2GHZ: + band = wiphy->band_2g; + break; + case NL80211_BAND_5GHZ: + band = wiphy->band_5g; + break; + case NL80211_BAND_6GHZ: + band = wiphy->band_6g; + break; + default: + continue; + } + + if (L_WARN_ON(!band)) + continue; + if (!l_genl_attr_recurse(&bands, &attr)) return; @@ -1993,8 +2087,14 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, if (type != NL80211_BAND_ATTR_FREQS) continue; + /* + * Just write over the old list for each frequency. In + * theory no new frequencies should be added so there + * should never be any stale values. + */ nl80211_parse_supported_frequencies(&attr, NULL, - wiphy->pending_freqs); + band->freq_attrs, + band->freqs_len); } } } diff --git a/src/wiphy.h b/src/wiphy.h @@ -28,7 +28,9 @@ struct scan_bss; struct scan_freq_set; struct wiphy_radio_work_item; struct ie_rsn_info; +struct band_freq_attrs; enum security; +enum band_freq; typedef bool (*wiphy_radio_work_func_t)(struct wiphy_radio_work_item *item); typedef void (*wiphy_radio_work_destroy_func_t)( @@ -99,6 +101,12 @@ uint32_t wiphy_get_supported_bands(struct wiphy *wiphy); const struct scan_freq_set *wiphy_get_supported_freqs( const struct wiphy *wiphy); const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy); + +const struct band_freq_attrs *wiphy_get_frequency_info( + const struct wiphy *wiphy, + uint32_t freq); +bool wiphy_band_is_disabled(const struct wiphy *wiphy, enum band_freq band); + bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy); bool wiphy_can_transition_disable(struct wiphy *wiphy); bool wiphy_can_offload(struct wiphy *wiphy); @@ -112,7 +120,8 @@ uint8_t wiphy_get_max_num_ssids_per_scan(struct wiphy *wiphy); uint16_t wiphy_get_max_scan_ie_len(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, +const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, + enum band_freq band, unsigned int *out_num); bool wiphy_supports_adhoc_rsn(struct wiphy *wiphy); bool wiphy_can_offchannel_tx(struct wiphy *wiphy);