blob: ea13a80a476c1fe0db6dc5e0059e2014f340926e [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 {
46 PLINK_OPEN = 0,
47 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{
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -080086 sta->plink_state = 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
Johannes Berg07346f812008-05-03 01:02:02 +0200108 sta->flags = WLAN_STA_AUTHORIZED;
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
John W. Linvillec9370192010-06-21 17:14:07 -0400129 if (sta->plink_state == 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 }
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800133 sta->plink_state = 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;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100163 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
164 struct ieee80211_mgmt *mgmt;
165 bool include_plid = false;
Rui Paulo09383932009-11-09 23:46:43 +0000166 static const u8 meshpeeringproto[] = { 0x00, 0x0F, 0xAC, 0x2A };
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100167 u8 *pos;
168 int ie_len;
169
170 if (!skb)
171 return -1;
172 skb_reserve(skb, local->hw.extra_tx_headroom);
173 /* 25 is the size of the common mgmt part (24) plus the size of the
174 * common action part (1)
175 */
176 mgmt = (struct ieee80211_mgmt *)
177 skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
178 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700179 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
180 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100181 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100182 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100183 /* BSSID is left zeroed, wildcard value */
Javier Cardona97ad9132010-03-29 11:00:21 -0700184 mgmt->u.action.category = WLAN_CATEGORY_MESH_PLINK;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100185 mgmt->u.action.u.plink_action.action_code = action;
186
187 if (action == PLINK_CLOSE)
188 mgmt->u.action.u.plink_action.aux = reason;
189 else {
190 mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
191 if (action == PLINK_CONFIRM) {
192 pos = skb_put(skb, 4);
193 /* two-byte status code followed by two-byte AID */
Rui Paulo77fa76b2009-11-09 23:46:52 +0000194 memset(pos, 0, 2);
195 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100196 }
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200197 mesh_mgmt_ies_add(skb, sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100198 }
199
200 /* Add Peer Link Management element */
201 switch (action) {
202 case PLINK_OPEN:
Rui Paulo09383932009-11-09 23:46:43 +0000203 ie_len = 6;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100204 break;
205 case PLINK_CONFIRM:
Rui Paulo09383932009-11-09 23:46:43 +0000206 ie_len = 8;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100207 include_plid = true;
208 break;
209 case PLINK_CLOSE:
210 default:
211 if (!plid)
Rui Paulo09383932009-11-09 23:46:43 +0000212 ie_len = 8;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100213 else {
Rui Paulo09383932009-11-09 23:46:43 +0000214 ie_len = 10;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100215 include_plid = true;
216 }
217 break;
218 }
219
220 pos = skb_put(skb, 2 + ie_len);
221 *pos++ = WLAN_EID_PEER_LINK;
222 *pos++ = ie_len;
Rui Paulo09383932009-11-09 23:46:43 +0000223 memcpy(pos, meshpeeringproto, sizeof(meshpeeringproto));
224 pos += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100225 memcpy(pos, &llid, 2);
226 if (include_plid) {
227 pos += 2;
228 memcpy(pos, &plid, 2);
229 }
230 if (action == PLINK_CLOSE) {
231 pos += 2;
232 memcpy(pos, &reason, 2);
233 }
234
Johannes Berg62ae67b2009-11-18 18:42:05 +0100235 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100236 return 0;
237}
238
Johannes Berg881d9482009-01-21 15:13:48 +0100239void mesh_neighbour_update(u8 *hw_addr, u32 rates, struct ieee80211_sub_if_data *sdata,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100240 bool peer_accepting_plinks)
241{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200242 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100243 struct sta_info *sta;
244
Johannes Bergd0709a62008-02-25 16:27:46 +0100245 rcu_read_lock();
246
Johannes Bergabe60632009-11-25 17:46:18 +0100247 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100248 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100249 rcu_read_unlock();
250
Johannes Berg03e44972008-02-27 09:56:40 +0100251 sta = mesh_plink_alloc(sdata, hw_addr, rates);
Johannes Berg34e89502010-02-03 13:59:58 +0100252 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100253 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100254 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100255 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100256 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100257 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100258 }
259
260 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200261 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800262 if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200263 sdata->u.mesh.accepting_plinks &&
264 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100265 mesh_plink_open(sta);
266
Johannes Bergd0709a62008-02-25 16:27:46 +0100267 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100268}
269
270static void mesh_plink_timer(unsigned long data)
271{
272 struct sta_info *sta;
273 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100274 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100275
Johannes Bergd0709a62008-02-25 16:27:46 +0100276 /*
277 * This STA is valid because sta_info_destroy() will
278 * del_timer_sync() this timer after having made sure
279 * it cannot be readded (by deleting the plink.)
280 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100281 sta = (struct sta_info *) data;
282
Johannes Berg5bb644a2009-05-17 11:40:42 +0200283 if (sta->sdata->local->quiescing) {
284 sta->plink_timer_was_running = true;
285 return;
286 }
287
Johannes Berg07346f812008-05-03 01:02:02 +0200288 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100289 if (sta->ignore_plink_timer) {
290 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200291 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100292 return;
293 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700294 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
295 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100296 reason = 0;
297 llid = sta->llid;
298 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100299 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100300
301 switch (sta->plink_state) {
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800302 case PLINK_OPN_RCVD:
303 case PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100304 /* retry timer */
305 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
306 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700307 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
308 sta->sta.addr, sta->plink_retries,
309 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100310 get_random_bytes(&rand, sizeof(u32));
311 sta->plink_timeout = sta->plink_timeout +
312 rand % sta->plink_timeout;
313 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100314 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200315 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200316 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100317 0, 0);
318 break;
319 }
320 reason = cpu_to_le16(MESH_MAX_RETRIES);
321 /* fall through on else */
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800322 case PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100323 /* confirm timer */
324 if (!reason)
325 reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800326 sta->plink_state = PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100327 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200328 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200329 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, plid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100330 reason);
331 break;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800332 case PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100333 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100334 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100335 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200336 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100337 break;
338 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200339 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100340 break;
341 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100342}
343
Johannes Berg5bb644a2009-05-17 11:40:42 +0200344#ifdef CONFIG_PM
345void mesh_plink_quiesce(struct sta_info *sta)
346{
347 if (del_timer_sync(&sta->plink_timer))
348 sta->plink_timer_was_running = true;
349}
350
351void mesh_plink_restart(struct sta_info *sta)
352{
353 if (sta->plink_timer_was_running) {
354 add_timer(&sta->plink_timer);
355 sta->plink_timer_was_running = false;
356 }
357}
358#endif
359
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100360static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
361{
362 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
363 sta->plink_timer.data = (unsigned long) sta;
364 sta->plink_timer.function = mesh_plink_timer;
365 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100366 add_timer(&sta->plink_timer);
367}
368
369int mesh_plink_open(struct sta_info *sta)
370{
371 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100372 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100373
Johannes Berg07346f812008-05-03 01:02:02 +0200374 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100375 get_random_bytes(&llid, 2);
376 sta->llid = llid;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800377 if (sta->plink_state != PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200378 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100379 return -EBUSY;
380 }
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800381 sta->plink_state = PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100382 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200383 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700384 mpl_dbg("Mesh plink: starting establishment with %pM\n",
385 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100386
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200387 return mesh_plink_frame_tx(sdata, PLINK_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200388 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100389}
390
391void mesh_plink_block(struct sta_info *sta)
392{
John W. Linvillec9370192010-06-21 17:14:07 -0400393 struct ieee80211_sub_if_data *sdata = sta->sdata;
394 bool deactivated;
395
Johannes Berg07346f812008-05-03 01:02:02 +0200396 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400397 deactivated = __mesh_plink_deactivate(sta);
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800398 sta->plink_state = PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200399 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400400
401 if (deactivated)
402 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100403}
404
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100405
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200406void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100407 size_t len, struct ieee80211_rx_status *rx_status)
408{
Johannes Bergd0709a62008-02-25 16:27:46 +0100409 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100410 struct ieee802_11_elems elems;
411 struct sta_info *sta;
412 enum plink_event event;
413 enum plink_frame_type ftype;
414 size_t baselen;
John W. Linvillec9370192010-06-21 17:14:07 -0400415 bool deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100416 u8 ie_len;
417 u8 *baseaddr;
418 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000419#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
420 static const char *mplstates[] = {
421 [PLINK_LISTEN] = "LISTEN",
422 [PLINK_OPN_SNT] = "OPN-SNT",
423 [PLINK_OPN_RCVD] = "OPN-RCVD",
424 [PLINK_CNF_RCVD] = "CNF_RCVD",
425 [PLINK_ESTAB] = "ESTAB",
426 [PLINK_HOLDING] = "HOLDING",
427 [PLINK_BLOCKED] = "BLOCKED"
428 };
429#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100430
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200431 /* need action_code, aux */
432 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
433 return;
434
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100435 if (is_multicast_ether_addr(mgmt->da)) {
436 mpl_dbg("Mesh plink: ignore frame from multicast address");
437 return;
438 }
439
440 baseaddr = mgmt->u.action.u.plink_action.variable;
441 baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
442 if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
443 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700444 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100445 }
446 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
447 if (!elems.peer_link) {
448 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
449 return;
450 }
451
Rui Paulo09383932009-11-09 23:46:43 +0000452 ftype = mgmt->u.action.u.plink_action.action_code;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100453 ie_len = elems.peer_link_len;
Rui Paulo09383932009-11-09 23:46:43 +0000454 if ((ftype == PLINK_OPEN && ie_len != 6) ||
455 (ftype == PLINK_CONFIRM && ie_len != 8) ||
456 (ftype == PLINK_CLOSE && ie_len != 8 && ie_len != 10)) {
457 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
458 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100459 return;
460 }
461
462 if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
463 mpl_dbg("Mesh plink: missing necessary ie\n");
464 return;
465 }
466 /* Note the lines below are correct, the llid in the frame is the plid
467 * from the point of view of this host.
468 */
469 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
Rui Paulo09383932009-11-09 23:46:43 +0000470 if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 10))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100471 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
472
Johannes Bergd0709a62008-02-25 16:27:46 +0100473 rcu_read_lock();
474
Johannes Bergabe60632009-11-25 17:46:18 +0100475 sta = sta_info_get(sdata, mgmt->sa);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100476 if (!sta && ftype != PLINK_OPEN) {
477 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100478 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100479 return;
480 }
481
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800482 if (sta && sta->plink_state == PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100483 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100484 return;
485 }
486
487 /* Now we will figure out the appropriate event... */
488 event = PLINK_UNDEFINED;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200489 if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, sdata))) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100490 switch (ftype) {
491 case PLINK_OPEN:
492 event = OPN_RJCT;
493 break;
494 case PLINK_CONFIRM:
495 event = CNF_RJCT;
496 break;
497 case PLINK_CLOSE:
498 /* avoid warning */
499 break;
500 }
Johannes Berg07346f812008-05-03 01:02:02 +0200501 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100502 } else if (!sta) {
503 /* ftype == PLINK_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100504 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100505
506 rcu_read_unlock();
507
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100508 if (!mesh_plink_free_count(sdata)) {
509 mpl_dbg("Mesh plink error: no more free plinks\n");
510 return;
511 }
512
513 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Johannes Berg03e44972008-02-27 09:56:40 +0100514 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
Johannes Berg73651ee2008-02-25 16:27:47 +0100515 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100516 mpl_dbg("Mesh plink error: plink table full\n");
517 return;
518 }
Johannes Berg34e89502010-02-03 13:59:58 +0100519 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100520 rcu_read_unlock();
521 return;
522 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100523 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200524 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100525 } else {
Johannes Berg07346f812008-05-03 01:02:02 +0200526 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100527 switch (ftype) {
528 case PLINK_OPEN:
529 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100530 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100531 event = OPN_IGNR;
532 else
533 event = OPN_ACPT;
534 break;
535 case PLINK_CONFIRM:
536 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100537 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100538 event = CNF_IGNR;
539 else
540 event = CNF_ACPT;
541 break;
542 case PLINK_CLOSE:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800543 if (sta->plink_state == PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100544 /* Do not check for llid or plid. This does not
545 * follow the standard but since multiple plinks
546 * per sta are not supported, it is necessary in
547 * order to avoid a livelock when MP A sees an
548 * establish peer link to MP B but MP B does not
549 * see it. This can be caused by a timeout in
550 * B's peer link establishment or B beign
551 * restarted.
552 */
553 event = CLS_ACPT;
554 else if (sta->plid != plid)
555 event = CLS_IGNR;
556 else if (ie_len == 7 && sta->llid != llid)
557 event = CLS_IGNR;
558 else
559 event = CLS_ACPT;
560 break;
561 default:
562 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200563 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100564 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100565 return;
566 }
567 }
568
Rui Paulo1460dd12009-11-09 23:46:48 +0000569 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
570 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700571 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
572 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100573 reason = 0;
574 switch (sta->plink_state) {
575 /* spin_unlock as soon as state is updated at each case */
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800576 case PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100577 switch (event) {
578 case CLS_ACPT:
579 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200580 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100581 break;
582 case OPN_ACPT:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800583 sta->plink_state = PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100584 sta->plid = plid;
585 get_random_bytes(&llid, 2);
586 sta->llid = llid;
587 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200588 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200589 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100590 0, 0);
Johannes Berg17741cd2008-09-11 00:02:02 +0200591 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100592 llid, plid, 0);
593 break;
594 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200595 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100596 break;
597 }
598 break;
599
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800600 case PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100601 switch (event) {
602 case OPN_RJCT:
603 case CNF_RJCT:
604 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
605 case CLS_ACPT:
606 if (!reason)
607 reason = cpu_to_le16(MESH_CLOSE_RCVD);
608 sta->reason = reason;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800609 sta->plink_state = PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100610 if (!mod_plink_timer(sta,
611 dot11MeshHoldingTimeout(sdata)))
612 sta->ignore_plink_timer = true;
613
614 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200615 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200616 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100617 plid, reason);
618 break;
619 case OPN_ACPT:
620 /* retry timer is left untouched */
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800621 sta->plink_state = PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100622 sta->plid = plid;
623 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200624 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200625 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100626 plid, 0);
627 break;
628 case CNF_ACPT:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800629 sta->plink_state = PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100630 if (!mod_plink_timer(sta,
631 dot11MeshConfirmTimeout(sdata)))
632 sta->ignore_plink_timer = true;
633
Johannes Berg07346f812008-05-03 01:02:02 +0200634 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100635 break;
636 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200637 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100638 break;
639 }
640 break;
641
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800642 case PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100643 switch (event) {
644 case OPN_RJCT:
645 case CNF_RJCT:
646 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
647 case CLS_ACPT:
648 if (!reason)
649 reason = cpu_to_le16(MESH_CLOSE_RCVD);
650 sta->reason = reason;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800651 sta->plink_state = PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100652 if (!mod_plink_timer(sta,
653 dot11MeshHoldingTimeout(sdata)))
654 sta->ignore_plink_timer = true;
655
656 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200657 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200658 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100659 plid, reason);
660 break;
661 case OPN_ACPT:
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:
Johannes Bergd0709a62008-02-25 16:27:46 +0100668 del_timer(&sta->plink_timer);
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800669 sta->plink_state = PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200670 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400671 mesh_plink_inc_estab_count(sdata);
672 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700673 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
674 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100675 break;
676 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200677 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100678 break;
679 }
680 break;
681
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800682 case PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100683 switch (event) {
684 case OPN_RJCT:
685 case CNF_RJCT:
686 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
687 case CLS_ACPT:
688 if (!reason)
689 reason = cpu_to_le16(MESH_CLOSE_RCVD);
690 sta->reason = reason;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800691 sta->plink_state = PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100692 if (!mod_plink_timer(sta,
693 dot11MeshHoldingTimeout(sdata)))
694 sta->ignore_plink_timer = true;
695
696 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200697 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200698 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100699 plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100700 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100701 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100702 del_timer(&sta->plink_timer);
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800703 sta->plink_state = PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200704 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400705 mesh_plink_inc_estab_count(sdata);
706 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700707 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
708 sta->sta.addr);
Johannes Berg17741cd2008-09-11 00:02:02 +0200709 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100710 plid, 0);
711 break;
712 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200713 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100714 break;
715 }
716 break;
717
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800718 case PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100719 switch (event) {
720 case CLS_ACPT:
721 reason = cpu_to_le16(MESH_CLOSE_RCVD);
722 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400723 deactivated = __mesh_plink_deactivate(sta);
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800724 sta->plink_state = PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100725 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100726 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200727 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400728 if (deactivated)
729 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg17741cd2008-09-11 00:02:02 +0200730 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100731 plid, reason);
732 break;
733 case OPN_ACPT:
734 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200735 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200736 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100737 plid, 0);
738 break;
739 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200740 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100741 break;
742 }
743 break;
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800744 case PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100745 switch (event) {
746 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100747 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100748 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100749 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200750 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100751 break;
752 case OPN_ACPT:
753 case CNF_ACPT:
754 case OPN_RJCT:
755 case CNF_RJCT:
756 llid = sta->llid;
757 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200758 spin_unlock_bh(&sta->lock);
Johannes Berg17741cd2008-09-11 00:02:02 +0200759 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr,
760 llid, plid, reason);
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 }
765 break;
766 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800767 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800768 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100769 */
Johannes Berg07346f812008-05-03 01:02:02 +0200770 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100771 break;
772 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100773
774 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100775}