blob: 4396906175ae22c00d55978171b4040632d72011 [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
46static inline
47void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
48{
Johannes Berg472dbc42008-09-11 00:01:49 +020049 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010050 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010051}
52
53static inline
54void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
55{
Johannes Berg472dbc42008-09-11 00:01:49 +020056 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010057 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010058}
59
60/**
61 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
62 *
Rui Paulo23c7a292009-11-09 23:46:42 +000063 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010064 *
Johannes Berg07346f812008-05-03 01:02:02 +020065 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010066 */
67static inline void mesh_plink_fsm_restart(struct sta_info *sta)
68{
Javier Cardona57cf8042011-05-13 10:45:43 -070069 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080070 sta->llid = sta->plid = sta->reason = 0;
71 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010072}
73
Johannes Berg93e5deb2008-04-01 15:21:00 +020074/*
75 * NOTE: This is just an alias for sta_info_alloc(), see notes
76 * on it in the lifecycle management section!
77 */
Johannes Berg03e44972008-02-27 09:56:40 +010078static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Johannes Berg881d9482009-01-21 15:13:48 +010079 u8 *hw_addr, u32 rates)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010080{
Johannes Bergd0709a62008-02-25 16:27:46 +010081 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010082 struct sta_info *sta;
83
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010084 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010085 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010086
Johannes Berg34e89502010-02-03 13:59:58 +010087 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +010088 if (!sta)
89 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010090
Javier Cardona5fbdf4a2011-09-07 17:49:54 -070091 sta->flags = WLAN_STA_AUTHORIZED | WLAN_STA_AUTH | WLAN_STA_WME;
Johannes Berg323ce792008-09-11 02:45:11 +020092 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Christian Lamparterb973c312008-12-27 22:19:49 +010093 rate_control_rate_init(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010094
95 return sta;
96}
97
98/**
John W. Linvillec9370192010-06-21 17:14:07 -040099 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100100 *
101 * @sta: mesh peer link to deactivate
102 *
103 * All mesh paths with this peer as next hop will be flushed
104 *
Johannes Berg07346f812008-05-03 01:02:02 +0200105 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100106 */
John W. Linvillec9370192010-06-21 17:14:07 -0400107static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100108{
Johannes Bergd0709a62008-02-25 16:27:46 +0100109 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400110 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100111
Javier Cardona57cf8042011-05-13 10:45:43 -0700112 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100113 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400114 deactivated = true;
115 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700116 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100117 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400118
119 return deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100120}
121
Johannes Berg902acc72008-02-23 15:17:19 +0100122/**
John W. Linvillec9370192010-06-21 17:14:07 -0400123 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100124 *
125 * @sta: mesh peer link to deactivate
126 *
127 * All mesh paths with this peer as next hop will be flushed
128 */
129void mesh_plink_deactivate(struct sta_info *sta)
130{
John W. Linvillec9370192010-06-21 17:14:07 -0400131 struct ieee80211_sub_if_data *sdata = sta->sdata;
132 bool deactivated;
133
Johannes Berg07346f812008-05-03 01:02:02 +0200134 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400135 deactivated = __mesh_plink_deactivate(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200136 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400137
138 if (deactivated)
139 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100140}
141
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200142static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700143 enum ieee80211_self_protected_actioncode action,
144 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200145 struct ieee80211_local *local = sdata->local;
Javier Cardonac80d5452010-12-16 17:37:49 -0800146 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400 +
Javier Cardona581a8b02011-04-07 15:08:27 -0700147 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100148 struct ieee80211_mgmt *mgmt;
149 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700150 int ie_len = 4;
151 u16 peering_proto = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100152 u8 *pos;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100153
154 if (!skb)
155 return -1;
156 skb_reserve(skb, local->hw.extra_tx_headroom);
157 /* 25 is the size of the common mgmt part (24) plus the size of the
158 * common action part (1)
159 */
160 mgmt = (struct ieee80211_mgmt *)
Thomas Pedersen8db09852011-08-12 20:01:00 -0700161 skb_put(skb, 25 + sizeof(mgmt->u.action.u.self_prot));
162 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.self_prot));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700163 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
164 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100165 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100166 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700167 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700168 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
169 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100170
Thomas Pedersen8db09852011-08-12 20:01:00 -0700171 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
172 /* capability info */
173 pos = skb_put(skb, 2);
174 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700175 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700176 /* AID */
177 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000178 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100179 }
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700180 if (mesh_add_srates_ie(skb, sdata) ||
181 mesh_add_ext_srates_ie(skb, sdata) ||
182 mesh_add_rsn_ie(skb, sdata) ||
183 mesh_add_meshid_ie(skb, sdata) ||
184 mesh_add_meshconf_ie(skb, sdata))
185 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700186 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
187 if (mesh_add_meshid_ie(skb, sdata))
188 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100189 }
190
Thomas Pedersen8db09852011-08-12 20:01:00 -0700191 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100192 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700193 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100194 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700195 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700196 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100197 include_plid = true;
198 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700199 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700200 if (plid) {
201 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100202 include_plid = true;
203 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700204 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100205 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700206 default:
207 return -EINVAL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100208 }
209
Thomas Pedersen8db09852011-08-12 20:01:00 -0700210 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
211 return -ENOMEM;
212
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100213 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700214 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100215 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700216 memcpy(pos, &peering_proto, 2);
217 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100218 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700219 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100220 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100221 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700222 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100223 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700224 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100225 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700226 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100227 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700228 if (mesh_add_vendor_ies(skb, sdata))
229 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100230
Johannes Berg62ae67b2009-11-18 18:42:05 +0100231 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100232 return 0;
233}
234
Javier Cardona1570ca52011-04-07 15:08:35 -0700235void mesh_neighbour_update(u8 *hw_addr, u32 rates,
236 struct ieee80211_sub_if_data *sdata,
237 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100238{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200239 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100240 struct sta_info *sta;
241
Johannes Bergd0709a62008-02-25 16:27:46 +0100242 rcu_read_lock();
243
Johannes Bergabe60632009-11-25 17:46:18 +0100244 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100245 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100246 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700247 /* Userspace handles peer allocation when security is enabled
248 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700249 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700250 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
251 elems->ie_start, elems->total_len,
252 GFP_KERNEL);
253 else
254 sta = mesh_plink_alloc(sdata, hw_addr, rates);
Johannes Berg34e89502010-02-03 13:59:58 +0100255 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100256 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100257 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100258 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100259 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100260 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100261 }
262
263 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200264 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700265 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700266 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200267 sdata->u.mesh.accepting_plinks &&
268 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100269 mesh_plink_open(sta);
270
Johannes Bergd0709a62008-02-25 16:27:46 +0100271 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100272}
273
274static void mesh_plink_timer(unsigned long data)
275{
276 struct sta_info *sta;
277 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100278 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100279
Johannes Bergd0709a62008-02-25 16:27:46 +0100280 /*
281 * This STA is valid because sta_info_destroy() will
282 * del_timer_sync() this timer after having made sure
283 * it cannot be readded (by deleting the plink.)
284 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100285 sta = (struct sta_info *) data;
286
Johannes Berg5bb644a2009-05-17 11:40:42 +0200287 if (sta->sdata->local->quiescing) {
288 sta->plink_timer_was_running = true;
289 return;
290 }
291
Johannes Berg07346f812008-05-03 01:02:02 +0200292 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100293 if (sta->ignore_plink_timer) {
294 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200295 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100296 return;
297 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700298 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
299 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100300 reason = 0;
301 llid = sta->llid;
302 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100303 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100304
305 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700306 case NL80211_PLINK_OPN_RCVD:
307 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100308 /* retry timer */
309 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
310 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700311 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
312 sta->sta.addr, sta->plink_retries,
313 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100314 get_random_bytes(&rand, sizeof(u32));
315 sta->plink_timeout = sta->plink_timeout +
316 rand % sta->plink_timeout;
317 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100318 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200319 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700320 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
321 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100322 break;
323 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700324 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100325 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700326 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100327 /* confirm timer */
328 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700329 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700330 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100331 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200332 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700333 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
334 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100335 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700336 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100337 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100338 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100339 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200340 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100341 break;
342 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200343 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100344 break;
345 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100346}
347
Johannes Berg5bb644a2009-05-17 11:40:42 +0200348#ifdef CONFIG_PM
349void mesh_plink_quiesce(struct sta_info *sta)
350{
351 if (del_timer_sync(&sta->plink_timer))
352 sta->plink_timer_was_running = true;
353}
354
355void mesh_plink_restart(struct sta_info *sta)
356{
357 if (sta->plink_timer_was_running) {
358 add_timer(&sta->plink_timer);
359 sta->plink_timer_was_running = false;
360 }
361}
362#endif
363
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100364static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
365{
366 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
367 sta->plink_timer.data = (unsigned long) sta;
368 sta->plink_timer.function = mesh_plink_timer;
369 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100370 add_timer(&sta->plink_timer);
371}
372
373int mesh_plink_open(struct sta_info *sta)
374{
375 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100376 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100377
Javier Cardona53e80512011-04-07 15:08:32 -0700378 if (!test_sta_flags(sta, WLAN_STA_AUTH))
379 return -EPERM;
380
Johannes Berg07346f812008-05-03 01:02:02 +0200381 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100382 get_random_bytes(&llid, 2);
383 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700384 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200385 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100386 return -EBUSY;
387 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700388 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100389 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200390 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700391 mpl_dbg("Mesh plink: starting establishment with %pM\n",
392 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100393
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700394 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200395 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100396}
397
398void mesh_plink_block(struct sta_info *sta)
399{
John W. Linvillec9370192010-06-21 17:14:07 -0400400 struct ieee80211_sub_if_data *sdata = sta->sdata;
401 bool deactivated;
402
Johannes Berg07346f812008-05-03 01:02:02 +0200403 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400404 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700405 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200406 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400407
408 if (deactivated)
409 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100410}
411
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100412
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200413void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100414 size_t len, struct ieee80211_rx_status *rx_status)
415{
Johannes Bergd0709a62008-02-25 16:27:46 +0100416 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100417 struct ieee802_11_elems elems;
418 struct sta_info *sta;
419 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700420 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100421 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200422 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100423 u8 ie_len;
424 u8 *baseaddr;
425 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000426#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
427 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700428 [NL80211_PLINK_LISTEN] = "LISTEN",
429 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
430 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
431 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
432 [NL80211_PLINK_ESTAB] = "ESTAB",
433 [NL80211_PLINK_HOLDING] = "HOLDING",
434 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000435 };
436#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100437
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200438 /* need action_code, aux */
439 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
440 return;
441
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100442 if (is_multicast_ether_addr(mgmt->da)) {
443 mpl_dbg("Mesh plink: ignore frame from multicast address");
444 return;
445 }
446
Thomas Pedersen8db09852011-08-12 20:01:00 -0700447 baseaddr = mgmt->u.action.u.self_prot.variable;
448 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
449 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700450 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100451 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700452 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100453 }
454 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700455 if (!elems.peering) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100456 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
457 return;
458 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700459 if (elems.rsn_len &&
460 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700461 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
462 return;
463 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100464
Thomas Pedersen8db09852011-08-12 20:01:00 -0700465 ftype = mgmt->u.action.u.self_prot.action_code;
466 ie_len = elems.peering_len;
467 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
468 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
469 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
470 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000471 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
472 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100473 return;
474 }
475
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700476 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
477 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100478 mpl_dbg("Mesh plink: missing necessary ie\n");
479 return;
480 }
481 /* Note the lines below are correct, the llid in the frame is the plid
482 * from the point of view of this host.
483 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700484 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700485 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700486 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
487 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100488
Johannes Bergd0709a62008-02-25 16:27:46 +0100489 rcu_read_lock();
490
Johannes Bergabe60632009-11-25 17:46:18 +0100491 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700492 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100493 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100494 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100495 return;
496 }
497
Javier Cardona53e80512011-04-07 15:08:32 -0700498 if (sta && !test_sta_flags(sta, WLAN_STA_AUTH)) {
499 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
500 rcu_read_unlock();
501 return;
502 }
503
Javier Cardona57cf8042011-05-13 10:45:43 -0700504 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100505 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100506 return;
507 }
508
509 /* Now we will figure out the appropriate event... */
510 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700511 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
512 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200513 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100514 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700515 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100516 event = OPN_RJCT;
517 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700518 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100519 event = CNF_RJCT;
520 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700521 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100522 break;
523 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200524 }
525
526 if (!sta && !matches_local) {
527 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700528 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200529 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700530 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
531 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200532 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100533 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700534 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100535 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100536
537 rcu_read_unlock();
538
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100539 if (!mesh_plink_free_count(sdata)) {
540 mpl_dbg("Mesh plink error: no more free plinks\n");
541 return;
542 }
543
544 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Johannes Berg03e44972008-02-27 09:56:40 +0100545 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
Johannes Berg73651ee2008-02-25 16:27:47 +0100546 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100547 mpl_dbg("Mesh plink error: plink table full\n");
548 return;
549 }
Johannes Berg34e89502010-02-03 13:59:58 +0100550 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100551 rcu_read_unlock();
552 return;
553 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100554 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200555 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200556 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200557 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100558 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700559 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100560 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100561 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100562 event = OPN_IGNR;
563 else
564 event = OPN_ACPT;
565 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700566 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100567 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100568 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100569 event = CNF_IGNR;
570 else
571 event = CNF_ACPT;
572 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700573 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700574 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100575 /* Do not check for llid or plid. This does not
576 * follow the standard but since multiple plinks
577 * per sta are not supported, it is necessary in
578 * order to avoid a livelock when MP A sees an
579 * establish peer link to MP B but MP B does not
580 * see it. This can be caused by a timeout in
581 * B's peer link establishment or B beign
582 * restarted.
583 */
584 event = CLS_ACPT;
585 else if (sta->plid != plid)
586 event = CLS_IGNR;
587 else if (ie_len == 7 && sta->llid != llid)
588 event = CLS_IGNR;
589 else
590 event = CLS_ACPT;
591 break;
592 default:
593 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200594 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100595 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100596 return;
597 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200598 } else {
599 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100600 }
601
Rui Paulo1460dd12009-11-09 23:46:48 +0000602 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
603 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700604 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
605 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100606 reason = 0;
607 switch (sta->plink_state) {
608 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700609 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100610 switch (event) {
611 case CLS_ACPT:
612 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200613 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100614 break;
615 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700616 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100617 sta->plid = plid;
618 get_random_bytes(&llid, 2);
619 sta->llid = llid;
620 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200621 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700622 mesh_plink_frame_tx(sdata,
623 WLAN_SP_MESH_PEERING_OPEN,
624 sta->sta.addr, llid, 0, 0);
625 mesh_plink_frame_tx(sdata,
626 WLAN_SP_MESH_PEERING_CONFIRM,
627 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100628 break;
629 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200630 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100631 break;
632 }
633 break;
634
Javier Cardona57cf8042011-05-13 10:45:43 -0700635 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100636 switch (event) {
637 case OPN_RJCT:
638 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700639 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100640 case CLS_ACPT:
641 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700642 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100643 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700644 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100645 if (!mod_plink_timer(sta,
646 dot11MeshHoldingTimeout(sdata)))
647 sta->ignore_plink_timer = true;
648
649 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200650 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700651 mesh_plink_frame_tx(sdata,
652 WLAN_SP_MESH_PEERING_CLOSE,
653 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100654 break;
655 case OPN_ACPT:
656 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700657 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100658 sta->plid = plid;
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_CONFIRM,
663 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100664 break;
665 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700666 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100667 if (!mod_plink_timer(sta,
668 dot11MeshConfirmTimeout(sdata)))
669 sta->ignore_plink_timer = true;
670
Johannes Berg07346f812008-05-03 01:02:02 +0200671 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100672 break;
673 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200674 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100675 break;
676 }
677 break;
678
Javier Cardona57cf8042011-05-13 10:45:43 -0700679 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100680 switch (event) {
681 case OPN_RJCT:
682 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700683 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100684 case CLS_ACPT:
685 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700686 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100687 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700688 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100689 if (!mod_plink_timer(sta,
690 dot11MeshHoldingTimeout(sdata)))
691 sta->ignore_plink_timer = true;
692
693 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200694 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700695 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
696 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100697 break;
698 case OPN_ACPT:
699 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200700 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700701 mesh_plink_frame_tx(sdata,
702 WLAN_SP_MESH_PEERING_CONFIRM,
703 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100704 break;
705 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100706 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700707 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200708 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400709 mesh_plink_inc_estab_count(sdata);
710 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700711 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
712 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100713 break;
714 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200715 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100716 break;
717 }
718 break;
719
Javier Cardona57cf8042011-05-13 10:45:43 -0700720 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100721 switch (event) {
722 case OPN_RJCT:
723 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700724 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100725 case CLS_ACPT:
726 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700727 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100728 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700729 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100730 if (!mod_plink_timer(sta,
731 dot11MeshHoldingTimeout(sdata)))
732 sta->ignore_plink_timer = true;
733
734 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200735 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700736 mesh_plink_frame_tx(sdata,
737 WLAN_SP_MESH_PEERING_CLOSE,
738 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100739 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100740 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100741 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700742 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200743 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400744 mesh_plink_inc_estab_count(sdata);
745 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700746 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
747 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700748 mesh_plink_frame_tx(sdata,
749 WLAN_SP_MESH_PEERING_CONFIRM,
750 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100751 break;
752 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200753 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100754 break;
755 }
756 break;
757
Javier Cardona57cf8042011-05-13 10:45:43 -0700758 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100759 switch (event) {
760 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700761 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100762 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400763 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700764 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100765 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100766 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200767 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400768 if (deactivated)
769 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700770 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
771 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100772 break;
773 case OPN_ACPT:
774 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200775 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700776 mesh_plink_frame_tx(sdata,
777 WLAN_SP_MESH_PEERING_CONFIRM,
778 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100779 break;
780 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200781 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100782 break;
783 }
784 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700785 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100786 switch (event) {
787 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100788 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100789 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100790 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200791 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100792 break;
793 case OPN_ACPT:
794 case CNF_ACPT:
795 case OPN_RJCT:
796 case CNF_RJCT:
797 llid = sta->llid;
798 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200799 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700800 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
801 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100802 break;
803 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200804 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100805 }
806 break;
807 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800808 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800809 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100810 */
Johannes Berg07346f812008-05-03 01:02:02 +0200811 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100812 break;
813 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100814
815 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100816}