blob: 7a47f4063d0a42a21791911accd66bc56ce84a64 [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,
41 enum ieee80211_self_protected_actioncode action,
42 u8 *da, __le16 llid, __le16 plid, __le16 reason);
43
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010044static inline
Marco Porschdf323812012-08-08 07:58:43 +020045u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010046{
Ashok Nagarajan1258d972012-10-09 13:27:47 -070047 atomic_inc(&sdata->u.mesh.estab_plinks);
Marco Porschdf323812012-08-08 07:58:43 +020048 return mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010049}
50
51static inline
Marco Porschdf323812012-08-08 07:58:43 +020052u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010053{
Ashok Nagarajan1258d972012-10-09 13:27:47 -070054 atomic_dec(&sdata->u.mesh.estab_plinks);
Marco Porschdf323812012-08-08 07:58:43 +020055 return mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010056}
57
58/**
59 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
60 *
Rui Paulo23c7a292009-11-09 23:46:42 +000061 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010062 *
Johannes Berg07346f812008-05-03 01:02:02 +020063 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010064 */
65static inline void mesh_plink_fsm_restart(struct sta_info *sta)
66{
Javier Cardona57cf8042011-05-13 10:45:43 -070067 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080068 sta->llid = sta->plid = sta->reason = 0;
69 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010070}
71
Johannes Berg93e5deb2008-04-01 15:21:00 +020072/*
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -070073 * Allocate mesh sta entry and insert into station table
Johannes Berg93e5deb2008-04-01 15:21:00 +020074 */
Johannes Berg03e44972008-02-27 09:56:40 +010075static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -070076 u8 *hw_addr)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010077{
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010078 struct sta_info *sta;
79
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -070080 if (sdata->local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010081 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010082
Johannes Berg34e89502010-02-03 13:59:58 +010083 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +010084 if (!sta)
85 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010086
Johannes Berg83d5cc02012-01-12 09:31:10 +010087 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
88 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
89 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +010090
Johannes Bergc2c98fd2011-09-29 16:04:36 +020091 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +010092
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010093 return sta;
94}
95
Ben Hutchings2c530402012-07-10 10:55:09 +000096/**
Ashok Nagarajancbf93222012-05-07 21:00:31 -070097 * mesh_set_ht_prot_mode - set correct HT protection mode
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -070098 *
Ashok Nagarajancbf93222012-05-07 21:00:31 -070099 * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
100 * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
101 * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
102 * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
103 * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
104 * HT20 peer is present. Otherwise no-protection mode is selected.
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700105 */
106static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
107{
108 struct ieee80211_local *local = sdata->local;
109 struct sta_info *sta;
110 u32 changed = 0;
111 u16 ht_opmode;
112 bool non_ht_sta = false, ht20_sta = false;
113
Johannes Berg466f3102012-07-25 13:51:49 +0200114 if (sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700115 return 0;
116
117 rcu_read_lock();
118 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700119 if (sdata != sta->sdata ||
120 sta->plink_state != NL80211_PLINK_ESTAB)
121 continue;
122
123 switch (sta->ch_type) {
124 case NL80211_CHAN_NO_HT:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200125 mpl_dbg(sdata,
126 "mesh_plink %pM: nonHT sta (%pM) is present\n",
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700127 sdata->vif.addr, sta->sta.addr);
128 non_ht_sta = true;
129 goto out;
130 case NL80211_CHAN_HT20:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200131 mpl_dbg(sdata,
132 "mesh_plink %pM: HT20 sta (%pM) is present\n",
Ashok Nagarajancbf93222012-05-07 21:00:31 -0700133 sdata->vif.addr, sta->sta.addr);
134 ht20_sta = true;
135 default:
136 break;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700137 }
138 }
139out:
140 rcu_read_unlock();
141
142 if (non_ht_sta)
143 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Johannes Berg466f3102012-07-25 13:51:49 +0200144 else if (ht20_sta &&
145 sdata->vif.bss_conf.channel_type > NL80211_CHAN_HT20)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700146 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
147 else
148 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
149
150 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
151 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -0700152 sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700153 changed = BSS_CHANGED_HT;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200154 mpl_dbg(sdata,
155 "mesh_plink %pM: protection mode changed to %d\n",
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700156 sdata->vif.addr, ht_opmode);
157 }
158
159 return changed;
160}
161
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100162/**
John W. Linvillec9370192010-06-21 17:14:07 -0400163 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100164 *
165 * @sta: mesh peer link to deactivate
166 *
167 * All mesh paths with this peer as next hop will be flushed
Marco Porschdf323812012-08-08 07:58:43 +0200168 * Returns beacon changed flag if the beacon content changed.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100169 *
Johannes Berg07346f812008-05-03 01:02:02 +0200170 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100171 */
Marco Porschdf323812012-08-08 07:58:43 +0200172static u32 __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100173{
Johannes Bergd0709a62008-02-25 16:27:46 +0100174 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200175 u32 changed = 0;
Johannes Bergd0709a62008-02-25 16:27:46 +0100176
Marco Porschdf323812012-08-08 07:58:43 +0200177 if (sta->plink_state == NL80211_PLINK_ESTAB)
178 changed = mesh_plink_dec_estab_count(sdata);
Javier Cardona57cf8042011-05-13 10:45:43 -0700179 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100180 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400181
Marco Porschdf323812012-08-08 07:58:43 +0200182 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100183}
184
Johannes Berg902acc72008-02-23 15:17:19 +0100185/**
John W. Linvillec9370192010-06-21 17:14:07 -0400186 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100187 *
188 * @sta: mesh peer link to deactivate
189 *
190 * All mesh paths with this peer as next hop will be flushed
191 */
192void mesh_plink_deactivate(struct sta_info *sta)
193{
John W. Linvillec9370192010-06-21 17:14:07 -0400194 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200195 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400196
Johannes Berg07346f812008-05-03 01:02:02 +0200197 spin_lock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200198 changed = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700199 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
200 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
201 sta->sta.addr, sta->llid, sta->plid,
202 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200203 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400204
Marco Porschdf323812012-08-08 07:58:43 +0200205 ieee80211_bss_info_change_notify(sdata, changed);
Johannes Berg902acc72008-02-23 15:17:19 +0100206}
207
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200208static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700209 enum ieee80211_self_protected_actioncode action,
210 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200211 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700212 struct sk_buff *skb;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700213 struct ieee80211_tx_info *info;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100214 struct ieee80211_mgmt *mgmt;
215 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700216 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700217 u8 *pos, ie_len = 4;
218 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
219 sizeof(mgmt->u.action.u.self_prot);
Thomas Pedersenf609a432012-08-03 12:21:35 -0700220 int err = -ENOMEM;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100221
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800222 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700223 hdr_len +
224 2 + /* capability info */
225 2 + /* AID */
226 2 + 8 + /* supported rates */
227 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
228 2 + sdata->u.mesh.mesh_id_len +
229 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700230 2 + sizeof(struct ieee80211_ht_cap) +
Johannes Berg074d46d2012-03-15 19:45:16 +0100231 2 + sizeof(struct ieee80211_ht_operation) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700232 2 + 8 + /* peering IE */
233 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100234 if (!skb)
235 return -1;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700236 info = IEEE80211_SKB_CB(skb);
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800237 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700238 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
239 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700240 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
241 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100242 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100243 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700244 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700245 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
246 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100247
Thomas Pedersen8db09852011-08-12 20:01:00 -0700248 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
Johannes Berg55de9082012-07-26 17:24:39 +0200249 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
250
Thomas Pedersen8db09852011-08-12 20:01:00 -0700251 /* capability info */
252 pos = skb_put(skb, 2);
253 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700254 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700255 /* AID */
256 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000257 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100258 }
Johannes Berg55de9082012-07-26 17:24:39 +0200259 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
260 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700261 mesh_add_rsn_ie(skb, sdata) ||
262 mesh_add_meshid_ie(skb, sdata) ||
263 mesh_add_meshconf_ie(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700264 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700265 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
Thomas Pedersene7570df2012-08-03 12:21:34 -0700266 info->flags |= IEEE80211_TX_CTL_NO_ACK;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700267 if (mesh_add_meshid_ie(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700268 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100269 }
270
Thomas Pedersen8db09852011-08-12 20:01:00 -0700271 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100272 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700273 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100274 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700275 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700276 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100277 include_plid = true;
278 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700279 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700280 if (plid) {
281 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100282 include_plid = true;
283 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700284 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100285 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700286 default:
Thomas Pedersenf609a432012-08-03 12:21:35 -0700287 err = -EINVAL;
288 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100289 }
290
Thomas Pedersen8db09852011-08-12 20:01:00 -0700291 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700292 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700293
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100294 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700295 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100296 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700297 memcpy(pos, &peering_proto, 2);
298 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100299 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700300 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100301 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100302 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700303 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100304 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700305 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100306 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700307 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100308 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700309
310 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
311 if (mesh_add_ht_cap_ie(skb, sdata) ||
Johannes Berg074d46d2012-03-15 19:45:16 +0100312 mesh_add_ht_oper_ie(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700313 goto free;
Thomas Pedersen176f3602011-10-26 14:47:27 -0700314 }
315
Thomas Pedersen8db09852011-08-12 20:01:00 -0700316 if (mesh_add_vendor_ies(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700317 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100318
Johannes Berg62ae67b2009-11-18 18:42:05 +0100319 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100320 return 0;
Thomas Pedersenf609a432012-08-03 12:21:35 -0700321free:
322 kfree_skb(skb);
323 return err;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100324}
325
Ben Hutchings2c530402012-07-10 10:55:09 +0000326/**
327 * mesh_peer_init - initialize new mesh peer and return resulting sta_info
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700328 *
329 * @sdata: local meshif
330 * @addr: peer's address
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700331 * @elems: IEs from beacon or mesh peering frame
332 *
333 * call under RCU
334 */
335static struct sta_info *mesh_peer_init(struct ieee80211_sub_if_data *sdata,
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700336 u8 *addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700337 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100338{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200339 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +0200340 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700341 struct ieee80211_supported_band *sband;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700342 u32 rates, basic_rates = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100343 struct sta_info *sta;
Thomas Pedersene87278e2012-04-26 15:01:06 -0700344 bool insert = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100345
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700346 sband = local->hw.wiphy->bands[band];
347 rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates);
Johannes Bergd0709a62008-02-25 16:27:46 +0100348
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700349 sta = sta_info_get(sdata, addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100350 if (!sta) {
Thomas Pedersenf5c56812012-05-03 15:06:09 -0700351 /* Userspace handles peer allocation when security is enabled */
352 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) {
353 cfg80211_notify_new_peer_candidate(sdata->dev, addr,
354 elems->ie_start,
355 elems->total_len,
356 GFP_ATOMIC);
357 return NULL;
358 }
359
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700360 sta = mesh_plink_alloc(sdata, addr);
Johannes Berg34e89502010-02-03 13:59:58 +0100361 if (!sta)
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700362 return NULL;
Thomas Pedersene87278e2012-04-26 15:01:06 -0700363 insert = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100364 }
365
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700366 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100367 sta->last_rx = jiffies;
Chun-Yeow Yeohbae35d92012-07-24 11:52:35 +0800368 if (sta->plink_state == NL80211_PLINK_ESTAB) {
369 spin_unlock_bh(&sta->lock);
370 return sta;
371 }
372
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700373 sta->sta.supp_rates[band] = rates;
Thomas Pedersene76781e2012-04-18 19:24:13 -0700374 if (elems->ht_cap_elem &&
Johannes Berg466f3102012-07-25 13:51:49 +0200375 sdata->vif.bss_conf.channel_type != NL80211_CHAN_NO_HT)
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700376 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
377 elems->ht_cap_elem,
378 &sta->sta.ht_cap);
379 else
380 memset(&sta->sta.ht_cap, 0, sizeof(sta->sta.ht_cap));
381
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700382 if (elems->ht_operation) {
Thomas Pedersenc7d25822012-04-26 15:01:07 -0700383 if (!(elems->ht_operation->ht_param &
384 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY))
385 sta->sta.ht_cap.cap &=
386 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700387 sta->ch_type =
388 ieee80211_ht_oper_to_channel_type(elems->ht_operation);
389 }
Thomas Pedersenc7d25822012-04-26 15:01:07 -0700390
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700391 rate_control_rate_init(sta);
392 spin_unlock_bh(&sta->lock);
393
Thomas Pedersene87278e2012-04-26 15:01:06 -0700394 if (insert && sta_info_insert(sta))
395 return NULL;
396
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700397 return sta;
398}
399
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700400void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
401 u8 *hw_addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700402 struct ieee802_11_elems *elems)
403{
404 struct sta_info *sta;
405
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700406 rcu_read_lock();
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700407 sta = mesh_peer_init(sdata, hw_addr, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700408 if (!sta)
409 goto out;
410
Javier Cardona1570ca52011-04-07 15:08:35 -0700411 if (mesh_peer_accepts_plinks(elems) &&
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700412 sta->plink_state == NL80211_PLINK_LISTEN &&
413 sdata->u.mesh.accepting_plinks &&
414 sdata->u.mesh.mshcfg.auto_open_plinks &&
415 rssi_threshold_check(sta, sdata))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100416 mesh_plink_open(sta);
417
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700418out:
Johannes Bergd0709a62008-02-25 16:27:46 +0100419 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100420}
421
422static void mesh_plink_timer(unsigned long data)
423{
424 struct sta_info *sta;
425 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100426 struct ieee80211_sub_if_data *sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800427 struct mesh_config *mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100428
Johannes Bergd0709a62008-02-25 16:27:46 +0100429 /*
430 * This STA is valid because sta_info_destroy() will
431 * del_timer_sync() this timer after having made sure
432 * it cannot be readded (by deleting the plink.)
433 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100434 sta = (struct sta_info *) data;
435
Johannes Berg5bb644a2009-05-17 11:40:42 +0200436 if (sta->sdata->local->quiescing) {
437 sta->plink_timer_was_running = true;
438 return;
439 }
440
Johannes Berg07346f812008-05-03 01:02:02 +0200441 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100442 if (sta->ignore_plink_timer) {
443 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200444 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100445 return;
446 }
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200447 mpl_dbg(sta->sdata,
448 "Mesh plink timer for %pM fired on state %d\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700449 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100450 reason = 0;
451 llid = sta->llid;
452 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100453 sdata = sta->sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800454 mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100455
456 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700457 case NL80211_PLINK_OPN_RCVD:
458 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100459 /* retry timer */
Marco Porsch453e66f22012-11-21 18:40:32 -0800460 if (sta->plink_retries < mshcfg->dot11MeshMaxRetries) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100461 u32 rand;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200462 mpl_dbg(sta->sdata,
463 "Mesh plink for %pM (retry, timeout): %d %d\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700464 sta->sta.addr, sta->plink_retries,
465 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100466 get_random_bytes(&rand, sizeof(u32));
467 sta->plink_timeout = sta->plink_timeout +
468 rand % sta->plink_timeout;
469 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100470 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200471 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700472 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
473 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100474 break;
475 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700476 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100477 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700478 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100479 /* confirm timer */
480 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700481 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700482 sta->plink_state = NL80211_PLINK_HOLDING;
Marco Porsch453e66f22012-11-21 18:40:32 -0800483 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200484 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700485 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
486 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100487 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700488 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100489 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100490 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100491 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200492 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100493 break;
494 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200495 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100496 break;
497 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100498}
499
Johannes Berg5bb644a2009-05-17 11:40:42 +0200500#ifdef CONFIG_PM
501void mesh_plink_quiesce(struct sta_info *sta)
502{
503 if (del_timer_sync(&sta->plink_timer))
504 sta->plink_timer_was_running = true;
505}
506
507void mesh_plink_restart(struct sta_info *sta)
508{
509 if (sta->plink_timer_was_running) {
510 add_timer(&sta->plink_timer);
511 sta->plink_timer_was_running = false;
512 }
513}
514#endif
515
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100516static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
517{
518 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
519 sta->plink_timer.data = (unsigned long) sta;
520 sta->plink_timer.function = mesh_plink_timer;
521 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100522 add_timer(&sta->plink_timer);
523}
524
525int mesh_plink_open(struct sta_info *sta)
526{
527 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100528 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100529
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200530 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700531 return -EPERM;
532
Johannes Berg07346f812008-05-03 01:02:02 +0200533 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100534 get_random_bytes(&llid, 2);
535 sta->llid = llid;
Chun-Yeow Yeoh9385d042012-09-14 14:18:31 +0800536 if (sta->plink_state != NL80211_PLINK_LISTEN &&
537 sta->plink_state != NL80211_PLINK_BLOCKED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200538 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100539 return -EBUSY;
540 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700541 sta->plink_state = NL80211_PLINK_OPN_SNT;
Marco Porsch453e66f22012-11-21 18:40:32 -0800542 mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200543 spin_unlock_bh(&sta->lock);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200544 mpl_dbg(sdata,
545 "Mesh plink: starting establishment with %pM\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700546 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100547
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700548 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200549 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100550}
551
552void mesh_plink_block(struct sta_info *sta)
553{
John W. Linvillec9370192010-06-21 17:14:07 -0400554 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200555 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400556
Johannes Berg07346f812008-05-03 01:02:02 +0200557 spin_lock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200558 changed = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700559 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200560 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400561
Marco Porschdf323812012-08-08 07:58:43 +0200562 ieee80211_bss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100563}
564
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100565
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200566void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100567 size_t len, struct ieee80211_rx_status *rx_status)
568{
Marco Porsch453e66f22012-11-21 18:40:32 -0800569 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100570 struct ieee802_11_elems elems;
571 struct sta_info *sta;
572 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700573 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100574 size_t baselen;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700575 bool matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100576 u8 ie_len;
577 u8 *baseaddr;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700578 u32 changed = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100579 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000580 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700581 [NL80211_PLINK_LISTEN] = "LISTEN",
582 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
583 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
584 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
585 [NL80211_PLINK_ESTAB] = "ESTAB",
586 [NL80211_PLINK_HOLDING] = "HOLDING",
587 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000588 };
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100589
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200590 /* need action_code, aux */
591 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
592 return;
593
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100594 if (is_multicast_ether_addr(mgmt->da)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200595 mpl_dbg(sdata,
596 "Mesh plink: ignore frame from multicast address\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100597 return;
598 }
599
Thomas Pedersen8db09852011-08-12 20:01:00 -0700600 baseaddr = mgmt->u.action.u.self_prot.variable;
601 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
602 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700603 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100604 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700605 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100606 }
607 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700608 if (!elems.peering) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200609 mpl_dbg(sdata,
610 "Mesh plink: missing necessary peer link ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100611 return;
612 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700613 if (elems.rsn_len &&
614 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200615 mpl_dbg(sdata,
616 "Mesh plink: can't establish link with secure peer\n");
Javier Cardona5cff5e02011-04-07 15:08:29 -0700617 return;
618 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100619
Thomas Pedersen8db09852011-08-12 20:01:00 -0700620 ftype = mgmt->u.action.u.self_prot.action_code;
621 ie_len = elems.peering_len;
622 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
623 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
624 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
625 && ie_len != 8)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200626 mpl_dbg(sdata,
627 "Mesh plink: incorrect plink ie length %d %d\n",
628 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100629 return;
630 }
631
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700632 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
633 (!elems.mesh_id || !elems.mesh_config)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200634 mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100635 return;
636 }
637 /* Note the lines below are correct, the llid in the frame is the plid
638 * from the point of view of this host.
639 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700640 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700641 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700642 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
643 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100644
Johannes Bergd0709a62008-02-25 16:27:46 +0100645 rcu_read_lock();
646
Johannes Bergabe60632009-11-25 17:46:18 +0100647 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700648 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200649 mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100650 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100651 return;
652 }
653
Ashok Nagarajan55335132012-02-28 17:04:08 -0800654 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800655 !rssi_threshold_check(sta, sdata)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200656 mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800657 mgmt->sa);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800658 rcu_read_unlock();
659 return;
660 }
661
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200662 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200663 mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
Javier Cardona53e80512011-04-07 15:08:32 -0700664 rcu_read_unlock();
665 return;
666 }
667
Javier Cardona57cf8042011-05-13 10:45:43 -0700668 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100669 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100670 return;
671 }
672
673 /* Now we will figure out the appropriate event... */
674 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700675 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700676 !mesh_matches_local(sdata, &elems)) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200677 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100678 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700679 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100680 event = OPN_RJCT;
681 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700682 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100683 event = CNF_RJCT;
684 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700685 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100686 break;
687 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200688 }
689
690 if (!sta && !matches_local) {
691 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700692 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200693 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700694 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
695 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200696 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100697 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700698 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100699 if (!mesh_plink_free_count(sdata)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200700 mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
Johannes Berg73651ee2008-02-25 16:27:47 +0100701 rcu_read_unlock();
702 return;
703 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100704 event = OPN_ACPT;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200705 } else if (matches_local) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100706 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700707 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100708 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100709 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100710 event = OPN_IGNR;
711 else
712 event = OPN_ACPT;
713 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700714 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100715 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100716 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100717 event = CNF_IGNR;
718 else
719 event = CNF_ACPT;
720 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700721 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700722 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100723 /* Do not check for llid or plid. This does not
724 * follow the standard but since multiple plinks
725 * per sta are not supported, it is necessary in
726 * order to avoid a livelock when MP A sees an
727 * establish peer link to MP B but MP B does not
728 * see it. This can be caused by a timeout in
729 * B's peer link establishment or B beign
730 * restarted.
731 */
732 event = CLS_ACPT;
733 else if (sta->plid != plid)
734 event = CLS_IGNR;
735 else if (ie_len == 7 && sta->llid != llid)
736 event = CLS_IGNR;
737 else
738 event = CLS_ACPT;
739 break;
740 default:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200741 mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100742 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100743 return;
744 }
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700745 }
746
747 if (event == OPN_ACPT) {
748 /* allocate sta entry if necessary and update info */
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700749 sta = mesh_peer_init(sdata, mgmt->sa, &elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700750 if (!sta) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200751 mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700752 rcu_read_unlock();
753 return;
754 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100755 }
756
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200757 mpl_dbg(sdata,
758 "Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
Rui Paulo1460dd12009-11-09 23:46:48 +0000759 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700760 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
761 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100762 reason = 0;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700763 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100764 switch (sta->plink_state) {
765 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700766 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100767 switch (event) {
768 case CLS_ACPT:
769 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200770 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100771 break;
772 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700773 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100774 sta->plid = plid;
775 get_random_bytes(&llid, 2);
776 sta->llid = llid;
Marco Porsch453e66f22012-11-21 18:40:32 -0800777 mesh_plink_timer_set(sta,
778 mshcfg->dot11MeshRetryTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200779 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700780 mesh_plink_frame_tx(sdata,
781 WLAN_SP_MESH_PEERING_OPEN,
782 sta->sta.addr, llid, 0, 0);
783 mesh_plink_frame_tx(sdata,
784 WLAN_SP_MESH_PEERING_CONFIRM,
785 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100786 break;
787 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200788 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100789 break;
790 }
791 break;
792
Javier Cardona57cf8042011-05-13 10:45:43 -0700793 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100794 switch (event) {
795 case OPN_RJCT:
796 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700797 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100798 case CLS_ACPT:
799 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700800 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100801 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700802 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100803 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800804 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100805 sta->ignore_plink_timer = true;
806
807 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200808 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700809 mesh_plink_frame_tx(sdata,
810 WLAN_SP_MESH_PEERING_CLOSE,
811 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100812 break;
813 case OPN_ACPT:
814 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700815 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100816 sta->plid = plid;
817 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200818 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700819 mesh_plink_frame_tx(sdata,
820 WLAN_SP_MESH_PEERING_CONFIRM,
821 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100822 break;
823 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700824 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100825 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800826 mshcfg->dot11MeshConfirmTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100827 sta->ignore_plink_timer = true;
828
Johannes Berg07346f812008-05-03 01:02:02 +0200829 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100830 break;
831 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200832 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100833 break;
834 }
835 break;
836
Javier Cardona57cf8042011-05-13 10:45:43 -0700837 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100838 switch (event) {
839 case OPN_RJCT:
840 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700841 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100842 case CLS_ACPT:
843 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700844 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100845 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700846 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100847 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800848 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100849 sta->ignore_plink_timer = true;
850
851 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200852 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700853 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
854 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100855 break;
856 case OPN_ACPT:
857 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200858 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700859 mesh_plink_frame_tx(sdata,
860 WLAN_SP_MESH_PEERING_CONFIRM,
861 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100862 break;
863 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100864 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700865 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200866 spin_unlock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200867 changed |= mesh_plink_inc_estab_count(sdata);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700868 changed |= mesh_set_ht_prot_mode(sdata);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200869 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700870 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100871 break;
872 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200873 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100874 break;
875 }
876 break;
877
Javier Cardona57cf8042011-05-13 10:45:43 -0700878 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100879 switch (event) {
880 case OPN_RJCT:
881 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700882 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100883 case CLS_ACPT:
884 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700885 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100886 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700887 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100888 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800889 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100890 sta->ignore_plink_timer = true;
891
892 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200893 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700894 mesh_plink_frame_tx(sdata,
895 WLAN_SP_MESH_PEERING_CLOSE,
896 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100897 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100898 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100899 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700900 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200901 spin_unlock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200902 changed |= mesh_plink_inc_estab_count(sdata);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700903 changed |= mesh_set_ht_prot_mode(sdata);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200904 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700905 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700906 mesh_plink_frame_tx(sdata,
907 WLAN_SP_MESH_PEERING_CONFIRM,
908 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100909 break;
910 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200911 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100912 break;
913 }
914 break;
915
Javier Cardona57cf8042011-05-13 10:45:43 -0700916 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100917 switch (event) {
918 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700919 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100920 sta->reason = reason;
Marco Porschdf323812012-08-08 07:58:43 +0200921 changed |= __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700922 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100923 llid = sta->llid;
Marco Porsch453e66f22012-11-21 18:40:32 -0800924 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200925 spin_unlock_bh(&sta->lock);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700926 changed |= mesh_set_ht_prot_mode(sdata);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700927 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
928 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100929 break;
930 case OPN_ACPT:
931 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200932 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700933 mesh_plink_frame_tx(sdata,
934 WLAN_SP_MESH_PEERING_CONFIRM,
935 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100936 break;
937 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200938 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100939 break;
940 }
941 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700942 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100943 switch (event) {
944 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100945 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100946 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100947 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200948 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100949 break;
950 case OPN_ACPT:
951 case CNF_ACPT:
952 case OPN_RJCT:
953 case CNF_RJCT:
954 llid = sta->llid;
955 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200956 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700957 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
958 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100959 break;
960 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200961 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100962 }
963 break;
964 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800965 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800966 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100967 */
Johannes Berg07346f812008-05-03 01:02:02 +0200968 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100969 break;
970 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100971
972 rcu_read_unlock();
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700973
974 if (changed)
975 ieee80211_bss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100976}