Files

692 lines
26 KiB
Diff
Raw Permalink Normal View History

--- a/drivers/net/wireless/mediatek/mt6797/mac-priv.h
+++ b/drivers/net/wireless/mediatek/mt6797/mac-priv.h
@@ -51,6 +51,7 @@
* several requests.
*/
#define MT6797_SCAN_REQUEST_CHANNELS 32U
+#define MT6797_ONLINE_SCAN_CHANNELS 4U
#define MT6797_SCAN_SSIDS 4U
struct mt6797_scan_frame {
@@ -433,11 +434,9 @@
#define MT6797_JOIN_TX_HDRLEN(fc) ((fc) & MT6797_JOIN_TX_QOS_BIT ? 26U : 24U)
-#define MT6797_JOIN_DATA_TX_FAILURES 8U
-/* At low signal eight frames can fail on a link that still works, and they take
- * under two seconds at low traffic, so they must also span this long.
- */
-#define MT6797_JOIN_DATA_TX_FAILURE_NS (3ULL * NSEC_PER_SEC)
+#define MT6797_JOIN_DATA_TX_FAILURES 16U
+/* Allow brief interference bursts without falsely tearing down the link. */
+#define MT6797_JOIN_DATA_TX_FAILURE_NS (5ULL * NSEC_PER_SEC)
/* One frame carries one rate here, so a failed probe of another rate loses that
* frame, and at low traffic minstrel_ht makes most frames probes. At most one
* in this many may be one.
@@ -691,6 +690,10 @@
unsigned int scan_packets;
/* A scan while connected: the worker submits it and reads its events. */
bool scan_online, scan_online_ready, scan_online_cancel;
+ u64 scan_online_end_ns;
+ u64 last_ap_activity_ns, last_beacon_timeout_ns;
+ unsigned int beacon_timeout_streak, ccmp_live_keys;
+ bool gtk_rekey_pending;
/* Signal threshold, from the access point's frames (1/16 dB average). */
int cqm_thold, cqm_last, cqm_average;
unsigned int cqm_hyst, cqm_samples, cqm_beacons;
@@ -728,7 +731,7 @@
* transmit fell to 0.5-9.5 Mbit/s on channel 40.
*/
#define MT6797_TX_ATTEMPTS 30U
-#define MT6797_TX_ATTEMPTS_DATA 3U
+#define MT6797_TX_ATTEMPTS_DATA 7U
/* A current, owned monitor notification is a normal connection loss, not a
* malformed transport event. End traffic and queue standard core teardown;
@@ -742,7 +745,7 @@
* (strictly checked PTK/GTK admissions only), so it ignores no more than the
* vendor would. A dead link stops that clock, and its next event is a loss.
*/
-#define MT6797_CCMP_TIMEOUT_FRESH_RX_MS 2000
+#define MT6797_CCMP_TIMEOUT_FRESH_RX_MS 6000
#define MT6797_CCMP_TIMEOUT_IGNORE_NAMED 16
@@ -839,9 +842,6 @@
const unsigned char ap[6], unsigned char bmc_index,
unsigned int *reason_out);
-bool mt6797_ccmp_rx_eapol_rekey(const unsigned char *packet, size_t bytes,
- const struct mt6797_ccmp_rx_context *context);
-
int mt6797_mac_join_open_lifetime(struct mt6797_mac *mac);
void mt6797_mac_join_read_bss(struct mt6797_mac *mac, struct ieee80211_vif *vif,
const struct ieee80211_bss_conf *info);
--- a/drivers/net/wireless/mediatek/mt6797/mcu.h
+++ b/drivers/net/wireless/mediatek/mt6797/mcu.h
@@ -868,7 +868,7 @@
(status_report ? (!pid || pid > 127) : pid != 0) ||
!lifetime_ms || lifetime_ms > 10000 || !attempt_count || attempt_count > 30)
return false;
- if ((frame[6] & 1) || (frame[12] == 0x88 && frame[13] == 0x8e))
+ if (frame[6] & 1)
return false;
lifetime = (lifetime_ms * 1000U / 1024U) >> 5;
if (!lifetime)
--- a/drivers/net/wireless/mediatek/mt6797/data.c
+++ b/drivers/net/wireless/mediatek/mt6797/data.c
@@ -807,10 +807,9 @@
source_any |= ethernet[6 + i] != 0;
pn[i] = packet[32 + 5 - i];
}
- /* Ethernet-II only; EAPOL remains on the existing control-port path. */
+ /* Ethernet-II (including PTK-encrypted EAPOL-Key GTK handshakes). */
if (!source_any || (ethernet[6] & 1) ||
- (((unsigned int)ethernet[12] << 8) | ethernet[13]) < 0x0600 ||
- (ethernet[12] == 0x88 && ethernet[13] == 0x8e))
+ (((unsigned int)ethernet[12] << 8) | ethernet[13]) < 0x0600)
return false;
tid = packet[9] & 15;
last = tid ? context->tid_pn[tid - 1] : context->pn;
@@ -1390,6 +1389,8 @@
if (mac->ccmp_queued < MT6797_CCMP_DIAG_CHECKED_MAX)
mac->ccmp_queued++;
mac->ccmp_last_checked_rx = ktime_get_ns();
+ mac->last_ap_activity_ns = mac->ccmp_last_checked_rx;
+ mac->beacon_timeout_streak = 0;
__skb_queue_tail(received, skb);
return 0;
}
@@ -1756,7 +1757,7 @@
bool mt6797_ccmp_owned_loss(struct mt6797_mac *mac, size_t bytes)
{
- u64 now;
+ u64 now, fresh;
if (!mt6797_join_event(mac->join_packet, bytes, 0x13, 4) ||
mac->join_packet[5] || mac->join_packet[8] || !mt6797_ccmp_rx_ready(mac) ||
@@ -1766,21 +1767,36 @@
mac->join_key_pairwise != 1 || mac->join_key_group != 1 || mac->ccmp_loss_reported)
return false;
now = ktime_get_ns();
- if (mac->join_packet[9] == 4 && mac->ccmp_queued &&
- mac->ccmp_last_checked_rx <= now &&
- now - mac->ccmp_last_checked_rx < MT6797_CCMP_TIMEOUT_FRESH_RX_MS * NSEC_PER_MSEC) {
- if (++mac->ccmp_timeout_ignored <= MT6797_CCMP_TIMEOUT_IGNORE_NAMED)
+ if (mac->join_packet[9] == 4) {
+ /* Firmware away on a scan or within post-scan settling window. */
+ if (mac->scan_online ||
+ (mac->scan_online_end_ns && now >= mac->scan_online_end_ns &&
+ now - mac->scan_online_end_ns < 5ULL * NSEC_PER_SEC))
+ return true;
+ fresh = max3(mac->ccmp_last_checked_rx, mac->last_ap_activity_ns,
+ mac->join_data_tx_ok_ns);
+ if (fresh && fresh <= now &&
+ now - fresh < (u64)MT6797_CCMP_TIMEOUT_FRESH_RX_MS * NSEC_PER_MSEC) {
+ mac->beacon_timeout_streak = 0;
+ if (++mac->ccmp_timeout_ignored <= MT6797_CCMP_TIMEOUT_IGNORE_NAMED)
+ dev_info(wiphy_dev(mac->hw->wiphy),
+ "one-shot WLAN BSS timeout ignored: reason=4 age_ms=%llu data_ms=%llu ignored=%u\n",
+ (now - fresh) / NSEC_PER_MSEC,
+ now > mac->join_data_started ?
+ (now - mac->join_data_started) / NSEC_PER_MSEC : 0,
+ mac->ccmp_timeout_ignored);
+ return true;
+ }
+ if (mac->last_beacon_timeout_ns && fresh > mac->last_beacon_timeout_ns)
+ mac->beacon_timeout_streak = 0;
+ mac->last_beacon_timeout_ns = now;
+ if (++mac->beacon_timeout_streak < 2) {
dev_info(wiphy_dev(mac->hw->wiphy),
- "one-shot WLAN BSS timeout ignored: reason=4 checked_rx_age_ms=%llu data_ms=%llu ignored=%u\n",
- (now - mac->ccmp_last_checked_rx) / NSEC_PER_MSEC,
- now > mac->join_data_started ?
- (now - mac->join_data_started) / NSEC_PER_MSEC : 0,
- mac->ccmp_timeout_ignored);
- return true;
- }
- /* The firmware away on a scan: its notice is not a lost connection. */
- if (mac->join_packet[9] == 4 && mac->scan_online)
- return true;
+ "one-shot WLAN BSS timeout deferred: reason=4 streak=%u\n",
+ mac->beacon_timeout_streak);
+ return true;
+ }
+ }
mt6797_mac_join_end_data(mac, "connection-loss");
mt6797_ccmp_connection_lost(mac, "monitor", mac->join_packet[9]);
return true;
@@ -1843,6 +1859,8 @@
IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_NO_SIGNAL_VAL;
}
mt6797_ccmp_pm_beacon(mac, offset, bytes);
+ mac->last_ap_activity_ns = ktime_get_ns();
+ mac->beacon_timeout_streak = 0;
__skb_queue_tail(received, skb);
return 0;
}
@@ -1983,71 +2001,3 @@
return true;
}
-bool mt6797_ccmp_rx_eapol_rekey(const unsigned char *packet, size_t bytes,
- const struct mt6797_ccmp_rx_context *context)
-{
- unsigned char pn[6];
- size_t offset = 48;
- unsigned int groups, fc, i, tid;
- const unsigned char *last;
- const unsigned char *ethernet;
- bool greater = false, own_any = false, ap_any = false, source_any = false;
-
- if (!packet || !context || bytes < 16 || bytes > 2352 ||
- !context->authorized || !context->active || !context->seeded ||
- !context->pairwise || context->cipher != 0x000fac04U ||
- context->key_bytes != 16 || context->key_id ||
- context->wlan_index != 1 || context->rxd_bssid > 63 || !context->channel ||
- (context->own[0] & 1) || (context->ap[0] & 1))
- return false;
- for (i = 0; i < 6; i++) {
- own_any |= context->own[i] != 0;
- ap_any |= context->ap[i] != 0;
- }
- if (!own_any || !ap_any || mt6797_join_le16(packet) != bytes ||
- (mt6797_join_le16(packet + 2) >> 13) != 2 ||
- packet[4] != 0x02 || packet[5] != context->channel ||
- (packet[6] & 0xbf) != 0x8e ||
- packet[7] != (unsigned int)context->rxd_bssid << 2 ||
- packet[8] != context->wlan_index || (packet[9] & 0xf0) != 0x40 ||
- !mt6797_ccmp_rx_status_ok(mt6797_join_le16(packet + 10)))
- return false;
- groups = (mt6797_join_le16(packet + 2) >> 9) & 15;
- if ((groups & 9) != 9)
- return false;
- if (groups & 2)
- offset += 8;
- if (groups & 4)
- offset += 24;
- if (packet[6] & 0x40)
- offset += 2;
- if (offset > bytes || bytes - offset <= 14)
- return false;
- fc = mt6797_join_le16(packet + 16);
- if ((fc & ~(0x2800U | MT6797_CCMP_RX_QOS_BIT)) != 0x4208 ||
- (mt6797_join_le16(packet + 24) & 15) ||
- !mt6797_ccmp_rx_tid_ok(packet, fc, 0x40) ||
- mt6797_join_le32(packet + 28))
- return false;
- ethernet = packet + offset;
- for (i = 0; i < 6; i++) {
- if (packet[18 + i] != context->ap[i] || ethernet[i] != context->own[i])
- return false;
- source_any |= ethernet[6 + i] != 0;
- pn[i] = packet[32 + 5 - i];
- }
- if (!source_any || (ethernet[6] & 1) ||
- ethernet[12] != 0x88 || ethernet[13] != 0x8e)
- return false;
- tid = packet[9] & 15;
- last = tid ? context->tid_pn[tid - 1] : context->pn;
- for (i = 0; i < 6; i++) {
- if (pn[i] < last[i])
- return false;
- if (pn[i] > last[i]) {
- greater = true;
- break;
- }
- }
- return greater;
-}
--- a/drivers/net/wireless/mediatek/mt6797/join.c
+++ b/drivers/net/wireless/mediatek/mt6797/join.c
@@ -595,6 +595,12 @@
mac->ps_failed = false;
mac->ccmp_last_checked_rx = 0;
mac->ccmp_timeout_ignored = 0;
+ mac->scan_online_end_ns = 0;
+ mac->last_ap_activity_ns = 0;
+ mac->last_beacon_timeout_ns = 0;
+ mac->beacon_timeout_streak = 0;
+ mac->ccmp_live_keys = 0;
+ mac->gtk_rekey_pending = false;
reinit_completion(&mac->ccmp_dtim_done);
mac->ccmp_dtim_period = 0;
mac->ccmp_dtim_status = 0;
@@ -913,6 +919,8 @@
mac->join_data_tx_done++;
mac->join_data_tx_failures_in_row = 0;
mac->join_data_tx_ok_ns = ktime_get_ns();
+ mac->last_ap_activity_ns = mac->join_data_tx_ok_ns;
+ mac->beacon_timeout_streak = 0;
ieee80211_tx_info_clear_status(IEEE80211_SKB_CB(skb));
IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
skb_queue_tail(&mac->credit_retired_queue, skb);
@@ -1218,6 +1226,9 @@
else if (owned && mac->join_key_done && mac->join_key_group_submitted &&
!mac->join_key_done_second)
window = "second after=group";
+ else if (owned && mac->join_key_done && mac->join_key_done_second &&
+ mac->join_data_phase && !mac->join_data_ended)
+ window = "rekey after=group";
if (!window) {
dev_info(wiphy_dev(mac->hw->wiphy),
"one-shot WLAN join key done refused: bss=%u peer=%u broadcast=%u seq=%u submitted=%u%u recorded=%u%u\n",
@@ -1967,6 +1978,8 @@
mac->join_data_tx_done++;
mac->join_data_tx_failures_in_row = 0;
mac->join_data_tx_ok_ns = ktime_get_ns();
+ mac->last_ap_activity_ns = mac->join_data_tx_ok_ns;
+ mac->beacon_timeout_streak = 0;
return;
}
mac->join_data_tx_failed++;
@@ -2055,10 +2068,10 @@
*/
if (!mac->join_closed && (mac->join_key_pairwise_submitted ||
mac->join_key_group_submitted) &&
- mac->ccmp_key_disables < 2) {
+ mac->ccmp_live_keys > 0) {
dev_info(wiphy_dev(mac->hw->wiphy),
- "one-shot WLAN join rearm deferred: key_removals=%u\n",
- mac->ccmp_key_disables);
+ "one-shot WLAN join rearm deferred: live_keys=%u\n",
+ mac->ccmp_live_keys);
goto unlock;
}
mac->join_rearm_pending = false;
@@ -2222,9 +2235,6 @@
ret = mt6797_mac_join_guard(mac, deadline);
if (ret)
goto failed;
- ret = mt6797_mac_online_scan_step(mac);
- if (ret)
- goto failed;
mt6797_native_diag_step(mac);
if (mac->join_data_phase && !mac->join_data_ended &&
ktime_get_ns() >= mac->join_data_deadline)
@@ -2237,7 +2247,8 @@
select_more:
branch = 3;
select = !mac->join_inflight && !mac->join_page_debt;
- if (channel_release_holds_tx)
+ if (channel_release_holds_tx || mac->gtk_rekey_pending ||
+ (mac->scan_online && !mac->scan_online_ready))
select = false;
/* PID-budget exhaustion ends the data phase in the queue path; evaluate it
* before any frame is selected so the step disables and the fence holds.
@@ -2268,9 +2279,11 @@
u64 now_ns = ktime_get_ns();
skb_queue_walk_safe(&mac->join_queue, walk, tmp) {
- bool data = (get_unaligned_le16(walk->data) & 0x0c) == 0x08;
+ u16 walk_fc = get_unaligned_le16(walk->data);
+ bool data = (walk_fc & 0x0c) == 0x08;
bool port = IEEE80211_SKB_CB(walk)->control.flags &
IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
+ bool prekey_eapol = port && !(walk_fc & IEEE80211_FCTL_PROTECTED);
if (walk == mac->join_internal &&
(now_ns < mac->join_hold_until ||
@@ -2281,18 +2294,18 @@
/* Ordinary data goes out only inside the data phase; a
* frame still queued when the phase ended is discarded.
*/
- if (data && !port && walk != mac->join_internal &&
+ if (data && !prekey_eapol && walk != mac->join_internal &&
mac->join_data_phase && !mac->join_data_ended &&
mac->join_next_pid > MT6797_JOIN_DATA_LAST_PID)
mt6797_mac_join_end_data(mac, "pidbudget");
- if (data && !port && walk != mac->join_internal &&
+ if (data && !prekey_eapol && walk != mac->join_internal &&
(!mac->join_data_phase || mac->join_data_ended)) {
__skb_unlink(walk, &mac->join_queue);
mac->join_queue_bytes -= walk->len;
__skb_queue_tail(&discard, walk);
continue;
}
- if (data && !port && walk != mac->join_internal) {
+ if (data && !prekey_eapol && walk != mac->join_internal) {
if (!mt6797_ccmp_data_room(mac, walk->len))
continue;
} else if (mac->data_slots.count) {
@@ -2349,19 +2362,20 @@
size_t eth_bytes = 14 + skb->len - (hl + 8);
bool port = IEEE80211_SKB_CB(skb)->control.flags &
IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
+ bool prekey_eapol = port && !(fc & IEEE80211_FCTL_PROTECTED);
if (skb->len < hl + 12 || eth_bytes > MT6797_JOIN_ETH_MAX_BYTES ||
!mac->join_sta_active ||
- (!port && (!mac->join_data_phase || mac->join_data_ended))) {
+ (!prekey_eapol && (!mac->join_data_phase || mac->join_data_ended))) {
ret = -EINVAL;
goto failed;
}
- ret = mt6797_ccmp_assign_pid(mac, false, !port);
+ ret = mt6797_ccmp_assign_pid(mac, false, !prekey_eapol);
if (ret)
goto failed;
mac->join_last_acked = false;
reinit_completion(&mac->join_frame_done);
- if (!port) {
+ if (!prekey_eapol) {
memcpy(mac->join_eth, skb->data + 16, ETH_ALEN);
memcpy(mac->join_eth + 6, skb->data + 10, ETH_ALEN);
memcpy(mac->join_eth + 12, skb->data + hl + 6, 2);
@@ -2387,6 +2401,8 @@
(IEEE80211_SKB_CB(skb)->flags &
IEEE80211_TX_CTL_RATE_CTRL_PROBE))
sample = true;
+ if (port)
+ sample = true;
if (sample) {
mac->tx_sample_counter = 0;
mac->tx_report_ns = ktime_get_ns();
@@ -2395,7 +2411,8 @@
eth_bytes, 1,
sample ? mac->join_pid : 0,
sample,
- 500, MT6797_TX_ATTEMPTS_DATA,
+ 500,
+ port ? MT6797_TX_ATTEMPTS : MT6797_TX_ATTEMPTS_DATA,
per_frame,
deadline);
if (ret)
@@ -2468,6 +2485,9 @@
}
}
}
+ ret = mt6797_mac_online_scan_step(mac);
+ if (ret)
+ goto failed;
mt6797_hif_rx_batch_pass(mac->hif);
mac->join_pass_read = true;
for (n = 0; n < 8; n++) {
@@ -2881,16 +2901,6 @@
}
continue;
}
- if (admitted && mt6797_ccmp_rx_ready(mac) &&
- mt6797_ccmp_rx_eapol_rekey(mac->join_packet,
- rx.logical_bytes,
- &mac->ccmp_rx)) {
- dev_info(wiphy_dev(mac->hw->wiphy),
- "one-shot WLAN peer GTK rekey: triggering reassociation\n");
- mt6797_mac_join_end_data(mac, "gtk-rekey");
- mt6797_ccmp_connection_lost(mac, "gtk-rekey", 0);
- continue;
- }
if (admitted)
ret = mt6797_ccmp_queue_rx(mac, rx.logical_bytes,
&received);
--- a/drivers/net/wireless/mediatek/mt6797/main.c
+++ b/drivers/net/wireless/mediatek/mt6797/main.c
@@ -13,8 +13,8 @@
/* Fast power save by default: with CONFIG_CFG80211_DEFAULT_PS it is on at every
* join, and it took about 57 mA off a quiet link. 0 offers none.
*/
-static uint power_save = 2;
-module_param(power_save, uint, 0444);
+static uint power_save = 0;
+module_param(power_save, uint, 0644);
MODULE_PARM_DESC(power_save, "802.11 power save offered to mac80211: 0 none, 1 maximum, 2 fast");
module_param(wlan_irq, bool, 0444);
MODULE_PARM_DESC(wlan_irq, "Serve receive from the WLAN interrupt when the device tree gives one");
@@ -858,9 +858,10 @@
unsigned int count, next_seq;
int ret;
- /* A request is all probing or all passive. */
+ /* Online scans use short 4-channel excursions so traffic is not stalled. */
count = min((probing ? mac->scan_probing : mac->scan_total) - mac->scan_next,
- MT6797_SCAN_REQUEST_CHANNELS);
+ mac->scan_online ? MT6797_ONLINE_SCAN_CHANNELS :
+ MT6797_SCAN_REQUEST_CHANNELS);
/* Keep scan_sequence monotonic within a session so stale 0x0d events
* emitted after a cancelled scan never match a later scan request.
*/
@@ -894,6 +895,7 @@
if (!mac->scan_online)
return;
mac->scan_online = false;
+ mac->scan_online_end_ns = ktime_get_ns();
dev_info(wiphy_dev(mac->hw->wiphy),
"one-shot WLAN connected scan: requests=%u aborted=%u\n",
mac->scan_sequence, aborted);
@@ -911,7 +913,8 @@
if (!mac->scan_online && !mac->scan_online_cancel)
return 0;
- if (mac->join_page_debt || mac->join_credit_pending || mac->join_inflight)
+ if (mac->join_page_debt || mac->join_credit_pending || mac->join_inflight ||
+ mac->data_slots.count || mac->join_data_page_debt || mac->gtk_rekey_pending)
return 0;
if (mac->scan_online_cancel) {
mac->scan_online_cancel = false;
@@ -1291,9 +1294,10 @@
/* The firmware's default dwell: it keeps returning to the channel. */
mac->scan_dwell_ms = 0;
mac->scan_channels = mask;
- mac->scan_deadline = ktime_get_ns() + 5 * NSEC_PER_SEC;
+ mac->scan_deadline = ktime_get_ns() + 15 * NSEC_PER_SEC;
mac->scan_online_ready = true;
mac->scan_online = true;
+ schedule_delayed_work(&mac->join_work, 0);
dev_info(wiphy_dev(hw->wiphy),
"one-shot WLAN connected scan: admitted=1 channels=%u probing=%u ssids=%u sequence=%u\n",
mac->scan_total, mac->scan_probing, mac->scan_n_ssids, mac->sequence);
@@ -1758,8 +1762,8 @@
* itself still decides with the rendezvous and quiescence rules.
*/
mutex_lock(&mac->mutex);
- if (mac->join_rearm_pending && !mac->join_closed && !mac->first_error &&
- !mac->closing)
+ if (mac->join_rearm_pending && !mac->ccmp_live_keys &&
+ !mac->join_closed && !mac->first_error && !mac->closing)
schedule_delayed_work(&mac->join_work, msecs_to_jiffies(20));
mutex_unlock(&mac->mutex);
while ((skb = __skb_dequeue(&discard))) {
@@ -1812,8 +1816,14 @@
mac->closing, mac->first_error);
return;
}
- if (mac->join_inflight || mac->data_slots.count || mac->join_page_debt) {
+ if (mac->data_slots.count || mac->join_data_page_debt) {
+ ret = -EBUSY;
+ goto out;
+ }
+ if (mac->join_inflight || mac->join_page_debt) {
ret = mt6797_mac_join_wait_management(mac);
+ if (ret == -EPROTO && (mac->data_slots.count || mac->join_data_page_debt))
+ ret = -EBUSY;
if (ret)
goto out;
}
@@ -1868,14 +1878,33 @@
if (cmd == DISABLE_KEY) {
mutex_lock(&mac->mutex);
- if (mac->ccmp_gtk_deferred == key)
+ if (mac->ccmp_gtk_deferred == key) {
mac->ccmp_gtk_deferred = NULL;
+ mutex_unlock(&mac->mutex);
+ return 0;
+ }
+ if (mac->ccmp_live_keys > 0)
+ mac->ccmp_live_keys--;
+ if (!pairwise && mac->join_data_phase && !mac->join_data_ended &&
+ mac->ccmp_rx.authorized && mac->ccmp_ptk &&
+ !mac->closing && !mac->first_error) {
+ if (mac->ccmp_gtk == key) {
+ mac->ccmp_gtk_rx.active = false;
+ spin_lock_irqsave(&mac->join_queue.lock, flags);
+ mac->ccmp_gtk = NULL;
+ spin_unlock_irqrestore(&mac->join_queue.lock, flags);
+ }
+ mutex_unlock(&mac->mutex);
+ mutex_lock(&mac->ccmp_receive_mutex);
+ mutex_unlock(&mac->ccmp_receive_mutex);
+ dev_info(wiphy_dev(hw->wiphy),
+ "one-shot WLAN GTK key retired in-place: keyidx=%d\n",
+ key->keyidx);
+ return 0;
+ }
mutex_unlock(&mac->mutex);
return mt6797_ccmp_disable_key(mac);
}
-
- if (cmd == DISABLE_KEY)
- return 0;
mutex_lock(&mac->mutex);
if (!mac->ccmp_pm_connected) {
ret = -EOPNOTSUPP;
@@ -1893,6 +1922,117 @@
"one-shot WLAN join key deferred: group before pairwise\n");
return 0;
}
+ /* In-place GTK rekey during an established data phase: install the new
+ * group key under MT6797_JOIN_BMC_WLAN_INDEX without tearing down the link.
+ */
+ if (!pairwise && !sta && vif == mac->vif && mac->join_rsn &&
+ mac->join_data_phase && !mac->join_data_ended &&
+ mac->ccmp_rx.active && mac->ccmp_rx.authorized &&
+ mac->join_key_pairwise == 1 && !mac->ccmp_closed &&
+ !mac->closing && !mac->first_error) {
+ u64 wait_end;
+
+ if (!((key->cipher == WLAN_CIPHER_SUITE_CCMP && key->keylen == 16) ||
+ (key->cipher == WLAN_CIPHER_SUITE_TKIP && key->keylen == 32)) ||
+ key->keyidx < 0 || key->keyidx > 3) {
+ ret = -EOPNOTSUPP;
+ goto failed;
+ }
+ mutex_unlock(&mac->mutex);
+ mutex_lock(&mac->ccmp_receive_mutex);
+ ieee80211_get_key_rx_seq(key, 0, &seed);
+ for (tid = 1; tid < MT6797_CCMP_RX_TIDS; tid++)
+ ieee80211_get_key_rx_seq(key, tid, &tid_seed[tid - 1]);
+ mutex_unlock(&mac->ccmp_receive_mutex);
+ mutex_lock(&mac->mutex);
+ if (mac->ccmp_closed || mac->first_error || mac->closing ||
+ mac->join_retired || !mac->join_data_phase || mac->join_data_ended) {
+ ret = mac->first_error ? mac->first_error : -EOPNOTSUPP;
+ goto failed;
+ }
+ mac->gtk_rekey_pending = true;
+ schedule_delayed_work(&mac->join_work, 0);
+ wait_end = ktime_get_ns() + 1000 * NSEC_PER_MSEC;
+ while ((mac->join_inflight || mac->data_slots.count ||
+ mac->join_page_debt || mac->join_data_page_debt ||
+ mac->join_credit_pending || !mt6797_hif_normal_idle(mac->hif)) &&
+ ktime_get_ns() < wait_end &&
+ !mac->first_error && !mac->closing &&
+ !mac->join_retired && !mac->join_data_ended) {
+ mutex_unlock(&mac->mutex);
+ usleep_range(2000, 4000);
+ mutex_lock(&mac->mutex);
+ }
+ if (mac->ccmp_closed || mac->first_error || mac->closing ||
+ mac->join_retired || !mac->join_data_phase || mac->join_data_ended) {
+ mac->gtk_rekey_pending = false;
+ ret = mac->first_error ? mac->first_error : -ECANCELED;
+ goto failed;
+ }
+ if (mac->join_inflight || mac->data_slots.count ||
+ mac->join_page_debt || mac->join_data_page_debt ||
+ mac->join_credit_pending || !mt6797_hif_normal_idle(mac->hif)) {
+ mac->gtk_rekey_pending = false;
+ ret = -EBUSY;
+ goto failed;
+ }
+ if (mac->sequence > 200 && mac->sequence_base &&
+ !mt6797_hif_recycle_sequences(mac->hif, mac->sequence_base))
+ mac->sequence = mac->sequence_base;
+ if (mac->sequence > 253) {
+ mac->gtk_rekey_pending = false;
+ ret = -ENOSPC;
+ goto failed;
+ }
+ mac->ccmp_gtk_rx.active = false;
+ mac->join_credit_deadline = ktime_get_ns() + 150 * NSEC_PER_MSEC;
+ reinit_completion(&mac->join_credit_done);
+ mac->join_credit_pending = true;
+ mac->join_page_debt = 1;
+ ret = mt6797_hif_join_key_cipher(mac->hif, mac->sequence++, true, false,
+ key->cipher == WLAN_CIPHER_SUITE_TKIP,
+ mac->join_ap, key->keyidx, key->key,
+ mac->join_credit_deadline);
+ mt6797_mac_join_refused(mac, ret);
+ if (!ret)
+ ret = mt6797_mac_join_wait_credit(mac);
+ mac->gtk_rekey_pending = false;
+ if (ret || mac->ccmp_closed || mac->first_error || mac->closing ||
+ mac->join_retired || !mac->join_data_phase || mac->join_data_ended) {
+ if (!ret)
+ ret = mac->first_error ? mac->first_error : -EOPNOTSUPP;
+ goto failed;
+ }
+ mt6797_copy_key_seq(key->cipher, &seed, mac->ccmp_gtk_rx.pn);
+ for (tid = 1; tid < MT6797_CCMP_RX_TIDS; tid++)
+ mt6797_copy_key_seq(key->cipher, &tid_seed[tid - 1],
+ mac->ccmp_gtk_rx.tid_pn[tid - 1]);
+ memcpy(mac->ccmp_gtk_rx.own, hw->wiphy->perm_addr, 6);
+ memcpy(mac->ccmp_gtk_rx.ap, mac->join_ap, 6);
+ mac->ccmp_gtk_rx.cipher = key->cipher;
+ mac->ccmp_gtk_rx.key_bytes = key->keylen;
+ mac->ccmp_gtk_rx.key_id = key->keyidx;
+ mac->ccmp_gtk_rx.wlan_index = MT6797_JOIN_BMC_WLAN_INDEX;
+ mac->ccmp_gtk_rx.rxd_bssid = 1;
+ mac->ccmp_gtk_rx.channel = mac->join_chan_number;
+ mac->ccmp_gtk_rx.pairwise = false;
+ mac->ccmp_gtk_rx.seeded = true;
+ mac->ccmp_gtk_rx.authorized = mac->ccmp_rx.authorized;
+ mac->ccmp_gtk_rx.active = true;
+ key->hw_key_idx = MT6797_JOIN_BMC_WLAN_INDEX;
+ spin_lock_irqsave(&mac->join_queue.lock, flags);
+ mac->ccmp_gtk = key;
+ spin_unlock_irqrestore(&mac->join_queue.lock, flags);
+ mac->join_key_group = 1;
+ mac->join_group_key_id = key->keyidx;
+ mac->ccmp_live_keys++;
+ schedule_delayed_work(&mac->join_work, 0);
+ dev_info(wiphy_dev(hw->wiphy),
+ "one-shot WLAN GTK rekey installed in-place: keyidx=%d sequence=%u\n",
+ key->keyidx, mac->sequence - 1);
+ mutex_unlock(&mac->mutex);
+ return 0;
+ }
if ((mac->ccmp_closed ||
(pairwise && mac->ccmp_ptk_attempted) ||
(!pairwise && mac->ccmp_gtk_attempted))) {
@@ -2051,6 +2191,7 @@
struct ieee80211_key_conf *deferred = mac->ccmp_gtk_deferred;
mac->join_key_pairwise = 1;
+ mac->ccmp_live_keys++;
mac->ccmp_gtk_deferred = NULL;
mutex_unlock(&mac->mutex);
/* A failure ends the lifetime there; the pairwise key stands. */
@@ -2059,6 +2200,7 @@
return 0;
} else {
mac->join_key_group = 1;
+ mac->ccmp_live_keys++;
mac->join_group_key_id = key->keyidx;
/* Both keys installed: open the bounded data phase inside the
* grant; the reserved deauthentication waits for its end and
@@ -2435,14 +2577,12 @@
* reported. Anything else below the admission is freed unsent.
*/
if (skb->len >= sizeof(header) && skb->len <= sizeof(header) + 1500 &&
- !(IEEE80211_SKB_CB(skb)->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) &&
IEEE80211_SKB_CB(skb)->control.hw_key &&
!skb_copy_bits(skb, 0, header, sizeof(header)) &&
mt6797_mac_tx_hdrlen(header, &hl) &&
(mt6797_join_le16(header) & ~(0x0800U | MT6797_JOIN_TX_QOS_BIT)) == 0x4108 &&
!mt6797_join_qos_tid_refused(mac, skb, header, hl) &&
!memcmp(header + hl, llc_eapol, 6) &&
- !(header[hl + 6] == 0x88 && header[hl + 7] == 0x8e) &&
ether_addr_equal(header + 4, mac->join_ap) &&
ether_addr_equal(header + 10, hw->wiphy->perm_addr)) {
spin_lock_irqsave(&mac->join_queue.lock, flags);