blob: 80ce5277253828dfac0af6d1b6b93e1ec267a74f [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
Ashok Nagarajan55335132012-02-28 17:04:08 -080034#define sta_meets_rssi_threshold(sta, sdata) \
35 (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\
36 (s8) -ewma_read(&sta->avg_signal) > \
37 sdata->u.mesh.mshcfg.rssi_threshold)
38
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010039enum plink_event {
40 PLINK_UNDEFINED,
41 OPN_ACPT,
42 OPN_RJCT,
43 OPN_IGNR,
44 CNF_ACPT,
45 CNF_RJCT,
46 CNF_IGNR,
47 CLS_ACPT,
48 CLS_IGNR
49};
50
Thomas Pedersenba4a14e2011-09-20 13:43:32 -070051static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
52 enum ieee80211_self_protected_actioncode action,
53 u8 *da, __le16 llid, __le16 plid, __le16 reason);
54
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010055static inline
56void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
57{
Johannes Berg472dbc42008-09-11 00:01:49 +020058 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010059 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010060}
61
62static inline
63void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
64{
Johannes Berg472dbc42008-09-11 00:01:49 +020065 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010066 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010067}
68
69/**
70 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
71 *
Rui Paulo23c7a292009-11-09 23:46:42 +000072 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010073 *
Johannes Berg07346f812008-05-03 01:02:02 +020074 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010075 */
76static inline void mesh_plink_fsm_restart(struct sta_info *sta)
77{
Javier Cardona57cf8042011-05-13 10:45:43 -070078 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080079 sta->llid = sta->plid = sta->reason = 0;
80 sta->plink_retries = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010081}
82
Johannes Berg93e5deb2008-04-01 15:21:00 +020083/*
84 * NOTE: This is just an alias for sta_info_alloc(), see notes
85 * on it in the lifecycle management section!
86 */
Johannes Berg03e44972008-02-27 09:56:40 +010087static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen739522b2011-10-26 14:47:28 -070088 u8 *hw_addr, u32 rates,
89 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010090{
Johannes Bergd0709a62008-02-25 16:27:46 +010091 struct ieee80211_local *local = sdata->local;
Thomas Pedersen739522b2011-10-26 14:47:28 -070092 struct ieee80211_supported_band *sband;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010093 struct sta_info *sta;
94
Thomas Pedersen739522b2011-10-26 14:47:28 -070095 sband = local->hw.wiphy->bands[local->oper_channel->band];
96
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010097 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010098 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010099
Johannes Berg34e89502010-02-03 13:59:58 +0100100 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100101 if (!sta)
102 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100103
Johannes Berg83d5cc02012-01-12 09:31:10 +0100104 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
105 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
106 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100107
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200108 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100109
Johannes Berg323ce792008-09-11 02:45:11 +0200110 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Thomas Pedersen739522b2011-10-26 14:47:28 -0700111 if (elems->ht_cap_elem)
Ben Greearef96a8422011-11-18 11:32:00 -0800112 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
113 elems->ht_cap_elem,
Thomas Pedersen739522b2011-10-26 14:47:28 -0700114 &sta->sta.ht_cap);
Christian Lamparterb973c312008-12-27 22:19:49 +0100115 rate_control_rate_init(sta);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100116
117 return sta;
118}
119
120/**
John W. Linvillec9370192010-06-21 17:14:07 -0400121 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100122 *
123 * @sta: mesh peer link to deactivate
124 *
125 * All mesh paths with this peer as next hop will be flushed
126 *
Johannes Berg07346f812008-05-03 01:02:02 +0200127 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100128 */
John W. Linvillec9370192010-06-21 17:14:07 -0400129static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100130{
Johannes Bergd0709a62008-02-25 16:27:46 +0100131 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400132 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100133
Javier Cardona57cf8042011-05-13 10:45:43 -0700134 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100135 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400136 deactivated = true;
137 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700138 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100139 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400140
141 return deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100142}
143
Johannes Berg902acc72008-02-23 15:17:19 +0100144/**
John W. Linvillec9370192010-06-21 17:14:07 -0400145 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100146 *
147 * @sta: mesh peer link to deactivate
148 *
149 * All mesh paths with this peer as next hop will be flushed
150 */
151void mesh_plink_deactivate(struct sta_info *sta)
152{
John W. Linvillec9370192010-06-21 17:14:07 -0400153 struct ieee80211_sub_if_data *sdata = sta->sdata;
154 bool deactivated;
155
Johannes Berg07346f812008-05-03 01:02:02 +0200156 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400157 deactivated = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700158 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
159 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
160 sta->sta.addr, sta->llid, sta->plid,
161 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200162 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400163
164 if (deactivated)
165 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100166}
167
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200168static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700169 enum ieee80211_self_protected_actioncode action,
170 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200171 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700172 struct sk_buff *skb;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100173 struct ieee80211_mgmt *mgmt;
174 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700175 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700176 u8 *pos, ie_len = 4;
177 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
178 sizeof(mgmt->u.action.u.self_prot);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100179
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800180 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700181 hdr_len +
182 2 + /* capability info */
183 2 + /* AID */
184 2 + 8 + /* supported rates */
185 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
186 2 + sdata->u.mesh.mesh_id_len +
187 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700188 2 + sizeof(struct ieee80211_ht_cap) +
189 2 + sizeof(struct ieee80211_ht_info) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700190 2 + 8 + /* peering IE */
191 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100192 if (!skb)
193 return -1;
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800194 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700195 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
196 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700197 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
198 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100199 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100200 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700201 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700202 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
203 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100204
Thomas Pedersen8db09852011-08-12 20:01:00 -0700205 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
206 /* capability info */
207 pos = skb_put(skb, 2);
208 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700209 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700210 /* AID */
211 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000212 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100213 }
Arik Nemtsov768db342011-09-28 14:12:51 +0300214 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
215 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700216 mesh_add_rsn_ie(skb, sdata) ||
217 mesh_add_meshid_ie(skb, sdata) ||
218 mesh_add_meshconf_ie(skb, sdata))
219 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700220 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
221 if (mesh_add_meshid_ie(skb, sdata))
222 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100223 }
224
Thomas Pedersen8db09852011-08-12 20:01:00 -0700225 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100226 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700227 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100228 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700229 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700230 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100231 include_plid = true;
232 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700233 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700234 if (plid) {
235 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100236 include_plid = true;
237 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700238 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100239 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700240 default:
241 return -EINVAL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100242 }
243
Thomas Pedersen8db09852011-08-12 20:01:00 -0700244 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
245 return -ENOMEM;
246
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100247 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700248 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100249 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700250 memcpy(pos, &peering_proto, 2);
251 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100252 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700253 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100254 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100255 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700256 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100257 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700258 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100259 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700260 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100261 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700262
263 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
264 if (mesh_add_ht_cap_ie(skb, sdata) ||
265 mesh_add_ht_info_ie(skb, sdata))
266 return -1;
267 }
268
Thomas Pedersen8db09852011-08-12 20:01:00 -0700269 if (mesh_add_vendor_ies(skb, sdata))
270 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100271
Johannes Berg62ae67b2009-11-18 18:42:05 +0100272 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100273 return 0;
274}
275
Javier Cardona1570ca52011-04-07 15:08:35 -0700276void mesh_neighbour_update(u8 *hw_addr, u32 rates,
277 struct ieee80211_sub_if_data *sdata,
278 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100279{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200280 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100281 struct sta_info *sta;
282
Johannes Bergd0709a62008-02-25 16:27:46 +0100283 rcu_read_lock();
284
Johannes Bergabe60632009-11-25 17:46:18 +0100285 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100286 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100287 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700288 /* Userspace handles peer allocation when security is enabled
289 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700290 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700291 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
292 elems->ie_start, elems->total_len,
293 GFP_KERNEL);
294 else
Thomas Pedersen739522b2011-10-26 14:47:28 -0700295 sta = mesh_plink_alloc(sdata, hw_addr, rates, elems);
Johannes Berg34e89502010-02-03 13:59:58 +0100296 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100297 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100298 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100299 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100300 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100301 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100302 }
303
304 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200305 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700306 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700307 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200308 sdata->u.mesh.accepting_plinks &&
Ashok Nagarajan55335132012-02-28 17:04:08 -0800309 sdata->u.mesh.mshcfg.auto_open_plinks &&
310 sta_meets_rssi_threshold(sta, sdata))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100311 mesh_plink_open(sta);
312
Johannes Bergd0709a62008-02-25 16:27:46 +0100313 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100314}
315
316static void mesh_plink_timer(unsigned long data)
317{
318 struct sta_info *sta;
319 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100320 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100321
Johannes Bergd0709a62008-02-25 16:27:46 +0100322 /*
323 * This STA is valid because sta_info_destroy() will
324 * del_timer_sync() this timer after having made sure
325 * it cannot be readded (by deleting the plink.)
326 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100327 sta = (struct sta_info *) data;
328
Johannes Berg5bb644a2009-05-17 11:40:42 +0200329 if (sta->sdata->local->quiescing) {
330 sta->plink_timer_was_running = true;
331 return;
332 }
333
Johannes Berg07346f812008-05-03 01:02:02 +0200334 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100335 if (sta->ignore_plink_timer) {
336 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200337 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100338 return;
339 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700340 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
341 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100342 reason = 0;
343 llid = sta->llid;
344 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100345 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100346
347 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700348 case NL80211_PLINK_OPN_RCVD:
349 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100350 /* retry timer */
351 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
352 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700353 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
354 sta->sta.addr, sta->plink_retries,
355 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100356 get_random_bytes(&rand, sizeof(u32));
357 sta->plink_timeout = sta->plink_timeout +
358 rand % sta->plink_timeout;
359 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100360 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200361 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700362 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
363 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100364 break;
365 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700366 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100367 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700368 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100369 /* confirm timer */
370 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700371 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700372 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100373 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200374 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700375 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
376 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100377 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700378 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100379 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100380 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100381 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200382 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100383 break;
384 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200385 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100386 break;
387 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100388}
389
Johannes Berg5bb644a2009-05-17 11:40:42 +0200390#ifdef CONFIG_PM
391void mesh_plink_quiesce(struct sta_info *sta)
392{
393 if (del_timer_sync(&sta->plink_timer))
394 sta->plink_timer_was_running = true;
395}
396
397void mesh_plink_restart(struct sta_info *sta)
398{
399 if (sta->plink_timer_was_running) {
400 add_timer(&sta->plink_timer);
401 sta->plink_timer_was_running = false;
402 }
403}
404#endif
405
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100406static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
407{
408 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
409 sta->plink_timer.data = (unsigned long) sta;
410 sta->plink_timer.function = mesh_plink_timer;
411 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100412 add_timer(&sta->plink_timer);
413}
414
415int mesh_plink_open(struct sta_info *sta)
416{
417 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100418 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100419
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200420 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700421 return -EPERM;
422
Johannes Berg07346f812008-05-03 01:02:02 +0200423 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100424 get_random_bytes(&llid, 2);
425 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700426 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200427 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100428 return -EBUSY;
429 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700430 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100431 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200432 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700433 mpl_dbg("Mesh plink: starting establishment with %pM\n",
434 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100435
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700436 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200437 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100438}
439
440void mesh_plink_block(struct sta_info *sta)
441{
John W. Linvillec9370192010-06-21 17:14:07 -0400442 struct ieee80211_sub_if_data *sdata = sta->sdata;
443 bool deactivated;
444
Johannes Berg07346f812008-05-03 01:02:02 +0200445 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400446 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700447 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200448 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400449
450 if (deactivated)
451 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100452}
453
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100454
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200455void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100456 size_t len, struct ieee80211_rx_status *rx_status)
457{
Johannes Bergd0709a62008-02-25 16:27:46 +0100458 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100459 struct ieee802_11_elems elems;
460 struct sta_info *sta;
461 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700462 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100463 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200464 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100465 u8 ie_len;
466 u8 *baseaddr;
467 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000468#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
469 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700470 [NL80211_PLINK_LISTEN] = "LISTEN",
471 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
472 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
473 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
474 [NL80211_PLINK_ESTAB] = "ESTAB",
475 [NL80211_PLINK_HOLDING] = "HOLDING",
476 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000477 };
478#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100479
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200480 /* need action_code, aux */
481 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
482 return;
483
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100484 if (is_multicast_ether_addr(mgmt->da)) {
485 mpl_dbg("Mesh plink: ignore frame from multicast address");
486 return;
487 }
488
Thomas Pedersen8db09852011-08-12 20:01:00 -0700489 baseaddr = mgmt->u.action.u.self_prot.variable;
490 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
491 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700492 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100493 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700494 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100495 }
496 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700497 if (!elems.peering) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100498 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
499 return;
500 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700501 if (elems.rsn_len &&
502 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700503 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
504 return;
505 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100506
Thomas Pedersen8db09852011-08-12 20:01:00 -0700507 ftype = mgmt->u.action.u.self_prot.action_code;
508 ie_len = elems.peering_len;
509 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
510 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
511 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
512 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000513 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
514 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100515 return;
516 }
517
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700518 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
519 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100520 mpl_dbg("Mesh plink: missing necessary ie\n");
521 return;
522 }
523 /* Note the lines below are correct, the llid in the frame is the plid
524 * from the point of view of this host.
525 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700526 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700527 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700528 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
529 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100530
Johannes Bergd0709a62008-02-25 16:27:46 +0100531 rcu_read_lock();
532
Johannes Bergabe60632009-11-25 17:46:18 +0100533 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700534 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100535 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100536 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100537 return;
538 }
539
Ashok Nagarajan55335132012-02-28 17:04:08 -0800540 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
541 !sta_meets_rssi_threshold(sta, sdata)) {
542 mpl_dbg("Mesh plink: %pM does not meet rssi threshold\n",
543 sta->sta.addr);
544 rcu_read_unlock();
545 return;
546 }
547
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200548 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700549 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
550 rcu_read_unlock();
551 return;
552 }
553
Javier Cardona57cf8042011-05-13 10:45:43 -0700554 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100555 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100556 return;
557 }
558
559 /* Now we will figure out the appropriate event... */
560 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700561 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
562 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200563 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100564 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700565 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100566 event = OPN_RJCT;
567 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700568 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100569 event = CNF_RJCT;
570 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700571 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100572 break;
573 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200574 }
575
576 if (!sta && !matches_local) {
577 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700578 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200579 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700580 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
581 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200582 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100583 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700584 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100585 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100586
587 rcu_read_unlock();
588
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100589 if (!mesh_plink_free_count(sdata)) {
590 mpl_dbg("Mesh plink error: no more free plinks\n");
591 return;
592 }
593
594 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Thomas Pedersen739522b2011-10-26 14:47:28 -0700595 sta = mesh_plink_alloc(sdata, mgmt->sa, rates, &elems);
Johannes Berg73651ee2008-02-25 16:27:47 +0100596 if (!sta) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100597 mpl_dbg("Mesh plink error: plink table full\n");
598 return;
599 }
Johannes Berg34e89502010-02-03 13:59:58 +0100600 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100601 rcu_read_unlock();
602 return;
603 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100604 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200605 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200606 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200607 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100608 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700609 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100610 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100611 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100612 event = OPN_IGNR;
613 else
614 event = OPN_ACPT;
615 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700616 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100617 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100618 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100619 event = CNF_IGNR;
620 else
621 event = CNF_ACPT;
622 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700623 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700624 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100625 /* Do not check for llid or plid. This does not
626 * follow the standard but since multiple plinks
627 * per sta are not supported, it is necessary in
628 * order to avoid a livelock when MP A sees an
629 * establish peer link to MP B but MP B does not
630 * see it. This can be caused by a timeout in
631 * B's peer link establishment or B beign
632 * restarted.
633 */
634 event = CLS_ACPT;
635 else if (sta->plid != plid)
636 event = CLS_IGNR;
637 else if (ie_len == 7 && sta->llid != llid)
638 event = CLS_IGNR;
639 else
640 event = CLS_ACPT;
641 break;
642 default:
643 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200644 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100645 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100646 return;
647 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200648 } else {
649 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100650 }
651
Rui Paulo1460dd12009-11-09 23:46:48 +0000652 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
653 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700654 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
655 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100656 reason = 0;
657 switch (sta->plink_state) {
658 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700659 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100660 switch (event) {
661 case CLS_ACPT:
662 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200663 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100664 break;
665 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700666 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100667 sta->plid = plid;
668 get_random_bytes(&llid, 2);
669 sta->llid = llid;
670 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200671 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700672 mesh_plink_frame_tx(sdata,
673 WLAN_SP_MESH_PEERING_OPEN,
674 sta->sta.addr, llid, 0, 0);
675 mesh_plink_frame_tx(sdata,
676 WLAN_SP_MESH_PEERING_CONFIRM,
677 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100678 break;
679 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200680 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100681 break;
682 }
683 break;
684
Javier Cardona57cf8042011-05-13 10:45:43 -0700685 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100686 switch (event) {
687 case OPN_RJCT:
688 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700689 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100690 case CLS_ACPT:
691 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700692 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100693 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700694 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100695 if (!mod_plink_timer(sta,
696 dot11MeshHoldingTimeout(sdata)))
697 sta->ignore_plink_timer = true;
698
699 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200700 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700701 mesh_plink_frame_tx(sdata,
702 WLAN_SP_MESH_PEERING_CLOSE,
703 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100704 break;
705 case OPN_ACPT:
706 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700707 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100708 sta->plid = plid;
709 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200710 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700711 mesh_plink_frame_tx(sdata,
712 WLAN_SP_MESH_PEERING_CONFIRM,
713 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100714 break;
715 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700716 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100717 if (!mod_plink_timer(sta,
718 dot11MeshConfirmTimeout(sdata)))
719 sta->ignore_plink_timer = true;
720
Johannes Berg07346f812008-05-03 01:02:02 +0200721 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100722 break;
723 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200724 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100725 break;
726 }
727 break;
728
Javier Cardona57cf8042011-05-13 10:45:43 -0700729 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100730 switch (event) {
731 case OPN_RJCT:
732 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700733 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100734 case CLS_ACPT:
735 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700736 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100737 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700738 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100739 if (!mod_plink_timer(sta,
740 dot11MeshHoldingTimeout(sdata)))
741 sta->ignore_plink_timer = true;
742
743 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200744 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700745 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
746 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100747 break;
748 case OPN_ACPT:
749 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200750 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700751 mesh_plink_frame_tx(sdata,
752 WLAN_SP_MESH_PEERING_CONFIRM,
753 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100754 break;
755 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100756 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700757 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200758 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400759 mesh_plink_inc_estab_count(sdata);
760 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700761 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
762 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100763 break;
764 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200765 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100766 break;
767 }
768 break;
769
Javier Cardona57cf8042011-05-13 10:45:43 -0700770 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100771 switch (event) {
772 case OPN_RJCT:
773 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700774 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100775 case CLS_ACPT:
776 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700777 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100778 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700779 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100780 if (!mod_plink_timer(sta,
781 dot11MeshHoldingTimeout(sdata)))
782 sta->ignore_plink_timer = true;
783
784 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200785 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700786 mesh_plink_frame_tx(sdata,
787 WLAN_SP_MESH_PEERING_CLOSE,
788 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100789 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100790 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100791 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700792 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200793 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400794 mesh_plink_inc_estab_count(sdata);
795 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700796 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
797 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700798 mesh_plink_frame_tx(sdata,
799 WLAN_SP_MESH_PEERING_CONFIRM,
800 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100801 break;
802 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200803 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100804 break;
805 }
806 break;
807
Javier Cardona57cf8042011-05-13 10:45:43 -0700808 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100809 switch (event) {
810 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700811 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100812 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400813 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700814 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100815 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100816 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200817 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400818 if (deactivated)
819 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700820 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
821 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100822 break;
823 case OPN_ACPT:
824 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200825 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700826 mesh_plink_frame_tx(sdata,
827 WLAN_SP_MESH_PEERING_CONFIRM,
828 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100829 break;
830 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200831 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100832 break;
833 }
834 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700835 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100836 switch (event) {
837 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100838 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100839 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100840 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200841 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100842 break;
843 case OPN_ACPT:
844 case CNF_ACPT:
845 case OPN_RJCT:
846 case CNF_RJCT:
847 llid = sta->llid;
848 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200849 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700850 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
851 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100852 break;
853 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200854 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100855 }
856 break;
857 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800858 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800859 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100860 */
Johannes Berg07346f812008-05-03 01:02:02 +0200861 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100862 break;
863 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100864
865 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100866}