blob: d74bdf94c8a4341cc804cbb769f9f44fb69c623d [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
19#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
20 jiffies + HZ * t / 1000))
21
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -080022/* We only need a valid sta if user configured a minimum rssi_threshold. */
23#define rssi_threshold_check(sta, sdata) \
Ashok Nagarajan55335132012-02-28 17:04:08 -080024 (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -080025 (sta && (s8) -ewma_read(&sta->avg_signal) > \
26 sdata->u.mesh.mshcfg.rssi_threshold))
Ashok Nagarajan55335132012-02-28 17:04:08 -080027
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010028enum plink_event {
29 PLINK_UNDEFINED,
30 OPN_ACPT,
31 OPN_RJCT,
32 OPN_IGNR,
33 CNF_ACPT,
34 CNF_RJCT,
35 CNF_IGNR,
36 CLS_ACPT,
37 CLS_IGNR
38};
39
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070040static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Johannes Bergbf7cd942013-02-15 14:40:31 +010041 enum ieee80211_self_protected_actioncode action,
42 u8 *da, __le16 llid, __le16 plid, __le16 reason);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070043
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010044/**
45 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
46 *
Rui Paulo23c7a292009-11-09 23:46:42 +000047 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010048 *
Johannes Berg07346f812008-05-03 01:02:02 +020049 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010050 */
51static inline void mesh_plink_fsm_restart(struct sta_info *sta)
52{
Javier Cardona57cf8042011-05-13 10:45:43 -070053 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080054 sta->llid = sta->plid = sta->reason = 0;
55 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010056}
57
Thomas Pedersen3b144652013-01-26 16:39:55 -080058/*
59 * mesh_set_short_slot_time - enable / disable ERP short slot time.
60 *
61 * The standard indirectly mandates mesh STAs to turn off short slot time by
62 * disallowing advertising this (802.11-2012 8.4.1.4), but that doesn't mean we
63 * can't be sneaky about it. Enable short slot time if all mesh STAs in the
64 * MBSS support ERP rates.
65 *
66 * Returns BSS_CHANGED_ERP_SLOT or 0 for no change.
67 */
68static u32 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
69{
70 struct ieee80211_local *local = sdata->local;
71 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
72 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
73 struct sta_info *sta;
74 u32 erp_rates = 0, changed = 0;
75 int i;
76 bool short_slot = false;
77
78 if (band == IEEE80211_BAND_5GHZ) {
79 /* (IEEE 802.11-2012 19.4.5) */
80 short_slot = true;
81 goto out;
82 } else if (band != IEEE80211_BAND_2GHZ ||
83 (band == IEEE80211_BAND_2GHZ &&
84 local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
85 goto out;
86
87 for (i = 0; i < sband->n_bitrates; i++)
88 if (sband->bitrates[i].flags & IEEE80211_RATE_ERP_G)
89 erp_rates |= BIT(i);
90
91 if (!erp_rates)
92 goto out;
93
94 rcu_read_lock();
95 list_for_each_entry_rcu(sta, &local->sta_list, list) {
96 if (sdata != sta->sdata ||
97 sta->plink_state != NL80211_PLINK_ESTAB)
98 continue;
99
100 short_slot = false;
101 if (erp_rates & sta->sta.supp_rates[band])
102 short_slot = true;
103 else
104 break;
105 }
106 rcu_read_unlock();
107
108out:
109 if (sdata->vif.bss_conf.use_short_slot != short_slot) {
110 sdata->vif.bss_conf.use_short_slot = short_slot;
111 changed = BSS_CHANGED_ERP_SLOT;
112 mpl_dbg(sdata, "mesh_plink %pM: ERP short slot time %d\n",
113 sdata->vif.addr, short_slot);
114 }
115 return changed;
116}
117
Ben Hutchings2c530402012-07-10 10:55:09 +0000118/**
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700119 * mesh_set_ht_prot_mode - set correct HT protection mode
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700120 *
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700121 * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
122 * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
123 * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
124 * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
125 * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
126 * HT20 peer is present. Otherwise no-protection mode is selected.
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700127 */
128static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
129{
130 struct ieee80211_local *local = sdata->local;
131 struct sta_info *sta;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700132 u16 ht_opmode;
133 bool non_ht_sta = false, ht20_sta = false;
134
Johannes Berg4bf88532012-11-09 11:39:59 +0100135 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700136 return 0;
137
138 rcu_read_lock();
139 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700140 if (sdata != sta->sdata ||
141 sta->plink_state != NL80211_PLINK_ESTAB)
142 continue;
143
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800144 if (sta->sta.bandwidth > IEEE80211_STA_RX_BW_20)
145 continue;
146
147 if (!sta->sta.ht_cap.ht_supported) {
148 mpl_dbg(sdata, "nonHT sta (%pM) is present\n",
149 sta->sta.addr);
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700150 non_ht_sta = true;
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700151 break;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700152 }
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800153
154 mpl_dbg(sdata, "HT20 sta (%pM) is present\n", sta->sta.addr);
155 ht20_sta = true;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700156 }
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700157 rcu_read_unlock();
158
159 if (non_ht_sta)
160 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Johannes Berg466f3102012-07-25 13:51:49 +0200161 else if (ht20_sta &&
Johannes Berg4bf88532012-11-09 11:39:59 +0100162 sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700163 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
164 else
165 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
166
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800167 if (sdata->vif.bss_conf.ht_operation_mode == ht_opmode)
168 return 0;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700169
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800170 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
171 sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
172 mpl_dbg(sdata, "selected new HT protection mode %d\n", ht_opmode);
173 return BSS_CHANGED_HT;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700174}
175
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100176/**
John W. Linvillec9370192010-06-21 17:14:07 -0400177 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100178 *
179 * @sta: mesh peer link to deactivate
180 *
181 * All mesh paths with this peer as next hop will be flushed
Marco Porschdf323812012-08-08 07:58:43 +0200182 * Returns beacon changed flag if the beacon content changed.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100183 *
Johannes Berg07346f812008-05-03 01:02:02 +0200184 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100185 */
Marco Porschdf323812012-08-08 07:58:43 +0200186static u32 __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100187{
Johannes Bergd0709a62008-02-25 16:27:46 +0100188 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200189 u32 changed = 0;
Johannes Bergd0709a62008-02-25 16:27:46 +0100190
Marco Porschdf323812012-08-08 07:58:43 +0200191 if (sta->plink_state == NL80211_PLINK_ESTAB)
192 changed = mesh_plink_dec_estab_count(sdata);
Javier Cardona57cf8042011-05-13 10:45:43 -0700193 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100194 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400195
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100196 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -0800197 changed |= ieee80211_mps_local_status_update(sdata);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100198
Marco Porschdf323812012-08-08 07:58:43 +0200199 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100200}
201
Johannes Berg902acc72008-02-23 15:17:19 +0100202/**
John W. Linvillec9370192010-06-21 17:14:07 -0400203 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100204 *
205 * @sta: mesh peer link to deactivate
206 *
207 * All mesh paths with this peer as next hop will be flushed
208 */
Thomas Pedersen45b50282013-02-06 10:17:21 -0800209u32 mesh_plink_deactivate(struct sta_info *sta)
Johannes Berg902acc72008-02-23 15:17:19 +0100210{
John W. Linvillec9370192010-06-21 17:14:07 -0400211 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200212 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400213
Johannes Berg07346f812008-05-03 01:02:02 +0200214 spin_lock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200215 changed = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700216 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
217 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
218 sta->sta.addr, sta->llid, sta->plid,
219 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200220 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400221
Thomas Pedersen45b50282013-02-06 10:17:21 -0800222 return changed;
Johannes Berg902acc72008-02-23 15:17:19 +0100223}
224
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200225static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Johannes Bergbf7cd942013-02-15 14:40:31 +0100226 enum ieee80211_self_protected_actioncode action,
227 u8 *da, __le16 llid, __le16 plid, __le16 reason)
228{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200229 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700230 struct sk_buff *skb;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700231 struct ieee80211_tx_info *info;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100232 struct ieee80211_mgmt *mgmt;
233 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700234 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700235 u8 *pos, ie_len = 4;
236 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
237 sizeof(mgmt->u.action.u.self_prot);
Thomas Pedersenf609a432012-08-03 12:21:35 -0700238 int err = -ENOMEM;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100239
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800240 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700241 hdr_len +
242 2 + /* capability info */
243 2 + /* AID */
244 2 + 8 + /* supported rates */
245 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
246 2 + sdata->u.mesh.mesh_id_len +
247 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700248 2 + sizeof(struct ieee80211_ht_cap) +
Johannes Berg074d46d2012-03-15 19:45:16 +0100249 2 + sizeof(struct ieee80211_ht_operation) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700250 2 + 8 + /* peering IE */
251 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100252 if (!skb)
253 return -1;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700254 info = IEEE80211_SKB_CB(skb);
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800255 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700256 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
257 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700258 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
259 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100260 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100261 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700262 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700263 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
264 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100265
Thomas Pedersen8db09852011-08-12 20:01:00 -0700266 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
Johannes Berg55de9082012-07-26 17:24:39 +0200267 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
268
Thomas Pedersen8db09852011-08-12 20:01:00 -0700269 /* capability info */
270 pos = skb_put(skb, 2);
271 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700272 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700273 /* AID */
274 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000275 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100276 }
Johannes Berg55de9082012-07-26 17:24:39 +0200277 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
278 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
Johannes Bergbf7cd942013-02-15 14:40:31 +0100279 mesh_add_rsn_ie(sdata, skb) ||
280 mesh_add_meshid_ie(sdata, skb) ||
281 mesh_add_meshconf_ie(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700282 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700283 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
Thomas Pedersene7570df2012-08-03 12:21:34 -0700284 info->flags |= IEEE80211_TX_CTL_NO_ACK;
Johannes Bergbf7cd942013-02-15 14:40:31 +0100285 if (mesh_add_meshid_ie(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700286 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100287 }
288
Thomas Pedersen8db09852011-08-12 20:01:00 -0700289 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100290 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700291 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100292 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700293 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700294 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100295 include_plid = true;
296 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700297 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700298 if (plid) {
299 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100300 include_plid = true;
301 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700302 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100303 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700304 default:
Thomas Pedersenf609a432012-08-03 12:21:35 -0700305 err = -EINVAL;
306 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100307 }
308
Thomas Pedersen8db09852011-08-12 20:01:00 -0700309 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700310 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700311
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100312 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700313 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100314 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700315 memcpy(pos, &peering_proto, 2);
316 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100317 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700318 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100319 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100320 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700321 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100322 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700323 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100324 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700325 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100326 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700327
328 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
Johannes Bergbf7cd942013-02-15 14:40:31 +0100329 if (mesh_add_ht_cap_ie(sdata, skb) ||
330 mesh_add_ht_oper_ie(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700331 goto free;
Thomas Pedersen176f3602011-10-26 14:47:27 -0700332 }
333
Johannes Bergbf7cd942013-02-15 14:40:31 +0100334 if (mesh_add_vendor_ies(sdata, skb))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700335 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100336
Johannes Berg62ae67b2009-11-18 18:42:05 +0100337 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100338 return 0;
Thomas Pedersenf609a432012-08-03 12:21:35 -0700339free:
340 kfree_skb(skb);
341 return err;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100342}
343
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800344static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
345 struct sta_info *sta,
346 struct ieee802_11_elems *elems, bool insert)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100347{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200348 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +0200349 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700350 struct ieee80211_supported_band *sband;
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800351 u32 rates, basic_rates = 0, changed = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100352
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700353 sband = local->hw.wiphy->bands[band];
354 rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates);
Johannes Bergd0709a62008-02-25 16:27:46 +0100355
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700356 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100357 sta->last_rx = jiffies;
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800358
359 /* rates and capabilities don't change during peering */
360 if (sta->plink_state == NL80211_PLINK_ESTAB)
361 goto out;
Chun-Yeow Yeohbae35d92012-07-24 11:52:35 +0800362
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800363 if (sta->sta.supp_rates[band] != rates)
364 changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700365 sta->sta.supp_rates[band] = rates;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700366
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800367 if (ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
368 elems->ht_cap_elem, sta))
369 changed |= IEEE80211_RC_BW_CHANGED;
Johannes Berg4bf88532012-11-09 11:39:59 +0100370
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800371 /* HT peer is operating 20MHz-only */
372 if (elems->ht_operation &&
373 !(elems->ht_operation->ht_param &
374 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
375 if (sta->sta.bandwidth != IEEE80211_STA_RX_BW_20)
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800376 changed |= IEEE80211_RC_BW_CHANGED;
Thomas Pedersen52ac8c42013-02-16 10:41:04 -0800377 sta->sta.bandwidth = IEEE80211_STA_RX_BW_20;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700378 }
Thomas Pedersenc7d25822012-04-26 15:01:07 -0700379
Helmut Schaa59cf1d62012-11-27 18:03:13 +0100380 if (insert)
381 rate_control_rate_init(sta);
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800382 else
383 rate_control_rate_update(local, sband, sta, changed);
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800384out:
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700385 spin_unlock_bh(&sta->lock);
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800386}
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700387
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800388static struct sta_info *
389__mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
390{
391 struct sta_info *sta;
392
393 if (sdata->local->num_sta >= MESH_MAX_PLINKS)
Thomas Pedersene87278e2012-04-26 15:01:06 -0700394 return NULL;
395
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800396 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
397 if (!sta)
398 return NULL;
399
400 sta->plink_state = NL80211_PLINK_LISTEN;
401 init_timer(&sta->plink_timer);
402
403 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
404 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
405 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
406
407 set_sta_flag(sta, WLAN_STA_WME);
408
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700409 return sta;
410}
411
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800412static struct sta_info *
413mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
414 struct ieee802_11_elems *elems)
415{
416 struct sta_info *sta = NULL;
417
418 /* Userspace handles peer allocation when security is enabled */
419 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
420 cfg80211_notify_new_peer_candidate(sdata->dev, addr,
421 elems->ie_start,
422 elems->total_len,
423 GFP_KERNEL);
424 else
425 sta = __mesh_sta_info_alloc(sdata, addr);
426
427 return sta;
428}
429
430/*
431 * mesh_sta_info_get - return mesh sta info entry for @addr.
432 *
433 * @sdata: local meshif
434 * @addr: peer's address
435 * @elems: IEs from beacon or mesh peering frame.
436 *
437 * Return existing or newly allocated sta_info under RCU read lock.
438 * (re)initialize with given IEs.
439 */
440static struct sta_info *
441mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
442 u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
443{
444 struct sta_info *sta = NULL;
445
446 rcu_read_lock();
447 sta = sta_info_get(sdata, addr);
448 if (sta) {
449 mesh_sta_info_init(sdata, sta, elems, false);
450 } else {
451 rcu_read_unlock();
452 /* can't run atomic */
453 sta = mesh_sta_info_alloc(sdata, addr, elems);
454 if (!sta) {
455 rcu_read_lock();
456 return NULL;
457 }
458
Thomas Pedersen3b4797b2013-01-26 17:00:02 -0800459 mesh_sta_info_init(sdata, sta, elems, true);
460
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800461 if (sta_info_insert_rcu(sta))
462 return NULL;
463 }
464
465 return sta;
466}
467
468/*
469 * mesh_neighbour_update - update or initialize new mesh neighbor.
470 *
471 * @sdata: local meshif
472 * @addr: peer's address
473 * @elems: IEs from beacon or mesh peering frame
474 *
475 * Initiates peering if appropriate.
476 */
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700477void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
478 u8 *hw_addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700479 struct ieee802_11_elems *elems)
480{
481 struct sta_info *sta;
Thomas Pedersen39886b62013-02-13 12:14:19 -0800482 u32 changed = 0;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700483
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800484 sta = mesh_sta_info_get(sdata, hw_addr, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700485 if (!sta)
486 goto out;
487
Javier Cardona1570ca52011-04-07 15:08:35 -0700488 if (mesh_peer_accepts_plinks(elems) &&
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700489 sta->plink_state == NL80211_PLINK_LISTEN &&
490 sdata->u.mesh.accepting_plinks &&
491 sdata->u.mesh.mshcfg.auto_open_plinks &&
492 rssi_threshold_check(sta, sdata))
Thomas Pedersen39886b62013-02-13 12:14:19 -0800493 changed = mesh_plink_open(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100494
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100495 ieee80211_mps_frame_release(sta, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700496out:
Johannes Bergd0709a62008-02-25 16:27:46 +0100497 rcu_read_unlock();
Thomas Pedersen2b5e1962013-02-14 11:20:13 -0800498 ieee80211_mbss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100499}
500
501static void mesh_plink_timer(unsigned long data)
502{
503 struct sta_info *sta;
504 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100505 struct ieee80211_sub_if_data *sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800506 struct mesh_config *mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100507
Johannes Bergd0709a62008-02-25 16:27:46 +0100508 /*
509 * This STA is valid because sta_info_destroy() will
510 * del_timer_sync() this timer after having made sure
511 * it cannot be readded (by deleting the plink.)
512 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100513 sta = (struct sta_info *) data;
514
Johannes Berg5bb644a2009-05-17 11:40:42 +0200515 if (sta->sdata->local->quiescing) {
516 sta->plink_timer_was_running = true;
517 return;
518 }
519
Johannes Berg07346f812008-05-03 01:02:02 +0200520 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100521 if (sta->ignore_plink_timer) {
522 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200523 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100524 return;
525 }
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200526 mpl_dbg(sta->sdata,
527 "Mesh plink timer for %pM fired on state %d\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700528 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100529 reason = 0;
530 llid = sta->llid;
531 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100532 sdata = sta->sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800533 mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100534
535 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700536 case NL80211_PLINK_OPN_RCVD:
537 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100538 /* retry timer */
Marco Porsch453e66f22012-11-21 18:40:32 -0800539 if (sta->plink_retries < mshcfg->dot11MeshMaxRetries) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100540 u32 rand;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200541 mpl_dbg(sta->sdata,
542 "Mesh plink for %pM (retry, timeout): %d %d\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700543 sta->sta.addr, sta->plink_retries,
544 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100545 get_random_bytes(&rand, sizeof(u32));
546 sta->plink_timeout = sta->plink_timeout +
547 rand % sta->plink_timeout;
548 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100549 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200550 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700551 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
552 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100553 break;
554 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700555 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100556 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700557 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100558 /* confirm timer */
559 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700560 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700561 sta->plink_state = NL80211_PLINK_HOLDING;
Marco Porsch453e66f22012-11-21 18:40:32 -0800562 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200563 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700564 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
565 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100566 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700567 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100568 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100569 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100570 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200571 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100572 break;
573 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200574 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100575 break;
576 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100577}
578
Johannes Berg5bb644a2009-05-17 11:40:42 +0200579#ifdef CONFIG_PM
580void mesh_plink_quiesce(struct sta_info *sta)
581{
Thomas Pedersenaa5a1b82013-02-04 14:12:41 -0800582 if (!ieee80211_vif_is_mesh(&sta->sdata->vif))
583 return;
584
Thomas Pedersen45b50282013-02-06 10:17:21 -0800585 /* no kernel mesh sta timers have been initialized */
586 if (sta->sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
587 return;
588
Johannes Berg5bb644a2009-05-17 11:40:42 +0200589 if (del_timer_sync(&sta->plink_timer))
590 sta->plink_timer_was_running = true;
591}
592
593void mesh_plink_restart(struct sta_info *sta)
594{
595 if (sta->plink_timer_was_running) {
596 add_timer(&sta->plink_timer);
597 sta->plink_timer_was_running = false;
598 }
599}
600#endif
601
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100602static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
603{
604 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
605 sta->plink_timer.data = (unsigned long) sta;
606 sta->plink_timer.function = mesh_plink_timer;
607 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100608 add_timer(&sta->plink_timer);
609}
610
Thomas Pedersen39886b62013-02-13 12:14:19 -0800611u32 mesh_plink_open(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100612{
613 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100614 struct ieee80211_sub_if_data *sdata = sta->sdata;
Thomas Pedersen39886b62013-02-13 12:14:19 -0800615 u32 changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100616
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200617 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Thomas Pedersen39886b62013-02-13 12:14:19 -0800618 return 0;
Javier Cardona53e80512011-04-07 15:08:32 -0700619
Johannes Berg07346f812008-05-03 01:02:02 +0200620 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100621 get_random_bytes(&llid, 2);
622 sta->llid = llid;
Chun-Yeow Yeoh9385d042012-09-14 14:18:31 +0800623 if (sta->plink_state != NL80211_PLINK_LISTEN &&
624 sta->plink_state != NL80211_PLINK_BLOCKED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200625 spin_unlock_bh(&sta->lock);
Thomas Pedersen39886b62013-02-13 12:14:19 -0800626 return 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100627 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700628 sta->plink_state = NL80211_PLINK_OPN_SNT;
Marco Porsch453e66f22012-11-21 18:40:32 -0800629 mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200630 spin_unlock_bh(&sta->lock);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200631 mpl_dbg(sdata,
632 "Mesh plink: starting establishment with %pM\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700633 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100634
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100635 /* set the non-peer mode to active during peering */
Thomas Pedersen39886b62013-02-13 12:14:19 -0800636 changed = ieee80211_mps_local_status_update(sdata);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100637
Thomas Pedersen39886b62013-02-13 12:14:19 -0800638 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
639 sta->sta.addr, llid, 0, 0);
640 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100641}
642
Thomas Pedersen39886b62013-02-13 12:14:19 -0800643u32 mesh_plink_block(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100644{
Marco Porschdf323812012-08-08 07:58:43 +0200645 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400646
Johannes Berg07346f812008-05-03 01:02:02 +0200647 spin_lock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200648 changed = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700649 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200650 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400651
Thomas Pedersen39886b62013-02-13 12:14:19 -0800652 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100653}
654
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100655
Johannes Bergbf7cd942013-02-15 14:40:31 +0100656void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
657 struct ieee80211_mgmt *mgmt, size_t len,
658 struct ieee80211_rx_status *rx_status)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100659{
Marco Porsch453e66f22012-11-21 18:40:32 -0800660 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100661 struct ieee802_11_elems elems;
662 struct sta_info *sta;
663 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700664 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100665 size_t baselen;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700666 bool matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100667 u8 ie_len;
668 u8 *baseaddr;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700669 u32 changed = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100670 __le16 plid, llid, reason;
Johannes Bergbf7cd942013-02-15 14:40:31 +0100671 static const char * const mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700672 [NL80211_PLINK_LISTEN] = "LISTEN",
673 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
674 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
675 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
676 [NL80211_PLINK_ESTAB] = "ESTAB",
677 [NL80211_PLINK_HOLDING] = "HOLDING",
678 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000679 };
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100680
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200681 /* need action_code, aux */
682 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
683 return;
684
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100685 if (is_multicast_ether_addr(mgmt->da)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200686 mpl_dbg(sdata,
687 "Mesh plink: ignore frame from multicast address\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100688 return;
689 }
690
Thomas Pedersen8db09852011-08-12 20:01:00 -0700691 baseaddr = mgmt->u.action.u.self_prot.variable;
692 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
693 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700694 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100695 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700696 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100697 }
698 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Johannes Bergbf7cd942013-02-15 14:40:31 +0100699
Thomas Pedersen8db09852011-08-12 20:01:00 -0700700 if (!elems.peering) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200701 mpl_dbg(sdata,
702 "Mesh plink: missing necessary peer link ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100703 return;
704 }
Johannes Bergbf7cd942013-02-15 14:40:31 +0100705
Javier Cardonab130e5c2011-05-03 16:57:07 -0700706 if (elems.rsn_len &&
Johannes Bergbf7cd942013-02-15 14:40:31 +0100707 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200708 mpl_dbg(sdata,
709 "Mesh plink: can't establish link with secure peer\n");
Javier Cardona5cff5e02011-04-07 15:08:29 -0700710 return;
711 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100712
Thomas Pedersen8db09852011-08-12 20:01:00 -0700713 ftype = mgmt->u.action.u.self_prot.action_code;
714 ie_len = elems.peering_len;
715 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
716 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
717 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
718 && ie_len != 8)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200719 mpl_dbg(sdata,
720 "Mesh plink: incorrect plink ie length %d %d\n",
721 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100722 return;
723 }
724
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700725 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Johannes Bergbf7cd942013-02-15 14:40:31 +0100726 (!elems.mesh_id || !elems.mesh_config)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200727 mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100728 return;
729 }
730 /* Note the lines below are correct, the llid in the frame is the plid
731 * from the point of view of this host.
732 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700733 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700734 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700735 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
736 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100737
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800738 /* WARNING: Only for sta pointer, is dropped & re-acquired */
Johannes Bergd0709a62008-02-25 16:27:46 +0100739 rcu_read_lock();
740
Johannes Bergabe60632009-11-25 17:46:18 +0100741 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700742 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200743 mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100744 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100745 return;
746 }
747
Ashok Nagarajan55335132012-02-28 17:04:08 -0800748 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800749 !rssi_threshold_check(sta, sdata)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200750 mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800751 mgmt->sa);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800752 rcu_read_unlock();
753 return;
754 }
755
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200756 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200757 mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
Javier Cardona53e80512011-04-07 15:08:32 -0700758 rcu_read_unlock();
759 return;
760 }
761
Javier Cardona57cf8042011-05-13 10:45:43 -0700762 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100763 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100764 return;
765 }
766
767 /* Now we will figure out the appropriate event... */
768 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700769 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700770 !mesh_matches_local(sdata, &elems)) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200771 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100772 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700773 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100774 event = OPN_RJCT;
775 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700776 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100777 event = CNF_RJCT;
778 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700779 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100780 break;
781 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200782 }
783
784 if (!sta && !matches_local) {
785 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700786 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200787 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700788 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
789 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200790 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100791 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700792 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100793 if (!mesh_plink_free_count(sdata)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200794 mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
Johannes Berg73651ee2008-02-25 16:27:47 +0100795 rcu_read_unlock();
796 return;
797 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100798 event = OPN_ACPT;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200799 } else if (matches_local) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100800 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700801 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100802 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100803 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100804 event = OPN_IGNR;
805 else
806 event = OPN_ACPT;
807 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700808 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100809 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100810 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100811 event = CNF_IGNR;
812 else
813 event = CNF_ACPT;
814 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700815 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700816 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100817 /* Do not check for llid or plid. This does not
818 * follow the standard but since multiple plinks
819 * per sta are not supported, it is necessary in
820 * order to avoid a livelock when MP A sees an
821 * establish peer link to MP B but MP B does not
822 * see it. This can be caused by a timeout in
823 * B's peer link establishment or B beign
824 * restarted.
825 */
826 event = CLS_ACPT;
827 else if (sta->plid != plid)
828 event = CLS_IGNR;
829 else if (ie_len == 7 && sta->llid != llid)
830 event = CLS_IGNR;
831 else
832 event = CLS_ACPT;
833 break;
834 default:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200835 mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100836 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100837 return;
838 }
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700839 }
840
841 if (event == OPN_ACPT) {
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800842 rcu_read_unlock();
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700843 /* allocate sta entry if necessary and update info */
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800844 sta = mesh_sta_info_get(sdata, mgmt->sa, &elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700845 if (!sta) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200846 mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700847 rcu_read_unlock();
848 return;
849 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100850 }
851
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200852 mpl_dbg(sdata,
853 "Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
Rui Paulo1460dd12009-11-09 23:46:48 +0000854 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700855 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
856 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100857 reason = 0;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700858 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100859 switch (sta->plink_state) {
860 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700861 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100862 switch (event) {
863 case CLS_ACPT:
864 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200865 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100866 break;
867 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700868 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100869 sta->plid = plid;
870 get_random_bytes(&llid, 2);
871 sta->llid = llid;
Marco Porsch453e66f22012-11-21 18:40:32 -0800872 mesh_plink_timer_set(sta,
873 mshcfg->dot11MeshRetryTimeout);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100874
875 /* set the non-peer mode to active during peering */
Thomas Pedersen39886b62013-02-13 12:14:19 -0800876 changed |= ieee80211_mps_local_status_update(sdata);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100877
Johannes Berg07346f812008-05-03 01:02:02 +0200878 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700879 mesh_plink_frame_tx(sdata,
880 WLAN_SP_MESH_PEERING_OPEN,
881 sta->sta.addr, llid, 0, 0);
882 mesh_plink_frame_tx(sdata,
883 WLAN_SP_MESH_PEERING_CONFIRM,
884 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100885 break;
886 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200887 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100888 break;
889 }
890 break;
891
Javier Cardona57cf8042011-05-13 10:45:43 -0700892 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100893 switch (event) {
894 case OPN_RJCT:
895 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700896 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100897 case CLS_ACPT:
898 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700899 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100900 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700901 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100902 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800903 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100904 sta->ignore_plink_timer = true;
905
906 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200907 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700908 mesh_plink_frame_tx(sdata,
909 WLAN_SP_MESH_PEERING_CLOSE,
910 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100911 break;
912 case OPN_ACPT:
913 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700914 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100915 sta->plid = plid;
916 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200917 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700918 mesh_plink_frame_tx(sdata,
919 WLAN_SP_MESH_PEERING_CONFIRM,
920 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100921 break;
922 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700923 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100924 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800925 mshcfg->dot11MeshConfirmTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100926 sta->ignore_plink_timer = true;
927
Johannes Berg07346f812008-05-03 01:02:02 +0200928 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100929 break;
930 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200931 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100932 break;
933 }
934 break;
935
Javier Cardona57cf8042011-05-13 10:45:43 -0700936 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100937 switch (event) {
938 case OPN_RJCT:
939 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700940 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100941 case CLS_ACPT:
942 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700943 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100944 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700945 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100946 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800947 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100948 sta->ignore_plink_timer = true;
949
950 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200951 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700952 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
953 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100954 break;
955 case OPN_ACPT:
956 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200957 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700958 mesh_plink_frame_tx(sdata,
959 WLAN_SP_MESH_PEERING_CONFIRM,
960 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100961 break;
962 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100963 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700964 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200965 spin_unlock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200966 changed |= mesh_plink_inc_estab_count(sdata);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700967 changed |= mesh_set_ht_prot_mode(sdata);
Thomas Pedersen3b144652013-01-26 16:39:55 -0800968 changed |= mesh_set_short_slot_time(sdata);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200969 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700970 sta->sta.addr);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100971 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -0800972 changed |= ieee80211_mps_set_sta_local_pm(sta,
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100973 mshcfg->power_mode);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100974 break;
975 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200976 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100977 break;
978 }
979 break;
980
Javier Cardona57cf8042011-05-13 10:45:43 -0700981 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100982 switch (event) {
983 case OPN_RJCT:
984 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700985 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100986 case CLS_ACPT:
987 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700988 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100989 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700990 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100991 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800992 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100993 sta->ignore_plink_timer = true;
994
995 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200996 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700997 mesh_plink_frame_tx(sdata,
998 WLAN_SP_MESH_PEERING_CLOSE,
999 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +01001000 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001001 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +01001002 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -07001003 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +02001004 spin_unlock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +02001005 changed |= mesh_plink_inc_estab_count(sdata);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -07001006 changed |= mesh_set_ht_prot_mode(sdata);
Thomas Pedersen3b144652013-01-26 16:39:55 -08001007 changed |= mesh_set_short_slot_time(sdata);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001008 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -07001009 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001010 mesh_plink_frame_tx(sdata,
1011 WLAN_SP_MESH_PEERING_CONFIRM,
1012 sta->sta.addr, llid, plid, 0);
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001013 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001014 changed |= ieee80211_mps_set_sta_local_pm(sta,
1015 mshcfg->power_mode);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001016 break;
1017 default:
Johannes Berg07346f812008-05-03 01:02:02 +02001018 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001019 break;
1020 }
1021 break;
1022
Javier Cardona57cf8042011-05-13 10:45:43 -07001023 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001024 switch (event) {
1025 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001026 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001027 sta->reason = reason;
Marco Porschdf323812012-08-08 07:58:43 +02001028 changed |= __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -07001029 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001030 llid = sta->llid;
Marco Porsch453e66f22012-11-21 18:40:32 -08001031 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +02001032 spin_unlock_bh(&sta->lock);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -07001033 changed |= mesh_set_ht_prot_mode(sdata);
Thomas Pedersen3b144652013-01-26 16:39:55 -08001034 changed |= mesh_set_short_slot_time(sdata);
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001035 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
1036 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001037 break;
1038 case OPN_ACPT:
1039 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +02001040 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001041 mesh_plink_frame_tx(sdata,
1042 WLAN_SP_MESH_PEERING_CONFIRM,
1043 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001044 break;
1045 default:
Johannes Berg07346f812008-05-03 01:02:02 +02001046 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001047 break;
1048 }
1049 break;
Javier Cardona57cf8042011-05-13 10:45:43 -07001050 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001051 switch (event) {
1052 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +01001053 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001054 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001055 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +02001056 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001057 break;
1058 case OPN_ACPT:
1059 case CNF_ACPT:
1060 case OPN_RJCT:
1061 case CNF_RJCT:
1062 llid = sta->llid;
1063 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +02001064 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -07001065 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
1066 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001067 break;
1068 default:
Johannes Berg07346f812008-05-03 01:02:02 +02001069 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001070 }
1071 break;
1072 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -08001073 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001074 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001075 */
Johannes Berg07346f812008-05-03 01:02:02 +02001076 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001077 break;
1078 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001079
1080 rcu_read_unlock();
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -07001081
1082 if (changed)
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001083 ieee80211_mbss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001084}