^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2008, 2009 open80211s Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2019 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Luis Carlos Cobo <luisca@cozybit.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "rate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "mesh.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define PLINK_CNF_AID(mgmt) ((mgmt)->u.action.u.self_prot.variable + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PLINK_GET_LLID(p) (p + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define PLINK_GET_PLID(p) (p + 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define mod_plink_timer(s, t) (mod_timer(&s->mesh->plink_timer, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) jiffies + msecs_to_jiffies(t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) enum plink_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) PLINK_UNDEFINED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) OPN_ACPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) OPN_RJCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) OPN_IGNR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) CNF_ACPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) CNF_RJCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) CNF_IGNR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) CLS_ACPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) CLS_IGNR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static const char * const mplstates[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) [NL80211_PLINK_LISTEN] = "LISTEN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) [NL80211_PLINK_ESTAB] = "ESTAB",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) [NL80211_PLINK_HOLDING] = "HOLDING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) [NL80211_PLINK_BLOCKED] = "BLOCKED"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const char * const mplevents[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) [PLINK_UNDEFINED] = "NONE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) [OPN_ACPT] = "OPN_ACPT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) [OPN_RJCT] = "OPN_RJCT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) [OPN_IGNR] = "OPN_IGNR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) [CNF_ACPT] = "CNF_ACPT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) [CNF_RJCT] = "CNF_RJCT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) [CNF_IGNR] = "CNF_IGNR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) [CLS_ACPT] = "CLS_ACPT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) [CLS_IGNR] = "CLS_IGNR"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* We only need a valid sta if user configured a minimum rssi_threshold. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static bool rssi_threshold_check(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) s32 rssi_threshold = sdata->u.mesh.mshcfg.rssi_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return rssi_threshold == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) (sta &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) (s8)-ewma_signal_read(&sta->rx_stats_avg.signal) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) rssi_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @sta: mesh peer link to restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Locking: this function must be called holding sta->mesh->plink_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static inline void mesh_plink_fsm_restart(struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) lockdep_assert_held(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sta->mesh->plink_state = NL80211_PLINK_LISTEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) sta->mesh->llid = sta->mesh->plid = sta->mesh->reason = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) sta->mesh->plink_retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * mesh_set_short_slot_time - enable / disable ERP short slot time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * The standard indirectly mandates mesh STAs to turn off short slot time by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * disallowing advertising this (802.11-2012 8.4.1.4), but that doesn't mean we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * can't be sneaky about it. Enable short slot time if all mesh STAs in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * MBSS support ERP rates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Returns BSS_CHANGED_ERP_SLOT or 0 for no change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static u32 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u32 erp_rates = 0, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) bool short_slot = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) sband = ieee80211_get_sband(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (!sband)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (sband->band == NL80211_BAND_5GHZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* (IEEE 802.11-2012 19.4.5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) short_slot = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) } else if (sband->band != NL80211_BAND_2GHZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) for (i = 0; i < sband->n_bitrates; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (sband->bitrates[i].flags & IEEE80211_RATE_ERP_G)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) erp_rates |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!erp_rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) list_for_each_entry_rcu(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (sdata != sta->sdata ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) sta->mesh->plink_state != NL80211_PLINK_ESTAB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) short_slot = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (erp_rates & sta->sta.supp_rates[sband->band])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) short_slot = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (sdata->vif.bss_conf.use_short_slot != short_slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) sdata->vif.bss_conf.use_short_slot = short_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) changed = BSS_CHANGED_ERP_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mpl_dbg(sdata, "mesh_plink %pM: ERP short slot time %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) sdata->vif.addr, short_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * mesh_set_ht_prot_mode - set correct HT protection mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * @sdata: the (mesh) interface to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * HT20 peer is present. Otherwise no-protection mode is selected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u16 ht_opmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) bool non_ht_sta = false, ht20_sta = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) switch (sdata->vif.bss_conf.chandef.width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case NL80211_CHAN_WIDTH_20_NOHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case NL80211_CHAN_WIDTH_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) case NL80211_CHAN_WIDTH_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) list_for_each_entry_rcu(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (sdata != sta->sdata ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) sta->mesh->plink_state != NL80211_PLINK_ESTAB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (sta->sta.bandwidth > IEEE80211_STA_RX_BW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!sta->sta.ht_cap.ht_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) mpl_dbg(sdata, "nonHT sta (%pM) is present\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) sta->sta.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) non_ht_sta = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) mpl_dbg(sdata, "HT20 sta (%pM) is present\n", sta->sta.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ht20_sta = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (non_ht_sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) else if (ht20_sta &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (sdata->vif.bss_conf.ht_operation_mode == ht_opmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) mpl_dbg(sdata, "selected new HT protection mode %d\n", ht_opmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return BSS_CHANGED_HT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct sta_info *sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) enum ieee80211_self_protected_actioncode action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) u8 *da, u16 llid, u16 plid, u16 reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct ieee80211_tx_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct ieee80211_mgmt *mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bool include_plid = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) u16 peering_proto = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) u8 *pos, ie_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) u8 ie_len_he_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.self_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ie_len_he_cap = ieee80211_ie_len_he_cap(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) NL80211_IFTYPE_MESH_POINT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) skb = dev_alloc_skb(local->tx_headroom +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) hdr_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 2 + /* capability info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 2 + /* AID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 2 + 8 + /* supported rates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 2 + sdata->u.mesh.mesh_id_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 2 + sizeof(struct ieee80211_meshconf_ie) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 2 + sizeof(struct ieee80211_ht_cap) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 2 + sizeof(struct ieee80211_ht_operation) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 2 + sizeof(struct ieee80211_vht_cap) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 2 + sizeof(struct ieee80211_vht_operation) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ie_len_he_cap +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 2 + 1 + sizeof(struct ieee80211_he_operation) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sizeof(struct ieee80211_he_6ghz_oper) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 2 + 8 + /* peering IE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) sdata->u.mesh.ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) skb_reserve(skb, local->tx_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) mgmt = skb_put_zero(skb, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) IEEE80211_STYPE_ACTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) memcpy(mgmt->da, da, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) mgmt->u.action.u.self_prot.action_code = action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (action != WLAN_SP_MESH_PEERING_CLOSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) enum nl80211_band band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) sband = ieee80211_get_sband(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!sband) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) band = sband->band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* capability info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) pos = skb_put_zero(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* AID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) pos = skb_put(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) put_unaligned_le16(sta->sta.aid, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) mesh_add_rsn_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mesh_add_meshid_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) mesh_add_meshconf_ie(sdata, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) } else { /* WLAN_SP_MESH_PEERING_CLOSE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) info->flags |= IEEE80211_TX_CTL_NO_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (mesh_add_meshid_ie(sdata, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* Add Mesh Peering Management element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) case WLAN_SP_MESH_PEERING_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) case WLAN_SP_MESH_PEERING_CONFIRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ie_len += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) include_plid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) case WLAN_SP_MESH_PEERING_CLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (plid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ie_len += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) include_plid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ie_len += 2; /* reason code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pos = skb_put(skb, 2 + ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) *pos++ = WLAN_EID_PEER_MGMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) *pos++ = ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) memcpy(pos, &peering_proto, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pos += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) put_unaligned_le16(llid, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pos += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (include_plid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) put_unaligned_le16(plid, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) pos += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (action == WLAN_SP_MESH_PEERING_CLOSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) put_unaligned_le16(reason, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) pos += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (action != WLAN_SP_MESH_PEERING_CLOSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (mesh_add_ht_cap_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) mesh_add_ht_oper_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mesh_add_vht_cap_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mesh_add_vht_oper_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) mesh_add_he_cap_ie(sdata, skb, ie_len_he_cap) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) mesh_add_he_oper_ie(sdata, skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) mesh_add_he_6ghz_cap_ie(sdata, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (mesh_add_vendor_ies(sdata, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ieee80211_tx_skb(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * __mesh_plink_deactivate - deactivate mesh peer link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * @sta: mesh peer link to deactivate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * Mesh paths with this peer as next hop should be flushed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * by the caller outside of plink_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * Returns beacon changed flag if the beacon content changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * Locking: the caller must hold sta->mesh->plink_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static u32 __mesh_plink_deactivate(struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct ieee80211_sub_if_data *sdata = sta->sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) lockdep_assert_held(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) changed = mesh_plink_dec_estab_count(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ieee80211_mps_sta_status_update(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) changed |= ieee80211_mps_set_sta_local_pm(sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) NL80211_MESH_POWER_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * mesh_plink_deactivate - deactivate mesh peer link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * @sta: mesh peer link to deactivate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * All mesh paths with this peer as next hop will be flushed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) u32 mesh_plink_deactivate(struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct ieee80211_sub_if_data *sdata = sta->sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) u32 changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) spin_lock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) changed = __mesh_plink_deactivate(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (!sdata->u.mesh.user_mpm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) sta->mesh->reason = WLAN_REASON_MESH_PEER_CANCELED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) mesh_plink_frame_tx(sdata, sta, WLAN_SP_MESH_PEERING_CLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) sta->sta.addr, sta->mesh->llid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) sta->mesh->plid, sta->mesh->reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!sdata->u.mesh.user_mpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) del_timer_sync(&sta->mesh->plink_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) mesh_path_flush_by_nexthop(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* make sure no readers can access nexthop sta from here on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct sta_info *sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct ieee802_11_elems *elems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) u32 rates, basic_rates = 0, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) enum ieee80211_sta_rx_bandwidth bw = sta->sta.bandwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) sband = ieee80211_get_sband(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!sband)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) rates = ieee80211_sta_get_rates(sdata, elems, sband->band,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) &basic_rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) spin_lock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) sta->rx_stats.last_rx = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* rates and capabilities don't change during peering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (sta->mesh->plink_state == NL80211_PLINK_ESTAB &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) sta->mesh->processed_beacon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) sta->mesh->processed_beacon = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (sta->sta.supp_rates[sband->band] != rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sta->sta.supp_rates[sband->band] = rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) elems->ht_cap_elem, sta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) changed |= IEEE80211_RC_BW_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) elems->vht_cap_elem, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, elems->he_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) elems->he_cap_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) elems->he_6ghz_capa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (bw != sta->sta.bandwidth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) changed |= IEEE80211_RC_BW_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* HT peer is operating 20MHz-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (elems->ht_operation &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) !(elems->ht_operation->ht_param &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (sta->sta.bandwidth != IEEE80211_STA_RX_BW_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) changed |= IEEE80211_RC_BW_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) sta->sta.bandwidth = IEEE80211_STA_RX_BW_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) rate_control_rate_init(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) rate_control_rate_update(local, sband, sta, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int mesh_allocate_aid(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) unsigned long *aid_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int aid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) aid_map = kcalloc(BITS_TO_LONGS(IEEE80211_MAX_AID + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) sizeof(*aid_map), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!aid_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* reserve aid 0 for mcast indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) __set_bit(0, aid_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) list_for_each_entry_rcu(sta, &sdata->local->sta_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) __set_bit(sta->sta.aid, aid_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) aid = find_first_zero_bit(aid_map, IEEE80211_MAX_AID + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) kfree(aid_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (aid > IEEE80211_MAX_AID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return aid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static struct sta_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) __mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int aid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (sdata->local->num_sta >= MESH_MAX_PLINKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) aid = mesh_allocate_aid(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (aid < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (!sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) sta->mesh->plink_state = NL80211_PLINK_LISTEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) sta->sta.wme = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) sta->sta.aid = aid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static struct sta_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct ieee80211_rx_status *rx_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct sta_info *sta = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* Userspace handles station allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (sdata->u.mesh.user_mpm ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (mesh_peer_accepts_plinks(elems) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) mesh_plink_availables(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) int sig = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) sig = rx_status->signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) cfg80211_notify_new_peer_candidate(sdata->dev, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) elems->ie_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) elems->total_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) sig, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) sta = __mesh_sta_info_alloc(sdata, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * mesh_sta_info_get - return mesh sta info entry for @addr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * @sdata: local meshif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * @addr: peer's address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * @elems: IEs from beacon or mesh peering frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * @rx_status: rx status for the frame for signal reporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) * Return existing or newly allocated sta_info under RCU read lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * (re)initialize with given IEs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static struct sta_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) u8 *addr, struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) struct ieee80211_rx_status *rx_status) __acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct sta_info *sta = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) sta = sta_info_get(sdata, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) mesh_sta_info_init(sdata, sta, elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* can't run atomic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) sta = mesh_sta_info_alloc(sdata, addr, elems, rx_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) mesh_sta_info_init(sdata, sta, elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (sta_info_insert_rcu(sta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * mesh_neighbour_update - update or initialize new mesh neighbor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * @sdata: local meshif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * @addr: peer's address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * @elems: IEs from beacon or mesh peering frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * @rx_status: rx status for the frame for signal reporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * Initiates peering if appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) u8 *hw_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct ieee80211_rx_status *rx_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) sta = mesh_sta_info_get(sdata, hw_addr, elems, rx_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (!sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) sta->mesh->connected_to_gate = elems->mesh_config->meshconf_form &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) IEEE80211_MESHCONF_FORM_CONNECTED_TO_GATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (mesh_peer_accepts_plinks(elems) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) sta->mesh->plink_state == NL80211_PLINK_LISTEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) sdata->u.mesh.accepting_plinks &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) sdata->u.mesh.mshcfg.auto_open_plinks &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) rssi_threshold_check(sdata, sta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) changed = mesh_plink_open(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) ieee80211_mps_frame_release(sta, elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) ieee80211_mbss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) void mesh_plink_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct mesh_sta *mesh = from_timer(mesh, t, plink_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) u16 reason = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct mesh_config *mshcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) enum ieee80211_self_protected_actioncode action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * This STA is valid because sta_info_destroy() will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * del_timer_sync() this timer after having made sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * it cannot be readded (by deleting the plink.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) sta = mesh->plink_sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (sta->sdata->local->quiescing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) spin_lock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* If a timer fires just before a state transition on another CPU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * we may have already extended the timeout and changed state by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * time we've acquired the lock and arrived here. In that case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * skip this timer and wait for the new one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (time_before(jiffies, sta->mesh->plink_timer.expires)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) mpl_dbg(sta->sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) "Ignoring timer for %pM in state %s (timer adjusted)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) sta->sta.addr, mplstates[sta->mesh->plink_state]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* del_timer() and handler may race when entering these states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (sta->mesh->plink_state == NL80211_PLINK_LISTEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) sta->mesh->plink_state == NL80211_PLINK_ESTAB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) mpl_dbg(sta->sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) "Ignoring timer for %pM in state %s (timer deleted)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) sta->sta.addr, mplstates[sta->mesh->plink_state]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) mpl_dbg(sta->sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) "Mesh plink timer for %pM fired on state %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) sta->sta.addr, mplstates[sta->mesh->plink_state]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) sdata = sta->sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) mshcfg = &sdata->u.mesh.mshcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) switch (sta->mesh->plink_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) case NL80211_PLINK_OPN_RCVD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) case NL80211_PLINK_OPN_SNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* retry timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (sta->mesh->plink_retries < mshcfg->dot11MeshMaxRetries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) u32 rand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) mpl_dbg(sta->sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) "Mesh plink for %pM (retry, timeout): %d %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) sta->sta.addr, sta->mesh->plink_retries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) sta->mesh->plink_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) get_random_bytes(&rand, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) sta->mesh->plink_timeout = sta->mesh->plink_timeout +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) rand % sta->mesh->plink_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ++sta->mesh->plink_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) mod_plink_timer(sta, sta->mesh->plink_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) action = WLAN_SP_MESH_PEERING_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) reason = WLAN_REASON_MESH_MAX_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) case NL80211_PLINK_CNF_RCVD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) /* confirm timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (!reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) sta->mesh->plink_state = NL80211_PLINK_HOLDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) action = WLAN_SP_MESH_PEERING_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) case NL80211_PLINK_HOLDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /* holding timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) del_timer(&sta->mesh->plink_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) mesh_plink_fsm_restart(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) mesh_plink_frame_tx(sdata, sta, action, sta->sta.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) sta->mesh->llid, sta->mesh->plid, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) static inline void mesh_plink_timer_set(struct sta_info *sta, u32 timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) sta->mesh->plink_timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) mod_timer(&sta->mesh->plink_timer, jiffies + msecs_to_jiffies(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static bool llid_in_use(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) u16 llid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) bool in_use = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) list_for_each_entry_rcu(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (sdata != sta->sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (!memcmp(&sta->mesh->llid, &llid, sizeof(llid))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) in_use = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) return in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static u16 mesh_get_new_llid(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) u16 llid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) get_random_bytes(&llid, sizeof(llid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) } while (llid_in_use(sdata, llid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return llid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) u32 mesh_plink_open(struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct ieee80211_sub_if_data *sdata = sta->sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) u32 changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (!test_sta_flag(sta, WLAN_STA_AUTH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) spin_lock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) sta->mesh->llid = mesh_get_new_llid(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (sta->mesh->plink_state != NL80211_PLINK_LISTEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) sta->mesh->plink_state != NL80211_PLINK_BLOCKED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) sta->mesh->plink_state = NL80211_PLINK_OPN_SNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) mpl_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) "Mesh plink: starting establishment with %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) sta->sta.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /* set the non-peer mode to active during peering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) changed = ieee80211_mps_local_status_update(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) mesh_plink_frame_tx(sdata, sta, WLAN_SP_MESH_PEERING_OPEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) sta->sta.addr, sta->mesh->llid, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) u32 mesh_plink_block(struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) u32 changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) spin_lock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) changed = __mesh_plink_deactivate(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) mesh_path_flush_by_nexthop(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) static void mesh_plink_close(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct sta_info *sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) enum plink_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) u16 reason = (event == CLS_ACPT) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) WLAN_REASON_MESH_CLOSE : WLAN_REASON_MESH_CONFIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) sta->mesh->reason = reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) sta->mesh->plink_state = NL80211_PLINK_HOLDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) static u32 mesh_plink_establish(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) del_timer(&sta->mesh->plink_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) sta->mesh->plink_state = NL80211_PLINK_ESTAB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) changed |= mesh_plink_inc_estab_count(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) changed |= mesh_set_ht_prot_mode(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) changed |= mesh_set_short_slot_time(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", sta->sta.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) ieee80211_mps_sta_status_update(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) changed |= ieee80211_mps_set_sta_local_pm(sta, mshcfg->power_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * mesh_plink_fsm - step @sta MPM based on @event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * @sdata: interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * @sta: mesh neighbor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * @event: peering event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) * Return: changed MBSS flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) static u32 mesh_plink_fsm(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) struct sta_info *sta, enum plink_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) enum ieee80211_self_protected_actioncode action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) bool flush = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) mpl_dbg(sdata, "peer %pM in state %s got event %s\n", sta->sta.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) mplstates[sta->mesh->plink_state], mplevents[event]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) spin_lock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) switch (sta->mesh->plink_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) case NL80211_PLINK_LISTEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) case CLS_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) mesh_plink_fsm_restart(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) case OPN_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) sta->mesh->llid = mesh_get_new_llid(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) mesh_plink_timer_set(sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) mshcfg->dot11MeshRetryTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /* set the non-peer mode to active during peering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) changed |= ieee80211_mps_local_status_update(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) action = WLAN_SP_MESH_PEERING_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) case NL80211_PLINK_OPN_SNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) case OPN_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) case CNF_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) case CLS_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) mesh_plink_close(sdata, sta, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) action = WLAN_SP_MESH_PEERING_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) case OPN_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) /* retry timer is left untouched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) action = WLAN_SP_MESH_PEERING_CONFIRM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) case CNF_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) sta->mesh->plink_state = NL80211_PLINK_CNF_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) mod_plink_timer(sta, mshcfg->dot11MeshConfirmTimeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) case NL80211_PLINK_OPN_RCVD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) case OPN_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) case CNF_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) case CLS_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) mesh_plink_close(sdata, sta, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) action = WLAN_SP_MESH_PEERING_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) case OPN_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) action = WLAN_SP_MESH_PEERING_CONFIRM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) case CNF_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) changed |= mesh_plink_establish(sdata, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) case NL80211_PLINK_CNF_RCVD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) case OPN_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) case CNF_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) case CLS_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) mesh_plink_close(sdata, sta, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) action = WLAN_SP_MESH_PEERING_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) case OPN_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) changed |= mesh_plink_establish(sdata, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) action = WLAN_SP_MESH_PEERING_CONFIRM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) case NL80211_PLINK_ESTAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) case CLS_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) changed |= __mesh_plink_deactivate(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) changed |= mesh_set_ht_prot_mode(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) changed |= mesh_set_short_slot_time(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) mesh_plink_close(sdata, sta, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) action = WLAN_SP_MESH_PEERING_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) flush = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) case OPN_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) action = WLAN_SP_MESH_PEERING_CONFIRM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) case NL80211_PLINK_HOLDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) case CLS_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) del_timer(&sta->mesh->plink_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) mesh_plink_fsm_restart(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) case OPN_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) case CNF_ACPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) case OPN_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) case CNF_RJCT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) action = WLAN_SP_MESH_PEERING_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) /* should not get here, PLINK_BLOCKED is dealt with at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) * beginning of the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) spin_unlock_bh(&sta->mesh->plink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) if (flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) mesh_path_flush_by_nexthop(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) mesh_plink_frame_tx(sdata, sta, action, sta->sta.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) sta->mesh->llid, sta->mesh->plid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) sta->mesh->reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /* also send confirm in open case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (action == WLAN_SP_MESH_PEERING_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) mesh_plink_frame_tx(sdata, sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) WLAN_SP_MESH_PEERING_CONFIRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) sta->sta.addr, sta->mesh->llid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) sta->mesh->plid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) * mesh_plink_get_event - get correct MPM event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) * @sdata: interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * @sta: peer, leave NULL if processing a frame from a new suitable peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) * @elems: peering management IEs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) * @ftype: frame type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) * @llid: peer's peer link ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * @plid: peer's local link ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * Return: new peering event for @sta, but PLINK_UNDEFINED should be treated as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) static enum plink_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) mesh_plink_get_event(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) struct sta_info *sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) enum ieee80211_self_protected_actioncode ftype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) u16 llid, u16 plid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) enum plink_event event = PLINK_UNDEFINED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) u8 ie_len = elems->peering_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) bool matches_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) matches_local = (ftype == WLAN_SP_MESH_PEERING_CLOSE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) mesh_matches_local(sdata, elems));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) /* deny open request from non-matching peer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (!matches_local && !sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) event = OPN_RJCT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) if (ftype != WLAN_SP_MESH_PEERING_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) /* ftype == WLAN_SP_MESH_PEERING_OPEN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (!mesh_plink_free_count(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /* new matching peer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) event = OPN_ACPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (!test_sta_flag(sta, WLAN_STA_AUTH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if (sta->mesh->plink_state == NL80211_PLINK_BLOCKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) switch (ftype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) case WLAN_SP_MESH_PEERING_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) if (!matches_local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) event = OPN_RJCT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (!mesh_plink_free_count(sdata) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) (sta->mesh->plid && sta->mesh->plid != plid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) event = OPN_IGNR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) event = OPN_ACPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) case WLAN_SP_MESH_PEERING_CONFIRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (!matches_local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) event = CNF_RJCT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (!mesh_plink_free_count(sdata) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) sta->mesh->llid != llid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) (sta->mesh->plid && sta->mesh->plid != plid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) event = CNF_IGNR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) event = CNF_ACPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) case WLAN_SP_MESH_PEERING_CLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) /* Do not check for llid or plid. This does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) * follow the standard but since multiple plinks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) * per sta are not supported, it is necessary in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) * order to avoid a livelock when MP A sees an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * establish peer link to MP B but MP B does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) * see it. This can be caused by a timeout in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) * B's peer link establishment or B beign
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) * restarted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) event = CLS_ACPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) else if (sta->mesh->plid != plid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) event = CLS_IGNR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) else if (ie_len == 8 && sta->mesh->llid != llid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) event = CLS_IGNR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) event = CLS_ACPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) mesh_process_plink_frame(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) struct ieee80211_mgmt *mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) struct ieee80211_rx_status *rx_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) enum plink_event event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) enum ieee80211_self_protected_actioncode ftype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) u8 ie_len = elems->peering_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) u16 plid, llid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) if (!elems->peering) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) mpl_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) "Mesh plink: missing necessary peer link ie\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) if (elems->rsn_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) mpl_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) "Mesh plink: can't establish link with secure peer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) ftype = mgmt->u.action.u.self_prot.action_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) && ie_len != 8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) mpl_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) "Mesh plink: incorrect plink ie length %d %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) ftype, ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) (!elems->mesh_id || !elems->mesh_config)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) /* Note the lines below are correct, the llid in the frame is the plid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) * from the point of view of this host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) plid = get_unaligned_le16(PLINK_GET_LLID(elems->peering));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) llid = get_unaligned_le16(PLINK_GET_PLID(elems->peering));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) /* WARNING: Only for sta pointer, is dropped & re-acquired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) sta = sta_info_get(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) !rssi_threshold_check(sdata, sta)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) goto unlock_rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) /* Now we will figure out the appropriate event... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) event = mesh_plink_get_event(sdata, sta, elems, ftype, llid, plid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (event == OPN_ACPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /* allocate sta entry if necessary and update info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) sta = mesh_sta_info_get(sdata, mgmt->sa, elems, rx_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) goto unlock_rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) sta->mesh->plid = plid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) } else if (!sta && event == OPN_RJCT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) mesh_plink_frame_tx(sdata, NULL, WLAN_SP_MESH_PEERING_CLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) mgmt->sa, 0, plid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) WLAN_REASON_MESH_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) goto unlock_rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) } else if (!sta || event == PLINK_UNDEFINED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) /* something went wrong */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) goto unlock_rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (event == CNF_ACPT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /* 802.11-2012 13.3.7.2 - update plid on CNF if not set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (!sta->mesh->plid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) sta->mesh->plid = plid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) sta->mesh->aid = get_unaligned_le16(PLINK_CNF_AID(mgmt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) changed |= mesh_plink_fsm(sdata, sta, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) unlock_rcu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) ieee80211_mbss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct ieee80211_mgmt *mgmt, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) struct ieee80211_rx_status *rx_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct ieee802_11_elems elems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) size_t baselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) u8 *baseaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) /* need action_code, aux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (len < IEEE80211_MIN_ACTION_SIZE + 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (sdata->u.mesh.user_mpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) /* userspace must register for these */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (is_multicast_ether_addr(mgmt->da)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) mpl_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) "Mesh plink: ignore frame from multicast address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) baseaddr = mgmt->u.action.u.self_prot.variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) if (mgmt->u.action.u.self_prot.action_code ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) WLAN_SP_MESH_PEERING_CONFIRM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) baseaddr += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) baselen += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if (baselen > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) mgmt->bssid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) mesh_process_plink_frame(sdata, mgmt, &elems, rx_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) }