blob: 2cf22127d3245f05c188f1846a896b64a95d8f22 [file] [log] [blame]
Luis Carlos Coboc3896d22008-02-23 15:17:13 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Coboc3896d22008-02-23 15:17:13 +01003 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/gfp.h>
Johannes Berg902acc72008-02-23 15:17:19 +010010#include <linux/kernel.h>
11#include <linux/random.h>
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010012#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010014#include "mesh.h"
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010015
16#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
18#else
19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
20#endif
21
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 Coboc3896d22008-02-23 15:17:13 +010024
25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000))
27
Johannes Berg472dbc42008-09-11 00:01:49 +020028#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
29#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
30#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
31#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
32#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010033
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010034enum plink_event {
35 PLINK_UNDEFINED,
36 OPN_ACPT,
37 OPN_RJCT,
38 OPN_IGNR,
39 CNF_ACPT,
40 CNF_RJCT,
41 CNF_IGNR,
42 CLS_ACPT,
43 CLS_IGNR
44};
45
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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +010080{
Johannes Bergd0709a62008-02-25 16:27:46 +010081 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010082 struct sta_info *sta;
83
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +010090
Javier Cardona96b78df2011-04-07 15:08:33 -070091 sta->flags = WLAN_STA_AUTHORIZED | WLAN_STA_AUTH;
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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +0100148 struct ieee80211_mgmt *mgmt;
149 bool include_plid = false;
Rui Paulo09383932009-11-09 23:46:43 +0000150 static const u8 meshpeeringproto[] = { 0x00, 0x0F, 0xAC, 0x2A };
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100151 u8 *pos;
152 int ie_len;
153
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 *)
161 skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
162 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700163 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
164 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d22008-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);
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700168 mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100169 mgmt->u.action.u.plink_action.action_code = action;
170
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700171 if (action == WLAN_SP_MESH_PEERING_CLOSE)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100172 mgmt->u.action.u.plink_action.aux = reason;
173 else {
174 mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700175 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100176 pos = skb_put(skb, 4);
177 /* two-byte status code followed by two-byte AID */
Rui Paulo77fa76b2009-11-09 23:46:52 +0000178 memset(pos, 0, 2);
179 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100180 }
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700181 if (mesh_add_srates_ie(skb, sdata) ||
182 mesh_add_ext_srates_ie(skb, sdata) ||
183 mesh_add_rsn_ie(skb, sdata) ||
184 mesh_add_meshid_ie(skb, sdata) ||
185 mesh_add_meshconf_ie(skb, sdata))
186 return -1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100187 }
188
189 /* Add Peer Link Management element */
190 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700191 case WLAN_SP_MESH_PEERING_OPEN:
Rui Paulo09383932009-11-09 23:46:43 +0000192 ie_len = 6;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100193 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700194 case WLAN_SP_MESH_PEERING_CONFIRM:
Rui Paulo09383932009-11-09 23:46:43 +0000195 ie_len = 8;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100196 include_plid = true;
197 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700198 case WLAN_SP_MESH_PEERING_CLOSE:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100199 default:
200 if (!plid)
Rui Paulo09383932009-11-09 23:46:43 +0000201 ie_len = 8;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100202 else {
Rui Paulo09383932009-11-09 23:46:43 +0000203 ie_len = 10;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100204 include_plid = true;
205 }
206 break;
207 }
208
209 pos = skb_put(skb, 2 + ie_len);
210 *pos++ = WLAN_EID_PEER_LINK;
211 *pos++ = ie_len;
Rui Paulo09383932009-11-09 23:46:43 +0000212 memcpy(pos, meshpeeringproto, sizeof(meshpeeringproto));
213 pos += 4;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100214 memcpy(pos, &llid, 2);
215 if (include_plid) {
216 pos += 2;
217 memcpy(pos, &plid, 2);
218 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700219 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100220 pos += 2;
221 memcpy(pos, &reason, 2);
222 }
223
Johannes Berg62ae67b2009-11-18 18:42:05 +0100224 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100225 return 0;
226}
227
Javier Cardona1570ca52011-04-07 15:08:35 -0700228void mesh_neighbour_update(u8 *hw_addr, u32 rates,
229 struct ieee80211_sub_if_data *sdata,
230 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100231{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200232 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100233 struct sta_info *sta;
234
Johannes Bergd0709a62008-02-25 16:27:46 +0100235 rcu_read_lock();
236
Johannes Bergabe60632009-11-25 17:46:18 +0100237 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100238 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100239 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700240 /* Userspace handles peer allocation when security is enabled
241 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700242 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700243 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
244 elems->ie_start, elems->total_len,
245 GFP_KERNEL);
246 else
247 sta = mesh_plink_alloc(sdata, hw_addr, rates);
Johannes Berg34e89502010-02-03 13:59:58 +0100248 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100249 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100250 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100251 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100252 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100253 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100254 }
255
256 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200257 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700258 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700259 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200260 sdata->u.mesh.accepting_plinks &&
261 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100262 mesh_plink_open(sta);
263
Johannes Bergd0709a62008-02-25 16:27:46 +0100264 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100265}
266
267static void mesh_plink_timer(unsigned long data)
268{
269 struct sta_info *sta;
270 __le16 llid, plid, reason;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100271 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100272
Johannes Bergd0709a62008-02-25 16:27:46 +0100273 /*
274 * This STA is valid because sta_info_destroy() will
275 * del_timer_sync() this timer after having made sure
276 * it cannot be readded (by deleting the plink.)
277 */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100278 sta = (struct sta_info *) data;
279
Johannes Berg5bb644a2009-05-17 11:40:42 +0200280 if (sta->sdata->local->quiescing) {
281 sta->plink_timer_was_running = true;
282 return;
283 }
284
Johannes Berg07346f812008-05-03 01:02:02 +0200285 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100286 if (sta->ignore_plink_timer) {
287 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200288 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100289 return;
290 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700291 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
292 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100293 reason = 0;
294 llid = sta->llid;
295 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100296 sdata = sta->sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100297
298 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700299 case NL80211_PLINK_OPN_RCVD:
300 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100301 /* retry timer */
302 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
303 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700304 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
305 sta->sta.addr, sta->plink_retries,
306 sta->plink_timeout);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100307 get_random_bytes(&rand, sizeof(u32));
308 sta->plink_timeout = sta->plink_timeout +
309 rand % sta->plink_timeout;
310 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100311 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200312 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700313 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
314 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100315 break;
316 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700317 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100318 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700319 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100320 /* confirm timer */
321 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700322 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700323 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100324 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200325 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700326 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
327 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100328 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700329 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100330 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100331 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100332 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200333 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100334 break;
335 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200336 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100337 break;
338 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100339}
340
Johannes Berg5bb644a2009-05-17 11:40:42 +0200341#ifdef CONFIG_PM
342void mesh_plink_quiesce(struct sta_info *sta)
343{
344 if (del_timer_sync(&sta->plink_timer))
345 sta->plink_timer_was_running = true;
346}
347
348void mesh_plink_restart(struct sta_info *sta)
349{
350 if (sta->plink_timer_was_running) {
351 add_timer(&sta->plink_timer);
352 sta->plink_timer_was_running = false;
353 }
354}
355#endif
356
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100357static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
358{
359 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
360 sta->plink_timer.data = (unsigned long) sta;
361 sta->plink_timer.function = mesh_plink_timer;
362 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100363 add_timer(&sta->plink_timer);
364}
365
366int mesh_plink_open(struct sta_info *sta)
367{
368 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100369 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100370
Javier Cardona53e80512011-04-07 15:08:32 -0700371 if (!test_sta_flags(sta, WLAN_STA_AUTH))
372 return -EPERM;
373
Johannes Berg07346f812008-05-03 01:02:02 +0200374 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100375 get_random_bytes(&llid, 2);
376 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700377 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200378 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100379 return -EBUSY;
380 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700381 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +0100386
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700387 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200388 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d22008-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);
Javier Cardona57cf8042011-05-13 10:45:43 -0700398 sta->plink_state = NL80211_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 Coboc3896d22008-02-23 15:17:13 +0100403}
404
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-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 Coboc3896d22008-02-23 15:17:13 +0100410 struct ieee802_11_elems elems;
411 struct sta_info *sta;
412 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700413 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100414 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200415 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d22008-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[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700421 [NL80211_PLINK_LISTEN] = "LISTEN",
422 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
423 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
424 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
425 [NL80211_PLINK_ESTAB] = "ESTAB",
426 [NL80211_PLINK_HOLDING] = "HOLDING",
427 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000428 };
429#endif
Luis Carlos Coboc3896d22008-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 Coboc3896d22008-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;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700442 if (mgmt->u.action.u.plink_action.action_code ==
443 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100444 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700445 baselen += 4;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100446 }
447 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
448 if (!elems.peer_link) {
449 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
450 return;
451 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700452 if (elems.rsn_len &&
453 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700454 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
455 return;
456 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100457
Rui Paulo09383932009-11-09 23:46:43 +0000458 ftype = mgmt->u.action.u.plink_action.action_code;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100459 ie_len = elems.peer_link_len;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700460 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 6) ||
461 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 8) ||
462 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 8
463 && ie_len != 10)) {
Rui Paulo09383932009-11-09 23:46:43 +0000464 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
465 ftype, ie_len);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100466 return;
467 }
468
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700469 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
470 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100471 mpl_dbg("Mesh plink: missing necessary ie\n");
472 return;
473 }
474 /* Note the lines below are correct, the llid in the frame is the plid
475 * from the point of view of this host.
476 */
477 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700478 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
479 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 10))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100480 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
481
Johannes Bergd0709a62008-02-25 16:27:46 +0100482 rcu_read_lock();
483
Johannes Bergabe60632009-11-25 17:46:18 +0100484 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700485 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100486 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100487 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100488 return;
489 }
490
Javier Cardona53e80512011-04-07 15:08:32 -0700491 if (sta && !test_sta_flags(sta, WLAN_STA_AUTH)) {
492 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
493 rcu_read_unlock();
494 return;
495 }
496
Javier Cardona57cf8042011-05-13 10:45:43 -0700497 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100498 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100499 return;
500 }
501
502 /* Now we will figure out the appropriate event... */
503 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700504 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
505 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200506 matches_local = false;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100507 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700508 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100509 event = OPN_RJCT;
510 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700511 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100512 event = CNF_RJCT;
513 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700514 default:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100515 break;
516 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200517 }
518
519 if (!sta && !matches_local) {
520 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700521 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200522 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700523 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
524 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200525 return;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100526 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700527 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100528 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100529
530 rcu_read_unlock();
531
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100532 if (!mesh_plink_free_count(sdata)) {
533 mpl_dbg("Mesh plink error: no more free plinks\n");
534 return;
535 }
536
537 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Johannes Berg03e44972008-02-27 09:56:40 +0100538 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
Johannes Berg73651ee2008-02-25 16:27:47 +0100539 if (!sta) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100540 mpl_dbg("Mesh plink error: plink table full\n");
541 return;
542 }
Johannes Berg34e89502010-02-03 13:59:58 +0100543 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100544 rcu_read_unlock();
545 return;
546 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100547 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200548 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200549 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200550 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100551 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700552 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100553 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100554 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100555 event = OPN_IGNR;
556 else
557 event = OPN_ACPT;
558 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700559 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100560 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100561 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100562 event = CNF_IGNR;
563 else
564 event = CNF_ACPT;
565 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700566 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700567 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100568 /* Do not check for llid or plid. This does not
569 * follow the standard but since multiple plinks
570 * per sta are not supported, it is necessary in
571 * order to avoid a livelock when MP A sees an
572 * establish peer link to MP B but MP B does not
573 * see it. This can be caused by a timeout in
574 * B's peer link establishment or B beign
575 * restarted.
576 */
577 event = CLS_ACPT;
578 else if (sta->plid != plid)
579 event = CLS_IGNR;
580 else if (ie_len == 7 && sta->llid != llid)
581 event = CLS_IGNR;
582 else
583 event = CLS_ACPT;
584 break;
585 default:
586 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200587 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100588 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100589 return;
590 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200591 } else {
592 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100593 }
594
Rui Paulo1460dd12009-11-09 23:46:48 +0000595 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
596 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700597 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
598 event);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100599 reason = 0;
600 switch (sta->plink_state) {
601 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700602 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100603 switch (event) {
604 case CLS_ACPT:
605 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200606 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100607 break;
608 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700609 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100610 sta->plid = plid;
611 get_random_bytes(&llid, 2);
612 sta->llid = llid;
613 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200614 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700615 mesh_plink_frame_tx(sdata,
616 WLAN_SP_MESH_PEERING_OPEN,
617 sta->sta.addr, llid, 0, 0);
618 mesh_plink_frame_tx(sdata,
619 WLAN_SP_MESH_PEERING_CONFIRM,
620 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100621 break;
622 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200623 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100624 break;
625 }
626 break;
627
Javier Cardona57cf8042011-05-13 10:45:43 -0700628 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100629 switch (event) {
630 case OPN_RJCT:
631 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700632 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100633 case CLS_ACPT:
634 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700635 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100636 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700637 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100638 if (!mod_plink_timer(sta,
639 dot11MeshHoldingTimeout(sdata)))
640 sta->ignore_plink_timer = true;
641
642 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200643 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700644 mesh_plink_frame_tx(sdata,
645 WLAN_SP_MESH_PEERING_CLOSE,
646 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100647 break;
648 case OPN_ACPT:
649 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700650 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100651 sta->plid = plid;
652 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200653 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700654 mesh_plink_frame_tx(sdata,
655 WLAN_SP_MESH_PEERING_CONFIRM,
656 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100657 break;
658 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700659 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100660 if (!mod_plink_timer(sta,
661 dot11MeshConfirmTimeout(sdata)))
662 sta->ignore_plink_timer = true;
663
Johannes Berg07346f812008-05-03 01:02:02 +0200664 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100665 break;
666 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200667 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100668 break;
669 }
670 break;
671
Javier Cardona57cf8042011-05-13 10:45:43 -0700672 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100673 switch (event) {
674 case OPN_RJCT:
675 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700676 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100677 case CLS_ACPT:
678 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700679 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100680 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700681 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100682 if (!mod_plink_timer(sta,
683 dot11MeshHoldingTimeout(sdata)))
684 sta->ignore_plink_timer = true;
685
686 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200687 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700688 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
689 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100690 break;
691 case OPN_ACPT:
692 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200693 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700694 mesh_plink_frame_tx(sdata,
695 WLAN_SP_MESH_PEERING_CONFIRM,
696 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100697 break;
698 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100699 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700700 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200701 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400702 mesh_plink_inc_estab_count(sdata);
703 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700704 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
705 sta->sta.addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100706 break;
707 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200708 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100709 break;
710 }
711 break;
712
Javier Cardona57cf8042011-05-13 10:45:43 -0700713 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100714 switch (event) {
715 case OPN_RJCT:
716 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700717 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100718 case CLS_ACPT:
719 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700720 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100721 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700722 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100723 if (!mod_plink_timer(sta,
724 dot11MeshHoldingTimeout(sdata)))
725 sta->ignore_plink_timer = true;
726
727 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200728 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700729 mesh_plink_frame_tx(sdata,
730 WLAN_SP_MESH_PEERING_CLOSE,
731 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100732 break;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100733 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100734 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700735 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200736 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400737 mesh_plink_inc_estab_count(sdata);
738 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700739 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
740 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700741 mesh_plink_frame_tx(sdata,
742 WLAN_SP_MESH_PEERING_CONFIRM,
743 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100744 break;
745 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200746 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100747 break;
748 }
749 break;
750
Javier Cardona57cf8042011-05-13 10:45:43 -0700751 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100752 switch (event) {
753 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700754 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100755 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400756 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700757 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100758 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100759 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200760 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400761 if (deactivated)
762 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700763 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
764 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100765 break;
766 case OPN_ACPT:
767 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200768 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700769 mesh_plink_frame_tx(sdata,
770 WLAN_SP_MESH_PEERING_CONFIRM,
771 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100772 break;
773 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200774 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100775 break;
776 }
777 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700778 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100779 switch (event) {
780 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100781 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100782 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100783 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200784 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100785 break;
786 case OPN_ACPT:
787 case CNF_ACPT:
788 case OPN_RJCT:
789 case CNF_RJCT:
790 llid = sta->llid;
791 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200792 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700793 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
794 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100795 break;
796 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200797 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100798 }
799 break;
800 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800801 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800802 * beginning of the function
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100803 */
Johannes Berg07346f812008-05-03 01:02:02 +0200804 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100805 break;
806 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100807
808 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100809}