eiwd

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

commit 9ced98883cae801b10e4e44f278844dc837df5d5
parent c0d033b80c7d321ba17cf062497f90ea96e790bc
Author: illiliti <illiliti@protonmail.com>
Date:   Mon, 29 Mar 2021 20:28:17 +0300

Merge tag '1.13'

Diffstat:
MChangeLog | 7+++++++
Mclient/diagnostic.c | 1+
Mconfigure.ac | 4++--
Mdoc/station-diagnostic-api.txt | 2++
Mmonitor/nlmon.c | 82++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/diagnostic.c | 4++++
Msrc/diagnostic.h | 2++
Msrc/eapol.c | 1+
Msrc/eapolutil.c | 1+
Msrc/handshake.h | 1+
Msrc/netdev.c | 193++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/netdev.h | 2++
Msrc/network.c | 33++++++++++++++++++++++-----------
Msrc/network.h | 1+
Msrc/scan.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/scan.h | 3+++
Msrc/station.c | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/wiphy.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/wiphy.h | 2++
19 files changed, 499 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,10 @@ +ver 1.13: + Fix issue with EAPoL protocol version 2010 handling. + Fix issue with authenticator method logic handling. + Fix issue with getting scan results from firmware. + Add support for handling SAE offload connections. + Add support for roaming with FullMAC devices. + ver 1.12: Fix issue with handling retry roaming without higher RSSI. Fix issue with WPA3, OWE and FILS authentication handling. diff --git a/client/diagnostic.c b/client/diagnostic.c @@ -88,6 +88,7 @@ static const struct diagnostic_dict_mapping diagnostic_mapping[] = { { "TxBitrate", 0, NULL, display_bitrate_100kbps }, { "ExpectedThroughput", 'u', "Kbit/s" }, { "RSSI", 'n', "dBm" }, + { "AverageRSSI", 'n', "dBm" }, { "RxMCS", 'y' }, { "TxMCS", 'y' }, { "Frequency", 'u' }, diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.60) -AC_INIT(iwd, 1.12) +AC_INIT(iwd, 1.13) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -267,7 +267,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.38" + ell_min_version="0.39" else ell_min_version="0.5" fi diff --git a/doc/station-diagnostic-api.txt b/doc/station-diagnostic-api.txt @@ -25,6 +25,8 @@ Methods dict GetDiagnostics() RSSI [optional] - The RSSI of the currently connected BSS. + AverageRSSI [optional] - Average RSSI of currently connected BSS. + RxMode [optional] - The phy technology being used (802.11n, 802.11ac or 802.11ax). diff --git a/monitor/nlmon.c b/monitor/nlmon.c @@ -5415,6 +5415,85 @@ static void print_eapol(unsigned int level, const char *label, print_hexdump(level + 1, data, size); } +#define EXT_ENTRY(a) #a + +static const char *ext_feature_map[] = { + EXT_ENTRY(NL80211_EXT_FEATURE_VHT_IBSS), + EXT_ENTRY(NL80211_EXT_FEATURE_RRM), + EXT_ENTRY(NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER), + EXT_ENTRY(NL80211_EXT_FEATURE_SCAN_START_TIME), + EXT_ENTRY(NL80211_EXT_FEATURE_BSS_PARENT_TSF), + EXT_ENTRY(NL80211_EXT_FEATURE_SET_SCAN_DWELL), + EXT_ENTRY(NL80211_EXT_FEATURE_BEACON_RATE_LEGACY), + EXT_ENTRY(NL80211_EXT_FEATURE_BEACON_RATE_HT), + EXT_ENTRY(NL80211_EXT_FEATURE_BEACON_RATE_VHT), + EXT_ENTRY(NL80211_EXT_FEATURE_FILS_STA), + EXT_ENTRY(NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA), + EXT_ENTRY(NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA_CONNECTED), + EXT_ENTRY(NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI), + EXT_ENTRY(NL80211_EXT_FEATURE_CQM_RSSI_LIST), + EXT_ENTRY(NL80211_EXT_FEATURE_FILS_SK_OFFLOAD), + EXT_ENTRY(NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK), + EXT_ENTRY(NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X), + EXT_ENTRY(NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME), + EXT_ENTRY(NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP), + EXT_ENTRY(NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE), + EXT_ENTRY(NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION), + EXT_ENTRY(NL80211_EXT_FEATURE_MFP_OPTIONAL), + EXT_ENTRY(NL80211_EXT_FEATURE_LOW_SPAN_SCAN), + EXT_ENTRY(NL80211_EXT_FEATURE_LOW_POWER_SCAN), + EXT_ENTRY(NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN), + EXT_ENTRY(NL80211_EXT_FEATURE_DFS_OFFLOAD), + EXT_ENTRY(NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211), + EXT_ENTRY(NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT), + EXT_ENTRY(NL80211_EXT_FEATURE_TXQS), + EXT_ENTRY(NL80211_EXT_FEATURE_SCAN_RANDOM_SN), + EXT_ENTRY(NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT), + EXT_ENTRY(NL80211_EXT_FEATURE_CAN_REPLACE_PTK0), + EXT_ENTRY(NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER), + EXT_ENTRY(NL80211_EXT_FEATURE_AIRTIME_FAIRNESS), + EXT_ENTRY(NL80211_EXT_FEATURE_AP_PMKSA_CACHING), + EXT_ENTRY(NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD), + EXT_ENTRY(NL80211_EXT_FEATURE_EXT_KEY_ID), + EXT_ENTRY(NL80211_EXT_FEATURE_STA_TX_PWR), + EXT_ENTRY(NL80211_EXT_FEATURE_SAE_OFFLOAD), + EXT_ENTRY(NL80211_EXT_FEATURE_VLAN_OFFLOAD), + EXT_ENTRY(NL80211_EXT_FEATURE_AQL), + EXT_ENTRY(NL80211_EXT_FEATURE_BEACON_PROTECTION), + EXT_ENTRY(NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH), + EXT_ENTRY(NL80211_EXT_FEATURE_PROTECTED_TWT), + EXT_ENTRY(NL80211_EXT_FEATURE_DEL_IBSS_STA), + EXT_ENTRY(NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS), + EXT_ENTRY(NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT), + EXT_ENTRY(NL80211_EXT_FEATURE_SCAN_FREQ_KHZ), + EXT_ENTRY(NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS), + EXT_ENTRY(NL80211_EXT_FEATURE_OPERATING_CHANNEL_VALIDATION), + EXT_ENTRY(NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK), + EXT_ENTRY(NL80211_EXT_FEATURE_SAE_OFFLOAD_AP), + EXT_ENTRY(NL80211_EXT_FEATURE_FILS_DISCOVERY), + EXT_ENTRY(NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP), + EXT_ENTRY(NL80211_EXT_FEATURE_BEACON_RATE_HE), +}; + +static void print_ext_features(unsigned int level, const char *label, + const void *data, uint16_t size) +{ + int i; + uint16_t bits; + + if (L_ARRAY_SIZE(ext_feature_map) < size * 8) + bits = L_ARRAY_SIZE(ext_feature_map); + else + bits = size * 8; + + print_attr(level, "Extended Features:"); + + for (i = 0; i < bits; i++) { + if (test_bit(data, i)) + print_attr(level + 1, "%s", ext_feature_map[i]); + } +} + /* * Control Port sends a EAPoL frame inside ATTR_FRAME and not a management * frame. So a separate table with all the possible attributes is provided @@ -5911,7 +5990,8 @@ static const struct attr_entry attr_table[] = { { NL80211_ATTR_USE_RRM, "Use RRM", ATTR_FLAG }, { NL80211_ATTR_EXT_FEATURES, - "Extended Features" }, + "Extended Features", ATTR_CUSTOM, + { .function = print_ext_features} }, { NL80211_ATTR_FILS_KEK, "FILS KEK" }, { NL80211_ATTR_FILS_NONCES, diff --git a/src/diagnostic.c b/src/diagnostic.c @@ -39,10 +39,14 @@ bool diagnostic_info_to_dict(const struct diagnostic_station_info *info, struct l_dbus_message_builder *builder) { int16_t rssi = (int16_t)info->cur_rssi; + int16_t avg_rssi = (int16_t)info->avg_rssi; if (info->have_cur_rssi) dbus_append_dict_basic(builder, "RSSI", 'n', &rssi); + if (info->have_avg_rssi) + dbus_append_dict_basic(builder, "AverageRSSI", 'n', &avg_rssi); + if (info->have_rx_mcs) { switch (info->rx_mcs_type) { case DIAGNOSTIC_MCS_TYPE_HT: diff --git a/src/diagnostic.h b/src/diagnostic.h @@ -30,6 +30,7 @@ enum diagnostic_mcs_type { struct diagnostic_station_info { uint8_t addr[6]; int8_t cur_rssi; + int8_t avg_rssi; enum diagnostic_mcs_type rx_mcs_type; uint32_t rx_bitrate; @@ -41,6 +42,7 @@ struct diagnostic_station_info { uint32_t expected_throughput; bool have_cur_rssi : 1; + bool have_avg_rssi : 1; bool have_rx_mcs : 1; bool have_tx_mcs : 1; bool have_rx_bitrate : 1; diff --git a/src/eapol.c b/src/eapol.c @@ -2796,6 +2796,7 @@ void __eapol_rx_packet(uint32_t ifindex, const uint8_t *src, uint16_t proto, switch (eh->protocol_version) { case EAPOL_PROTOCOL_VERSION_2001: case EAPOL_PROTOCOL_VERSION_2004: + case EAPOL_PROTOCOL_VERSION_2010: break; default: return; diff --git a/src/eapolutil.c b/src/eapolutil.c @@ -50,6 +50,7 @@ const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len, switch (ek->header.protocol_version) { case EAPOL_PROTOCOL_VERSION_2001: case EAPOL_PROTOCOL_VERSION_2004: + case EAPOL_PROTOCOL_VERSION_2010: break; default: return NULL; diff --git a/src/handshake.h b/src/handshake.h @@ -116,6 +116,7 @@ struct handshake_state { bool wait_for_gtk : 1; bool no_rekey : 1; bool support_fils : 1; + bool offload : 1; uint8_t ssid[32]; size_t ssid_len; char *passphrase; diff --git a/src/netdev.c b/src/netdev.c @@ -128,6 +128,8 @@ struct netdev { uint32_t rssi_poll_cmd_id; uint8_t set_mac_once[6]; + struct scan_bss *fw_roam_bss; + uint32_t set_powered_cmd_id; netdev_command_cb_t set_powered_cb; void *set_powered_user_data; @@ -451,6 +453,14 @@ static bool netdev_parse_sta_info(struct l_genl_attr *attr, info->have_cur_rssi = true; break; + case NL80211_STA_INFO_SIGNAL_AVG: + if (len != 1) + return false; + + info->avg_rssi = *(const int8_t *) data; + info->have_avg_rssi = true; + + break; case NL80211_STA_INFO_RX_BITRATE: if (!l_genl_attr_recurse(attr, &nested)) return false; @@ -770,6 +780,9 @@ static void netdev_free(void *data) netdev->get_station_cmd_id = 0; } + if (netdev->fw_roam_bss) + scan_bss_free(netdev->fw_roam_bss); + if (netdev->events_ready) WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t, netdev, NETDEV_WATCH_EVENT_DEL); @@ -1188,6 +1201,22 @@ static void netdev_connect_ok(struct netdev *netdev) netdev->operational = true; + if (netdev->fw_roam_bss) { + if (netdev->event_filter) + netdev->event_filter(netdev, NETDEV_EVENT_ROAMED, + netdev->fw_roam_bss, + netdev->user_data); + else + scan_bss_free(netdev->fw_roam_bss); + + netdev->fw_roam_bss = NULL; + } + + /* Allow station to sync the PSK to disk */ + if (netdev->handshake && netdev->handshake->offload) + handshake_event(netdev->handshake, + HANDSHAKE_EVENT_SETTING_KEYS); + if (netdev->connect_cb) { netdev->connect_cb(netdev, NETDEV_RESULT_OK, NULL, netdev->user_data); @@ -1807,6 +1836,7 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) struct ie_tlv_iter iter; const uint8_t *resp_ies = NULL; size_t resp_ies_len; + uint8_t cmd = l_genl_msg_get_command(msg); l_debug(""); @@ -1860,9 +1890,16 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) goto error; } - /* AP Rejected the authenticate / associate */ - if (!status_code || *status_code != 0) - goto error; + /* + * A CMD_ROAM event will not have a status code, since it indicates + * the hardware has already roamed. A failed roam on fullmac should + * result in an explicit disconnect event. + */ + if (cmd == NL80211_CMD_CONNECT) { + /* AP Rejected the authenticate / associate */ + if (!status_code || *status_code != 0) + goto error; + } if (!ies) goto process_resp_ies; @@ -1947,8 +1984,28 @@ process_resp_ies: netdev_send_qos_map_set(netdev, qos_set, qos_len); } + /* + * TODO: Only SAE/WPA3-personal offload is supported. In this case IWD + * is 'done'. In the case of 8021x offload EAP still needs to take + * place, so this must be updated accordingly when that is implemented. + */ + if (netdev->handshake->offload) + goto done; + if (netdev->sm) { /* + * Let station know about the roam so a state change can occur. + */ + if (cmd == NL80211_CMD_ROAM) { + if (netdev->event_filter) + netdev->event_filter(netdev, + NETDEV_EVENT_ROAMING, + NULL, netdev->user_data); + /* EAPoL started after GET_SCAN */ + return; + } + + /* * Start processing EAPoL frames now that the state machine * has all the input data even in FT mode. */ @@ -1958,6 +2015,7 @@ process_resp_ies: return; } +done: netdev_connect_ok(netdev); return; @@ -2557,7 +2615,9 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, const struct iovec *vendor_ies, size_t num_vendor_ies) { - uint32_t auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; + uint32_t auth_type = IE_AKM_IS_SAE(hs->akm_suite) ? + NL80211_AUTHTYPE_SAE : + NL80211_AUTHTYPE_OPEN_SYSTEM; struct l_genl_msg *msg; struct iovec iov[4 + num_vendor_ies]; int iov_elems = 0; @@ -2574,6 +2634,12 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, bss->ssid_len, bss->ssid); l_genl_msg_append_attr(msg, NL80211_ATTR_AUTH_TYPE, 4, &auth_type); + if (hs->offload) { + if (IE_AKM_IS_SAE(hs->akm_suite)) + l_genl_msg_append_attr(msg, NL80211_ATTR_SAE_PASSWORD, + strlen(hs->passphrase), hs->passphrase); + } + if (prev_bssid) l_genl_msg_append_attr(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, prev_bssid); @@ -2615,7 +2681,9 @@ static struct l_genl_msg *netdev_build_cmd_connect(struct netdev *netdev, l_genl_msg_append_attr(msg, NL80211_ATTR_AKM_SUITES, 4, &nl_akm); - if (hs->wpa_ie) + if (IE_AKM_IS_SAE(hs->akm_suite)) + wpa_version = NL80211_WPA_VERSION_3; + else if (hs->wpa_ie) wpa_version = NL80211_WPA_VERSION_1; else wpa_version = NL80211_WPA_VERSION_2; @@ -2976,6 +3044,9 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss, switch (hs->akm_suite) { case IE_RSN_AKM_SUITE_SAE_SHA256: case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256: + if (hs->offload) + goto build_cmd_connect; + netdev->ap = sae_sm_new(hs, netdev_sae_tx_authenticate, netdev_sae_tx_associate, netdev); @@ -2994,13 +3065,14 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss, netdev); break; default: +build_cmd_connect: cmd_connect = netdev_build_cmd_connect(netdev, bss, hs, NULL, vendor_ies, num_vendor_ies); if (!cmd_connect) return -EINVAL; - if (is_rsn || hs->settings_8021x) + if (!hs->offload && (is_rsn || hs->settings_8021x)) sm = eapol_sm_new(hs); } @@ -3905,6 +3977,111 @@ static void netdev_scan_notify(struct l_genl_msg *msg, void *user_data) } } +static bool match_addr(const void *a, const void *b) +{ + const struct scan_bss *bss = a; + + return memcmp(bss->addr, b, 6) == 0; +} + +static bool netdev_get_fw_scan_cb(int err, struct l_queue *bss_list, + const struct scan_freq_set *freqs, + void *user_data) +{ + struct netdev *netdev = user_data; + struct scan_bss *bss = NULL; + + /* + * If there was a failure in netdev_connect_event this would reset + * the connect state (netdev_connect_free) causing the sm to be freed. + * In this case we should just ignore this and allow the disconnect + * logic to continue. + */ + if (!netdev->sm) + return false; + + if (err < 0) { + l_error("Failed to get scan after roam (%d)", err); + netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED, + MMPDU_REASON_CODE_UNSPECIFIED); + return false; + } + + /* + * We don't actually need the entire list since we only provide + * station with the roamed BSS. We can remove the BSS we want and by + * returning false scan will keep ownership of the list. + */ + bss = l_queue_remove_if(bss_list, match_addr, netdev->handshake->aa); + + if (!bss) { + l_error("Roam target BSS not found in scan results"); + netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED, + MMPDU_REASON_CODE_UNSPECIFIED); + return false; + } + + netdev->fw_roam_bss = bss; + + handshake_state_set_authenticator_ie(netdev->handshake, bss->rsne); + + eapol_start(netdev->sm); + + return false; +} + +/* + * CMD_ROAM indicates that the driver has already roamed/associated with a new + * AP. This event is nearly identical to the CMD_CONNECT event which is why + * netdev_connect_event will handle all the parsing of IE's just as it does + * normally. + * + * Using GET_SCAN we can grab all the required scan_bss data, create that object + * and provide it to station. + * + * The current handshake/netdev_handshake objects are reused after being + * reset to allow eapol to happen again without it thinking this is a re-key. + */ +static bool netdev_roam_event(struct l_genl_msg *msg, struct netdev *netdev) +{ + struct netdev_handshake_state *nhs = + l_container_of(netdev->handshake, + struct netdev_handshake_state, + super); + const uint8_t *mac; + + l_debug(""); + + netdev->operational = false; + + if (nl80211_parse_attrs(msg, NL80211_ATTR_MAC, &mac, + NL80211_ATTR_UNSPEC) < 0) { + l_error("Failed to parse ATTR_MAC from CMD_ROAM"); + goto failed; + } + + /* Reset handshake state */ + nhs->complete = false; + nhs->ptk_installed = false; + nhs->gtk_installed = true; + nhs->igtk_installed = true; + handshake_state_set_authenticator_address(netdev->handshake, mac); + netdev->handshake->ptk_complete = false; + + if (!scan_get_firmware_scan(netdev->wdev_id, netdev_get_fw_scan_cb, + netdev, NULL)) + goto failed; + + return true; + +failed: + l_error("Failed to roam to new BSS"); + netdev_connect_failed(netdev, NETDEV_RESULT_ABORTED, + MMPDU_REASON_CODE_UNSPECIFIED); + + return false; +} + static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data) { struct netdev *netdev = NULL; @@ -3946,6 +4123,10 @@ static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data) case NL80211_CMD_ASSOCIATE: netdev_associate_event(msg, netdev); break; + case NL80211_CMD_ROAM: + if (!netdev_roam_event(msg, netdev)) + return; + /* fall through */ case NL80211_CMD_CONNECT: netdev_connect_event(msg, netdev); break; diff --git a/src/netdev.h b/src/netdev.h @@ -41,6 +41,8 @@ enum netdev_result { enum netdev_event { NETDEV_EVENT_AUTHENTICATING, NETDEV_EVENT_ASSOCIATING, + NETDEV_EVENT_ROAMING, + NETDEV_EVENT_ROAMED, NETDEV_EVENT_DISCONNECT_BY_AP, NETDEV_EVENT_DISCONNECT_BY_SME, NETDEV_EVENT_RSSI_THRESHOLD_LOW, diff --git a/src/network.c b/src/network.c @@ -674,6 +674,27 @@ bool network_bss_add(struct network *network, struct scan_bss *bss) return true; } +static bool match_addr(const void *a, const void *b) +{ + const struct scan_bss *bss = a; + + return memcmp(bss->addr, b, 6) == 0; +} + +/* + * Replaces an old scan_bss (if exists) in the bss list with a new bss object. + * Note this BSS is *not* freed and must be by the caller. scan_bss objects are + * shared between network/station but station technically owns them. + */ +bool network_bss_update(struct network *network, struct scan_bss *bss) +{ + l_queue_remove_if(network->bss_list, match_addr, bss->addr); + + l_queue_insert(network->bss_list, bss, scan_bss_rank_compare, NULL); + + return true; +} + bool network_bss_list_isempty(struct network *network) { return l_queue_isempty(network->bss_list); @@ -693,17 +714,7 @@ struct scan_bss *network_bss_list_pop(struct network *network) struct scan_bss *network_bss_find_by_addr(struct network *network, const uint8_t *addr) { - const struct l_queue_entry *bss_entry; - - for (bss_entry = l_queue_get_entries(network->bss_list); bss_entry; - bss_entry = bss_entry->next) { - struct scan_bss *bss = bss_entry->data; - - if (!memcmp(bss->addr, addr, sizeof(bss->addr))) - return bss; - } - - return NULL; + return l_queue_find(network->bss_list, match_addr, addr); } static bool match_bss(const void *a, const void *b) diff --git a/src/network.h b/src/network.h @@ -55,6 +55,7 @@ void network_set_info(struct network *network, struct network_info *info); int network_autoconnect(struct network *network, struct scan_bss *bss); void network_connect_failed(struct network *network, bool in_handshake); bool network_bss_add(struct network *network, struct scan_bss *bss); +bool network_bss_update(struct network *network, struct scan_bss *bss); bool network_bss_list_isempty(struct network *network); void network_bss_list_clear(struct network *network); struct scan_bss *network_bss_list_pop(struct network *network); diff --git a/src/scan.c b/src/scan.c @@ -101,6 +101,11 @@ struct scan_context { /* Non-zero if GET_SCAN is still running */ unsigned int get_scan_cmd_id; /* + * Special request used for getting scan results after the firmware + * roamed automatically. + */ + unsigned int get_fw_scan_cmd_id; + /* * Whether the top request in the queue has triggered the current * scan. May be set and cleared multiple times during a single * request. May be false when the current request is waiting due @@ -208,6 +213,9 @@ static void scan_context_free(struct scan_context *sc) if (sc->get_scan_cmd_id && nl80211) l_genl_family_cancel(nl80211, sc->get_scan_cmd_id); + if (sc->get_fw_scan_cmd_id && nl80211) + l_genl_family_cancel(nl80211, sc->get_fw_scan_cmd_id); + l_free(sc); } @@ -1809,6 +1817,72 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data) } } +static void get_fw_scan_done(void *userdata) +{ + struct scan_results *results = userdata; + struct scan_request *sr = results->sr; + struct scan_context *sc = results->sc; + int err = l_queue_length(results->bss_list) == 0 ? -ENOENT : 0; + bool new_owner = false; + + sc->get_fw_scan_cmd_id = 0; + + if (sr->callback) + new_owner = sr->callback(err, results->bss_list, NULL, + sr->userdata); + + if (!new_owner) + l_queue_destroy(results->bss_list, + (l_queue_destroy_func_t) scan_bss_free); + + if (sr->destroy) + sr->destroy(sr->userdata); + + l_free(sr); + l_free(results); +} + +bool scan_get_firmware_scan(uint64_t wdev_id, scan_notify_func_t notify, + void *userdata, scan_destroy_func_t destroy) +{ + struct l_genl_msg *scan_msg; + struct scan_results *results; + struct scan_request *sr; + struct scan_context *sc = l_queue_find(scan_contexts, + scan_context_match, &wdev_id); + + if (!sc) + return false; + + sr = l_new(struct scan_request, 1); + sr->callback = notify; + sr->destroy = destroy; + sr->userdata = userdata; + + results = l_new(struct scan_results, 1); + results->sc = sc; + results->time_stamp = l_time_now(); + results->bss_list = l_queue_new(); + results->sr = sr; + + scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8); + l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8, &sc->wdev_id); + + sc->get_fw_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg, + get_scan_callback, + results, + get_fw_scan_done); + if (!sc->get_fw_scan_cmd_id) { + l_queue_destroy(results->bss_list, + (l_queue_destroy_func_t) scan_bss_free); + l_free(results); + l_free(sr); + return false; + } + + return true; +} + uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band) { uint32_t channel = 0; diff --git a/src/scan.h b/src/scan.h @@ -151,6 +151,9 @@ bool scan_periodic_stop(uint64_t wdev_id); uint64_t scan_get_triggered_time(uint64_t wdev_id, uint32_t id); +bool scan_get_firmware_scan(uint64_t wdev_id, scan_notify_func_t notify, + void *userdata, scan_destroy_func_t destroy); + void scan_bss_free(struct scan_bss *bss); int scan_bss_rank_compare(const void *a, const void *b, void *user); diff --git a/src/station.c b/src/station.c @@ -738,6 +738,7 @@ static void station_handshake_event(struct handshake_state *hs, netdev_handshake_failed(hs, va_arg(args, int)); break; case HANDSHAKE_EVENT_REKEY_FAILED: + l_warn("Unable to securely rekey on this hw/kernel..."); station_reconnect(station); break; case HANDSHAKE_EVENT_COMPLETE: @@ -981,6 +982,16 @@ static struct handshake_state *station_handshake_setup(struct station *station, goto no_psk; handshake_state_set_passphrase(hs, passphrase); + + /* + * TODO: This check isn't strictly correct since + * some drivers may support EXTERNAL_AUTH but since + * wiphy_can_connect takes this into account IWD should + * have already rejected the connection if this was the + * case. + */ + if (!wiphy_supports_cmds_auth_assoc(wiphy)) + hs->offload = true; } else { const uint8_t *psk = network_get_psk(network); @@ -2186,6 +2197,14 @@ static bool station_cannot_roam(struct station *station) const struct l_settings *config = iwd_get_config(); bool disabled; + /* + * Disable roaming with hardware that can roam automatically. Note this + * is now required for recent kernels which have CQM event support on + * this type of hardware (e.g. brcmfmac). + */ + if (wiphy_supports_firmware_roam(station->wiphy)) + return true; + if (!l_settings_get_bool(config, "Scan", "DisableRoamingScan", &disabled)) disabled = false; @@ -2307,6 +2326,25 @@ static void station_ok_rssi(struct station *station) station->roam_min_time.tv_sec = 0; } +static void station_event_roamed(struct station *station, struct scan_bss *new) +{ + struct scan_bss *stale; + + network_bss_update(station->connected_network, new); + + /* Remove new BSS if it exists in past scan results */ + stale = l_queue_remove_if(station->bss_list, bss_match_bssid, + new->addr); + if (stale) + scan_bss_free(stale); + + station->connected_bss = new; + + l_queue_insert(station->bss_list, new, scan_bss_rank_compare, NULL); + + station_enter_state(station, STATION_STATE_CONNECTED); +} + static void station_rssi_level_changed(struct station *station, uint8_t level_idx); @@ -2335,6 +2373,12 @@ static void station_netdev_event(struct netdev *netdev, enum netdev_event event, case NETDEV_EVENT_RSSI_LEVEL_NOTIFY: station_rssi_level_changed(station, l_get_u8(event_data)); break; + case NETDEV_EVENT_ROAMING: + station_enter_state(station, STATION_STATE_ROAMING); + break; + case NETDEV_EVENT_ROAMED: + station_event_roamed(station, (struct scan_bss *) event_data); + break; } } diff --git a/src/wiphy.c b/src/wiphy.c @@ -96,6 +96,7 @@ struct wiphy { bool support_adhoc_rsn:1; bool support_qos_set_map:1; bool support_cmds_auth_assoc:1; + bool support_fw_roam:1; bool soft_rfkill : 1; bool hard_rfkill : 1; bool offchannel_tx_ok : 1; @@ -125,6 +126,52 @@ enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask) return 0; } +static bool wiphy_can_connect_sae(struct wiphy *wiphy) +{ + /* + * SAE support in the kernel is a complete mess in that there are 3 + * different ways the hardware can support SAE: + * + * 1. Cards which allow SAE in userspace, meaning they support both + * CMD_AUTHENTICATE and CMD_ASSOCIATE as well as advertise support + * for FEATURE_SAE (SoftMAC). + * + * 2. Cards which allow SAE to be offloaded to hardware. These cards + * do not support AUTH/ASSOC commands, do not advertise FEATURE_SAE, + * but advertise support for EXT_FEATURE_SAE_OFFLOAD. With these + * cards the entire SAE protocol as well as the subsequent 4-way + * handshake are all done in the driver/firmware (fullMAC). + * + * 3. TODO: Cards which allow SAE in userspace via CMD_EXTERNAL_AUTH. + * These cards do not support AUTH/ASSOC commands but do implement + * CMD_EXTERNAL_AUTH which is supposed to allow userspace to + * generate Authenticate frames as it would for case (1). As it + * stands today only one driver actually uses CMD_EXTERNAL_AUTH and + * for now IWD will not allow connections to SAE networks using this + * mechanism. + */ + + if (wiphy_has_feature(wiphy, NL80211_FEATURE_SAE)) { + /* Case (1) */ + if (wiphy->support_cmds_auth_assoc) + return true; + + /* + * Case (3) + * + * TODO: No support for CMD_EXTERNAL_AUTH yet. + */ + return false; + } else { + /* Case (2) */ + if (wiphy_has_ext_feature(wiphy, + NL80211_EXT_FEATURE_SAE_OFFLOAD)) + return true; + + return false; + } +} + enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy, struct scan_bss *bss, bool fils_capable_hint) @@ -187,19 +234,8 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy, goto wpa2_personal; } - /* - * TODO: Only SoftMAC (mac80211) drivers are currently - * capable of SAE since it requires ability to send - * Authenticate and Associate frames (which is given by - * support_cmds_auth_assoc). FullMAC drivers require - * SAE offload which we do not support nor supported - * in any upstream driver as of this time. - */ - if (!wiphy_has_feature(wiphy, NL80211_FEATURE_SAE) || - !wiphy->support_cmds_auth_assoc) { - l_debug("No HW WPA3 support, trying WPA2"); + if (!wiphy_can_connect_sae(wiphy)) goto wpa2_personal; - } if (info.akm_suites & IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256) @@ -375,15 +411,7 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss) switch (rsn_info.akm_suites) { case IE_RSN_AKM_SUITE_SAE_SHA256: case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256: - /* - * if the AP ONLY supports SAE/WPA3, then we can only - * connect if the wiphy feature is supported. Otherwise - * the AP may list SAE as one of the AKM's but also - * support PSK (hybrid). In this case we still want to - * allow a connection even if SAE is not supported. - */ - if (!wiphy_has_feature(wiphy, NL80211_FEATURE_SAE) || - !wiphy->support_cmds_auth_assoc) + if (!wiphy_can_connect_sae(wiphy)) return false; break; @@ -403,6 +431,11 @@ bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss) return true; } +bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy) +{ + return wiphy->support_cmds_auth_assoc; +} + bool wiphy_has_feature(struct wiphy *wiphy, uint32_t feature) { return wiphy->feature_flags & feature; @@ -462,6 +495,11 @@ bool wiphy_supports_qos_set_map(struct wiphy *wiphy) return wiphy->support_qos_set_map; } +bool wiphy_supports_firmware_roam(struct wiphy *wiphy) +{ + return wiphy->support_fw_roam; +} + const char *wiphy_get_driver(struct wiphy *wiphy) { return wiphy->driver_str; @@ -990,6 +1028,9 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, else wiphy->max_roc_duration = *((uint32_t *) data); break; + case NL80211_ATTR_ROAM_SUPPORT: + wiphy->support_fw_roam = true; + break; } } } diff --git a/src/wiphy.h b/src/wiphy.h @@ -79,6 +79,7 @@ uint32_t wiphy_get_supported_bands(struct wiphy *wiphy); const struct scan_freq_set *wiphy_get_supported_freqs( const struct wiphy *wiphy); bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss); +bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy); bool wiphy_can_randomize_mac_addr(struct wiphy *wiphy); bool wiphy_rrm_capable(struct wiphy *wiphy); bool wiphy_has_feature(struct wiphy *wiphy, uint32_t feature); @@ -92,6 +93,7 @@ const uint8_t *wiphy_get_supported_rates(struct wiphy *wiphy, unsigned int band, 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); +bool wiphy_supports_firmware_roam(struct wiphy *wiphy); const char *wiphy_get_driver(struct wiphy *wiphy); const char *wiphy_get_name(struct wiphy *wiphy); const uint8_t *wiphy_get_permanent_address(struct wiphy *wiphy);