blob: 1a7d98398626260238c2f49ce2fc859b4aa4117e [file] [log] [blame]
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01003 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/gfp.h>
Johannes Berg902acc72008-02-23 15:17:19 +010010#include <linux/kernel.h>
11#include <linux/random.h>
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010012#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010014#include "mesh.h"
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010015
Thomas Pedersen8db09852011-08-12 20:01:00 -070016#define PLINK_GET_LLID(p) (p + 2)
17#define PLINK_GET_PLID(p) (p + 4)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010018
Johannes Berg433f5bc2015-06-17 10:31:00 +020019#define mod_plink_timer(s, t) (mod_timer(&s->mesh->plink_timer, \
Nicholas Mc Guirecc57ac52015-03-02 04:54:13 -050020 jiffies + msecs_to_jiffies(t)))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010021
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010022enum plink_event {
23 PLINK_UNDEFINED,
24 OPN_ACPT,
25 OPN_RJCT,
26 OPN_IGNR,
27 CNF_ACPT,
28 CNF_RJCT,
29 CNF_IGNR,
30 CLS_ACPT,
31 CLS_IGNR
32};
33
Thomas Pedersen95e48ad2013-02-16 10:41:05 -080034static const char * const mplstates[] = {
35 [NL80211_PLINK_LISTEN] = "LISTEN",
36 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
37 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
38 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
39 [NL80211_PLINK_ESTAB] = "ESTAB",
40 [NL80211_PLINK_HOLDING] = "HOLDING",
41 [NL80211_PLINK_BLOCKED] = "BLOCKED"
42};
43
44static const char * const mplevents[] = {
45 [PLINK_UNDEFINED] = "NONE",
46 [OPN_ACPT] = "OPN_ACPT",
47 [OPN_RJCT] = "OPN_RJCT",
48 [OPN_IGNR] = "OPN_IGNR",
49 [CNF_ACPT] = "CNF_ACPT",
50 [CNF_RJCT] = "CNF_RJCT",
51 [CNF_IGNR] = "CNF_IGNR",
52 [CLS_ACPT] = "CLS_ACPT",
53 [CLS_IGNR] = "CLS_IGNR"
54};
55
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070056static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Johannes Bergbf7cd942013-02-15 14:40:31 +010057 enum ieee80211_self_protected_actioncode action,
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +080058 u8 *da, u16 llid, u16 plid, u16 reason);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070059
Bob Copeland36c9bb22013-11-05 11:16:54 -080060
61/* We only need a valid sta if user configured a minimum rssi_threshold. */
62static bool rssi_threshold_check(struct ieee80211_sub_if_data *sdata,
63 struct sta_info *sta)
64{
65 s32 rssi_threshold = sdata->u.mesh.mshcfg.rssi_threshold;
66 return rssi_threshold == 0 ||
67 (sta && (s8) -ewma_read(&sta->avg_signal) > rssi_threshold);
68}
69
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010070/**
71 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
72 *
Rui Paulo23c7a292009-11-09 23:46:42 +000073 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010074 *
Johannes Berg433f5bc2015-06-17 10:31:00 +020075 * Locking: this function must be called holding sta->mesh->plink_lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010076 */
77static inline void mesh_plink_fsm_restart(struct sta_info *sta)
78{
Johannes Berg433f5bc2015-06-17 10:31:00 +020079 lockdep_assert_held(&sta->mesh->plink_lock);
80 sta->mesh->plink_state = NL80211_PLINK_LISTEN;
81 sta->mesh->llid = sta->mesh->plid = sta->mesh->reason = 0;
82 sta->mesh->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010083}
84
Thomas Pedersen3b144652013-01-26 16:39:55 -080085/*
86 * mesh_set_short_slot_time - enable / disable ERP short slot time.
87 *
88 * The standard indirectly mandates mesh STAs to turn off short slot time by
89 * disallowing advertising this (802.11-2012 8.4.1.4), but that doesn't mean we
90 * can't be sneaky about it. Enable short slot time if all mesh STAs in the
91 * MBSS support ERP rates.
92 *
93 * Returns BSS_CHANGED_ERP_SLOT or 0 for no change.
94 */
95static u32 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
96{
97 struct ieee80211_local *local = sdata->local;
98 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
99 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
100 struct sta_info *sta;
101 u32 erp_rates = 0, changed = 0;
102 int i;
103 bool short_slot = false;
104
105 if (band == IEEE80211_BAND_5GHZ) {
106 /* (IEEE 802.11-2012 19.4.5) */
107 short_slot = true;
108 goto out;
Johannes Bergea1b2b452015-06-02 20:15:49 +0200109 } else if (band != IEEE80211_BAND_2GHZ)
Thomas Pedersen3b144652013-01-26 16:39:55 -0800110 goto out;
111
112 for (i = 0; i < sband->n_bitrates; i++)
113 if (sband->bitrates[i].flags & IEEE80211_RATE_ERP_G)
114 erp_rates |= BIT(i);
115
116 if (!erp_rates)
117 goto out;
118
119 rcu_read_lock();
120 list_for_each_entry_rcu(sta, &local->sta_list, list) {
121 if (sdata != sta->sdata ||
Johannes Berg433f5bc2015-06-17 10:31:00 +0200122 sta->mesh->plink_state != NL80211_PLINK_ESTAB)
Thomas Pedersen3b144652013-01-26 16:39:55 -0800123 continue;
124
125 short_slot = false;
126 if (erp_rates & sta->sta.supp_rates[band])
127 short_slot = true;
128 else
129 break;
130 }
131 rcu_read_unlock();
132
133out:
134 if (sdata->vif.bss_conf.use_short_slot != short_slot) {
135 sdata->vif.bss_conf.use_short_slot = short_slot;
136 changed = BSS_CHANGED_ERP_SLOT;
137 mpl_dbg(sdata, "mesh_plink %pM: ERP short slot time %d\n",
138 sdata->vif.addr, short_slot);
139 }
140 return changed;
141}
142
Ben Hutchings2c530402012-07-10 10:55:09 +0000143/**
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700144 * mesh_set_ht_prot_mode - set correct HT protection mode
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700145 *
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700146 * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
147 * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
148 * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
149 * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
150 * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
151 * HT20 peer is present. Otherwise no-protection mode is selected.
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700152 */
153static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
154{
155 struct ieee80211_local *local = sdata->local;
156 struct sta_info *sta;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700157 u16 ht_opmode;
158 bool non_ht_sta = false, ht20_sta = false;
159
Simon Wunderlich0418a442013-05-16 13:00:31 +0200160 switch (sdata->vif.bss_conf.chandef.width) {
161 case NL80211_CHAN_WIDTH_20_NOHT:
162 case NL80211_CHAN_WIDTH_5:
163 case NL80211_CHAN_WIDTH_10:
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700164 return 0;
Simon Wunderlich0418a442013-05-16 13:00:31 +0200165 default:
166 break;
167 }
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700168
169 rcu_read_lock();
170 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700171 if (sdata != sta->sdata ||
Johannes Berg433f5bc2015-06-17 10:31:00 +0200172 sta->mesh->plink_state != NL80211_PLINK_ESTAB)
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700173 continue;
174
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800175 if (sta->sta.bandwidth > IEEE80211_STA_RX_BW_20)
176 continue;
177
178 if (!sta->sta.ht_cap.ht_supported) {
179 mpl_dbg(sdata, "nonHT sta (%pM) is present\n",
180 sta->sta.addr);
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700181 non_ht_sta = true;
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700182 break;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700183 }
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800184
185 mpl_dbg(sdata, "HT20 sta (%pM) is present\n", sta->sta.addr);
186 ht20_sta = true;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700187 }
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700188 rcu_read_unlock();
189
190 if (non_ht_sta)
191 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Johannes Berg466f3102012-07-25 13:51:49 +0200192 else if (ht20_sta &&
Johannes Berg4bf88532012-11-09 11:39:59 +0100193 sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700194 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
195 else
196 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
197
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800198 if (sdata->vif.bss_conf.ht_operation_mode == ht_opmode)
199 return 0;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700200
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800201 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
202 sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
203 mpl_dbg(sdata, "selected new HT protection mode %d\n", ht_opmode);
204 return BSS_CHANGED_HT;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700205}
206
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100207/**
John W. Linvillec9370192010-06-21 17:14:07 -0400208 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100209 *
210 * @sta: mesh peer link to deactivate
211 *
212 * All mesh paths with this peer as next hop will be flushed
Marco Porschdf323812012-08-08 07:58:43 +0200213 * Returns beacon changed flag if the beacon content changed.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100214 *
Johannes Berg433f5bc2015-06-17 10:31:00 +0200215 * Locking: the caller must hold sta->mesh->plink_lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100216 */
Marco Porschdf323812012-08-08 07:58:43 +0200217static u32 __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100218{
Johannes Bergd0709a62008-02-25 16:27:46 +0100219 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200220 u32 changed = 0;
Johannes Bergd0709a62008-02-25 16:27:46 +0100221
Johannes Berg433f5bc2015-06-17 10:31:00 +0200222 lockdep_assert_held(&sta->mesh->plink_lock);
Bob Copeland48bf6be2015-04-13 17:26:28 -0400223
Johannes Berg433f5bc2015-06-17 10:31:00 +0200224 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
Marco Porschdf323812012-08-08 07:58:43 +0200225 changed = mesh_plink_dec_estab_count(sdata);
Johannes Berg433f5bc2015-06-17 10:31:00 +0200226 sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100227 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400228
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100229 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +0200230 changed |= ieee80211_mps_set_sta_local_pm(sta,
231 NL80211_MESH_POWER_UNKNOWN);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100232
Marco Porschdf323812012-08-08 07:58:43 +0200233 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100234}
235
Johannes Berg902acc72008-02-23 15:17:19 +0100236/**
John W. Linvillec9370192010-06-21 17:14:07 -0400237 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100238 *
239 * @sta: mesh peer link to deactivate
240 *
241 * All mesh paths with this peer as next hop will be flushed
242 */
Thomas Pedersen45b50282013-02-06 10:17:21 -0800243u32 mesh_plink_deactivate(struct sta_info *sta)
Johannes Berg902acc72008-02-23 15:17:19 +0100244{
John W. Linvillec9370192010-06-21 17:14:07 -0400245 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200246 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400247
Johannes Berg433f5bc2015-06-17 10:31:00 +0200248 spin_lock_bh(&sta->mesh->plink_lock);
Marco Porschdf323812012-08-08 07:58:43 +0200249 changed = __mesh_plink_deactivate(sta);
Johannes Berg433f5bc2015-06-17 10:31:00 +0200250 sta->mesh->reason = WLAN_REASON_MESH_PEER_CANCELED;
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700251 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
Johannes Berg433f5bc2015-06-17 10:31:00 +0200252 sta->sta.addr, sta->mesh->llid, sta->mesh->plid,
253 sta->mesh->reason);
254 spin_unlock_bh(&sta->mesh->plink_lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400255
Thomas Pedersen45b50282013-02-06 10:17:21 -0800256 return changed;
Johannes Berg902acc72008-02-23 15:17:19 +0100257}
258
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200259static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Johannes Bergbf7cd942013-02-15 14:40:31 +0100260 enum ieee80211_self_protected_actioncode action,
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800261 u8 *da, u16 llid, u16 plid, u16 reason)
Johannes Bergbf7cd942013-02-15 14:40:31 +0100262{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200263 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700264 struct sk_buff *skb;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700265 struct ieee80211_tx_info *info;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100266 struct ieee80211_mgmt *mgmt;
267 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700268 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700269 u8 *pos, ie_len = 4;
270 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
271 sizeof(mgmt->u.action.u.self_prot);
Thomas Pedersenf609a432012-08-03 12:21:35 -0700272 int err = -ENOMEM;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100273
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800274 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700275 hdr_len +
276 2 + /* capability info */
277 2 + /* AID */
278 2 + 8 + /* supported rates */
279 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
280 2 + sdata->u.mesh.mesh_id_len +
281 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700282 2 + sizeof(struct ieee80211_ht_cap) +
Johannes Berg074d46d2012-03-15 19:45:16 +0100283 2 + sizeof(struct ieee80211_ht_operation) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700284 2 + 8 + /* peering IE */
285 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100286 if (!skb)
Bob Copeland87d84c42013-11-05 11:16:57 -0800287 return err;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700288 info = IEEE80211_SKB_CB(skb);
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800289 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700290 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
291 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700292 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
293 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100294 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100295 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700296 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700297 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
298 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100299
Thomas Pedersen8db09852011-08-12 20:01:00 -0700300 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
Johannes Berg55de9082012-07-26 17:24:39 +0200301 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
302
Thomas Pedersen8db09852011-08-12 20:01:00 -0700303 /* capability info */
304 pos = skb_put(skb, 2);
305 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700306 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700307 /* AID */
308 pos = skb_put(skb, 2);
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800309 put_unaligned_le16(plid, pos + 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100310 }
Johannes Berg55de9082012-07-26 17:24:39 +0200311 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
312 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
Johannes Bergbf7cd942013-02-15 14:40:31 +0100313 mesh_add_rsn_ie(sdata, skb) ||
314 mesh_add_meshid_ie(sdata, skb) ||
315 mesh_add_meshconf_ie(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700316 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700317 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
Thomas Pedersene7570df2012-08-03 12:21:34 -0700318 info->flags |= IEEE80211_TX_CTL_NO_ACK;
Johannes Bergbf7cd942013-02-15 14:40:31 +0100319 if (mesh_add_meshid_ie(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700320 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100321 }
322
Thomas Pedersen8db09852011-08-12 20:01:00 -0700323 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100324 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700325 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100326 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700327 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700328 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100329 include_plid = true;
330 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700331 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700332 if (plid) {
333 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100334 include_plid = true;
335 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700336 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100337 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700338 default:
Thomas Pedersenf609a432012-08-03 12:21:35 -0700339 err = -EINVAL;
340 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100341 }
342
Thomas Pedersen8db09852011-08-12 20:01:00 -0700343 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700344 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700345
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100346 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700347 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100348 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700349 memcpy(pos, &peering_proto, 2);
350 pos += 2;
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800351 put_unaligned_le16(llid, pos);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700352 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100353 if (include_plid) {
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800354 put_unaligned_le16(plid, pos);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700355 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100356 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700357 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800358 put_unaligned_le16(reason, pos);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700359 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100360 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700361
362 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
Johannes Bergbf7cd942013-02-15 14:40:31 +0100363 if (mesh_add_ht_cap_ie(sdata, skb) ||
364 mesh_add_ht_oper_ie(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700365 goto free;
Thomas Pedersen176f3602011-10-26 14:47:27 -0700366 }
367
Johannes Bergbf7cd942013-02-15 14:40:31 +0100368 if (mesh_add_vendor_ies(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700369 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100370
Johannes Berg62ae67b2009-11-18 18:42:05 +0100371 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100372 return 0;
Thomas Pedersenf609a432012-08-03 12:21:35 -0700373free:
374 kfree_skb(skb);
375 return err;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100376}
377
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800378static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
379 struct sta_info *sta,
380 struct ieee802_11_elems *elems, bool insert)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100381{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200382 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +0200383 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700384 struct ieee80211_supported_band *sband;
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800385 u32 rates, basic_rates = 0, changed = 0;
Janusz.Dziedzic@tieto.comabcff6e2015-03-20 06:37:01 +0100386 enum ieee80211_sta_rx_bandwidth bw = sta->sta.bandwidth;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100387
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700388 sband = local->hw.wiphy->bands[band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200389 rates = ieee80211_sta_get_rates(sdata, elems, band, &basic_rates);
Johannes Bergd0709a62008-02-25 16:27:46 +0100390
Johannes Berg433f5bc2015-06-17 10:31:00 +0200391 spin_lock_bh(&sta->mesh->plink_lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100392 sta->last_rx = jiffies;
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800393
394 /* rates and capabilities don't change during peering */
Johannes Berg433f5bc2015-06-17 10:31:00 +0200395 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB &&
396 sta->mesh->processed_beacon)
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800397 goto out;
Johannes Berg433f5bc2015-06-17 10:31:00 +0200398 sta->mesh->processed_beacon = true;
Chun-Yeow Yeohbae35d92012-07-24 11:52:35 +0800399
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800400 if (sta->sta.supp_rates[band] != rates)
401 changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700402 sta->sta.supp_rates[band] = rates;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700403
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800404 if (ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
405 elems->ht_cap_elem, sta))
406 changed |= IEEE80211_RC_BW_CHANGED;
Johannes Berg4bf88532012-11-09 11:39:59 +0100407
Janusz.Dziedzic@tieto.comabcff6e2015-03-20 06:37:01 +0100408 if (bw != sta->sta.bandwidth)
409 changed |= IEEE80211_RC_BW_CHANGED;
410
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800411 /* HT peer is operating 20MHz-only */
412 if (elems->ht_operation &&
413 !(elems->ht_operation->ht_param &
414 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
415 if (sta->sta.bandwidth != IEEE80211_STA_RX_BW_20)
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800416 changed |= IEEE80211_RC_BW_CHANGED;
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800417 sta->sta.bandwidth = IEEE80211_STA_RX_BW_20;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700418 }
Thomas Pedersenc7d25822012-04-26 15:01:07 -0700419
Helmut Schaa59cf1d62012-11-27 18:03:13 +0100420 if (insert)
421 rate_control_rate_init(sta);
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800422 else
423 rate_control_rate_update(local, sband, sta, changed);
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800424out:
Johannes Berg433f5bc2015-06-17 10:31:00 +0200425 spin_unlock_bh(&sta->mesh->plink_lock);
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800426}
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700427
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800428static struct sta_info *
429__mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
430{
431 struct sta_info *sta;
432
433 if (sdata->local->num_sta >= MESH_MAX_PLINKS)
Thomas Pedersene87278e2012-04-26 15:01:06 -0700434 return NULL;
435
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800436 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
437 if (!sta)
438 return NULL;
439
Johannes Berg433f5bc2015-06-17 10:31:00 +0200440 sta->mesh->plink_state = NL80211_PLINK_LISTEN;
Johannes Berga74a8c82014-07-22 14:50:47 +0200441 sta->sta.wme = true;
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800442
443 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
444 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
445 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
446
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700447 return sta;
448}
449
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800450static struct sta_info *
451mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
452 struct ieee802_11_elems *elems)
453{
454 struct sta_info *sta = NULL;
455
Thomas Pedersena6dad6a2013-03-04 13:06:12 -0800456 /* Userspace handles station allocation */
457 if (sdata->u.mesh.user_mpm ||
458 sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800459 cfg80211_notify_new_peer_candidate(sdata->dev, addr,
460 elems->ie_start,
461 elems->total_len,
462 GFP_KERNEL);
463 else
464 sta = __mesh_sta_info_alloc(sdata, addr);
465
466 return sta;
467}
468
469/*
470 * mesh_sta_info_get - return mesh sta info entry for @addr.
471 *
472 * @sdata: local meshif
473 * @addr: peer's address
474 * @elems: IEs from beacon or mesh peering frame.
475 *
476 * Return existing or newly allocated sta_info under RCU read lock.
477 * (re)initialize with given IEs.
478 */
479static struct sta_info *
480mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
481 u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
482{
483 struct sta_info *sta = NULL;
484
485 rcu_read_lock();
486 sta = sta_info_get(sdata, addr);
487 if (sta) {
488 mesh_sta_info_init(sdata, sta, elems, false);
489 } else {
490 rcu_read_unlock();
491 /* can't run atomic */
492 sta = mesh_sta_info_alloc(sdata, addr, elems);
493 if (!sta) {
494 rcu_read_lock();
495 return NULL;
496 }
497
Thomas Pedersen3b4797b2013-01-26 17:00:02 -0800498 mesh_sta_info_init(sdata, sta, elems, true);
499
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800500 if (sta_info_insert_rcu(sta))
501 return NULL;
502 }
503
504 return sta;
505}
506
507/*
508 * mesh_neighbour_update - update or initialize new mesh neighbor.
509 *
510 * @sdata: local meshif
511 * @addr: peer's address
512 * @elems: IEs from beacon or mesh peering frame
513 *
514 * Initiates peering if appropriate.
515 */
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700516void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
517 u8 *hw_addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700518 struct ieee802_11_elems *elems)
519{
520 struct sta_info *sta;
Thomas Pedersen39886b62013-02-13 12:14:19 -0800521 u32 changed = 0;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700522
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800523 sta = mesh_sta_info_get(sdata, hw_addr, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700524 if (!sta)
525 goto out;
526
Javier Cardona1570ca52011-04-07 15:08:35 -0700527 if (mesh_peer_accepts_plinks(elems) &&
Johannes Berg433f5bc2015-06-17 10:31:00 +0200528 sta->mesh->plink_state == NL80211_PLINK_LISTEN &&
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700529 sdata->u.mesh.accepting_plinks &&
530 sdata->u.mesh.mshcfg.auto_open_plinks &&
Bob Copeland36c9bb22013-11-05 11:16:54 -0800531 rssi_threshold_check(sdata, sta))
Thomas Pedersen39886b62013-02-13 12:14:19 -0800532 changed = mesh_plink_open(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100533
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100534 ieee80211_mps_frame_release(sta, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700535out:
Johannes Bergd0709a62008-02-25 16:27:46 +0100536 rcu_read_unlock();
Thomas Pedersen2b5e1962013-02-14 11:20:13 -0800537 ieee80211_mbss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100538}
539
540static void mesh_plink_timer(unsigned long data)
541{
542 struct sta_info *sta;
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800543 u16 reason = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100544 struct ieee80211_sub_if_data *sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800545 struct mesh_config *mshcfg;
Thomas Pedersen4efec452013-11-05 11:16:50 -0800546 enum ieee80211_self_protected_actioncode action = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100547
Johannes Bergd0709a62008-02-25 16:27:46 +0100548 /*
549 * This STA is valid because sta_info_destroy() will
550 * del_timer_sync() this timer after having made sure
551 * it cannot be readded (by deleting the plink.)
552 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100553 sta = (struct sta_info *) data;
554
Stanislaw Gruszka690205f2013-02-28 10:55:29 +0100555 if (sta->sdata->local->quiescing)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200556 return;
Johannes Berg5bb644a2009-05-17 11:40:42 +0200557
Johannes Berg433f5bc2015-06-17 10:31:00 +0200558 spin_lock_bh(&sta->mesh->plink_lock);
Bob Copeland2b470c32014-06-04 09:27:31 -0400559
560 /* If a timer fires just before a state transition on another CPU,
561 * we may have already extended the timeout and changed state by the
562 * time we've acquired the lock and arrived here. In that case,
563 * skip this timer and wait for the new one.
564 */
Johannes Berg433f5bc2015-06-17 10:31:00 +0200565 if (time_before(jiffies, sta->mesh->plink_timer.expires)) {
Bob Copeland2b470c32014-06-04 09:27:31 -0400566 mpl_dbg(sta->sdata,
567 "Ignoring timer for %pM in state %s (timer adjusted)",
Johannes Berg433f5bc2015-06-17 10:31:00 +0200568 sta->sta.addr, mplstates[sta->mesh->plink_state]);
569 spin_unlock_bh(&sta->mesh->plink_lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100570 return;
571 }
Bob Copeland2b470c32014-06-04 09:27:31 -0400572
573 /* del_timer() and handler may race when entering these states */
Johannes Berg433f5bc2015-06-17 10:31:00 +0200574 if (sta->mesh->plink_state == NL80211_PLINK_LISTEN ||
575 sta->mesh->plink_state == NL80211_PLINK_ESTAB) {
Bob Copeland2b470c32014-06-04 09:27:31 -0400576 mpl_dbg(sta->sdata,
577 "Ignoring timer for %pM in state %s (timer deleted)",
Johannes Berg433f5bc2015-06-17 10:31:00 +0200578 sta->sta.addr, mplstates[sta->mesh->plink_state]);
579 spin_unlock_bh(&sta->mesh->plink_lock);
Bob Copeland2b470c32014-06-04 09:27:31 -0400580 return;
581 }
582
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200583 mpl_dbg(sta->sdata,
Thomas Pedersen3088f7d2013-04-08 11:06:16 -0700584 "Mesh plink timer for %pM fired on state %s\n",
Johannes Berg433f5bc2015-06-17 10:31:00 +0200585 sta->sta.addr, mplstates[sta->mesh->plink_state]);
Johannes Bergd0709a62008-02-25 16:27:46 +0100586 sdata = sta->sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800587 mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100588
Johannes Berg433f5bc2015-06-17 10:31:00 +0200589 switch (sta->mesh->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700590 case NL80211_PLINK_OPN_RCVD:
591 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100592 /* retry timer */
Johannes Berg433f5bc2015-06-17 10:31:00 +0200593 if (sta->mesh->plink_retries < mshcfg->dot11MeshMaxRetries) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100594 u32 rand;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200595 mpl_dbg(sta->sdata,
596 "Mesh plink for %pM (retry, timeout): %d %d\n",
Johannes Berg433f5bc2015-06-17 10:31:00 +0200597 sta->sta.addr, sta->mesh->plink_retries,
598 sta->mesh->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100599 get_random_bytes(&rand, sizeof(u32));
Johannes Berg433f5bc2015-06-17 10:31:00 +0200600 sta->mesh->plink_timeout = sta->mesh->plink_timeout +
601 rand % sta->mesh->plink_timeout;
602 ++sta->mesh->plink_retries;
603 mod_plink_timer(sta, sta->mesh->plink_timeout);
Thomas Pedersen4efec452013-11-05 11:16:50 -0800604 action = WLAN_SP_MESH_PEERING_OPEN;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100605 break;
606 }
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800607 reason = WLAN_REASON_MESH_MAX_RETRIES;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100608 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700609 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100610 /* confirm timer */
611 if (!reason)
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800612 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
Johannes Berg433f5bc2015-06-17 10:31:00 +0200613 sta->mesh->plink_state = NL80211_PLINK_HOLDING;
Marco Porsch453e66f22012-11-21 18:40:32 -0800614 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Thomas Pedersen4efec452013-11-05 11:16:50 -0800615 action = WLAN_SP_MESH_PEERING_CLOSE;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100616 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700617 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100618 /* holding timer */
Johannes Berg433f5bc2015-06-17 10:31:00 +0200619 del_timer(&sta->mesh->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100620 mesh_plink_fsm_restart(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100621 break;
622 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100623 break;
624 }
Johannes Berg433f5bc2015-06-17 10:31:00 +0200625 spin_unlock_bh(&sta->mesh->plink_lock);
Thomas Pedersen4efec452013-11-05 11:16:50 -0800626 if (action)
627 mesh_plink_frame_tx(sdata, action, sta->sta.addr,
Johannes Berg433f5bc2015-06-17 10:31:00 +0200628 sta->mesh->llid, sta->mesh->plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100629}
630
Nicholas Mc Guire0df2f6c2015-03-02 04:54:14 -0500631static inline void mesh_plink_timer_set(struct sta_info *sta, u32 timeout)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100632{
Johannes Berg433f5bc2015-06-17 10:31:00 +0200633 sta->mesh->plink_timer.expires = jiffies + msecs_to_jiffies(timeout);
634 sta->mesh->plink_timer.data = (unsigned long) sta;
635 sta->mesh->plink_timer.function = mesh_plink_timer;
636 sta->mesh->plink_timeout = timeout;
637 add_timer(&sta->mesh->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100638}
639
Thomas Pedersen204d1302013-11-05 11:17:05 -0800640static bool llid_in_use(struct ieee80211_sub_if_data *sdata,
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800641 u16 llid)
Thomas Pedersen204d1302013-11-05 11:17:05 -0800642{
643 struct ieee80211_local *local = sdata->local;
644 bool in_use = false;
645 struct sta_info *sta;
646
647 rcu_read_lock();
648 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Johannes Berg433f5bc2015-06-17 10:31:00 +0200649 if (!memcmp(&sta->mesh->llid, &llid, sizeof(llid))) {
Thomas Pedersen204d1302013-11-05 11:17:05 -0800650 in_use = true;
651 break;
652 }
653 }
654 rcu_read_unlock();
655
656 return in_use;
657}
658
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800659static u16 mesh_get_new_llid(struct ieee80211_sub_if_data *sdata)
Thomas Pedersen204d1302013-11-05 11:17:05 -0800660{
661 u16 llid;
662
663 do {
664 get_random_bytes(&llid, sizeof(llid));
665 /* for mesh PS we still only have the AID range for TIM bits */
666 llid = (llid % IEEE80211_MAX_AID) + 1;
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800667 } while (llid_in_use(sdata, llid));
Thomas Pedersen204d1302013-11-05 11:17:05 -0800668
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800669 return llid;
Thomas Pedersen204d1302013-11-05 11:17:05 -0800670}
671
Thomas Pedersen39886b62013-02-13 12:14:19 -0800672u32 mesh_plink_open(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100673{
Johannes Bergd0709a62008-02-25 16:27:46 +0100674 struct ieee80211_sub_if_data *sdata = sta->sdata;
Thomas Pedersen39886b62013-02-13 12:14:19 -0800675 u32 changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100676
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200677 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Thomas Pedersen39886b62013-02-13 12:14:19 -0800678 return 0;
Javier Cardona53e80512011-04-07 15:08:32 -0700679
Johannes Berg433f5bc2015-06-17 10:31:00 +0200680 spin_lock_bh(&sta->mesh->plink_lock);
681 sta->mesh->llid = mesh_get_new_llid(sdata);
682 if (sta->mesh->plink_state != NL80211_PLINK_LISTEN &&
683 sta->mesh->plink_state != NL80211_PLINK_BLOCKED) {
684 spin_unlock_bh(&sta->mesh->plink_lock);
Thomas Pedersen39886b62013-02-13 12:14:19 -0800685 return 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100686 }
Johannes Berg433f5bc2015-06-17 10:31:00 +0200687 sta->mesh->plink_state = NL80211_PLINK_OPN_SNT;
Marco Porsch453e66f22012-11-21 18:40:32 -0800688 mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
Johannes Berg433f5bc2015-06-17 10:31:00 +0200689 spin_unlock_bh(&sta->mesh->plink_lock);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200690 mpl_dbg(sdata,
691 "Mesh plink: starting establishment with %pM\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700692 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100693
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100694 /* set the non-peer mode to active during peering */
Thomas Pedersen39886b62013-02-13 12:14:19 -0800695 changed = ieee80211_mps_local_status_update(sdata);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100696
Thomas Pedersen39886b62013-02-13 12:14:19 -0800697 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg433f5bc2015-06-17 10:31:00 +0200698 sta->sta.addr, sta->mesh->llid, 0, 0);
Thomas Pedersen39886b62013-02-13 12:14:19 -0800699 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100700}
701
Thomas Pedersen39886b62013-02-13 12:14:19 -0800702u32 mesh_plink_block(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100703{
Marco Porschdf323812012-08-08 07:58:43 +0200704 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400705
Johannes Berg433f5bc2015-06-17 10:31:00 +0200706 spin_lock_bh(&sta->mesh->plink_lock);
Marco Porschdf323812012-08-08 07:58:43 +0200707 changed = __mesh_plink_deactivate(sta);
Johannes Berg433f5bc2015-06-17 10:31:00 +0200708 sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
709 spin_unlock_bh(&sta->mesh->plink_lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400710
Thomas Pedersen39886b62013-02-13 12:14:19 -0800711 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100712}
713
Bob Copelande76d67f2013-11-05 11:16:52 -0800714static void mesh_plink_close(struct ieee80211_sub_if_data *sdata,
715 struct sta_info *sta,
716 enum plink_event event)
717{
718 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800719 u16 reason = (event == CLS_ACPT) ?
720 WLAN_REASON_MESH_CLOSE : WLAN_REASON_MESH_CONFIG;
Bob Copelande76d67f2013-11-05 11:16:52 -0800721
Johannes Berg433f5bc2015-06-17 10:31:00 +0200722 sta->mesh->reason = reason;
723 sta->mesh->plink_state = NL80211_PLINK_HOLDING;
Bob Copeland272a9e22013-11-05 11:16:56 -0800724 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Bob Copelande76d67f2013-11-05 11:16:52 -0800725}
726
727static u32 mesh_plink_establish(struct ieee80211_sub_if_data *sdata,
728 struct sta_info *sta)
729{
730 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
731 u32 changed = 0;
732
Johannes Berg433f5bc2015-06-17 10:31:00 +0200733 del_timer(&sta->mesh->plink_timer);
734 sta->mesh->plink_state = NL80211_PLINK_ESTAB;
Bob Copelande76d67f2013-11-05 11:16:52 -0800735 changed |= mesh_plink_inc_estab_count(sdata);
736 changed |= mesh_set_ht_prot_mode(sdata);
737 changed |= mesh_set_short_slot_time(sdata);
738 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", sta->sta.addr);
739 ieee80211_mps_sta_status_update(sta);
740 changed |= ieee80211_mps_set_sta_local_pm(sta, mshcfg->power_mode);
741 return changed;
742}
743
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800744/**
745 * mesh_plink_fsm - step @sta MPM based on @event
746 *
747 * @sdata: interface
748 * @sta: mesh neighbor
749 * @event: peering event
750 *
751 * Return: changed MBSS flags
752 */
753static u32 mesh_plink_fsm(struct ieee80211_sub_if_data *sdata,
754 struct sta_info *sta, enum plink_event event)
755{
756 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
757 enum ieee80211_self_protected_actioncode action = 0;
758 u32 changed = 0;
759
760 mpl_dbg(sdata, "peer %pM in state %s got event %s\n", sta->sta.addr,
Johannes Berg433f5bc2015-06-17 10:31:00 +0200761 mplstates[sta->mesh->plink_state], mplevents[event]);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800762
Johannes Berg433f5bc2015-06-17 10:31:00 +0200763 spin_lock_bh(&sta->mesh->plink_lock);
764 switch (sta->mesh->plink_state) {
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800765 case NL80211_PLINK_LISTEN:
766 switch (event) {
767 case CLS_ACPT:
768 mesh_plink_fsm_restart(sta);
769 break;
770 case OPN_ACPT:
Johannes Berg433f5bc2015-06-17 10:31:00 +0200771 sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
772 sta->mesh->llid = mesh_get_new_llid(sdata);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800773 mesh_plink_timer_set(sta,
774 mshcfg->dot11MeshRetryTimeout);
775
776 /* set the non-peer mode to active during peering */
777 changed |= ieee80211_mps_local_status_update(sdata);
778 action = WLAN_SP_MESH_PEERING_OPEN;
779 break;
780 default:
781 break;
782 }
783 break;
784 case NL80211_PLINK_OPN_SNT:
785 switch (event) {
786 case OPN_RJCT:
787 case CNF_RJCT:
788 case CLS_ACPT:
789 mesh_plink_close(sdata, sta, event);
790 action = WLAN_SP_MESH_PEERING_CLOSE;
791 break;
792 case OPN_ACPT:
793 /* retry timer is left untouched */
Johannes Berg433f5bc2015-06-17 10:31:00 +0200794 sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800795 action = WLAN_SP_MESH_PEERING_CONFIRM;
796 break;
797 case CNF_ACPT:
Johannes Berg433f5bc2015-06-17 10:31:00 +0200798 sta->mesh->plink_state = NL80211_PLINK_CNF_RCVD;
Bob Copeland2b470c32014-06-04 09:27:31 -0400799 mod_plink_timer(sta, mshcfg->dot11MeshConfirmTimeout);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800800 break;
801 default:
802 break;
803 }
804 break;
805 case NL80211_PLINK_OPN_RCVD:
806 switch (event) {
807 case OPN_RJCT:
808 case CNF_RJCT:
809 case CLS_ACPT:
810 mesh_plink_close(sdata, sta, event);
811 action = WLAN_SP_MESH_PEERING_CLOSE;
812 break;
813 case OPN_ACPT:
814 action = WLAN_SP_MESH_PEERING_CONFIRM;
815 break;
816 case CNF_ACPT:
817 changed |= mesh_plink_establish(sdata, sta);
818 break;
819 default:
820 break;
821 }
822 break;
823 case NL80211_PLINK_CNF_RCVD:
824 switch (event) {
825 case OPN_RJCT:
826 case CNF_RJCT:
827 case CLS_ACPT:
828 mesh_plink_close(sdata, sta, event);
829 action = WLAN_SP_MESH_PEERING_CLOSE;
830 break;
831 case OPN_ACPT:
832 changed |= mesh_plink_establish(sdata, sta);
833 action = WLAN_SP_MESH_PEERING_CONFIRM;
834 break;
835 default:
836 break;
837 }
838 break;
839 case NL80211_PLINK_ESTAB:
840 switch (event) {
841 case CLS_ACPT:
842 changed |= __mesh_plink_deactivate(sta);
843 changed |= mesh_set_ht_prot_mode(sdata);
844 changed |= mesh_set_short_slot_time(sdata);
845 mesh_plink_close(sdata, sta, event);
846 action = WLAN_SP_MESH_PEERING_CLOSE;
847 break;
848 case OPN_ACPT:
849 action = WLAN_SP_MESH_PEERING_CONFIRM;
850 break;
851 default:
852 break;
853 }
854 break;
855 case NL80211_PLINK_HOLDING:
856 switch (event) {
857 case CLS_ACPT:
Johannes Berg433f5bc2015-06-17 10:31:00 +0200858 del_timer(&sta->mesh->plink_timer);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800859 mesh_plink_fsm_restart(sta);
860 break;
861 case OPN_ACPT:
862 case CNF_ACPT:
863 case OPN_RJCT:
864 case CNF_RJCT:
865 action = WLAN_SP_MESH_PEERING_CLOSE;
866 break;
867 default:
868 break;
869 }
870 break;
871 default:
872 /* should not get here, PLINK_BLOCKED is dealt with at the
873 * beginning of the function
874 */
875 break;
876 }
Johannes Berg433f5bc2015-06-17 10:31:00 +0200877 spin_unlock_bh(&sta->mesh->plink_lock);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800878 if (action) {
879 mesh_plink_frame_tx(sdata, action, sta->sta.addr,
Johannes Berg433f5bc2015-06-17 10:31:00 +0200880 sta->mesh->llid, sta->mesh->plid,
881 sta->mesh->reason);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800882
883 /* also send confirm in open case */
884 if (action == WLAN_SP_MESH_PEERING_OPEN) {
885 mesh_plink_frame_tx(sdata,
886 WLAN_SP_MESH_PEERING_CONFIRM,
Johannes Berg433f5bc2015-06-17 10:31:00 +0200887 sta->sta.addr, sta->mesh->llid,
888 sta->mesh->plid, 0);
Thomas Pedersenc7e67812013-11-05 11:17:02 -0800889 }
890 }
891
892 return changed;
893}
894
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800895/*
896 * mesh_plink_get_event - get correct MPM event
897 *
898 * @sdata: interface
899 * @sta: peer, leave NULL if processing a frame from a new suitable peer
900 * @elems: peering management IEs
901 * @ftype: frame type
902 * @llid: peer's peer link ID
903 * @plid: peer's local link ID
904 *
905 * Return: new peering event for @sta, but PLINK_UNDEFINED should be treated as
906 * an error.
907 */
908static enum plink_event
909mesh_plink_get_event(struct ieee80211_sub_if_data *sdata,
910 struct sta_info *sta,
911 struct ieee802_11_elems *elems,
912 enum ieee80211_self_protected_actioncode ftype,
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800913 u16 llid, u16 plid)
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800914{
915 enum plink_event event = PLINK_UNDEFINED;
916 u8 ie_len = elems->peering_len;
917 bool matches_local;
918
919 matches_local = (ftype == WLAN_SP_MESH_PEERING_CLOSE ||
920 mesh_matches_local(sdata, elems));
921
922 /* deny open request from non-matching peer */
923 if (!matches_local && !sta) {
924 event = OPN_RJCT;
925 goto out;
926 }
927
928 if (!sta) {
929 if (ftype != WLAN_SP_MESH_PEERING_OPEN) {
930 mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
931 goto out;
932 }
933 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
934 if (!mesh_plink_free_count(sdata)) {
935 mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
936 goto out;
937 }
938 } else {
939 if (!test_sta_flag(sta, WLAN_STA_AUTH)) {
940 mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
941 goto out;
942 }
Johannes Berg433f5bc2015-06-17 10:31:00 +0200943 if (sta->mesh->plink_state == NL80211_PLINK_BLOCKED)
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800944 goto out;
945 }
946
947 /* new matching peer */
948 if (!sta) {
949 event = OPN_ACPT;
950 goto out;
951 }
952
953 switch (ftype) {
954 case WLAN_SP_MESH_PEERING_OPEN:
955 if (!matches_local)
956 event = OPN_RJCT;
957 if (!mesh_plink_free_count(sdata) ||
Johannes Berg433f5bc2015-06-17 10:31:00 +0200958 (sta->mesh->plid && sta->mesh->plid != plid))
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800959 event = OPN_IGNR;
960 else
961 event = OPN_ACPT;
962 break;
963 case WLAN_SP_MESH_PEERING_CONFIRM:
964 if (!matches_local)
965 event = CNF_RJCT;
966 if (!mesh_plink_free_count(sdata) ||
Johannes Berg433f5bc2015-06-17 10:31:00 +0200967 sta->mesh->llid != llid ||
968 (sta->mesh->plid && sta->mesh->plid != plid))
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800969 event = CNF_IGNR;
970 else
971 event = CNF_ACPT;
972 break;
973 case WLAN_SP_MESH_PEERING_CLOSE:
Johannes Berg433f5bc2015-06-17 10:31:00 +0200974 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800975 /* Do not check for llid or plid. This does not
976 * follow the standard but since multiple plinks
977 * per sta are not supported, it is necessary in
978 * order to avoid a livelock when MP A sees an
979 * establish peer link to MP B but MP B does not
980 * see it. This can be caused by a timeout in
981 * B's peer link establishment or B beign
982 * restarted.
983 */
984 event = CLS_ACPT;
Johannes Berg433f5bc2015-06-17 10:31:00 +0200985 else if (sta->mesh->plid != plid)
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800986 event = CLS_IGNR;
Johannes Berg433f5bc2015-06-17 10:31:00 +0200987 else if (ie_len == 8 && sta->mesh->llid != llid)
Thomas Pedersenc99a89e2013-11-05 11:17:03 -0800988 event = CLS_IGNR;
989 else
990 event = CLS_ACPT;
991 break;
992 default:
993 mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
994 break;
995 }
996
997out:
998 return event;
999}
1000
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001001static void
1002mesh_process_plink_frame(struct ieee80211_sub_if_data *sdata,
1003 struct ieee80211_mgmt *mgmt,
1004 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001005{
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001006
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001007 struct sta_info *sta;
1008 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001009 enum ieee80211_self_protected_actioncode ftype;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -07001010 u32 changed = 0;
Thomas Pedersenc99a89e2013-11-05 11:17:03 -08001011 u8 ie_len = elems->peering_len;
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +08001012 u16 plid, llid = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001013
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001014 if (!elems->peering) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001015 mpl_dbg(sdata,
1016 "Mesh plink: missing necessary peer link ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001017 return;
1018 }
Johannes Bergbf7cd942013-02-15 14:40:31 +01001019
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001020 if (elems->rsn_len &&
Johannes Bergbf7cd942013-02-15 14:40:31 +01001021 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001022 mpl_dbg(sdata,
1023 "Mesh plink: can't establish link with secure peer\n");
Javier Cardona5cff5e02011-04-07 15:08:29 -07001024 return;
1025 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001026
Thomas Pedersen8db09852011-08-12 20:01:00 -07001027 ftype = mgmt->u.action.u.self_prot.action_code;
Thomas Pedersen8db09852011-08-12 20:01:00 -07001028 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
1029 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
1030 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
1031 && ie_len != 8)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001032 mpl_dbg(sdata,
1033 "Mesh plink: incorrect plink ie length %d %d\n",
1034 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001035 return;
1036 }
1037
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001038 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001039 (!elems->mesh_id || !elems->mesh_config)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001040 mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001041 return;
1042 }
1043 /* Note the lines below are correct, the llid in the frame is the plid
1044 * from the point of view of this host.
1045 */
Bob Copelandf8134fe2014-06-28 16:35:26 -04001046 plid = get_unaligned_le16(PLINK_GET_LLID(elems->peering));
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001047 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Bob Copelandf8134fe2014-06-28 16:35:26 -04001048 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
1049 llid = get_unaligned_le16(PLINK_GET_PLID(elems->peering));
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001050
Thomas Pedersen296fcba2013-01-23 12:18:12 -08001051 /* WARNING: Only for sta pointer, is dropped & re-acquired */
Johannes Bergd0709a62008-02-25 16:27:46 +01001052 rcu_read_lock();
1053
Johannes Bergabe60632009-11-25 17:46:18 +01001054 sta = sta_info_get(sdata, mgmt->sa);
Bob Copeland32cb05b2013-11-05 11:16:53 -08001055
Ashok Nagarajan55335132012-02-28 17:04:08 -08001056 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Bob Copeland36c9bb22013-11-05 11:16:54 -08001057 !rssi_threshold_check(sdata, sta)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001058 mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -08001059 mgmt->sa);
Thomas Pedersenfc103022013-11-05 11:17:00 -08001060 goto unlock_rcu;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001061 }
1062
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001063 /* Now we will figure out the appropriate event... */
Thomas Pedersenc99a89e2013-11-05 11:17:03 -08001064 event = mesh_plink_get_event(sdata, sta, elems, ftype, llid, plid);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -07001065
1066 if (event == OPN_ACPT) {
Thomas Pedersen296fcba2013-01-23 12:18:12 -08001067 rcu_read_unlock();
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -07001068 /* allocate sta entry if necessary and update info */
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001069 sta = mesh_sta_info_get(sdata, mgmt->sa, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -07001070 if (!sta) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001071 mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
Thomas Pedersenfc103022013-11-05 11:17:00 -08001072 goto unlock_rcu;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -07001073 }
Johannes Berg433f5bc2015-06-17 10:31:00 +02001074 sta->mesh->plid = plid;
Thomas Pedersenc99a89e2013-11-05 11:17:03 -08001075 } else if (!sta && event == OPN_RJCT) {
1076 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
1077 mgmt->sa, 0, plid,
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +08001078 WLAN_REASON_MESH_CONFIG);
Thomas Pedersenc99a89e2013-11-05 11:17:03 -08001079 goto unlock_rcu;
1080 } else if (!sta || event == PLINK_UNDEFINED) {
1081 /* something went wrong */
1082 goto unlock_rcu;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001083 }
1084
Bob Copeland6c6fa492014-06-28 16:35:25 -04001085 /* 802.11-2012 13.3.7.2 - update plid on CNF if not set */
Johannes Berg433f5bc2015-06-17 10:31:00 +02001086 if (!sta->mesh->plid && event == CNF_ACPT)
1087 sta->mesh->plid = plid;
Bob Copeland6c6fa492014-06-28 16:35:25 -04001088
Thomas Pedersenc7e67812013-11-05 11:17:02 -08001089 changed |= mesh_plink_fsm(sdata, sta, event);
Johannes Bergd0709a62008-02-25 16:27:46 +01001090
Thomas Pedersenfc103022013-11-05 11:17:00 -08001091unlock_rcu:
Johannes Bergd0709a62008-02-25 16:27:46 +01001092 rcu_read_unlock();
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -07001093
Thomas Pedersenecccd072013-06-10 13:17:21 -07001094 if (changed)
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001095 ieee80211_mbss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001096}
Thomas Pedersen05a23ae2013-11-05 11:16:59 -08001097
1098void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
1099 struct ieee80211_mgmt *mgmt, size_t len,
1100 struct ieee80211_rx_status *rx_status)
1101{
1102 struct ieee802_11_elems elems;
1103 size_t baselen;
1104 u8 *baseaddr;
1105
1106 /* need action_code, aux */
1107 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
1108 return;
1109
1110 if (sdata->u.mesh.user_mpm)
1111 /* userspace must register for these */
1112 return;
1113
1114 if (is_multicast_ether_addr(mgmt->da)) {
1115 mpl_dbg(sdata,
1116 "Mesh plink: ignore frame from multicast address\n");
1117 return;
1118 }
1119
1120 baseaddr = mgmt->u.action.u.self_prot.variable;
1121 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
1122 if (mgmt->u.action.u.self_prot.action_code ==
1123 WLAN_SP_MESH_PEERING_CONFIRM) {
1124 baseaddr += 4;
1125 baselen += 4;
1126 }
1127 ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
1128 mesh_process_plink_frame(sdata, mgmt, &elems);
1129}