blob: 7314372b12ba2eb2096a749737ae05434be2e8bb [file] [log] [blame]
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01003 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/gfp.h>
Johannes Berg902acc72008-02-23 15:17:19 +010010#include <linux/kernel.h>
11#include <linux/random.h>
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010012#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010014#include "mesh.h"
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010015
16#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
18#else
19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
20#endif
21
Thomas Pedersen8db09852011-08-12 20:01:00 -070022#define PLINK_GET_LLID(p) (p + 2)
23#define PLINK_GET_PLID(p) (p + 4)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010024
25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000))
27
Johannes Berg472dbc42008-09-11 00:01:49 +020028#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
29#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
30#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
31#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
32#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010033
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010034enum plink_event {
35 PLINK_UNDEFINED,
36 OPN_ACPT,
37 OPN_RJCT,
38 OPN_IGNR,
39 CNF_ACPT,
40 CNF_RJCT,
41 CNF_IGNR,
42 CLS_ACPT,
43 CLS_IGNR
44};
45
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070046static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
47 enum ieee80211_self_protected_actioncode action,
48 u8 *da, __le16 llid, __le16 plid, __le16 reason);
49
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010050static inline
51void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
52{
Johannes Berg472dbc42008-09-11 00:01:49 +020053 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010054 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010055}
56
57static inline
58void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
59{
Johannes Berg472dbc42008-09-11 00:01:49 +020060 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010061 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010062}
63
64/**
65 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
66 *
Rui Paulo23c7a292009-11-09 23:46:42 +000067 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010068 *
Johannes Berg07346f812008-05-03 01:02:02 +020069 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010070 */
71static inline void mesh_plink_fsm_restart(struct sta_info *sta)
72{
Javier Cardona57cf8042011-05-13 10:45:43 -070073 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080074 sta->llid = sta->plid = sta->reason = 0;
75 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010076}
77
Johannes Berg93e5deb2008-04-01 15:21:00 +020078/*
79 * NOTE: This is just an alias for sta_info_alloc(), see notes
80 * on it in the lifecycle management section!
81 */
Johannes Berg03e44972008-02-27 09:56:40 +010082static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen739522b2011-10-26 14:47:28 -070083 u8 *hw_addr, u32 rates,
84 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010085{
Johannes Bergd0709a62008-02-25 16:27:46 +010086 struct ieee80211_local *local = sdata->local;
Thomas Pedersen739522b2011-10-26 14:47:28 -070087 struct ieee80211_supported_band *sband;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010088 struct sta_info *sta;
89
Thomas Pedersen739522b2011-10-26 14:47:28 -070090 sband = local->hw.wiphy->bands[local->oper_channel->band];
91
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010092 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010093 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010094
Johannes Berg34e89502010-02-03 13:59:58 +010095 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +010096 if (!sta)
97 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010098
Johannes Bergc2c98fd2011-09-29 16:04:36 +020099 set_sta_flag(sta, WLAN_STA_AUTH);
100 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
101 set_sta_flag(sta, WLAN_STA_WME);
Johannes Berg323ce792008-09-11 02:45:11 +0200102 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Thomas Pedersen739522b2011-10-26 14:47:28 -0700103 if (elems->ht_cap_elem)
Ben Greearef96a8422011-11-18 11:32:00 -0800104 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
105 elems->ht_cap_elem,
Thomas Pedersen739522b2011-10-26 14:47:28 -0700106 &sta->sta.ht_cap);
Christian Lamparterb973c312008-12-27 22:19:49 +0100107 rate_control_rate_init(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100108
109 return sta;
110}
111
112/**
John W. Linvillec9370192010-06-21 17:14:07 -0400113 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100114 *
115 * @sta: mesh peer link to deactivate
116 *
117 * All mesh paths with this peer as next hop will be flushed
118 *
Johannes Berg07346f812008-05-03 01:02:02 +0200119 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100120 */
John W. Linvillec9370192010-06-21 17:14:07 -0400121static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100122{
Johannes Bergd0709a62008-02-25 16:27:46 +0100123 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400124 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100125
Javier Cardona57cf8042011-05-13 10:45:43 -0700126 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100127 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400128 deactivated = true;
129 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700130 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100131 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400132
133 return deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100134}
135
Johannes Berg902acc72008-02-23 15:17:19 +0100136/**
John W. Linvillec9370192010-06-21 17:14:07 -0400137 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100138 *
139 * @sta: mesh peer link to deactivate
140 *
141 * All mesh paths with this peer as next hop will be flushed
142 */
143void mesh_plink_deactivate(struct sta_info *sta)
144{
John W. Linvillec9370192010-06-21 17:14:07 -0400145 struct ieee80211_sub_if_data *sdata = sta->sdata;
146 bool deactivated;
147
Johannes Berg07346f812008-05-03 01:02:02 +0200148 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400149 deactivated = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700150 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
151 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
152 sta->sta.addr, sta->llid, sta->plid,
153 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200154 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400155
156 if (deactivated)
157 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100158}
159
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200160static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700161 enum ieee80211_self_protected_actioncode action,
162 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200163 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700164 struct sk_buff *skb;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100165 struct ieee80211_mgmt *mgmt;
166 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700167 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700168 u8 *pos, ie_len = 4;
169 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
170 sizeof(mgmt->u.action.u.self_prot);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100171
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700172 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
173 hdr_len +
174 2 + /* capability info */
175 2 + /* AID */
176 2 + 8 + /* supported rates */
177 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
178 2 + sdata->u.mesh.mesh_id_len +
179 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700180 2 + sizeof(struct ieee80211_ht_cap) +
181 2 + sizeof(struct ieee80211_ht_info) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700182 2 + 8 + /* peering IE */
183 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100184 if (!skb)
185 return -1;
186 skb_reserve(skb, local->hw.extra_tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700187 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
188 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700189 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
190 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100191 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100192 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700193 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700194 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
195 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100196
Thomas Pedersen8db09852011-08-12 20:01:00 -0700197 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
198 /* capability info */
199 pos = skb_put(skb, 2);
200 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700201 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700202 /* AID */
203 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000204 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100205 }
Arik Nemtsov768db342011-09-28 14:12:51 +0300206 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
207 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700208 mesh_add_rsn_ie(skb, sdata) ||
209 mesh_add_meshid_ie(skb, sdata) ||
210 mesh_add_meshconf_ie(skb, sdata))
211 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700212 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
213 if (mesh_add_meshid_ie(skb, sdata))
214 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100215 }
216
Thomas Pedersen8db09852011-08-12 20:01:00 -0700217 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100218 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700219 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100220 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700221 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700222 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100223 include_plid = true;
224 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700225 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700226 if (plid) {
227 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100228 include_plid = true;
229 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700230 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100231 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700232 default:
233 return -EINVAL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100234 }
235
Thomas Pedersen8db09852011-08-12 20:01:00 -0700236 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
237 return -ENOMEM;
238
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100239 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700240 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100241 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700242 memcpy(pos, &peering_proto, 2);
243 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100244 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700245 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100246 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100247 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700248 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100249 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700250 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100251 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700252 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100253 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700254
255 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
256 if (mesh_add_ht_cap_ie(skb, sdata) ||
257 mesh_add_ht_info_ie(skb, sdata))
258 return -1;
259 }
260
Thomas Pedersen8db09852011-08-12 20:01:00 -0700261 if (mesh_add_vendor_ies(skb, sdata))
262 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100263
Johannes Berg62ae67b2009-11-18 18:42:05 +0100264 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100265 return 0;
266}
267
Javier Cardona1570ca52011-04-07 15:08:35 -0700268void mesh_neighbour_update(u8 *hw_addr, u32 rates,
269 struct ieee80211_sub_if_data *sdata,
270 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100271{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200272 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100273 struct sta_info *sta;
274
Johannes Bergd0709a62008-02-25 16:27:46 +0100275 rcu_read_lock();
276
Johannes Bergabe60632009-11-25 17:46:18 +0100277 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100278 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100279 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700280 /* Userspace handles peer allocation when security is enabled
281 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700282 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700283 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
284 elems->ie_start, elems->total_len,
285 GFP_KERNEL);
286 else
Thomas Pedersen739522b2011-10-26 14:47:28 -0700287 sta = mesh_plink_alloc(sdata, hw_addr, rates, elems);
Johannes Berg34e89502010-02-03 13:59:58 +0100288 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100289 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100290 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100291 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100292 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100293 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100294 }
295
296 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200297 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700298 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700299 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200300 sdata->u.mesh.accepting_plinks &&
301 sdata->u.mesh.mshcfg.auto_open_plinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100302 mesh_plink_open(sta);
303
Johannes Bergd0709a62008-02-25 16:27:46 +0100304 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100305}
306
307static void mesh_plink_timer(unsigned long data)
308{
309 struct sta_info *sta;
310 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100311 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100312
Johannes Bergd0709a62008-02-25 16:27:46 +0100313 /*
314 * This STA is valid because sta_info_destroy() will
315 * del_timer_sync() this timer after having made sure
316 * it cannot be readded (by deleting the plink.)
317 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100318 sta = (struct sta_info *) data;
319
Johannes Berg5bb644a2009-05-17 11:40:42 +0200320 if (sta->sdata->local->quiescing) {
321 sta->plink_timer_was_running = true;
322 return;
323 }
324
Johannes Berg07346f812008-05-03 01:02:02 +0200325 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100326 if (sta->ignore_plink_timer) {
327 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200328 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100329 return;
330 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700331 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
332 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100333 reason = 0;
334 llid = sta->llid;
335 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100336 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100337
338 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700339 case NL80211_PLINK_OPN_RCVD:
340 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100341 /* retry timer */
342 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
343 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700344 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
345 sta->sta.addr, sta->plink_retries,
346 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100347 get_random_bytes(&rand, sizeof(u32));
348 sta->plink_timeout = sta->plink_timeout +
349 rand % sta->plink_timeout;
350 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100351 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200352 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700353 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
354 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100355 break;
356 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700357 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100358 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700359 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100360 /* confirm timer */
361 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700362 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700363 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100364 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200365 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700366 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
367 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100368 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700369 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100370 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100371 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100372 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200373 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100374 break;
375 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200376 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100377 break;
378 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100379}
380
Johannes Berg5bb644a2009-05-17 11:40:42 +0200381#ifdef CONFIG_PM
382void mesh_plink_quiesce(struct sta_info *sta)
383{
384 if (del_timer_sync(&sta->plink_timer))
385 sta->plink_timer_was_running = true;
386}
387
388void mesh_plink_restart(struct sta_info *sta)
389{
390 if (sta->plink_timer_was_running) {
391 add_timer(&sta->plink_timer);
392 sta->plink_timer_was_running = false;
393 }
394}
395#endif
396
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100397static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
398{
399 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
400 sta->plink_timer.data = (unsigned long) sta;
401 sta->plink_timer.function = mesh_plink_timer;
402 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100403 add_timer(&sta->plink_timer);
404}
405
406int mesh_plink_open(struct sta_info *sta)
407{
408 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100409 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100410
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200411 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700412 return -EPERM;
413
Johannes Berg07346f812008-05-03 01:02:02 +0200414 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100415 get_random_bytes(&llid, 2);
416 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700417 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200418 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100419 return -EBUSY;
420 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700421 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100422 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200423 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700424 mpl_dbg("Mesh plink: starting establishment with %pM\n",
425 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100426
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700427 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200428 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100429}
430
431void mesh_plink_block(struct sta_info *sta)
432{
John W. Linvillec9370192010-06-21 17:14:07 -0400433 struct ieee80211_sub_if_data *sdata = sta->sdata;
434 bool deactivated;
435
Johannes Berg07346f812008-05-03 01:02:02 +0200436 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400437 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700438 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200439 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400440
441 if (deactivated)
442 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100443}
444
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100445
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200446void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100447 size_t len, struct ieee80211_rx_status *rx_status)
448{
Johannes Bergd0709a62008-02-25 16:27:46 +0100449 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100450 struct ieee802_11_elems elems;
451 struct sta_info *sta;
452 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700453 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100454 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200455 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100456 u8 ie_len;
457 u8 *baseaddr;
458 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000459#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
460 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700461 [NL80211_PLINK_LISTEN] = "LISTEN",
462 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
463 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
464 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
465 [NL80211_PLINK_ESTAB] = "ESTAB",
466 [NL80211_PLINK_HOLDING] = "HOLDING",
467 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000468 };
469#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100470
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200471 /* need action_code, aux */
472 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
473 return;
474
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100475 if (is_multicast_ether_addr(mgmt->da)) {
476 mpl_dbg("Mesh plink: ignore frame from multicast address");
477 return;
478 }
479
Thomas Pedersen8db09852011-08-12 20:01:00 -0700480 baseaddr = mgmt->u.action.u.self_prot.variable;
481 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
482 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700483 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100484 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700485 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100486 }
487 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700488 if (!elems.peering) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100489 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
490 return;
491 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700492 if (elems.rsn_len &&
493 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700494 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
495 return;
496 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100497
Thomas Pedersen8db09852011-08-12 20:01:00 -0700498 ftype = mgmt->u.action.u.self_prot.action_code;
499 ie_len = elems.peering_len;
500 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
501 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
502 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
503 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000504 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
505 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100506 return;
507 }
508
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700509 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
510 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100511 mpl_dbg("Mesh plink: missing necessary ie\n");
512 return;
513 }
514 /* Note the lines below are correct, the llid in the frame is the plid
515 * from the point of view of this host.
516 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700517 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700518 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700519 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
520 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100521
Johannes Bergd0709a62008-02-25 16:27:46 +0100522 rcu_read_lock();
523
Johannes Bergabe60632009-11-25 17:46:18 +0100524 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700525 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100526 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100527 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100528 return;
529 }
530
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200531 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700532 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
533 rcu_read_unlock();
534 return;
535 }
536
Javier Cardona57cf8042011-05-13 10:45:43 -0700537 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100538 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100539 return;
540 }
541
542 /* Now we will figure out the appropriate event... */
543 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700544 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
545 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200546 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100547 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700548 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100549 event = OPN_RJCT;
550 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700551 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100552 event = CNF_RJCT;
553 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700554 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100555 break;
556 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200557 }
558
559 if (!sta && !matches_local) {
560 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700561 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200562 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700563 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
564 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200565 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100566 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700567 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100568 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100569
570 rcu_read_unlock();
571
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100572 if (!mesh_plink_free_count(sdata)) {
573 mpl_dbg("Mesh plink error: no more free plinks\n");
574 return;
575 }
576
577 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Thomas Pedersen739522b2011-10-26 14:47:28 -0700578 sta = mesh_plink_alloc(sdata, mgmt->sa, rates, &elems);
Johannes Berg73651ee2008-02-25 16:27:47 +0100579 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100580 mpl_dbg("Mesh plink error: plink table full\n");
581 return;
582 }
Johannes Berg34e89502010-02-03 13:59:58 +0100583 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100584 rcu_read_unlock();
585 return;
586 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100587 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200588 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200589 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200590 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100591 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700592 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100593 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100594 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100595 event = OPN_IGNR;
596 else
597 event = OPN_ACPT;
598 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700599 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100600 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100601 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100602 event = CNF_IGNR;
603 else
604 event = CNF_ACPT;
605 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700606 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700607 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100608 /* Do not check for llid or plid. This does not
609 * follow the standard but since multiple plinks
610 * per sta are not supported, it is necessary in
611 * order to avoid a livelock when MP A sees an
612 * establish peer link to MP B but MP B does not
613 * see it. This can be caused by a timeout in
614 * B's peer link establishment or B beign
615 * restarted.
616 */
617 event = CLS_ACPT;
618 else if (sta->plid != plid)
619 event = CLS_IGNR;
620 else if (ie_len == 7 && sta->llid != llid)
621 event = CLS_IGNR;
622 else
623 event = CLS_ACPT;
624 break;
625 default:
626 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200627 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100628 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100629 return;
630 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200631 } else {
632 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100633 }
634
Rui Paulo1460dd12009-11-09 23:46:48 +0000635 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
636 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700637 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
638 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100639 reason = 0;
640 switch (sta->plink_state) {
641 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700642 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100643 switch (event) {
644 case CLS_ACPT:
645 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200646 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100647 break;
648 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700649 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100650 sta->plid = plid;
651 get_random_bytes(&llid, 2);
652 sta->llid = llid;
653 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200654 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700655 mesh_plink_frame_tx(sdata,
656 WLAN_SP_MESH_PEERING_OPEN,
657 sta->sta.addr, llid, 0, 0);
658 mesh_plink_frame_tx(sdata,
659 WLAN_SP_MESH_PEERING_CONFIRM,
660 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100661 break;
662 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200663 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100664 break;
665 }
666 break;
667
Javier Cardona57cf8042011-05-13 10:45:43 -0700668 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100669 switch (event) {
670 case OPN_RJCT:
671 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700672 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100673 case CLS_ACPT:
674 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700675 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100676 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700677 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100678 if (!mod_plink_timer(sta,
679 dot11MeshHoldingTimeout(sdata)))
680 sta->ignore_plink_timer = true;
681
682 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200683 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700684 mesh_plink_frame_tx(sdata,
685 WLAN_SP_MESH_PEERING_CLOSE,
686 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100687 break;
688 case OPN_ACPT:
689 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700690 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100691 sta->plid = plid;
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 Coboc3896d2c2008-02-23 15:17:13 +0100697 break;
698 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700699 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100700 if (!mod_plink_timer(sta,
701 dot11MeshConfirmTimeout(sdata)))
702 sta->ignore_plink_timer = true;
703
Johannes Berg07346f812008-05-03 01:02:02 +0200704 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100705 break;
706 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200707 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100708 break;
709 }
710 break;
711
Javier Cardona57cf8042011-05-13 10:45:43 -0700712 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100713 switch (event) {
714 case OPN_RJCT:
715 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700716 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100717 case CLS_ACPT:
718 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700719 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100720 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700721 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100722 if (!mod_plink_timer(sta,
723 dot11MeshHoldingTimeout(sdata)))
724 sta->ignore_plink_timer = true;
725
726 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200727 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700728 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
729 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100730 break;
731 case OPN_ACPT:
732 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200733 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700734 mesh_plink_frame_tx(sdata,
735 WLAN_SP_MESH_PEERING_CONFIRM,
736 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100737 break;
738 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100739 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700740 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200741 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400742 mesh_plink_inc_estab_count(sdata);
743 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700744 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
745 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100746 break;
747 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200748 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100749 break;
750 }
751 break;
752
Javier Cardona57cf8042011-05-13 10:45:43 -0700753 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100754 switch (event) {
755 case OPN_RJCT:
756 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700757 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100758 case CLS_ACPT:
759 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700760 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100761 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700762 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100763 if (!mod_plink_timer(sta,
764 dot11MeshHoldingTimeout(sdata)))
765 sta->ignore_plink_timer = true;
766
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_CLOSE,
771 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100772 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100773 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100774 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700775 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200776 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400777 mesh_plink_inc_estab_count(sdata);
778 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700779 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
780 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700781 mesh_plink_frame_tx(sdata,
782 WLAN_SP_MESH_PEERING_CONFIRM,
783 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100784 break;
785 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200786 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100787 break;
788 }
789 break;
790
Javier Cardona57cf8042011-05-13 10:45:43 -0700791 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100792 switch (event) {
793 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700794 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100795 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400796 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700797 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100798 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100799 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200800 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400801 if (deactivated)
802 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700803 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
804 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100805 break;
806 case OPN_ACPT:
807 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200808 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700809 mesh_plink_frame_tx(sdata,
810 WLAN_SP_MESH_PEERING_CONFIRM,
811 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100812 break;
813 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200814 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100815 break;
816 }
817 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700818 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100819 switch (event) {
820 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100821 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100822 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100823 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200824 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100825 break;
826 case OPN_ACPT:
827 case CNF_ACPT:
828 case OPN_RJCT:
829 case CNF_RJCT:
830 llid = sta->llid;
831 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200832 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700833 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
834 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100835 break;
836 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200837 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100838 }
839 break;
840 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800841 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800842 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100843 */
Johannes Berg07346f812008-05-03 01:02:02 +0200844 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100845 break;
846 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100847
848 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100849}