blob: 81e612682bc3320e05ffd0a1e18149c7fdb1012f [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 +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
Ben Hutchings2c530402012-07-10 10:55:09 +000058/**
Ashok Nagarajancbf93222012-05-07 21:00:31 -070059 * mesh_set_ht_prot_mode - set correct HT protection mode
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -070060 *
Ashok Nagarajancbf93222012-05-07 21:00:31 -070061 * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
62 * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
63 * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
64 * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
65 * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
66 * HT20 peer is present. Otherwise no-protection mode is selected.
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -070067 */
68static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
69{
70 struct ieee80211_local *local = sdata->local;
71 struct sta_info *sta;
72 u32 changed = 0;
73 u16 ht_opmode;
74 bool non_ht_sta = false, ht20_sta = false;
75
Johannes Berg4bf88532012-11-09 11:39:59 +010076 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -070077 return 0;
78
79 rcu_read_lock();
80 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Ashok Nagarajancbf93222012-05-07 21:00:31 -070081 if (sdata != sta->sdata ||
82 sta->plink_state != NL80211_PLINK_ESTAB)
83 continue;
84
Johannes Berg4bf88532012-11-09 11:39:59 +010085 switch (sta->ch_width) {
86 case NL80211_CHAN_WIDTH_20_NOHT:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +020087 mpl_dbg(sdata,
88 "mesh_plink %pM: nonHT sta (%pM) is present\n",
Ashok Nagarajancbf93222012-05-07 21:00:31 -070089 sdata->vif.addr, sta->sta.addr);
90 non_ht_sta = true;
91 goto out;
Johannes Berg4bf88532012-11-09 11:39:59 +010092 case NL80211_CHAN_WIDTH_20:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +020093 mpl_dbg(sdata,
94 "mesh_plink %pM: HT20 sta (%pM) is present\n",
Ashok Nagarajancbf93222012-05-07 21:00:31 -070095 sdata->vif.addr, sta->sta.addr);
96 ht20_sta = true;
97 default:
98 break;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -070099 }
100 }
101out:
102 rcu_read_unlock();
103
104 if (non_ht_sta)
105 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Johannes Berg466f3102012-07-25 13:51:49 +0200106 else if (ht20_sta &&
Johannes Berg4bf88532012-11-09 11:39:59 +0100107 sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700108 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
109 else
110 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
111
112 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
113 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -0700114 sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700115 changed = BSS_CHANGED_HT;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200116 mpl_dbg(sdata,
117 "mesh_plink %pM: protection mode changed to %d\n",
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700118 sdata->vif.addr, ht_opmode);
119 }
120
121 return changed;
122}
123
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100124/**
John W. Linvillec9370192010-06-21 17:14:07 -0400125 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100126 *
127 * @sta: mesh peer link to deactivate
128 *
129 * All mesh paths with this peer as next hop will be flushed
Marco Porschdf323812012-08-08 07:58:43 +0200130 * Returns beacon changed flag if the beacon content changed.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100131 *
Johannes Berg07346f812008-05-03 01:02:02 +0200132 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100133 */
Marco Porschdf323812012-08-08 07:58:43 +0200134static u32 __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100135{
Johannes Bergd0709a62008-02-25 16:27:46 +0100136 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200137 u32 changed = 0;
Johannes Bergd0709a62008-02-25 16:27:46 +0100138
Marco Porschdf323812012-08-08 07:58:43 +0200139 if (sta->plink_state == NL80211_PLINK_ESTAB)
140 changed = mesh_plink_dec_estab_count(sdata);
Javier Cardona57cf8042011-05-13 10:45:43 -0700141 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100142 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400143
Marco Porschdf323812012-08-08 07:58:43 +0200144 return changed;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100145}
146
Johannes Berg902acc72008-02-23 15:17:19 +0100147/**
John W. Linvillec9370192010-06-21 17:14:07 -0400148 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100149 *
150 * @sta: mesh peer link to deactivate
151 *
152 * All mesh paths with this peer as next hop will be flushed
153 */
154void mesh_plink_deactivate(struct sta_info *sta)
155{
John W. Linvillec9370192010-06-21 17:14:07 -0400156 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200157 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400158
Johannes Berg07346f812008-05-03 01:02:02 +0200159 spin_lock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200160 changed = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700161 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
162 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
163 sta->sta.addr, sta->llid, sta->plid,
164 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200165 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400166
Marco Porschdf323812012-08-08 07:58:43 +0200167 ieee80211_bss_info_change_notify(sdata, changed);
Johannes Berg902acc72008-02-23 15:17:19 +0100168}
169
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200170static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700171 enum ieee80211_self_protected_actioncode action,
172 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200173 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700174 struct sk_buff *skb;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700175 struct ieee80211_tx_info *info;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100176 struct ieee80211_mgmt *mgmt;
177 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700178 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700179 u8 *pos, ie_len = 4;
180 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
181 sizeof(mgmt->u.action.u.self_prot);
Thomas Pedersenf609a432012-08-03 12:21:35 -0700182 int err = -ENOMEM;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100183
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800184 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700185 hdr_len +
186 2 + /* capability info */
187 2 + /* AID */
188 2 + 8 + /* supported rates */
189 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
190 2 + sdata->u.mesh.mesh_id_len +
191 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700192 2 + sizeof(struct ieee80211_ht_cap) +
Johannes Berg074d46d2012-03-15 19:45:16 +0100193 2 + sizeof(struct ieee80211_ht_operation) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700194 2 + 8 + /* peering IE */
195 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100196 if (!skb)
197 return -1;
Thomas Pedersene7570df2012-08-03 12:21:34 -0700198 info = IEEE80211_SKB_CB(skb);
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800199 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700200 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
201 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700202 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
203 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100204 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100205 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700206 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700207 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
208 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100209
Thomas Pedersen8db09852011-08-12 20:01:00 -0700210 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
Johannes Berg55de9082012-07-26 17:24:39 +0200211 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
212
Thomas Pedersen8db09852011-08-12 20:01:00 -0700213 /* capability info */
214 pos = skb_put(skb, 2);
215 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700216 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700217 /* AID */
218 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000219 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100220 }
Johannes Berg55de9082012-07-26 17:24:39 +0200221 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
222 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700223 mesh_add_rsn_ie(skb, sdata) ||
224 mesh_add_meshid_ie(skb, sdata) ||
225 mesh_add_meshconf_ie(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700226 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700227 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
Thomas Pedersene7570df2012-08-03 12:21:34 -0700228 info->flags |= IEEE80211_TX_CTL_NO_ACK;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700229 if (mesh_add_meshid_ie(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700230 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100231 }
232
Thomas Pedersen8db09852011-08-12 20:01:00 -0700233 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100234 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700235 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100236 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700237 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700238 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100239 include_plid = true;
240 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700241 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700242 if (plid) {
243 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100244 include_plid = true;
245 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700246 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100247 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700248 default:
Thomas Pedersenf609a432012-08-03 12:21:35 -0700249 err = -EINVAL;
250 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100251 }
252
Thomas Pedersen8db09852011-08-12 20:01:00 -0700253 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700254 goto free;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700255
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100256 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700257 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100258 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700259 memcpy(pos, &peering_proto, 2);
260 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100261 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700262 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100263 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100264 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700265 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100266 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700267 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100268 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700269 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100270 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700271
272 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
273 if (mesh_add_ht_cap_ie(skb, sdata) ||
Johannes Berg074d46d2012-03-15 19:45:16 +0100274 mesh_add_ht_oper_ie(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700275 goto free;
Thomas Pedersen176f3602011-10-26 14:47:27 -0700276 }
277
Thomas Pedersen8db09852011-08-12 20:01:00 -0700278 if (mesh_add_vendor_ies(skb, sdata))
Thomas Pedersenf609a432012-08-03 12:21:35 -0700279 goto free;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100280
Johannes Berg62ae67b2009-11-18 18:42:05 +0100281 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100282 return 0;
Thomas Pedersenf609a432012-08-03 12:21:35 -0700283free:
284 kfree_skb(skb);
285 return err;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100286}
287
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800288static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
289 struct sta_info *sta,
290 struct ieee802_11_elems *elems, bool insert)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100291{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200292 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +0200293 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700294 struct ieee80211_supported_band *sband;
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800295 u32 rates, basic_rates = 0, changed = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100296
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700297 sband = local->hw.wiphy->bands[band];
298 rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates);
Johannes Bergd0709a62008-02-25 16:27:46 +0100299
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700300 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100301 sta->last_rx = jiffies;
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800302
303 /* rates and capabilities don't change during peering */
304 if (sta->plink_state == NL80211_PLINK_ESTAB)
305 goto out;
Chun-Yeow Yeohbae35d92012-07-24 11:52:35 +0800306
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800307 if (sta->sta.supp_rates[band] != rates)
308 changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700309 sta->sta.supp_rates[band] = rates;
Thomas Pedersene76781e2012-04-18 19:24:13 -0700310 if (elems->ht_cap_elem &&
Johannes Berg4bf88532012-11-09 11:39:59 +0100311 sdata->vif.bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700312 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
313 elems->ht_cap_elem,
314 &sta->sta.ht_cap);
315 else
316 memset(&sta->sta.ht_cap, 0, sizeof(sta->sta.ht_cap));
317
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700318 if (elems->ht_operation) {
Johannes Berg4bf88532012-11-09 11:39:59 +0100319 struct cfg80211_chan_def chandef;
320
Thomas Pedersenc7d25822012-04-26 15:01:07 -0700321 if (!(elems->ht_operation->ht_param &
322 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY))
323 sta->sta.ht_cap.cap &=
324 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg4bf88532012-11-09 11:39:59 +0100325 ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan,
326 elems->ht_operation, &chandef);
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800327 if (sta->ch_width != chandef.width)
328 changed |= IEEE80211_RC_BW_CHANGED;
Johannes Berg4bf88532012-11-09 11:39:59 +0100329 sta->ch_width = chandef.width;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700330 }
Thomas Pedersenc7d25822012-04-26 15:01:07 -0700331
Helmut Schaa59cf1d62012-11-27 18:03:13 +0100332 if (insert)
333 rate_control_rate_init(sta);
Thomas Pedersenf68d7762013-01-23 12:18:13 -0800334 else
335 rate_control_rate_update(local, sband, sta, changed);
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800336out:
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700337 spin_unlock_bh(&sta->lock);
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800338}
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700339
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800340static struct sta_info *
341__mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
342{
343 struct sta_info *sta;
344
345 if (sdata->local->num_sta >= MESH_MAX_PLINKS)
Thomas Pedersene87278e2012-04-26 15:01:06 -0700346 return NULL;
347
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800348 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
349 if (!sta)
350 return NULL;
351
352 sta->plink_state = NL80211_PLINK_LISTEN;
353 init_timer(&sta->plink_timer);
354
355 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
356 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
357 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
358
359 set_sta_flag(sta, WLAN_STA_WME);
360
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700361 return sta;
362}
363
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800364static struct sta_info *
365mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
366 struct ieee802_11_elems *elems)
367{
368 struct sta_info *sta = NULL;
369
370 /* Userspace handles peer allocation when security is enabled */
371 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
372 cfg80211_notify_new_peer_candidate(sdata->dev, addr,
373 elems->ie_start,
374 elems->total_len,
375 GFP_KERNEL);
376 else
377 sta = __mesh_sta_info_alloc(sdata, addr);
378
379 return sta;
380}
381
382/*
383 * mesh_sta_info_get - return mesh sta info entry for @addr.
384 *
385 * @sdata: local meshif
386 * @addr: peer's address
387 * @elems: IEs from beacon or mesh peering frame.
388 *
389 * Return existing or newly allocated sta_info under RCU read lock.
390 * (re)initialize with given IEs.
391 */
392static struct sta_info *
393mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
394 u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
395{
396 struct sta_info *sta = NULL;
397
398 rcu_read_lock();
399 sta = sta_info_get(sdata, addr);
400 if (sta) {
401 mesh_sta_info_init(sdata, sta, elems, false);
402 } else {
403 rcu_read_unlock();
404 /* can't run atomic */
405 sta = mesh_sta_info_alloc(sdata, addr, elems);
406 if (!sta) {
407 rcu_read_lock();
408 return NULL;
409 }
410
Thomas Pedersen3b4797b2013-01-26 17:00:02 -0800411 mesh_sta_info_init(sdata, sta, elems, true);
412
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800413 if (sta_info_insert_rcu(sta))
414 return NULL;
415 }
416
417 return sta;
418}
419
420/*
421 * mesh_neighbour_update - update or initialize new mesh neighbor.
422 *
423 * @sdata: local meshif
424 * @addr: peer's address
425 * @elems: IEs from beacon or mesh peering frame
426 *
427 * Initiates peering if appropriate.
428 */
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700429void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
430 u8 *hw_addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700431 struct ieee802_11_elems *elems)
432{
433 struct sta_info *sta;
434
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800435 sta = mesh_sta_info_get(sdata, hw_addr, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700436 if (!sta)
437 goto out;
438
Javier Cardona1570ca52011-04-07 15:08:35 -0700439 if (mesh_peer_accepts_plinks(elems) &&
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700440 sta->plink_state == NL80211_PLINK_LISTEN &&
441 sdata->u.mesh.accepting_plinks &&
442 sdata->u.mesh.mshcfg.auto_open_plinks &&
443 rssi_threshold_check(sta, sdata))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100444 mesh_plink_open(sta);
445
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700446out:
Johannes Bergd0709a62008-02-25 16:27:46 +0100447 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100448}
449
450static void mesh_plink_timer(unsigned long data)
451{
452 struct sta_info *sta;
453 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100454 struct ieee80211_sub_if_data *sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800455 struct mesh_config *mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100456
Johannes Bergd0709a62008-02-25 16:27:46 +0100457 /*
458 * This STA is valid because sta_info_destroy() will
459 * del_timer_sync() this timer after having made sure
460 * it cannot be readded (by deleting the plink.)
461 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100462 sta = (struct sta_info *) data;
463
Johannes Berg5bb644a2009-05-17 11:40:42 +0200464 if (sta->sdata->local->quiescing) {
465 sta->plink_timer_was_running = true;
466 return;
467 }
468
Johannes Berg07346f812008-05-03 01:02:02 +0200469 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100470 if (sta->ignore_plink_timer) {
471 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200472 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100473 return;
474 }
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200475 mpl_dbg(sta->sdata,
476 "Mesh plink timer for %pM fired on state %d\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700477 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100478 reason = 0;
479 llid = sta->llid;
480 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100481 sdata = sta->sdata;
Marco Porsch453e66f22012-11-21 18:40:32 -0800482 mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100483
484 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700485 case NL80211_PLINK_OPN_RCVD:
486 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100487 /* retry timer */
Marco Porsch453e66f22012-11-21 18:40:32 -0800488 if (sta->plink_retries < mshcfg->dot11MeshMaxRetries) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100489 u32 rand;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200490 mpl_dbg(sta->sdata,
491 "Mesh plink for %pM (retry, timeout): %d %d\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700492 sta->sta.addr, sta->plink_retries,
493 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100494 get_random_bytes(&rand, sizeof(u32));
495 sta->plink_timeout = sta->plink_timeout +
496 rand % sta->plink_timeout;
497 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100498 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200499 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700500 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
501 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100502 break;
503 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700504 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100505 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700506 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100507 /* confirm timer */
508 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700509 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700510 sta->plink_state = NL80211_PLINK_HOLDING;
Marco Porsch453e66f22012-11-21 18:40:32 -0800511 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200512 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700513 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
514 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100515 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700516 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100517 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100518 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100519 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200520 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100521 break;
522 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200523 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100524 break;
525 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100526}
527
Johannes Berg5bb644a2009-05-17 11:40:42 +0200528#ifdef CONFIG_PM
529void mesh_plink_quiesce(struct sta_info *sta)
530{
531 if (del_timer_sync(&sta->plink_timer))
532 sta->plink_timer_was_running = true;
533}
534
535void mesh_plink_restart(struct sta_info *sta)
536{
537 if (sta->plink_timer_was_running) {
538 add_timer(&sta->plink_timer);
539 sta->plink_timer_was_running = false;
540 }
541}
542#endif
543
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100544static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
545{
546 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
547 sta->plink_timer.data = (unsigned long) sta;
548 sta->plink_timer.function = mesh_plink_timer;
549 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100550 add_timer(&sta->plink_timer);
551}
552
553int mesh_plink_open(struct sta_info *sta)
554{
555 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100556 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100557
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200558 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700559 return -EPERM;
560
Johannes Berg07346f812008-05-03 01:02:02 +0200561 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100562 get_random_bytes(&llid, 2);
563 sta->llid = llid;
Chun-Yeow Yeoh9385d042012-09-14 14:18:31 +0800564 if (sta->plink_state != NL80211_PLINK_LISTEN &&
565 sta->plink_state != NL80211_PLINK_BLOCKED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200566 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100567 return -EBUSY;
568 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700569 sta->plink_state = NL80211_PLINK_OPN_SNT;
Marco Porsch453e66f22012-11-21 18:40:32 -0800570 mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200571 spin_unlock_bh(&sta->lock);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200572 mpl_dbg(sdata,
573 "Mesh plink: starting establishment with %pM\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700574 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100575
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700576 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200577 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100578}
579
580void mesh_plink_block(struct sta_info *sta)
581{
John W. Linvillec9370192010-06-21 17:14:07 -0400582 struct ieee80211_sub_if_data *sdata = sta->sdata;
Marco Porschdf323812012-08-08 07:58:43 +0200583 u32 changed;
John W. Linvillec9370192010-06-21 17:14:07 -0400584
Johannes Berg07346f812008-05-03 01:02:02 +0200585 spin_lock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200586 changed = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700587 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200588 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400589
Marco Porschdf323812012-08-08 07:58:43 +0200590 ieee80211_bss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100591}
592
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100593
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200594void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100595 size_t len, struct ieee80211_rx_status *rx_status)
596{
Marco Porsch453e66f22012-11-21 18:40:32 -0800597 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100598 struct ieee802_11_elems elems;
599 struct sta_info *sta;
600 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700601 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100602 size_t baselen;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700603 bool matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100604 u8 ie_len;
605 u8 *baseaddr;
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700606 u32 changed = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100607 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000608 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700609 [NL80211_PLINK_LISTEN] = "LISTEN",
610 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
611 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
612 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
613 [NL80211_PLINK_ESTAB] = "ESTAB",
614 [NL80211_PLINK_HOLDING] = "HOLDING",
615 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000616 };
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100617
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200618 /* need action_code, aux */
619 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
620 return;
621
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100622 if (is_multicast_ether_addr(mgmt->da)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200623 mpl_dbg(sdata,
624 "Mesh plink: ignore frame from multicast address\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100625 return;
626 }
627
Thomas Pedersen8db09852011-08-12 20:01:00 -0700628 baseaddr = mgmt->u.action.u.self_prot.variable;
629 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
630 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700631 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100632 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700633 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100634 }
635 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700636 if (!elems.peering) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200637 mpl_dbg(sdata,
638 "Mesh plink: missing necessary peer link ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100639 return;
640 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700641 if (elems.rsn_len &&
642 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200643 mpl_dbg(sdata,
644 "Mesh plink: can't establish link with secure peer\n");
Javier Cardona5cff5e02011-04-07 15:08:29 -0700645 return;
646 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100647
Thomas Pedersen8db09852011-08-12 20:01:00 -0700648 ftype = mgmt->u.action.u.self_prot.action_code;
649 ie_len = elems.peering_len;
650 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
651 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
652 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
653 && ie_len != 8)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200654 mpl_dbg(sdata,
655 "Mesh plink: incorrect plink ie length %d %d\n",
656 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100657 return;
658 }
659
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700660 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
661 (!elems.mesh_id || !elems.mesh_config)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200662 mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100663 return;
664 }
665 /* Note the lines below are correct, the llid in the frame is the plid
666 * from the point of view of this host.
667 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700668 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700669 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700670 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
671 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100672
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800673 /* WARNING: Only for sta pointer, is dropped & re-acquired */
Johannes Bergd0709a62008-02-25 16:27:46 +0100674 rcu_read_lock();
675
Johannes Bergabe60632009-11-25 17:46:18 +0100676 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700677 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200678 mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100679 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100680 return;
681 }
682
Ashok Nagarajan55335132012-02-28 17:04:08 -0800683 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800684 !rssi_threshold_check(sta, sdata)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200685 mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800686 mgmt->sa);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800687 rcu_read_unlock();
688 return;
689 }
690
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200691 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200692 mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
Javier Cardona53e80512011-04-07 15:08:32 -0700693 rcu_read_unlock();
694 return;
695 }
696
Javier Cardona57cf8042011-05-13 10:45:43 -0700697 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100698 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100699 return;
700 }
701
702 /* Now we will figure out the appropriate event... */
703 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700704 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700705 !mesh_matches_local(sdata, &elems)) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200706 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100707 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700708 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100709 event = OPN_RJCT;
710 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700711 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100712 event = CNF_RJCT;
713 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700714 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100715 break;
716 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200717 }
718
719 if (!sta && !matches_local) {
720 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700721 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200722 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700723 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
724 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200725 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100726 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700727 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100728 if (!mesh_plink_free_count(sdata)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200729 mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
Johannes Berg73651ee2008-02-25 16:27:47 +0100730 rcu_read_unlock();
731 return;
732 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100733 event = OPN_ACPT;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200734 } else if (matches_local) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100735 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700736 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100737 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100738 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100739 event = OPN_IGNR;
740 else
741 event = OPN_ACPT;
742 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700743 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100744 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100745 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100746 event = CNF_IGNR;
747 else
748 event = CNF_ACPT;
749 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700750 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700751 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100752 /* Do not check for llid or plid. This does not
753 * follow the standard but since multiple plinks
754 * per sta are not supported, it is necessary in
755 * order to avoid a livelock when MP A sees an
756 * establish peer link to MP B but MP B does not
757 * see it. This can be caused by a timeout in
758 * B's peer link establishment or B beign
759 * restarted.
760 */
761 event = CLS_ACPT;
762 else if (sta->plid != plid)
763 event = CLS_IGNR;
764 else if (ie_len == 7 && sta->llid != llid)
765 event = CLS_IGNR;
766 else
767 event = CLS_ACPT;
768 break;
769 default:
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200770 mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100771 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100772 return;
773 }
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700774 }
775
776 if (event == OPN_ACPT) {
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800777 rcu_read_unlock();
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700778 /* allocate sta entry if necessary and update info */
Thomas Pedersen296fcba2013-01-23 12:18:12 -0800779 sta = mesh_sta_info_get(sdata, mgmt->sa, &elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700780 if (!sta) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200781 mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700782 rcu_read_unlock();
783 return;
784 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100785 }
786
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200787 mpl_dbg(sdata,
788 "Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
Rui Paulo1460dd12009-11-09 23:46:48 +0000789 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700790 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
791 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100792 reason = 0;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700793 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100794 switch (sta->plink_state) {
795 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700796 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100797 switch (event) {
798 case CLS_ACPT:
799 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200800 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100801 break;
802 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700803 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100804 sta->plid = plid;
805 get_random_bytes(&llid, 2);
806 sta->llid = llid;
Marco Porsch453e66f22012-11-21 18:40:32 -0800807 mesh_plink_timer_set(sta,
808 mshcfg->dot11MeshRetryTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200809 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700810 mesh_plink_frame_tx(sdata,
811 WLAN_SP_MESH_PEERING_OPEN,
812 sta->sta.addr, llid, 0, 0);
813 mesh_plink_frame_tx(sdata,
814 WLAN_SP_MESH_PEERING_CONFIRM,
815 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100816 break;
817 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200818 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100819 break;
820 }
821 break;
822
Javier Cardona57cf8042011-05-13 10:45:43 -0700823 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100824 switch (event) {
825 case OPN_RJCT:
826 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700827 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100828 case CLS_ACPT:
829 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700830 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100831 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700832 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100833 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800834 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100835 sta->ignore_plink_timer = true;
836
837 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200838 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700839 mesh_plink_frame_tx(sdata,
840 WLAN_SP_MESH_PEERING_CLOSE,
841 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100842 break;
843 case OPN_ACPT:
844 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700845 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100846 sta->plid = plid;
847 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200848 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700849 mesh_plink_frame_tx(sdata,
850 WLAN_SP_MESH_PEERING_CONFIRM,
851 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100852 break;
853 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700854 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100855 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800856 mshcfg->dot11MeshConfirmTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100857 sta->ignore_plink_timer = true;
858
Johannes Berg07346f812008-05-03 01:02:02 +0200859 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100860 break;
861 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200862 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100863 break;
864 }
865 break;
866
Javier Cardona57cf8042011-05-13 10:45:43 -0700867 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100868 switch (event) {
869 case OPN_RJCT:
870 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700871 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100872 case CLS_ACPT:
873 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700874 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100875 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700876 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100877 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800878 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100879 sta->ignore_plink_timer = true;
880
881 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200882 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700883 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
884 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100885 break;
886 case OPN_ACPT:
887 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200888 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700889 mesh_plink_frame_tx(sdata,
890 WLAN_SP_MESH_PEERING_CONFIRM,
891 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100892 break;
893 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100894 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700895 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200896 spin_unlock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200897 changed |= mesh_plink_inc_estab_count(sdata);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700898 changed |= mesh_set_ht_prot_mode(sdata);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200899 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700900 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100901 break;
902 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200903 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100904 break;
905 }
906 break;
907
Javier Cardona57cf8042011-05-13 10:45:43 -0700908 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100909 switch (event) {
910 case OPN_RJCT:
911 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700912 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100913 case CLS_ACPT:
914 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700915 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100916 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700917 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100918 if (!mod_plink_timer(sta,
Marco Porsch453e66f22012-11-21 18:40:32 -0800919 mshcfg->dot11MeshHoldingTimeout))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100920 sta->ignore_plink_timer = true;
921
922 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200923 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700924 mesh_plink_frame_tx(sdata,
925 WLAN_SP_MESH_PEERING_CLOSE,
926 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100927 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100928 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100929 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700930 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200931 spin_unlock_bh(&sta->lock);
Marco Porschdf323812012-08-08 07:58:43 +0200932 changed |= mesh_plink_inc_estab_count(sdata);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700933 changed |= mesh_set_ht_prot_mode(sdata);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200934 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -0700935 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700936 mesh_plink_frame_tx(sdata,
937 WLAN_SP_MESH_PEERING_CONFIRM,
938 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100939 break;
940 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200941 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100942 break;
943 }
944 break;
945
Javier Cardona57cf8042011-05-13 10:45:43 -0700946 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100947 switch (event) {
948 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700949 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100950 sta->reason = reason;
Marco Porschdf323812012-08-08 07:58:43 +0200951 changed |= __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700952 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100953 llid = sta->llid;
Marco Porsch453e66f22012-11-21 18:40:32 -0800954 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200955 spin_unlock_bh(&sta->lock);
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -0700956 changed |= mesh_set_ht_prot_mode(sdata);
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 case OPN_ACPT:
961 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200962 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700963 mesh_plink_frame_tx(sdata,
964 WLAN_SP_MESH_PEERING_CONFIRM,
965 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100966 break;
967 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200968 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100969 break;
970 }
971 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700972 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100973 switch (event) {
974 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100975 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100976 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100977 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200978 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100979 break;
980 case OPN_ACPT:
981 case CNF_ACPT:
982 case OPN_RJCT:
983 case CNF_RJCT:
984 llid = sta->llid;
985 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200986 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700987 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
988 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100989 break;
990 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200991 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100992 }
993 break;
994 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800995 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800996 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100997 */
Johannes Berg07346f812008-05-03 01:02:02 +0200998 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100999 break;
1000 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001001
1002 rcu_read_unlock();
Ashok Nagarajan57aac7c2012-04-30 14:20:30 -07001003
1004 if (changed)
1005 ieee80211_bss_info_change_notify(sdata, changed);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001006}