diff --git a/Documentation/networking/device_drivers/wifi/mt7932-neo.rst b/Documentation/networking/device_drivers/wifi/mt7932-neo.rst index a14b9221d0a5d..3fd4a1c81853e 100644 --- a/Documentation/networking/device_drivers/wifi/mt7932-neo.rst +++ b/Documentation/networking/device_drivers/wifi/mt7932-neo.rst @@ -125,21 +125,27 @@ permit security fallback. For SAE, userspace supplies SAE authentication, an 8-63 byte password and required or optional management frame protection (MFP). Firmware uses required MFP for the SAE arm. On a PSK+SAE transition network, the first AKM supplied -by userspace selects the arm: PSK keeps the existing binary-PMK request and -disables MFP, while SAE uses the password and required MFP. PSK with required -MFP is rejected on legacy AKM 2. WPA2 PMF uses the explicitly selected -PSK-SHA256 AKM (6), with a binary 32-byte PMK and optional or required MFP. -The only EA/40 security delta is little-endian 0x0400 at body +0x14. The -host retains the MFP policy; there is no standalone optional/required field. +by userspace selects the arm: PSK keeps the binary-PMK request, while SAE +uses the password and required MFP. On the PSK (AKM 2) arm the firmware sets +MFPC in its own RSN element and negotiates PMF with any AP that sets MFPC, so +a WPA2 network with optional or required PMF is joined with PMF on. iwd and +wpa_supplicant both ask for required MFP once they have negotiated PMF with +such an AP, and wpa_supplicant asks for optional MFP when either outcome will +do; every MFP setting is accepted on this arm. WPA2 PMF with the PSK-SHA256 AKM (6) +also takes a binary 32-byte PMK and optional or required MFP; its only EA/40 +security delta is little-endian 0x0400 at body +0x14. There is no standalone +optional/required field. Before any association command, the host validates the candidate's RSN IE, -selected AKM, CCMP and MFPC/MFPR. A required request cannot downgrade to -AKM 2 or a non-MFPC AP. Only BIP-CMAC-128 is accepted as an explicit group +selected AKM, CCMP and MFPC/MFPR. A request for PMF cannot join an AP +without MFPC, and a request with MFP disabled cannot join an AP that sets +MFPR. With MFP disabled, the AKM 2 arm still negotiates PMF when the AP +offers it, because the firmware always sets MFPC there. Only BIP-CMAC-128 +is accepted as an explicit group management suite; the standard omitted-suite default is also CMAC-128. Firmware owns IGTK extraction, install/removal and BIP verification. No -add_key or set_default_mgmt_key operation is added. iwd's BIP gate is now -satisfied, but WPA2-PMF and iwd behavior still require hardware qualification. -The admitted PMF state is host policy, not a firmware readback. Selectors +add_key or set_default_mgmt_key operation is added. The admitted PMF state +follows the AP's RSN capabilities; it is not a firmware readback. Selectors 0x40/0x42 retain their normal completion contract; neither reports PMF state. The standard SAE PWE settings (unspecified, hunting-and-pecking, @@ -156,6 +162,14 @@ transition network has confirmed, on 2.4 GHz channel 6 and 5 GHz channel 149: joins the transition network as PSK; * repeated reconnection through NetworkManager after each change of profile. +With iwd 3.12 and with NetworkManager and wpa_supplicant, against hostapd +access points, every network that offers PMF is joined with it (hostapd +lists the station with MFP): WPA2 with optional PMF and with required PMF on +AKM 2, WPA2 with required PMF on AKM 6, the WPA2/WPA3 transition network and +WPA3-only networks on 5 GHz, and WPA3 on 6 GHz. OWE with iwd needs an iwd +that knows ``NL80211_EXT_FEATURE_OWE_OFFLOAD``; iwd 3.12 runs its own OWE +exchange, which a firmware-offload device cannot serve. + The request layout, transition admission and PMK derivation also have automated tests. A pure WPA3 network, exact PWE policy behavior, WPA2 throughput regression comparisons and long-duration reliability still need diff --git a/drivers/net/wireless/mediatek/mt7932/association-test.c b/drivers/net/wireless/mediatek/mt7932/association-test.c index 81ef3f6a5470b..2d959e173624b 100644 --- a/drivers/net/wireless/mediatek/mt7932/association-test.c +++ b/drivers/net/wireless/mediatek/mt7932/association-test.c @@ -188,7 +188,7 @@ static void mt_connect_auth_test(struct kunit *test) } cases[] = { { "pure PSK", MT_AUTH_PSK, 0, WLAN_AKM_SUITE_PSK }, { "PSK missing PMK", MT_AUTH_PSK, 1, -EOPNOTSUPP }, - { "PSK required MFP", MT_AUTH_PSK, 2, -EOPNOTSUPP }, + { "PSK required MFP", MT_AUTH_PSK, 2, WLAN_AKM_SUITE_PSK }, { "pure SAE", MT_AUTH_NONE, 0, WLAN_AKM_SUITE_SAE }, { "optional MFP", MT_AUTH_MFP, NL80211_MFP_OPTIONAL, WLAN_AKM_SUITE_SAE }, { "no MFP", MT_AUTH_MFP, NL80211_MFP_NO, -EOPNOTSUPP }, @@ -221,7 +221,7 @@ static void mt_connect_auth_test(struct kunit *test) { "SAE first missing password", MT_AUTH_SAE_FIRST, 1, -EOPNOTSUPP }, { "PSK first optional MFP", MT_AUTH_PSK_FIRST, 0, WLAN_AKM_SUITE_PSK }, { "PSK first missing PMK", MT_AUTH_PSK_FIRST, 1, -EOPNOTSUPP }, - { "PSK first required MFP", MT_AUTH_PSK_FIRST, 2, -EOPNOTSUPP }, + { "PSK first required MFP", MT_AUTH_PSK_FIRST, 2, WLAN_AKM_SUITE_PSK }, { "PSK first no MFP", MT_AUTH_PSK_FIRST, 3, WLAN_AKM_SUITE_PSK }, { "PSK first mixed versions", MT_AUTH_PSK_FIRST, 4, WLAN_AKM_SUITE_PSK }, { "PSK first VERSION_3 only", MT_AUTH_PSK_FIRST, 5, -EOPNOTSUPP }, diff --git a/drivers/net/wireless/mediatek/mt7932/association.h b/drivers/net/wireless/mediatek/mt7932/association.h index 011a029f20357..26c3dfbcf7e92 100644 --- a/drivers/net/wireless/mediatek/mt7932/association.h +++ b/drivers/net/wireless/mediatek/mt7932/association.h @@ -52,8 +52,12 @@ mt7932_connect_auth(const struct cfg80211_connect_params *p) switch (p->crypto.akm_suites[0]) { case WLAN_AKM_SUITE_PSK: - if ((versions & NL80211_WPA_VERSION_2) && p->crypto.psk && - (p->mfp == NL80211_MFP_NO || p->mfp == NL80211_MFP_OPTIONAL)) + /* iwd and wpa_supplicant both send REQUIRED once they have + * negotiated PMF with an MFPC AP; wpa_supplicant sends OPTIONAL + * when either outcome will do. Admission against the AP's RSN + * capabilities decides. + */ + if ((versions & NL80211_WPA_VERSION_2) && p->crypto.psk) return WLAN_AKM_SUITE_PSK; break; case WLAN_AKM_SUITE_PSK_SHA256: @@ -166,13 +170,18 @@ static inline int mt7932_rsn_admit(const u8 *rsn, size_t length, u32 akm, return -EOPNOTSUPP; if ((caps & BIT(6)) && !(caps & BIT(7))) return -EINVAL; - /* Legacy PSK has no established PMF firmware selection. Optional may - * join it without PMF; required must never downgrade to that arm. + /* On the AKM 2 arm the firmware sets MFPC itself and negotiates PMF + * with any AP that sets MFPC, so the AP's capability is the outcome. + * A request for PMF needs an MFPC AP, and refusing PMF cannot join + * an AP that sets MFPR. */ - if (akm == WLAN_AKM_SUITE_PSK) - return mfp == NL80211_MFP_REQUIRED || (caps & BIT(6)) ? - -EOPNOTSUPP : - 0; + if (akm == WLAN_AKM_SUITE_PSK) { + if ((mfp == NL80211_MFP_REQUIRED && !(caps & BIT(7))) || + (mfp == NL80211_MFP_NO && (caps & BIT(6)))) + return -EOPNOTSUPP; + *pmf = !!(caps & BIT(7)); + return 0; + } if (mfp == NL80211_MFP_NO || !(caps & BIT(7))) return -EOPNOTSUPP; *pmf = true; diff --git a/drivers/net/wireless/mediatek/mt7932/frontend.c b/drivers/net/wireless/mediatek/mt7932/frontend.c index 0fb4b97ec7690..3a3ab2ac47973 100644 --- a/drivers/net/wireless/mediatek/mt7932/frontend.c +++ b/drivers/net/wireless/mediatek/mt7932/frontend.c @@ -141,6 +141,25 @@ static void mt_scan_retire_wait(struct mt7932 *m, unsigned long timeout) } } +/* No lock held. A supplicant cancels its scan just before it connects, and + * the firmware ends the cancelled batch a moment later. Wait for that end, + * bounded, instead of refusing the connect: wpa_supplicant answers a refused + * connect by skipping the BSS for 10 s. A scan that is still running belongs + * to its requester and is left alone. + */ +void mt_scan_settle_retired(struct mt7932 *m) +{ + unsigned long deadline = jiffies + msecs_to_jiffies(2000); + long left; + + while (READ_ONCE(m->retired_scan_seq) && !READ_ONCE(m->scan_request) && + !READ_ONCE(m->stopping)) { + left = (long)(deadline - jiffies); + if (left <= 0 || !wait_for_completion_timeout(&m->scan_done, left)) + break; + } +} + /* No command/response lock held. The caller closes new scan admission first. * Natural EID0d completion fences the scan; a local cancel alone does not. * The batch awaited here may already have been followed by the next one, diff --git a/drivers/net/wireless/mediatek/mt7932/link.c b/drivers/net/wireless/mediatek/mt7932/link.c index ce2c679d13549..7824d6f6d9b10 100644 --- a/drivers/net/wireless/mediatek/mt7932/link.c +++ b/drivers/net/wireless/mediatek/mt7932/link.c @@ -964,6 +964,7 @@ int mt_connect(struct wiphy *wiphy, struct net_device *netdev, } if (ret) return ret; + mt_scan_settle_retired(m); mutex_lock(&m->command_mutex); spin_lock_irqsave(&m->response_lock, flags); if (!mt_rf_allowed(m) || m->link_failed || m->connecting || m->connected || m->disconnecting || m->scan_request || m->retired_scan_seq) { diff --git a/drivers/net/wireless/mediatek/mt7932/mt7932.h b/drivers/net/wireless/mediatek/mt7932/mt7932.h index 8c48ab0a1f8e3..a0d5a307f6cba 100644 --- a/drivers/net/wireless/mediatek/mt7932/mt7932.h +++ b/drivers/net/wireless/mediatek/mt7932/mt7932.h @@ -307,6 +307,7 @@ struct mt7932 *mt_from_wiphy(struct wiphy *wiphy); void mt_scan_event(struct mt7932 *m, const struct mt7932_event *event); void mt_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev); int mt_scan_quiesce(struct mt7932 *m); +void mt_scan_settle_retired(struct mt7932 *m); int mt_connect_discover(struct mt7932 *m); int mt_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request); int mt_register_interface(struct mt7932 *m); diff --git a/drivers/net/wireless/mediatek/mt7932/pmf-lpi-test.c b/drivers/net/wireless/mediatek/mt7932/pmf-lpi-test.c index 927b0e43b3a9c..59c9633c954df 100644 --- a/drivers/net/wireless/mediatek/mt7932/pmf-lpi-test.c +++ b/drivers/net/wireless/mediatek/mt7932/pmf-lpi-test.c @@ -47,7 +47,16 @@ static void mt_pmf_admission_test(struct kunit *test) request.crypto.n_akm_suites = 2; request.crypto.akm_suites[0] = WLAN_AKM_SUITE_PSK; request.crypto.akm_suites[1] = WLAN_AKM_SUITE_PSK_SHA256; + /* AKM 2 takes every MFP request; the AP's RSN decides at admission. */ + for (i = NL80211_MFP_NO; i <= NL80211_MFP_OPTIONAL; i++) { + request.mfp = i; + KUNIT_EXPECT_EQ(test, mt7932_connect_auth(&request), + WLAN_AKM_SUITE_PSK); + } + request.mfp = NL80211_MFP_REQUIRED; + request.crypto.psk = NULL; KUNIT_EXPECT_LT(test, mt7932_connect_auth(&request), 0); + request.crypto.psk = pmk; KUNIT_EXPECT_LT(test, mt7932_connect_admit(pmf_rsn, sizeof(pmf_rsn), WLAN_AKM_SUITE_PSK_SHA256, @@ -92,17 +101,45 @@ static void mt_pmf_admission_test(struct kunit *test) mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK_SHA256, NL80211_MFP_REQUIRED, &pmf), 0); - ies[19] = 2; /* legacy PSK cannot satisfy required PMF */ + /* AKM 2 on an MFPC AP: firmware negotiates PMF for every request. */ + ies[19] = 2; + for (i = NL80211_MFP_NO; i <= NL80211_MFP_OPTIONAL; i++) { + pmf = false; + KUNIT_EXPECT_EQ(test, + mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK, + i, &pmf), + 0); + KUNIT_EXPECT_TRUE(test, pmf); + } + /* AKM 2 on an MFPR AP: PMF is mandatory, so it cannot be refused. */ + ies[20] |= 64; + for (i = NL80211_MFP_REQUIRED; i <= NL80211_MFP_OPTIONAL; i++) { + KUNIT_EXPECT_EQ(test, + mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK, + i, &pmf), + 0); + KUNIT_EXPECT_TRUE(test, pmf); + } KUNIT_EXPECT_LT(test, mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK, - NL80211_MFP_REQUIRED, &pmf), + NL80211_MFP_NO, &pmf), 0); - KUNIT_EXPECT_EQ(test, + /* AKM 2 on an AP without MFPC: no PMF, and required cannot join. */ + ies[20] = 0; + KUNIT_EXPECT_LT(test, mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK, - NL80211_MFP_OPTIONAL, &pmf), + NL80211_MFP_REQUIRED, &pmf), 0); - KUNIT_EXPECT_FALSE(test, pmf); - ies[20] |= 64; + for (i = NL80211_MFP_NO; i <= NL80211_MFP_OPTIONAL; + i += NL80211_MFP_OPTIONAL) { + pmf = true; + KUNIT_EXPECT_EQ(test, + mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK, + i, &pmf), + 0); + KUNIT_EXPECT_FALSE(test, pmf); + } + ies[20] = 64; /* MFPR without MFPC stays malformed */ KUNIT_EXPECT_LT(test, mt7932_connect_admit(ies, 22, WLAN_AKM_SUITE_PSK, NL80211_MFP_OPTIONAL, &pmf), diff --git a/drivers/net/wireless/mediatek/mt7932/rf-test.c b/drivers/net/wireless/mediatek/mt7932/rf-test.c index a8f5f7d00dbf5..1d901861fb69f 100644 --- a/drivers/net/wireless/mediatek/mt7932/rf-test.c +++ b/drivers/net/wireless/mediatek/mt7932/rf-test.c @@ -340,6 +340,48 @@ static void mt_scan_retire_test_finish(struct work_struct *work) schedule_delayed_work(&ctx->retire, msecs_to_jiffies(300)); } +/* A connect right after a cancelled scan waits for the firmware to end it. */ +static void mt_scan_connect_settle_test(struct kunit *test) +{ + struct mt_scan_retire_test_context ctx = {}; + struct cfg80211_scan_request *scan; + struct mt7932 *m = test->priv; + unsigned long start; + + scan = kunit_kzalloc(test, sizeof(*scan), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, scan); + init_completion(&m->scan_done); + INIT_DELAYED_WORK(&ctx.retire, mt_scan_retire_test_late); + ctx.m = m; + + /* The cancelled batch ends 300 ms later: the connect goes ahead then. */ + m->scan_request = NULL; + m->retired_scan_seq = 8; + schedule_delayed_work(&ctx.retire, msecs_to_jiffies(300)); + start = jiffies; + mt_scan_settle_retired(m); + KUNIT_EXPECT_EQ(test, m->retired_scan_seq, 0); + KUNIT_EXPECT_LT(test, jiffies - start, msecs_to_jiffies(1500)); + cancel_delayed_work_sync(&ctx.retire); + + /* A batch the firmware never ends is waited for only up to the bound. */ + reinit_completion(&m->scan_done); + m->retired_scan_seq = 8; + start = jiffies; + mt_scan_settle_retired(m); + KUNIT_EXPECT_EQ(test, m->retired_scan_seq, 8); + KUNIT_EXPECT_GE(test, jiffies - start, msecs_to_jiffies(1900)); + KUNIT_EXPECT_LE(test, jiffies - start, msecs_to_jiffies(3000)); + + /* A running scan is not waited for: the connect refuses it as before. */ + m->scan_request = scan; + start = jiffies; + mt_scan_settle_retired(m); + KUNIT_EXPECT_LT(test, jiffies - start, msecs_to_jiffies(100)); + m->scan_request = NULL; + m->retired_scan_seq = 0; +} + static void mt_scan_quiesce_retirement_test(struct kunit *test) { static const struct cfg80211_ops ops = {}; @@ -571,6 +613,7 @@ static struct kunit_case mt_rf_test_cases[] = { KUNIT_CASE(mt_rf_failure_blocks_startup_test), KUNIT_CASE(mt_rf_failure_preserves_first_error_test), KUNIT_CASE(mt_scan_quiesce_retirement_test), + KUNIT_CASE(mt_scan_connect_settle_test), KUNIT_CASE(mt_rf_failure_during_publication_test), KUNIT_CASE(mt_rf_failure_at_move_start_test), {}