blob: e4113f243fc4abbedee6741b3d75d730ffe8517a [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
Rui Paulo09383932009-11-09 23:46:43 +000022#define PLINK_GET_LLID(p) (p + 4)
23#define PLINK_GET_PLID(p) (p + 6)
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
28/* Peer link cancel reasons, all subject to ANA approval */
29#define MESH_LINK_CANCELLED 2
30#define MESH_MAX_NEIGHBORS 3
31#define MESH_CAPABILITY_POLICY_VIOLATION 4
32#define MESH_CLOSE_RCVD 5
33#define MESH_MAX_RETRIES 6
34#define MESH_CONFIRM_TIMEOUT 7
35#define MESH_SECURITY_ROLE_NEGOTIATION_DIFFERS 8
36#define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9
37#define MESH_SECURITY_FAILED_VERIFICATION 10
38
Johannes Berg472dbc42008-09-11 00:01:49 +020039#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
40#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
41#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
42#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
43#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010044
45enum plink_frame_type {
Javier Cardona915b5c52011-05-03 16:57:10 -070046 PLINK_OPEN = 1,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010047 PLINK_CONFIRM,
48 PLINK_CLOSE
49};
50
51enum plink_event {
52 PLINK_UNDEFINED,
53 OPN_ACPT,
54 OPN_RJCT,
55 OPN_IGNR,
56 CNF_ACPT,
57 CNF_RJCT,
58 CNF_IGNR,
59 CLS_ACPT,
60 CLS_IGNR
61};
62
63static inline
64void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
65{
Johannes Berg472dbc42008-09-11 00:01:49 +020066 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010067 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010068}
69
70static inline
71void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
72{
Johannes Berg472dbc42008-09-11 00:01:49 +020073 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010074 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010075}
76
77/**
78 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
79 *
Rui Paulo23c7a292009-11-09 23:46:42 +000080 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010081 *
Johannes Berg07346f812008-05-03 01:02:02 +020082 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010083 */
84static inline void mesh_plink_fsm_restart(struct sta_info *sta)
85{
Javier Cardona57cf8042011-05-13 10:45:43 -070086 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080087 sta->llid = sta->plid = sta->reason = 0;
88 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010089}
90
Johannes Berg93e5deb2008-04-01 15:21:00 +020091/*
92 * NOTE: This is just an alias for sta_info_alloc(), see notes
93 * on it in the lifecycle management section!
94 */
Johannes Berg03e44972008-02-27 09:56:40 +010095static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Johannes Berg881d9482009-01-21 15:13:48 +010096 u8 *hw_addr, u32 rates)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010097{
Johannes Bergd0709a62008-02-25 16:27:46 +010098 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010099 struct sta_info *sta;
100
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100101 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +0100102 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100103
Johannes Berg34e89502010-02-03 13:59:58 +0100104 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100105 if (!sta)
106 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100107
Javier Cardona96b78df2011-04-07 15:08:33 -0700108 sta->flags = WLAN_STA_AUTHORIZED | WLAN_STA_AUTH;
Johannes Berg323ce792008-09-11 02:45:11 +0200109 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Christian Lamparterb973c312008-12-27 22:19:49 +0100110 rate_control_rate_init(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100111
112 return sta;
113}
114
115/**
John W. Linvillec9370192010-06-21 17:14:07 -0400116 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100117 *
118 * @sta: mesh peer link to deactivate
119 *
120 * All mesh paths with this peer as next hop will be flushed
121 *
Johannes Berg07346f812008-05-03 01:02:02 +0200122 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100123 */
John W. Linvillec9370192010-06-21 17:14:07 -0400124static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100125{
Johannes Bergd0709a62008-02-25 16:27:46 +0100126 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400127 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100128
Javier Cardona57cf8042011-05-13 10:45:43 -0700129 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100130 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400131 deactivated = true;
132 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700133 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100134 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400135
136 return deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100137}
138
Johannes Berg902acc72008-02-23 15:17:19 +0100139/**
John W. Linvillec9370192010-06-21 17:14:07 -0400140 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100141 *
142 * @sta: mesh peer link to deactivate
143 *
144 * All mesh paths with this peer as next hop will be flushed
145 */
146void mesh_plink_deactivate(struct sta_info *sta)
147{
John W. Linvillec9370192010-06-21 17:14:07 -0400148 struct ieee80211_sub_if_data *sdata = sta->sdata;
149 bool deactivated;
150
Johannes Berg07346f812008-05-03 01:02:02 +0200151 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400152 deactivated = __mesh_plink_deactivate(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200153 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400154
155 if (deactivated)
156 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100157}
158
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200159static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100160 enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid,
161 __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200162 struct ieee80211_local *local = sdata->local;
Javier Cardonac80d5452010-12-16 17:37:49 -0800163 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400 +
Javier Cardona581a8b02011-04-07 15:08:27 -0700164 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100165 struct ieee80211_mgmt *mgmt;
166 bool include_plid = false;
Rui Paulo09383932009-11-09 23:46:43 +0000167 static const u8 meshpeeringproto[] = { 0x00, 0x0F, 0xAC, 0x2A };
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100168 u8 *pos;
169 int ie_len;
170
171 if (!skb)
172 return -1;
173 skb_reserve(skb, local->hw.extra_tx_headroom);
174 /* 25 is the size of the common mgmt part (24) plus the size of the
175 * common action part (1)
176 */
177 mgmt = (struct ieee80211_mgmt *)
178 skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
179 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700180 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
181 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100182 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100183 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700184 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700185 mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100186 mgmt->u.action.u.plink_action.action_code = action;
187
188 if (action == PLINK_CLOSE)
189 mgmt->u.action.u.plink_action.aux = reason;
190 else {
191 mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
192 if (action == PLINK_CONFIRM) {
193 pos = skb_put(skb, 4);
194 /* two-byte status code followed by two-byte AID */
Rui Paulo77fa76b2009-11-09 23:46:52 +0000195 memset(pos, 0, 2);
196 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100197 }
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700198 if (mesh_add_srates_ie(skb, sdata) ||
199 mesh_add_ext_srates_ie(skb, sdata) ||
200 mesh_add_rsn_ie(skb, sdata) ||
201 mesh_add_meshid_ie(skb, sdata) ||
202 mesh_add_meshconf_ie(skb, sdata))
203 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100204 }
205
206 /* Add Peer Link Management element */
207 switch (action) {
208 case PLINK_OPEN:
Rui Paulo09383932009-11-09 23:46:43 +0000209 ie_len = 6;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100210 break;
211 case PLINK_CONFIRM:
Rui Paulo09383932009-11-09 23:46:43 +0000212 ie_len = 8;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100213 include_plid = true;
214 break;
215 case PLINK_CLOSE:
216 default:
217 if (!plid)
Rui Paulo09383932009-11-09 23:46:43 +0000218 ie_len = 8;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100219 else {
Rui Paulo09383932009-11-09 23:46:43 +0000220 ie_len = 10;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100221 include_plid = true;
222 }
223 break;
224 }
225
226 pos = skb_put(skb, 2 + ie_len);
227 *pos++ = WLAN_EID_PEER_LINK;
228 *pos++ = ie_len;
Rui Paulo09383932009-11-09 23:46:43 +0000229 memcpy(pos, meshpeeringproto, sizeof(meshpeeringproto));
230 pos += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100231 memcpy(pos, &llid, 2);
232 if (include_plid) {
233 pos += 2;
234 memcpy(pos, &plid, 2);
235 }
236 if (action == PLINK_CLOSE) {
237 pos += 2;
238 memcpy(pos, &reason, 2);
239 }
240
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);
Johannes Berg17741cd2008-09-11 00:02:02 +0200330 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100331 0, 0);
332 break;
333 }
334 reason = cpu_to_le16(MESH_MAX_RETRIES);
335 /* 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)
339 reason = cpu_to_le16(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);
Johannes Berg17741cd2008-09-11 00:02:02 +0200343 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, plid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100344 reason);
345 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
Javier Cardona53e80512011-04-07 15:08:32 -0700388 if (!test_sta_flags(sta, WLAN_STA_AUTH))
389 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
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200404 return mesh_plink_frame_tx(sdata, PLINK_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;
430 enum plink_frame_type ftype;
431 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
457 baseaddr = mgmt->u.action.u.plink_action.variable;
458 baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
459 if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
460 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700461 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100462 }
463 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
464 if (!elems.peer_link) {
465 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
466 return;
467 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700468 if (elems.rsn_len &&
469 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700470 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
471 return;
472 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100473
Rui Paulo09383932009-11-09 23:46:43 +0000474 ftype = mgmt->u.action.u.plink_action.action_code;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100475 ie_len = elems.peer_link_len;
Rui Paulo09383932009-11-09 23:46:43 +0000476 if ((ftype == PLINK_OPEN && ie_len != 6) ||
477 (ftype == PLINK_CONFIRM && ie_len != 8) ||
478 (ftype == PLINK_CLOSE && ie_len != 8 && ie_len != 10)) {
479 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
480 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100481 return;
482 }
483
484 if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
485 mpl_dbg("Mesh plink: missing necessary ie\n");
486 return;
487 }
488 /* Note the lines below are correct, the llid in the frame is the plid
489 * from the point of view of this host.
490 */
491 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
Rui Paulo09383932009-11-09 23:46:43 +0000492 if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 10))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100493 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
494
Johannes Bergd0709a62008-02-25 16:27:46 +0100495 rcu_read_lock();
496
Johannes Bergabe60632009-11-25 17:46:18 +0100497 sta = sta_info_get(sdata, mgmt->sa);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100498 if (!sta && ftype != PLINK_OPEN) {
499 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100500 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100501 return;
502 }
503
Javier Cardona53e80512011-04-07 15:08:32 -0700504 if (sta && !test_sta_flags(sta, WLAN_STA_AUTH)) {
505 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
506 rcu_read_unlock();
507 return;
508 }
509
Javier Cardona57cf8042011-05-13 10:45:43 -0700510 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100511 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100512 return;
513 }
514
515 /* Now we will figure out the appropriate event... */
516 event = PLINK_UNDEFINED;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200517 if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200518 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100519 switch (ftype) {
520 case PLINK_OPEN:
521 event = OPN_RJCT;
522 break;
523 case PLINK_CONFIRM:
524 event = CNF_RJCT;
525 break;
526 case PLINK_CLOSE:
527 /* avoid warning */
528 break;
529 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200530 }
531
532 if (!sta && !matches_local) {
533 rcu_read_unlock();
534 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
535 llid = 0;
536 mesh_plink_frame_tx(sdata, PLINK_CLOSE, mgmt->sa, llid,
537 plid, reason);
538 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100539 } else if (!sta) {
540 /* ftype == PLINK_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100541 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100542
543 rcu_read_unlock();
544
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100545 if (!mesh_plink_free_count(sdata)) {
546 mpl_dbg("Mesh plink error: no more free plinks\n");
547 return;
548 }
549
550 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Johannes Berg03e44972008-02-27 09:56:40 +0100551 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
Johannes Berg73651ee2008-02-25 16:27:47 +0100552 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100553 mpl_dbg("Mesh plink error: plink table full\n");
554 return;
555 }
Johannes Berg34e89502010-02-03 13:59:58 +0100556 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100557 rcu_read_unlock();
558 return;
559 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100560 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200561 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200562 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200563 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100564 switch (ftype) {
565 case PLINK_OPEN:
566 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100567 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100568 event = OPN_IGNR;
569 else
570 event = OPN_ACPT;
571 break;
572 case PLINK_CONFIRM:
573 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100574 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100575 event = CNF_IGNR;
576 else
577 event = CNF_ACPT;
578 break;
579 case PLINK_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700580 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100581 /* Do not check for llid or plid. This does not
582 * follow the standard but since multiple plinks
583 * per sta are not supported, it is necessary in
584 * order to avoid a livelock when MP A sees an
585 * establish peer link to MP B but MP B does not
586 * see it. This can be caused by a timeout in
587 * B's peer link establishment or B beign
588 * restarted.
589 */
590 event = CLS_ACPT;
591 else if (sta->plid != plid)
592 event = CLS_IGNR;
593 else if (ie_len == 7 && sta->llid != llid)
594 event = CLS_IGNR;
595 else
596 event = CLS_ACPT;
597 break;
598 default:
599 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200600 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100601 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100602 return;
603 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200604 } else {
605 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100606 }
607
Rui Paulo1460dd12009-11-09 23:46:48 +0000608 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
609 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700610 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
611 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100612 reason = 0;
613 switch (sta->plink_state) {
614 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700615 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100616 switch (event) {
617 case CLS_ACPT:
618 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200619 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100620 break;
621 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700622 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100623 sta->plid = plid;
624 get_random_bytes(&llid, 2);
625 sta->llid = llid;
626 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200627 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200628 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100629 0, 0);
Johannes Berg17741cd2008-09-11 00:02:02 +0200630 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100631 llid, plid, 0);
632 break;
633 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200634 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100635 break;
636 }
637 break;
638
Javier Cardona57cf8042011-05-13 10:45:43 -0700639 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100640 switch (event) {
641 case OPN_RJCT:
642 case CNF_RJCT:
643 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
644 case CLS_ACPT:
645 if (!reason)
646 reason = cpu_to_le16(MESH_CLOSE_RCVD);
647 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700648 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100649 if (!mod_plink_timer(sta,
650 dot11MeshHoldingTimeout(sdata)))
651 sta->ignore_plink_timer = true;
652
653 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200654 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200655 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100656 plid, reason);
657 break;
658 case OPN_ACPT:
659 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700660 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100661 sta->plid = plid;
662 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200663 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200664 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100665 plid, 0);
666 break;
667 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700668 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100669 if (!mod_plink_timer(sta,
670 dot11MeshConfirmTimeout(sdata)))
671 sta->ignore_plink_timer = true;
672
Johannes Berg07346f812008-05-03 01:02:02 +0200673 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100674 break;
675 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200676 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100677 break;
678 }
679 break;
680
Javier Cardona57cf8042011-05-13 10:45:43 -0700681 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100682 switch (event) {
683 case OPN_RJCT:
684 case CNF_RJCT:
685 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
686 case CLS_ACPT:
687 if (!reason)
688 reason = cpu_to_le16(MESH_CLOSE_RCVD);
689 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700690 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100691 if (!mod_plink_timer(sta,
692 dot11MeshHoldingTimeout(sdata)))
693 sta->ignore_plink_timer = true;
694
695 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200696 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200697 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100698 plid, reason);
699 break;
700 case OPN_ACPT:
701 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200702 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200703 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100704 plid, 0);
705 break;
706 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100707 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700708 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200709 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400710 mesh_plink_inc_estab_count(sdata);
711 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700712 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
713 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100714 break;
715 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200716 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100717 break;
718 }
719 break;
720
Javier Cardona57cf8042011-05-13 10:45:43 -0700721 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100722 switch (event) {
723 case OPN_RJCT:
724 case CNF_RJCT:
725 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
726 case CLS_ACPT:
727 if (!reason)
728 reason = cpu_to_le16(MESH_CLOSE_RCVD);
729 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700730 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100731 if (!mod_plink_timer(sta,
732 dot11MeshHoldingTimeout(sdata)))
733 sta->ignore_plink_timer = true;
734
735 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200736 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200737 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100738 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);
Johannes Berg17741cd2008-09-11 00:02:02 +0200748 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100749 plid, 0);
750 break;
751 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200752 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100753 break;
754 }
755 break;
756
Javier Cardona57cf8042011-05-13 10:45:43 -0700757 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100758 switch (event) {
759 case CLS_ACPT:
760 reason = cpu_to_le16(MESH_CLOSE_RCVD);
761 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400762 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700763 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100764 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100765 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200766 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400767 if (deactivated)
768 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg17741cd2008-09-11 00:02:02 +0200769 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100770 plid, reason);
771 break;
772 case OPN_ACPT:
773 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200774 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200775 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100776 plid, 0);
777 break;
778 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200779 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100780 break;
781 }
782 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700783 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100784 switch (event) {
785 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100786 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100787 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100788 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200789 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100790 break;
791 case OPN_ACPT:
792 case CNF_ACPT:
793 case OPN_RJCT:
794 case CNF_RJCT:
795 llid = sta->llid;
796 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200797 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200798 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr,
799 llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100800 break;
801 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200802 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100803 }
804 break;
805 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800806 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800807 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100808 */
Johannes Berg07346f812008-05-03 01:02:02 +0200809 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100810 break;
811 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100812
813 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100814}