blob: 986af8acc49e2b142fd67119aab4bb08ece80c69 [file] [log] [blame]
Luis Carlos Coboc3896d22008-02-23 15:17:13 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +010012#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010014#include "mesh.h"
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +010033
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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,
Johannes Berg881d9482009-01-21 15:13:48 +010083 u8 *hw_addr, u32 rates)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010084{
Johannes Bergd0709a62008-02-25 16:27:46 +010085 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010086 struct sta_info *sta;
87
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010088 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010089 return NULL;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010090
Johannes Berg34e89502010-02-03 13:59:58 +010091 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +010092 if (!sta)
93 return NULL;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010094
Johannes Bergc2c98fd2011-09-29 16:04:36 +020095 set_sta_flag(sta, WLAN_STA_AUTH);
96 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
97 set_sta_flag(sta, WLAN_STA_WME);
Johannes Berg323ce792008-09-11 02:45:11 +020098 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Christian Lamparterb973c312008-12-27 22:19:49 +010099 rate_control_rate_init(sta);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100100
101 return sta;
102}
103
104/**
John W. Linvillec9370192010-06-21 17:14:07 -0400105 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100106 *
107 * @sta: mesh peer link to deactivate
108 *
109 * All mesh paths with this peer as next hop will be flushed
110 *
Johannes Berg07346f812008-05-03 01:02:02 +0200111 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100112 */
John W. Linvillec9370192010-06-21 17:14:07 -0400113static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100114{
Johannes Bergd0709a62008-02-25 16:27:46 +0100115 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400116 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100117
Javier Cardona57cf8042011-05-13 10:45:43 -0700118 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100119 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400120 deactivated = true;
121 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700122 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100123 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400124
125 return deactivated;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100126}
127
Johannes Berg902acc72008-02-23 15:17:19 +0100128/**
John W. Linvillec9370192010-06-21 17:14:07 -0400129 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100130 *
131 * @sta: mesh peer link to deactivate
132 *
133 * All mesh paths with this peer as next hop will be flushed
134 */
135void mesh_plink_deactivate(struct sta_info *sta)
136{
John W. Linvillec9370192010-06-21 17:14:07 -0400137 struct ieee80211_sub_if_data *sdata = sta->sdata;
138 bool deactivated;
139
Johannes Berg07346f812008-05-03 01:02:02 +0200140 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400141 deactivated = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700142 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
143 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
144 sta->sta.addr, sta->llid, sta->plid,
145 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200146 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400147
148 if (deactivated)
149 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100150}
151
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200152static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700153 enum ieee80211_self_protected_actioncode action,
154 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200155 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700156 struct sk_buff *skb;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100157 struct ieee80211_mgmt *mgmt;
158 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700159 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700160 u8 *pos, ie_len = 4;
161 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
162 sizeof(mgmt->u.action.u.self_prot);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100163
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700164 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
165 hdr_len +
166 2 + /* capability info */
167 2 + /* AID */
168 2 + 8 + /* supported rates */
169 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
170 2 + sdata->u.mesh.mesh_id_len +
171 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700172 2 + sizeof(struct ieee80211_ht_cap) +
173 2 + sizeof(struct ieee80211_ht_info) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700174 2 + 8 + /* peering IE */
175 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100176 if (!skb)
177 return -1;
178 skb_reserve(skb, local->hw.extra_tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700179 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
180 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700181 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
182 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100183 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100184 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700185 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700186 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
187 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100188
Thomas Pedersen8db09852011-08-12 20:01:00 -0700189 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
190 /* capability info */
191 pos = skb_put(skb, 2);
192 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700193 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700194 /* AID */
195 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000196 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100197 }
Arik Nemtsov768db342011-09-28 14:12:51 +0300198 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
199 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700200 mesh_add_rsn_ie(skb, sdata) ||
201 mesh_add_meshid_ie(skb, sdata) ||
202 mesh_add_meshconf_ie(skb, sdata))
203 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700204 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
205 if (mesh_add_meshid_ie(skb, sdata))
206 return -1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100207 }
208
Thomas Pedersen8db09852011-08-12 20:01:00 -0700209 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100210 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700211 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100212 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700213 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700214 ie_len += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100215 include_plid = true;
216 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700217 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700218 if (plid) {
219 ie_len += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100220 include_plid = true;
221 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700222 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100223 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700224 default:
225 return -EINVAL;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100226 }
227
Thomas Pedersen8db09852011-08-12 20:01:00 -0700228 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
229 return -ENOMEM;
230
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100231 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700232 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100233 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700234 memcpy(pos, &peering_proto, 2);
235 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100236 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700237 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100238 if (include_plid) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100239 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700240 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100241 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700242 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100243 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700244 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100245 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700246
247 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
248 if (mesh_add_ht_cap_ie(skb, sdata) ||
249 mesh_add_ht_info_ie(skb, sdata))
250 return -1;
251 }
252
Thomas Pedersen8db09852011-08-12 20:01:00 -0700253 if (mesh_add_vendor_ies(skb, sdata))
254 return -1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100255
Johannes Berg62ae67b2009-11-18 18:42:05 +0100256 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100257 return 0;
258}
259
Javier Cardona1570ca52011-04-07 15:08:35 -0700260void mesh_neighbour_update(u8 *hw_addr, u32 rates,
261 struct ieee80211_sub_if_data *sdata,
262 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100263{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200264 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100265 struct sta_info *sta;
266
Johannes Bergd0709a62008-02-25 16:27:46 +0100267 rcu_read_lock();
268
Johannes Bergabe60632009-11-25 17:46:18 +0100269 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100270 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100271 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700272 /* Userspace handles peer allocation when security is enabled
273 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700274 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700275 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
276 elems->ie_start, elems->total_len,
277 GFP_KERNEL);
278 else
279 sta = mesh_plink_alloc(sdata, hw_addr, rates);
Johannes Berg34e89502010-02-03 13:59:58 +0100280 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100281 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100282 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100283 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100284 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100285 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100286 }
287
288 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200289 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700290 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700291 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200292 sdata->u.mesh.accepting_plinks &&
293 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100294 mesh_plink_open(sta);
295
Johannes Bergd0709a62008-02-25 16:27:46 +0100296 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100297}
298
299static void mesh_plink_timer(unsigned long data)
300{
301 struct sta_info *sta;
302 __le16 llid, plid, reason;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100303 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100304
Johannes Bergd0709a62008-02-25 16:27:46 +0100305 /*
306 * This STA is valid because sta_info_destroy() will
307 * del_timer_sync() this timer after having made sure
308 * it cannot be readded (by deleting the plink.)
309 */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100310 sta = (struct sta_info *) data;
311
Johannes Berg5bb644a2009-05-17 11:40:42 +0200312 if (sta->sdata->local->quiescing) {
313 sta->plink_timer_was_running = true;
314 return;
315 }
316
Johannes Berg07346f812008-05-03 01:02:02 +0200317 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100318 if (sta->ignore_plink_timer) {
319 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200320 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100321 return;
322 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700323 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
324 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100325 reason = 0;
326 llid = sta->llid;
327 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100328 sdata = sta->sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100329
330 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700331 case NL80211_PLINK_OPN_RCVD:
332 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100333 /* retry timer */
334 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
335 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700336 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
337 sta->sta.addr, sta->plink_retries,
338 sta->plink_timeout);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100339 get_random_bytes(&rand, sizeof(u32));
340 sta->plink_timeout = sta->plink_timeout +
341 rand % sta->plink_timeout;
342 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100343 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200344 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700345 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
346 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100347 break;
348 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700349 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100350 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700351 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100352 /* confirm timer */
353 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700354 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700355 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100356 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200357 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700358 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
359 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100360 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700361 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100362 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100363 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100364 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200365 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100366 break;
367 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200368 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100369 break;
370 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100371}
372
Johannes Berg5bb644a2009-05-17 11:40:42 +0200373#ifdef CONFIG_PM
374void mesh_plink_quiesce(struct sta_info *sta)
375{
376 if (del_timer_sync(&sta->plink_timer))
377 sta->plink_timer_was_running = true;
378}
379
380void mesh_plink_restart(struct sta_info *sta)
381{
382 if (sta->plink_timer_was_running) {
383 add_timer(&sta->plink_timer);
384 sta->plink_timer_was_running = false;
385 }
386}
387#endif
388
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100389static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
390{
391 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
392 sta->plink_timer.data = (unsigned long) sta;
393 sta->plink_timer.function = mesh_plink_timer;
394 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100395 add_timer(&sta->plink_timer);
396}
397
398int mesh_plink_open(struct sta_info *sta)
399{
400 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100401 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100402
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200403 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700404 return -EPERM;
405
Johannes Berg07346f812008-05-03 01:02:02 +0200406 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100407 get_random_bytes(&llid, 2);
408 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700409 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200410 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100411 return -EBUSY;
412 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700413 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100414 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200415 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700416 mpl_dbg("Mesh plink: starting establishment with %pM\n",
417 sta->sta.addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100418
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700419 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200420 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100421}
422
423void mesh_plink_block(struct sta_info *sta)
424{
John W. Linvillec9370192010-06-21 17:14:07 -0400425 struct ieee80211_sub_if_data *sdata = sta->sdata;
426 bool deactivated;
427
Johannes Berg07346f812008-05-03 01:02:02 +0200428 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400429 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700430 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200431 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400432
433 if (deactivated)
434 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100435}
436
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100437
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200438void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100439 size_t len, struct ieee80211_rx_status *rx_status)
440{
Johannes Bergd0709a62008-02-25 16:27:46 +0100441 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100442 struct ieee802_11_elems elems;
443 struct sta_info *sta;
444 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700445 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100446 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200447 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100448 u8 ie_len;
449 u8 *baseaddr;
450 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000451#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
452 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700453 [NL80211_PLINK_LISTEN] = "LISTEN",
454 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
455 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
456 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
457 [NL80211_PLINK_ESTAB] = "ESTAB",
458 [NL80211_PLINK_HOLDING] = "HOLDING",
459 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000460 };
461#endif
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100462
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200463 /* need action_code, aux */
464 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
465 return;
466
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100467 if (is_multicast_ether_addr(mgmt->da)) {
468 mpl_dbg("Mesh plink: ignore frame from multicast address");
469 return;
470 }
471
Thomas Pedersen8db09852011-08-12 20:01:00 -0700472 baseaddr = mgmt->u.action.u.self_prot.variable;
473 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
474 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700475 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100476 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700477 baselen += 4;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100478 }
479 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700480 if (!elems.peering) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100481 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
482 return;
483 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700484 if (elems.rsn_len &&
485 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700486 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
487 return;
488 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100489
Thomas Pedersen8db09852011-08-12 20:01:00 -0700490 ftype = mgmt->u.action.u.self_prot.action_code;
491 ie_len = elems.peering_len;
492 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
493 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
494 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
495 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000496 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
497 ftype, ie_len);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100498 return;
499 }
500
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700501 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
502 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100503 mpl_dbg("Mesh plink: missing necessary ie\n");
504 return;
505 }
506 /* Note the lines below are correct, the llid in the frame is the plid
507 * from the point of view of this host.
508 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700509 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700510 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700511 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
512 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100513
Johannes Bergd0709a62008-02-25 16:27:46 +0100514 rcu_read_lock();
515
Johannes Bergabe60632009-11-25 17:46:18 +0100516 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700517 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100518 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100519 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100520 return;
521 }
522
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200523 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700524 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
525 rcu_read_unlock();
526 return;
527 }
528
Javier Cardona57cf8042011-05-13 10:45:43 -0700529 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100530 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100531 return;
532 }
533
534 /* Now we will figure out the appropriate event... */
535 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700536 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
537 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200538 matches_local = false;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100539 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700540 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100541 event = OPN_RJCT;
542 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700543 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100544 event = CNF_RJCT;
545 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700546 default:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100547 break;
548 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200549 }
550
551 if (!sta && !matches_local) {
552 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700553 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200554 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700555 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
556 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200557 return;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100558 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700559 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100560 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100561
562 rcu_read_unlock();
563
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100564 if (!mesh_plink_free_count(sdata)) {
565 mpl_dbg("Mesh plink error: no more free plinks\n");
566 return;
567 }
568
569 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Johannes Berg03e44972008-02-27 09:56:40 +0100570 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
Johannes Berg73651ee2008-02-25 16:27:47 +0100571 if (!sta) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100572 mpl_dbg("Mesh plink error: plink table full\n");
573 return;
574 }
Johannes Berg34e89502010-02-03 13:59:58 +0100575 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100576 rcu_read_unlock();
577 return;
578 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100579 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200580 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200581 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200582 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100583 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700584 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100585 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100586 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100587 event = OPN_IGNR;
588 else
589 event = OPN_ACPT;
590 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700591 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100592 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100593 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100594 event = CNF_IGNR;
595 else
596 event = CNF_ACPT;
597 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700598 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700599 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100600 /* Do not check for llid or plid. This does not
601 * follow the standard but since multiple plinks
602 * per sta are not supported, it is necessary in
603 * order to avoid a livelock when MP A sees an
604 * establish peer link to MP B but MP B does not
605 * see it. This can be caused by a timeout in
606 * B's peer link establishment or B beign
607 * restarted.
608 */
609 event = CLS_ACPT;
610 else if (sta->plid != plid)
611 event = CLS_IGNR;
612 else if (ie_len == 7 && sta->llid != llid)
613 event = CLS_IGNR;
614 else
615 event = CLS_ACPT;
616 break;
617 default:
618 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200619 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100620 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100621 return;
622 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200623 } else {
624 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100625 }
626
Rui Paulo1460dd12009-11-09 23:46:48 +0000627 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
628 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700629 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
630 event);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100631 reason = 0;
632 switch (sta->plink_state) {
633 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700634 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100635 switch (event) {
636 case CLS_ACPT:
637 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200638 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100639 break;
640 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700641 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100642 sta->plid = plid;
643 get_random_bytes(&llid, 2);
644 sta->llid = llid;
645 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200646 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700647 mesh_plink_frame_tx(sdata,
648 WLAN_SP_MESH_PEERING_OPEN,
649 sta->sta.addr, llid, 0, 0);
650 mesh_plink_frame_tx(sdata,
651 WLAN_SP_MESH_PEERING_CONFIRM,
652 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100653 break;
654 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200655 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100656 break;
657 }
658 break;
659
Javier Cardona57cf8042011-05-13 10:45:43 -0700660 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100661 switch (event) {
662 case OPN_RJCT:
663 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700664 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100665 case CLS_ACPT:
666 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700667 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100668 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700669 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100670 if (!mod_plink_timer(sta,
671 dot11MeshHoldingTimeout(sdata)))
672 sta->ignore_plink_timer = true;
673
674 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200675 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700676 mesh_plink_frame_tx(sdata,
677 WLAN_SP_MESH_PEERING_CLOSE,
678 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100679 break;
680 case OPN_ACPT:
681 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700682 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100683 sta->plid = plid;
684 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200685 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700686 mesh_plink_frame_tx(sdata,
687 WLAN_SP_MESH_PEERING_CONFIRM,
688 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100689 break;
690 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700691 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100692 if (!mod_plink_timer(sta,
693 dot11MeshConfirmTimeout(sdata)))
694 sta->ignore_plink_timer = true;
695
Johannes Berg07346f812008-05-03 01:02:02 +0200696 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100697 break;
698 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200699 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100700 break;
701 }
702 break;
703
Javier Cardona57cf8042011-05-13 10:45:43 -0700704 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100705 switch (event) {
706 case OPN_RJCT:
707 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700708 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100709 case CLS_ACPT:
710 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700711 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100712 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700713 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100714 if (!mod_plink_timer(sta,
715 dot11MeshHoldingTimeout(sdata)))
716 sta->ignore_plink_timer = true;
717
718 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200719 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700720 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
721 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100722 break;
723 case OPN_ACPT:
724 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200725 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700726 mesh_plink_frame_tx(sdata,
727 WLAN_SP_MESH_PEERING_CONFIRM,
728 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100729 break;
730 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100731 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700732 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200733 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400734 mesh_plink_inc_estab_count(sdata);
735 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700736 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
737 sta->sta.addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100738 break;
739 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200740 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100741 break;
742 }
743 break;
744
Javier Cardona57cf8042011-05-13 10:45:43 -0700745 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100746 switch (event) {
747 case OPN_RJCT:
748 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700749 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100750 case CLS_ACPT:
751 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700752 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100753 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700754 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100755 if (!mod_plink_timer(sta,
756 dot11MeshHoldingTimeout(sdata)))
757 sta->ignore_plink_timer = true;
758
759 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200760 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700761 mesh_plink_frame_tx(sdata,
762 WLAN_SP_MESH_PEERING_CLOSE,
763 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100764 break;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100765 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100766 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700767 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200768 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400769 mesh_plink_inc_estab_count(sdata);
770 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700771 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
772 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700773 mesh_plink_frame_tx(sdata,
774 WLAN_SP_MESH_PEERING_CONFIRM,
775 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100776 break;
777 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200778 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100779 break;
780 }
781 break;
782
Javier Cardona57cf8042011-05-13 10:45:43 -0700783 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100784 switch (event) {
785 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700786 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100787 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400788 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700789 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100790 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100791 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200792 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400793 if (deactivated)
794 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700795 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
796 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100797 break;
798 case OPN_ACPT:
799 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200800 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700801 mesh_plink_frame_tx(sdata,
802 WLAN_SP_MESH_PEERING_CONFIRM,
803 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100804 break;
805 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200806 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100807 break;
808 }
809 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700810 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100811 switch (event) {
812 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100813 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100814 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100815 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200816 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100817 break;
818 case OPN_ACPT:
819 case CNF_ACPT:
820 case OPN_RJCT:
821 case CNF_RJCT:
822 llid = sta->llid;
823 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200824 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700825 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
826 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100827 break;
828 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200829 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100830 }
831 break;
832 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800833 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +0800834 * beginning of the function
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100835 */
Johannes Berg07346f812008-05-03 01:02:02 +0200836 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100837 break;
838 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100839
840 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100841}