blob: 7e57f5d07f660ad7b19c432f95518952382832b9 [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,
Johannes Berg881d9482009-01-21 15:13:48 +010083 u8 *hw_addr, u32 rates)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010084{
Johannes Bergd0709a62008-02-25 16:27:46 +010085 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010086 struct sta_info *sta;
87
Luis Carlos Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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;
Javier Cardonac80d5452010-12-16 17:37:49 -0800156 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400 +
Javier Cardona581a8b02011-04-07 15:08:27 -0700157 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100158 struct ieee80211_mgmt *mgmt;
159 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700160 int ie_len = 4;
161 u16 peering_proto = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100162 u8 *pos;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100163
164 if (!skb)
165 return -1;
166 skb_reserve(skb, local->hw.extra_tx_headroom);
167 /* 25 is the size of the common mgmt part (24) plus the size of the
168 * common action part (1)
169 */
170 mgmt = (struct ieee80211_mgmt *)
Thomas Pedersen8db09852011-08-12 20:01:00 -0700171 skb_put(skb, 25 + sizeof(mgmt->u.action.u.self_prot));
172 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.self_prot));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700173 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
174 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100175 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100176 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700177 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700178 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
179 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100180
Thomas Pedersen8db09852011-08-12 20:01:00 -0700181 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
182 /* capability info */
183 pos = skb_put(skb, 2);
184 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700185 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700186 /* AID */
187 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000188 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100189 }
Arik Nemtsov768db342011-09-28 14:12:51 +0300190 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
191 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700192 mesh_add_rsn_ie(skb, sdata) ||
193 mesh_add_meshid_ie(skb, sdata) ||
194 mesh_add_meshconf_ie(skb, sdata))
195 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700196 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
197 if (mesh_add_meshid_ie(skb, sdata))
198 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100199 }
200
Thomas Pedersen8db09852011-08-12 20:01:00 -0700201 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100202 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700203 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100204 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700205 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700206 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100207 include_plid = true;
208 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700209 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700210 if (plid) {
211 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100212 include_plid = true;
213 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700214 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100215 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700216 default:
217 return -EINVAL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100218 }
219
Thomas Pedersen8db09852011-08-12 20:01:00 -0700220 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
221 return -ENOMEM;
222
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100223 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700224 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100225 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700226 memcpy(pos, &peering_proto, 2);
227 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100228 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700229 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100230 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100231 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700232 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100233 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700234 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100235 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700236 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100237 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700238 if (mesh_add_vendor_ies(skb, sdata))
239 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100240
Johannes Berg62ae67b2009-11-18 18:42:05 +0100241 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100242 return 0;
243}
244
Javier Cardona1570ca52011-04-07 15:08:35 -0700245void mesh_neighbour_update(u8 *hw_addr, u32 rates,
246 struct ieee80211_sub_if_data *sdata,
247 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100248{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200249 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100250 struct sta_info *sta;
251
Johannes Bergd0709a62008-02-25 16:27:46 +0100252 rcu_read_lock();
253
Johannes Bergabe60632009-11-25 17:46:18 +0100254 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100255 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100256 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700257 /* Userspace handles peer allocation when security is enabled
258 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700259 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700260 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
261 elems->ie_start, elems->total_len,
262 GFP_KERNEL);
263 else
264 sta = mesh_plink_alloc(sdata, hw_addr, rates);
Johannes Berg34e89502010-02-03 13:59:58 +0100265 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100266 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100267 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100268 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100269 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100270 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100271 }
272
273 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200274 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700275 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700276 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200277 sdata->u.mesh.accepting_plinks &&
278 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100279 mesh_plink_open(sta);
280
Johannes Bergd0709a62008-02-25 16:27:46 +0100281 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100282}
283
284static void mesh_plink_timer(unsigned long data)
285{
286 struct sta_info *sta;
287 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100288 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100289
Johannes Bergd0709a62008-02-25 16:27:46 +0100290 /*
291 * This STA is valid because sta_info_destroy() will
292 * del_timer_sync() this timer after having made sure
293 * it cannot be readded (by deleting the plink.)
294 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100295 sta = (struct sta_info *) data;
296
Johannes Berg5bb644a2009-05-17 11:40:42 +0200297 if (sta->sdata->local->quiescing) {
298 sta->plink_timer_was_running = true;
299 return;
300 }
301
Johannes Berg07346f812008-05-03 01:02:02 +0200302 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100303 if (sta->ignore_plink_timer) {
304 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200305 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100306 return;
307 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700308 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
309 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100310 reason = 0;
311 llid = sta->llid;
312 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100313 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100314
315 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700316 case NL80211_PLINK_OPN_RCVD:
317 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100318 /* retry timer */
319 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
320 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700321 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
322 sta->sta.addr, sta->plink_retries,
323 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100324 get_random_bytes(&rand, sizeof(u32));
325 sta->plink_timeout = sta->plink_timeout +
326 rand % sta->plink_timeout;
327 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100328 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200329 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700330 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
331 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100332 break;
333 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700334 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100335 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700336 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100337 /* confirm timer */
338 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700339 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700340 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100341 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200342 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700343 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
344 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100345 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700346 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100347 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100348 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100349 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200350 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100351 break;
352 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200353 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100354 break;
355 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100356}
357
Johannes Berg5bb644a2009-05-17 11:40:42 +0200358#ifdef CONFIG_PM
359void mesh_plink_quiesce(struct sta_info *sta)
360{
361 if (del_timer_sync(&sta->plink_timer))
362 sta->plink_timer_was_running = true;
363}
364
365void mesh_plink_restart(struct sta_info *sta)
366{
367 if (sta->plink_timer_was_running) {
368 add_timer(&sta->plink_timer);
369 sta->plink_timer_was_running = false;
370 }
371}
372#endif
373
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100374static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
375{
376 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
377 sta->plink_timer.data = (unsigned long) sta;
378 sta->plink_timer.function = mesh_plink_timer;
379 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100380 add_timer(&sta->plink_timer);
381}
382
383int mesh_plink_open(struct sta_info *sta)
384{
385 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100386 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100387
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200388 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700389 return -EPERM;
390
Johannes Berg07346f812008-05-03 01:02:02 +0200391 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100392 get_random_bytes(&llid, 2);
393 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700394 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200395 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100396 return -EBUSY;
397 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700398 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100399 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200400 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700401 mpl_dbg("Mesh plink: starting establishment with %pM\n",
402 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100403
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700404 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200405 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100406}
407
408void mesh_plink_block(struct sta_info *sta)
409{
John W. Linvillec9370192010-06-21 17:14:07 -0400410 struct ieee80211_sub_if_data *sdata = sta->sdata;
411 bool deactivated;
412
Johannes Berg07346f812008-05-03 01:02:02 +0200413 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400414 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700415 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200416 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400417
418 if (deactivated)
419 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100420}
421
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100422
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200423void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100424 size_t len, struct ieee80211_rx_status *rx_status)
425{
Johannes Bergd0709a62008-02-25 16:27:46 +0100426 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100427 struct ieee802_11_elems elems;
428 struct sta_info *sta;
429 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700430 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100431 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200432 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100433 u8 ie_len;
434 u8 *baseaddr;
435 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000436#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
437 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700438 [NL80211_PLINK_LISTEN] = "LISTEN",
439 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
440 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
441 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
442 [NL80211_PLINK_ESTAB] = "ESTAB",
443 [NL80211_PLINK_HOLDING] = "HOLDING",
444 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000445 };
446#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100447
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200448 /* need action_code, aux */
449 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
450 return;
451
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100452 if (is_multicast_ether_addr(mgmt->da)) {
453 mpl_dbg("Mesh plink: ignore frame from multicast address");
454 return;
455 }
456
Thomas Pedersen8db09852011-08-12 20:01:00 -0700457 baseaddr = mgmt->u.action.u.self_prot.variable;
458 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
459 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700460 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100461 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700462 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100463 }
464 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700465 if (!elems.peering) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100466 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
467 return;
468 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700469 if (elems.rsn_len &&
470 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700471 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
472 return;
473 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100474
Thomas Pedersen8db09852011-08-12 20:01:00 -0700475 ftype = mgmt->u.action.u.self_prot.action_code;
476 ie_len = elems.peering_len;
477 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
478 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
479 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
480 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000481 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
482 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100483 return;
484 }
485
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700486 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
487 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100488 mpl_dbg("Mesh plink: missing necessary ie\n");
489 return;
490 }
491 /* Note the lines below are correct, the llid in the frame is the plid
492 * from the point of view of this host.
493 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700494 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700495 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700496 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
497 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100498
Johannes Bergd0709a62008-02-25 16:27:46 +0100499 rcu_read_lock();
500
Johannes Bergabe60632009-11-25 17:46:18 +0100501 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700502 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100503 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100504 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100505 return;
506 }
507
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200508 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700509 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
510 rcu_read_unlock();
511 return;
512 }
513
Javier Cardona57cf8042011-05-13 10:45:43 -0700514 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100515 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100516 return;
517 }
518
519 /* Now we will figure out the appropriate event... */
520 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700521 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
522 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200523 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100524 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700525 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100526 event = OPN_RJCT;
527 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700528 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100529 event = CNF_RJCT;
530 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700531 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100532 break;
533 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200534 }
535
536 if (!sta && !matches_local) {
537 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700538 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200539 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700540 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
541 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200542 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100543 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700544 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100545 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100546
547 rcu_read_unlock();
548
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100549 if (!mesh_plink_free_count(sdata)) {
550 mpl_dbg("Mesh plink error: no more free plinks\n");
551 return;
552 }
553
554 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Johannes Berg03e44972008-02-27 09:56:40 +0100555 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
Johannes Berg73651ee2008-02-25 16:27:47 +0100556 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100557 mpl_dbg("Mesh plink error: plink table full\n");
558 return;
559 }
Johannes Berg34e89502010-02-03 13:59:58 +0100560 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100561 rcu_read_unlock();
562 return;
563 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100564 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200565 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200566 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200567 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100568 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700569 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100570 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100571 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100572 event = OPN_IGNR;
573 else
574 event = OPN_ACPT;
575 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700576 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100577 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100578 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100579 event = CNF_IGNR;
580 else
581 event = CNF_ACPT;
582 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700583 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700584 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100585 /* Do not check for llid or plid. This does not
586 * follow the standard but since multiple plinks
587 * per sta are not supported, it is necessary in
588 * order to avoid a livelock when MP A sees an
589 * establish peer link to MP B but MP B does not
590 * see it. This can be caused by a timeout in
591 * B's peer link establishment or B beign
592 * restarted.
593 */
594 event = CLS_ACPT;
595 else if (sta->plid != plid)
596 event = CLS_IGNR;
597 else if (ie_len == 7 && sta->llid != llid)
598 event = CLS_IGNR;
599 else
600 event = CLS_ACPT;
601 break;
602 default:
603 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200604 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100605 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100606 return;
607 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200608 } else {
609 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100610 }
611
Rui Paulo1460dd12009-11-09 23:46:48 +0000612 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
613 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700614 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
615 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100616 reason = 0;
617 switch (sta->plink_state) {
618 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700619 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100620 switch (event) {
621 case CLS_ACPT:
622 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200623 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100624 break;
625 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700626 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100627 sta->plid = plid;
628 get_random_bytes(&llid, 2);
629 sta->llid = llid;
630 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200631 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700632 mesh_plink_frame_tx(sdata,
633 WLAN_SP_MESH_PEERING_OPEN,
634 sta->sta.addr, llid, 0, 0);
635 mesh_plink_frame_tx(sdata,
636 WLAN_SP_MESH_PEERING_CONFIRM,
637 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100638 break;
639 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200640 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100641 break;
642 }
643 break;
644
Javier Cardona57cf8042011-05-13 10:45:43 -0700645 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100646 switch (event) {
647 case OPN_RJCT:
648 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700649 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100650 case CLS_ACPT:
651 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700652 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100653 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700654 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100655 if (!mod_plink_timer(sta,
656 dot11MeshHoldingTimeout(sdata)))
657 sta->ignore_plink_timer = true;
658
659 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200660 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700661 mesh_plink_frame_tx(sdata,
662 WLAN_SP_MESH_PEERING_CLOSE,
663 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100664 break;
665 case OPN_ACPT:
666 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700667 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100668 sta->plid = plid;
669 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200670 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700671 mesh_plink_frame_tx(sdata,
672 WLAN_SP_MESH_PEERING_CONFIRM,
673 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100674 break;
675 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700676 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100677 if (!mod_plink_timer(sta,
678 dot11MeshConfirmTimeout(sdata)))
679 sta->ignore_plink_timer = true;
680
Johannes Berg07346f812008-05-03 01:02:02 +0200681 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100682 break;
683 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200684 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100685 break;
686 }
687 break;
688
Javier Cardona57cf8042011-05-13 10:45:43 -0700689 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100690 switch (event) {
691 case OPN_RJCT:
692 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700693 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100694 case CLS_ACPT:
695 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700696 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100697 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700698 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100699 if (!mod_plink_timer(sta,
700 dot11MeshHoldingTimeout(sdata)))
701 sta->ignore_plink_timer = true;
702
703 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200704 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700705 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
706 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100707 break;
708 case OPN_ACPT:
709 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200710 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700711 mesh_plink_frame_tx(sdata,
712 WLAN_SP_MESH_PEERING_CONFIRM,
713 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100714 break;
715 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100716 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700717 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200718 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400719 mesh_plink_inc_estab_count(sdata);
720 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700721 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
722 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100723 break;
724 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200725 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100726 break;
727 }
728 break;
729
Javier Cardona57cf8042011-05-13 10:45:43 -0700730 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100731 switch (event) {
732 case OPN_RJCT:
733 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700734 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100735 case CLS_ACPT:
736 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700737 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100738 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700739 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100740 if (!mod_plink_timer(sta,
741 dot11MeshHoldingTimeout(sdata)))
742 sta->ignore_plink_timer = true;
743
744 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200745 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700746 mesh_plink_frame_tx(sdata,
747 WLAN_SP_MESH_PEERING_CLOSE,
748 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100749 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100750 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100751 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700752 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200753 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400754 mesh_plink_inc_estab_count(sdata);
755 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700756 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
757 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700758 mesh_plink_frame_tx(sdata,
759 WLAN_SP_MESH_PEERING_CONFIRM,
760 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100761 break;
762 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200763 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100764 break;
765 }
766 break;
767
Javier Cardona57cf8042011-05-13 10:45:43 -0700768 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100769 switch (event) {
770 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700771 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100772 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400773 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700774 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100775 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100776 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200777 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400778 if (deactivated)
779 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700780 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
781 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100782 break;
783 case OPN_ACPT:
784 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200785 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700786 mesh_plink_frame_tx(sdata,
787 WLAN_SP_MESH_PEERING_CONFIRM,
788 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100789 break;
790 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200791 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100792 break;
793 }
794 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700795 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100796 switch (event) {
797 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100798 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100799 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100800 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200801 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100802 break;
803 case OPN_ACPT:
804 case CNF_ACPT:
805 case OPN_RJCT:
806 case CNF_RJCT:
807 llid = sta->llid;
808 reason = sta->reason;
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, WLAN_SP_MESH_PEERING_CLOSE,
811 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100812 break;
813 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200814 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100815 }
816 break;
817 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800818 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800819 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100820 */
Johannes Berg07346f812008-05-03 01:02:02 +0200821 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100822 break;
823 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100824
825 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100826}