blob: 41ef1b4764422a85d56334f16c320b8d1d4db292 [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
16#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
18#else
19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
20#endif
21
Thomas Pedersen8db09852011-08-12 20:01:00 -070022#define PLINK_GET_LLID(p) (p + 2)
23#define PLINK_GET_PLID(p) (p + 4)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010024
25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000))
27
Johannes Berg472dbc42008-09-11 00:01:49 +020028#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
29#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
30#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
31#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
32#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010033
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010034enum plink_event {
35 PLINK_UNDEFINED,
36 OPN_ACPT,
37 OPN_RJCT,
38 OPN_IGNR,
39 CNF_ACPT,
40 CNF_RJCT,
41 CNF_IGNR,
42 CLS_ACPT,
43 CLS_IGNR
44};
45
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070046static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
47 enum ieee80211_self_protected_actioncode action,
48 u8 *da, __le16 llid, __le16 plid, __le16 reason);
49
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010050static inline
51void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
52{
Johannes Berg472dbc42008-09-11 00:01:49 +020053 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010054 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010055}
56
57static inline
58void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
59{
Johannes Berg472dbc42008-09-11 00:01:49 +020060 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010061 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010062}
63
64/**
65 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
66 *
Rui Paulo23c7a292009-11-09 23:46:42 +000067 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010068 *
Johannes Berg07346f812008-05-03 01:02:02 +020069 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010070 */
71static inline void mesh_plink_fsm_restart(struct sta_info *sta)
72{
Javier Cardona57cf8042011-05-13 10:45:43 -070073 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080074 sta->llid = sta->plid = sta->reason = 0;
75 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010076}
77
Johannes Berg93e5deb2008-04-01 15:21:00 +020078/*
79 * NOTE: This is just an alias for sta_info_alloc(), see notes
80 * on it in the lifecycle management section!
81 */
Johannes Berg03e44972008-02-27 09:56:40 +010082static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen739522b2011-10-26 14:47:28 -070083 u8 *hw_addr, u32 rates,
84 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010085{
Johannes Bergd0709a62008-02-25 16:27:46 +010086 struct ieee80211_local *local = sdata->local;
Thomas Pedersen739522b2011-10-26 14:47:28 -070087 struct ieee80211_supported_band *sband;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010088 struct sta_info *sta;
89
Thomas Pedersen739522b2011-10-26 14:47:28 -070090 sband = local->hw.wiphy->bands[local->oper_channel->band];
91
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010092 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010093 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010094
Johannes Berg34e89502010-02-03 13:59:58 +010095 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +010096 if (!sta)
97 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010098
Johannes Bergd9a7ddb2011-12-14 12:35:30 +010099 sta_info_move_state(sta, IEEE80211_STA_AUTH);
100 sta_info_move_state(sta, IEEE80211_STA_ASSOC);
101 sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
102
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200103 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100104
Johannes Berg323ce792008-09-11 02:45:11 +0200105 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Thomas Pedersen739522b2011-10-26 14:47:28 -0700106 if (elems->ht_cap_elem)
Ben Greearef96a8422011-11-18 11:32:00 -0800107 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
108 elems->ht_cap_elem,
Thomas Pedersen739522b2011-10-26 14:47:28 -0700109 &sta->sta.ht_cap);
Christian Lamparterb973c312008-12-27 22:19:49 +0100110 rate_control_rate_init(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100111
112 return sta;
113}
114
115/**
John W. Linvillec9370192010-06-21 17:14:07 -0400116 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100117 *
118 * @sta: mesh peer link to deactivate
119 *
120 * All mesh paths with this peer as next hop will be flushed
121 *
Johannes Berg07346f812008-05-03 01:02:02 +0200122 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100123 */
John W. Linvillec9370192010-06-21 17:14:07 -0400124static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100125{
Johannes Bergd0709a62008-02-25 16:27:46 +0100126 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400127 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100128
Javier Cardona57cf8042011-05-13 10:45:43 -0700129 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100130 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400131 deactivated = true;
132 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700133 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100134 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400135
136 return deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100137}
138
Johannes Berg902acc72008-02-23 15:17:19 +0100139/**
John W. Linvillec9370192010-06-21 17:14:07 -0400140 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100141 *
142 * @sta: mesh peer link to deactivate
143 *
144 * All mesh paths with this peer as next hop will be flushed
145 */
146void mesh_plink_deactivate(struct sta_info *sta)
147{
John W. Linvillec9370192010-06-21 17:14:07 -0400148 struct ieee80211_sub_if_data *sdata = sta->sdata;
149 bool deactivated;
150
Johannes Berg07346f812008-05-03 01:02:02 +0200151 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400152 deactivated = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700153 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
154 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
155 sta->sta.addr, sta->llid, sta->plid,
156 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200157 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400158
159 if (deactivated)
160 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100161}
162
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200163static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700164 enum ieee80211_self_protected_actioncode action,
165 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200166 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700167 struct sk_buff *skb;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100168 struct ieee80211_mgmt *mgmt;
169 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700170 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700171 u8 *pos, ie_len = 4;
172 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
173 sizeof(mgmt->u.action.u.self_prot);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100174
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700175 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
176 hdr_len +
177 2 + /* capability info */
178 2 + /* AID */
179 2 + 8 + /* supported rates */
180 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
181 2 + sdata->u.mesh.mesh_id_len +
182 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700183 2 + sizeof(struct ieee80211_ht_cap) +
184 2 + sizeof(struct ieee80211_ht_info) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700185 2 + 8 + /* peering IE */
186 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100187 if (!skb)
188 return -1;
189 skb_reserve(skb, local->hw.extra_tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700190 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
191 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700192 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
193 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100194 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100195 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700196 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700197 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
198 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100199
Thomas Pedersen8db09852011-08-12 20:01:00 -0700200 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
201 /* capability info */
202 pos = skb_put(skb, 2);
203 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700204 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700205 /* AID */
206 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000207 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100208 }
Arik Nemtsov768db342011-09-28 14:12:51 +0300209 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
210 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700211 mesh_add_rsn_ie(skb, sdata) ||
212 mesh_add_meshid_ie(skb, sdata) ||
213 mesh_add_meshconf_ie(skb, sdata))
214 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700215 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
216 if (mesh_add_meshid_ie(skb, sdata))
217 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100218 }
219
Thomas Pedersen8db09852011-08-12 20:01:00 -0700220 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100221 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700222 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100223 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700224 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700225 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100226 include_plid = true;
227 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700228 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700229 if (plid) {
230 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100231 include_plid = true;
232 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700233 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100234 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700235 default:
236 return -EINVAL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100237 }
238
Thomas Pedersen8db09852011-08-12 20:01:00 -0700239 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
240 return -ENOMEM;
241
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100242 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700243 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100244 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700245 memcpy(pos, &peering_proto, 2);
246 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100247 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700248 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100249 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100250 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700251 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100252 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700253 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100254 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700255 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100256 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700257
258 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
259 if (mesh_add_ht_cap_ie(skb, sdata) ||
260 mesh_add_ht_info_ie(skb, sdata))
261 return -1;
262 }
263
Thomas Pedersen8db09852011-08-12 20:01:00 -0700264 if (mesh_add_vendor_ies(skb, sdata))
265 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100266
Johannes Berg62ae67b2009-11-18 18:42:05 +0100267 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100268 return 0;
269}
270
Javier Cardona1570ca52011-04-07 15:08:35 -0700271void mesh_neighbour_update(u8 *hw_addr, u32 rates,
272 struct ieee80211_sub_if_data *sdata,
273 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100274{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200275 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100276 struct sta_info *sta;
277
Johannes Bergd0709a62008-02-25 16:27:46 +0100278 rcu_read_lock();
279
Johannes Bergabe60632009-11-25 17:46:18 +0100280 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100281 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100282 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700283 /* Userspace handles peer allocation when security is enabled
284 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700285 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700286 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
287 elems->ie_start, elems->total_len,
288 GFP_KERNEL);
289 else
Thomas Pedersen739522b2011-10-26 14:47:28 -0700290 sta = mesh_plink_alloc(sdata, hw_addr, rates, elems);
Johannes Berg34e89502010-02-03 13:59:58 +0100291 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100292 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100293 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100294 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100295 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100296 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100297 }
298
299 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200300 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700301 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700302 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200303 sdata->u.mesh.accepting_plinks &&
304 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100305 mesh_plink_open(sta);
306
Johannes Bergd0709a62008-02-25 16:27:46 +0100307 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100308}
309
310static void mesh_plink_timer(unsigned long data)
311{
312 struct sta_info *sta;
313 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100314 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100315
Johannes Bergd0709a62008-02-25 16:27:46 +0100316 /*
317 * This STA is valid because sta_info_destroy() will
318 * del_timer_sync() this timer after having made sure
319 * it cannot be readded (by deleting the plink.)
320 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100321 sta = (struct sta_info *) data;
322
Johannes Berg5bb644a2009-05-17 11:40:42 +0200323 if (sta->sdata->local->quiescing) {
324 sta->plink_timer_was_running = true;
325 return;
326 }
327
Johannes Berg07346f812008-05-03 01:02:02 +0200328 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100329 if (sta->ignore_plink_timer) {
330 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200331 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100332 return;
333 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700334 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
335 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100336 reason = 0;
337 llid = sta->llid;
338 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100339 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100340
341 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700342 case NL80211_PLINK_OPN_RCVD:
343 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100344 /* retry timer */
345 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
346 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700347 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
348 sta->sta.addr, sta->plink_retries,
349 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100350 get_random_bytes(&rand, sizeof(u32));
351 sta->plink_timeout = sta->plink_timeout +
352 rand % sta->plink_timeout;
353 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100354 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200355 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700356 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
357 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100358 break;
359 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700360 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100361 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700362 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100363 /* confirm timer */
364 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700365 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700366 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100367 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200368 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700369 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
370 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100371 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700372 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100373 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100374 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100375 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200376 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100377 break;
378 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200379 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100380 break;
381 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100382}
383
Johannes Berg5bb644a2009-05-17 11:40:42 +0200384#ifdef CONFIG_PM
385void mesh_plink_quiesce(struct sta_info *sta)
386{
387 if (del_timer_sync(&sta->plink_timer))
388 sta->plink_timer_was_running = true;
389}
390
391void mesh_plink_restart(struct sta_info *sta)
392{
393 if (sta->plink_timer_was_running) {
394 add_timer(&sta->plink_timer);
395 sta->plink_timer_was_running = false;
396 }
397}
398#endif
399
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100400static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
401{
402 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
403 sta->plink_timer.data = (unsigned long) sta;
404 sta->plink_timer.function = mesh_plink_timer;
405 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100406 add_timer(&sta->plink_timer);
407}
408
409int mesh_plink_open(struct sta_info *sta)
410{
411 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100412 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100413
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200414 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700415 return -EPERM;
416
Johannes Berg07346f812008-05-03 01:02:02 +0200417 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100418 get_random_bytes(&llid, 2);
419 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700420 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200421 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100422 return -EBUSY;
423 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700424 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100425 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200426 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700427 mpl_dbg("Mesh plink: starting establishment with %pM\n",
428 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100429
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700430 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200431 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100432}
433
434void mesh_plink_block(struct sta_info *sta)
435{
John W. Linvillec9370192010-06-21 17:14:07 -0400436 struct ieee80211_sub_if_data *sdata = sta->sdata;
437 bool deactivated;
438
Johannes Berg07346f812008-05-03 01:02:02 +0200439 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400440 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700441 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200442 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400443
444 if (deactivated)
445 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100446}
447
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100448
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200449void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100450 size_t len, struct ieee80211_rx_status *rx_status)
451{
Johannes Bergd0709a62008-02-25 16:27:46 +0100452 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100453 struct ieee802_11_elems elems;
454 struct sta_info *sta;
455 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700456 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100457 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200458 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100459 u8 ie_len;
460 u8 *baseaddr;
461 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000462#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
463 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700464 [NL80211_PLINK_LISTEN] = "LISTEN",
465 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
466 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
467 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
468 [NL80211_PLINK_ESTAB] = "ESTAB",
469 [NL80211_PLINK_HOLDING] = "HOLDING",
470 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000471 };
472#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100473
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200474 /* need action_code, aux */
475 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
476 return;
477
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100478 if (is_multicast_ether_addr(mgmt->da)) {
479 mpl_dbg("Mesh plink: ignore frame from multicast address");
480 return;
481 }
482
Thomas Pedersen8db09852011-08-12 20:01:00 -0700483 baseaddr = mgmt->u.action.u.self_prot.variable;
484 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
485 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700486 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100487 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700488 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100489 }
490 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700491 if (!elems.peering) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100492 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
493 return;
494 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700495 if (elems.rsn_len &&
496 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700497 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
498 return;
499 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100500
Thomas Pedersen8db09852011-08-12 20:01:00 -0700501 ftype = mgmt->u.action.u.self_prot.action_code;
502 ie_len = elems.peering_len;
503 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
504 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
505 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
506 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000507 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
508 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100509 return;
510 }
511
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700512 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
513 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100514 mpl_dbg("Mesh plink: missing necessary ie\n");
515 return;
516 }
517 /* Note the lines below are correct, the llid in the frame is the plid
518 * from the point of view of this host.
519 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700520 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700521 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700522 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
523 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100524
Johannes Bergd0709a62008-02-25 16:27:46 +0100525 rcu_read_lock();
526
Johannes Bergabe60632009-11-25 17:46:18 +0100527 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700528 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100529 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100530 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100531 return;
532 }
533
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200534 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700535 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
536 rcu_read_unlock();
537 return;
538 }
539
Javier Cardona57cf8042011-05-13 10:45:43 -0700540 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100541 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100542 return;
543 }
544
545 /* Now we will figure out the appropriate event... */
546 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700547 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
548 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200549 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100550 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700551 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100552 event = OPN_RJCT;
553 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700554 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100555 event = CNF_RJCT;
556 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700557 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100558 break;
559 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200560 }
561
562 if (!sta && !matches_local) {
563 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700564 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200565 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700566 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
567 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200568 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100569 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700570 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100571 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100572
573 rcu_read_unlock();
574
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100575 if (!mesh_plink_free_count(sdata)) {
576 mpl_dbg("Mesh plink error: no more free plinks\n");
577 return;
578 }
579
580 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Thomas Pedersen739522b2011-10-26 14:47:28 -0700581 sta = mesh_plink_alloc(sdata, mgmt->sa, rates, &elems);
Johannes Berg73651ee2008-02-25 16:27:47 +0100582 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100583 mpl_dbg("Mesh plink error: plink table full\n");
584 return;
585 }
Johannes Berg34e89502010-02-03 13:59:58 +0100586 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100587 rcu_read_unlock();
588 return;
589 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100590 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200591 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200592 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200593 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100594 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700595 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100596 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100597 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100598 event = OPN_IGNR;
599 else
600 event = OPN_ACPT;
601 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700602 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100603 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100604 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100605 event = CNF_IGNR;
606 else
607 event = CNF_ACPT;
608 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700609 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700610 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100611 /* Do not check for llid or plid. This does not
612 * follow the standard but since multiple plinks
613 * per sta are not supported, it is necessary in
614 * order to avoid a livelock when MP A sees an
615 * establish peer link to MP B but MP B does not
616 * see it. This can be caused by a timeout in
617 * B's peer link establishment or B beign
618 * restarted.
619 */
620 event = CLS_ACPT;
621 else if (sta->plid != plid)
622 event = CLS_IGNR;
623 else if (ie_len == 7 && sta->llid != llid)
624 event = CLS_IGNR;
625 else
626 event = CLS_ACPT;
627 break;
628 default:
629 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200630 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100631 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100632 return;
633 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200634 } else {
635 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100636 }
637
Rui Paulo1460dd12009-11-09 23:46:48 +0000638 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
639 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700640 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
641 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100642 reason = 0;
643 switch (sta->plink_state) {
644 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700645 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100646 switch (event) {
647 case CLS_ACPT:
648 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200649 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100650 break;
651 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700652 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100653 sta->plid = plid;
654 get_random_bytes(&llid, 2);
655 sta->llid = llid;
656 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200657 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700658 mesh_plink_frame_tx(sdata,
659 WLAN_SP_MESH_PEERING_OPEN,
660 sta->sta.addr, llid, 0, 0);
661 mesh_plink_frame_tx(sdata,
662 WLAN_SP_MESH_PEERING_CONFIRM,
663 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100664 break;
665 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200666 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100667 break;
668 }
669 break;
670
Javier Cardona57cf8042011-05-13 10:45:43 -0700671 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100672 switch (event) {
673 case OPN_RJCT:
674 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700675 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100676 case CLS_ACPT:
677 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700678 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100679 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700680 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100681 if (!mod_plink_timer(sta,
682 dot11MeshHoldingTimeout(sdata)))
683 sta->ignore_plink_timer = true;
684
685 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200686 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700687 mesh_plink_frame_tx(sdata,
688 WLAN_SP_MESH_PEERING_CLOSE,
689 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100690 break;
691 case OPN_ACPT:
692 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700693 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100694 sta->plid = plid;
695 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200696 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700697 mesh_plink_frame_tx(sdata,
698 WLAN_SP_MESH_PEERING_CONFIRM,
699 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100700 break;
701 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700702 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100703 if (!mod_plink_timer(sta,
704 dot11MeshConfirmTimeout(sdata)))
705 sta->ignore_plink_timer = true;
706
Johannes Berg07346f812008-05-03 01:02:02 +0200707 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100708 break;
709 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200710 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100711 break;
712 }
713 break;
714
Javier Cardona57cf8042011-05-13 10:45:43 -0700715 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100716 switch (event) {
717 case OPN_RJCT:
718 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700719 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100720 case CLS_ACPT:
721 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700722 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100723 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700724 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100725 if (!mod_plink_timer(sta,
726 dot11MeshHoldingTimeout(sdata)))
727 sta->ignore_plink_timer = true;
728
729 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200730 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700731 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
732 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100733 break;
734 case OPN_ACPT:
735 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200736 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700737 mesh_plink_frame_tx(sdata,
738 WLAN_SP_MESH_PEERING_CONFIRM,
739 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100740 break;
741 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100742 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700743 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200744 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400745 mesh_plink_inc_estab_count(sdata);
746 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700747 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
748 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100749 break;
750 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200751 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100752 break;
753 }
754 break;
755
Javier Cardona57cf8042011-05-13 10:45:43 -0700756 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100757 switch (event) {
758 case OPN_RJCT:
759 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700760 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100761 case CLS_ACPT:
762 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700763 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100764 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700765 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100766 if (!mod_plink_timer(sta,
767 dot11MeshHoldingTimeout(sdata)))
768 sta->ignore_plink_timer = true;
769
770 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200771 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700772 mesh_plink_frame_tx(sdata,
773 WLAN_SP_MESH_PEERING_CLOSE,
774 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100775 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100776 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100777 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700778 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200779 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400780 mesh_plink_inc_estab_count(sdata);
781 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700782 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
783 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700784 mesh_plink_frame_tx(sdata,
785 WLAN_SP_MESH_PEERING_CONFIRM,
786 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100787 break;
788 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200789 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100790 break;
791 }
792 break;
793
Javier Cardona57cf8042011-05-13 10:45:43 -0700794 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100795 switch (event) {
796 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700797 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100798 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400799 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700800 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100801 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100802 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200803 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400804 if (deactivated)
805 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700806 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
807 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100808 break;
809 case OPN_ACPT:
810 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200811 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700812 mesh_plink_frame_tx(sdata,
813 WLAN_SP_MESH_PEERING_CONFIRM,
814 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100815 break;
816 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200817 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100818 break;
819 }
820 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700821 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100822 switch (event) {
823 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100824 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100825 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100826 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200827 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100828 break;
829 case OPN_ACPT:
830 case CNF_ACPT:
831 case OPN_RJCT:
832 case CNF_RJCT:
833 llid = sta->llid;
834 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200835 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700836 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
837 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100838 break;
839 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200840 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100841 }
842 break;
843 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800844 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800845 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100846 */
Johannes Berg07346f812008-05-03 01:02:02 +0200847 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100848 break;
849 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100850
851 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100852}