--- a/drivers/net/wireless/mediatek/mt6797/mac-priv.h +++ b/drivers/net/wireless/mediatek/mt6797/mac-priv.h @@ -832,6 +832,16 @@ void mt6797_ccmp_connection_lost(struct mt6797_mac *mac, const char *source, void mt6797_ccmp_receive(struct mt6797_mac *mac, struct sk_buff *skb); +bool mt6797_ccmp_rx_ready(struct mt6797_mac *mac); + +bool mt6797_join_peer_deauth(const unsigned char *packet, size_t bytes, + unsigned char channel, const unsigned char own[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/data.c +++ b/drivers/net/wireless/mediatek/mt6797/data.c @@ -1174,7 +1174,7 @@ void mt6797_ccmp_withdraw(struct mt6797_mac *mac) complete_all(&mac->ccmp_key_done); } -static bool mt6797_ccmp_rx_ready(struct mt6797_mac *mac) +bool mt6797_ccmp_rx_ready(struct mt6797_mac *mac) { return !mac->ccmp_closed && mac->ccmp_rx.active && mac->ccmp_rx.authorized && mac->ccmp_decap && rcu_access_pointer(mac->ccmp_sta) && mac->ccmp_ptk && @@ -1919,3 +1919,135 @@ void mt6797_mac_eapol_trace(struct mt6797_mac *mac, size_t bytes, bytes, frame_bytes, eapol_bytes, p[5], !!(p[6] & 0x80), copied, (int)sizeof(header), header); } + +bool mt6797_join_peer_deauth(const unsigned char *packet, size_t bytes, + unsigned char channel, const unsigned char own[6], + const unsigned char ap[6], unsigned char bmc_index, + unsigned int *reason_out) +{ + static const unsigned char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + size_t offset = 16; + unsigned int type, groups, match, status, fc, subtype; + const unsigned char *f; + + if (!packet || !own || !ap || !channel || bytes < 16 || bytes > 4096 || + mt6797_join_le16(packet) != bytes || packet[5] != channel) + return false; + type = mt6797_join_le16(packet + 2); + if ((type & 0xe00f) != 0xe001) + return false; + if ((packet[6] & 0xbf) != 24 || packet[7] != 0x04) + return false; + match = packet[4] & 0x3f; + if (match == 0x02) { + if (packet[8] != 1) + return false; + } else if (match == 0x08) { + if (packet[8] != bmc_index) + return false; + } else { + return false; + } + status = mt6797_join_le16(packet + 10); + if (status != 0xe000 && status != 0xe004) + return false; + groups = (type >> 9) & 15; + if (groups & 8) + offset += 16; + if (groups & 1) + offset += 16; + if (groups & 2) + offset += 8; + if (groups & 4) + offset += 24; + if (packet[6] & 0x40) + offset += 2; + if (offset > bytes || bytes - offset < 26) + return false; + f = packet + offset; + fc = mt6797_join_le16(f); + subtype = (fc >> 4) & 15; + if ((fc & 0xc70f) || (subtype != 10 && subtype != 12) || + (mt6797_join_le16(f + 22) & 15)) + return false; + if (match == 0x02) { + if (memcmp(f + 4, own, 6)) + return false; + } else if (memcmp(f + 4, broadcast, 6)) { + return false; + } + if (memcmp(f + 10, ap, 6) || memcmp(f + 16, ap, 6)) + return false; + if (reason_out) + *reason_out = mt6797_join_le16(f + 24); + 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 @@ -2838,6 +2838,7 @@ void mt6797_mac_join_work(struct work_struct *work) mac->native_diag_bytes }; bool admitted; struct mt6797_native_beacon nbcn; + unsigned int deauth_reason; nb.native_rx = mac->ccmp_queued; admitted = mac->native_diag_state == MT6797_ND_ACTIVE && @@ -2861,6 +2862,35 @@ void mt6797_mac_join_work(struct work_struct *work) goto failed; continue; } + if (mac->join_assoc_received && !mac->join_assoc_status && + !mac->join_cleanup_done && + mt6797_join_peer_deauth(mac->join_packet, + rx.logical_bytes, + mac->join_chan_number, + mac->hw->wiphy->perm_addr, + mac->join_ap, + MT6797_JOIN_BMC_WLAN_INDEX, + &deauth_reason)) { + if (mac->join_data_phase && !mac->join_data_ended) { + dev_info(wiphy_dev(mac->hw->wiphy), + "one-shot WLAN peer deauth/disassoc: reason=%u\n", + deauth_reason); + mt6797_mac_join_end_data(mac, "peer-deauth"); + mt6797_ccmp_connection_lost(mac, "peer-deauth", + deauth_reason); + } + 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);