blob: 4e53c4cbca9e5248f26254a261796ffdd5236681 [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
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 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
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -080034/* We only need a valid sta if user configured a minimum rssi_threshold. */
35#define rssi_threshold_check(sta, sdata) \
Ashok Nagarajan55335132012-02-28 17:04:08 -080036 (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -080037 (sta && (s8) -ewma_read(&sta->avg_signal) > \
38 sdata->u.mesh.mshcfg.rssi_threshold))
Ashok Nagarajan55335132012-02-28 17:04:08 -080039
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010040enum plink_event {
41 PLINK_UNDEFINED,
42 OPN_ACPT,
43 OPN_RJCT,
44 OPN_IGNR,
45 CNF_ACPT,
46 CNF_RJCT,
47 CNF_IGNR,
48 CLS_ACPT,
49 CLS_IGNR
50};
51
Thomas Pedersenba4a14e12011-09-20 13:43:32 -070052static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
53 enum ieee80211_self_protected_actioncode action,
54 u8 *da, __le16 llid, __le16 plid, __le16 reason);
55
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010056static inline
57void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
58{
Johannes Berg472dbc42008-09-11 00:01:49 +020059 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010060 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010061}
62
63static inline
64void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
65{
Johannes Berg472dbc42008-09-11 00:01:49 +020066 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
Johannes Bergd0709a62008-02-25 16:27:46 +010067 mesh_accept_plinks_update(sdata);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010068}
69
70/**
71 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
72 *
Rui Paulo23c7a292009-11-09 23:46:42 +000073 * @sta: mesh peer link to restart
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010074 *
Johannes Berg07346f812008-05-03 01:02:02 +020075 * Locking: this function must be called holding sta->lock
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010076 */
77static inline void mesh_plink_fsm_restart(struct sta_info *sta)
78{
Javier Cardona57cf8042011-05-13 10:45:43 -070079 sta->plink_state = NL80211_PLINK_LISTEN;
Luis Carlos Cobo37659ff2008-02-29 12:13:38 -080080 sta->llid = sta->plid = sta->reason = 0;
81 sta->plink_retries = 0;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010082}
83
Johannes Berg93e5deb2008-04-01 15:21:00 +020084/*
85 * NOTE: This is just an alias for sta_info_alloc(), see notes
86 * on it in the lifecycle management section!
87 */
Johannes Berg03e44972008-02-27 09:56:40 +010088static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen739522b2011-10-26 14:47:28 -070089 u8 *hw_addr, u32 rates,
90 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010091{
Johannes Bergd0709a62008-02-25 16:27:46 +010092 struct ieee80211_local *local = sdata->local;
Thomas Pedersen739522b2011-10-26 14:47:28 -070093 struct ieee80211_supported_band *sband;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010094 struct sta_info *sta;
95
Thomas Pedersen739522b2011-10-26 14:47:28 -070096 sband = local->hw.wiphy->bands[local->oper_channel->band];
97
Luis Carlos Coboc3896d22008-02-23 15:17:13 +010098 if (local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010099 return NULL;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100100
Johannes Berg34e89502010-02-03 13:59:58 +0100101 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100102 if (!sta)
103 return NULL;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100104
Johannes Berg83d5cc02012-01-12 09:31:10 +0100105 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
106 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
107 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100108
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200109 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100110
Johannes Berg323ce792008-09-11 02:45:11 +0200111 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Thomas Pedersen739522b2011-10-26 14:47:28 -0700112 if (elems->ht_cap_elem)
Ben Greearef96a8422011-11-18 11:32:00 -0800113 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
114 elems->ht_cap_elem,
Thomas Pedersen739522b2011-10-26 14:47:28 -0700115 &sta->sta.ht_cap);
Christian Lamparterb973c312008-12-27 22:19:49 +0100116 rate_control_rate_init(sta);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100117
118 return sta;
119}
120
121/**
John W. Linvillec9370192010-06-21 17:14:07 -0400122 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100123 *
124 * @sta: mesh peer link to deactivate
125 *
126 * All mesh paths with this peer as next hop will be flushed
127 *
Johannes Berg07346f812008-05-03 01:02:02 +0200128 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100129 */
John W. Linvillec9370192010-06-21 17:14:07 -0400130static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100131{
Johannes Bergd0709a62008-02-25 16:27:46 +0100132 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400133 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100134
Javier Cardona57cf8042011-05-13 10:45:43 -0700135 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100136 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400137 deactivated = true;
138 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700139 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100140 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400141
142 return deactivated;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100143}
144
Johannes Berg902acc72008-02-23 15:17:19 +0100145/**
John W. Linvillec9370192010-06-21 17:14:07 -0400146 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100147 *
148 * @sta: mesh peer link to deactivate
149 *
150 * All mesh paths with this peer as next hop will be flushed
151 */
152void mesh_plink_deactivate(struct sta_info *sta)
153{
John W. Linvillec9370192010-06-21 17:14:07 -0400154 struct ieee80211_sub_if_data *sdata = sta->sdata;
155 bool deactivated;
156
Johannes Berg07346f812008-05-03 01:02:02 +0200157 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400158 deactivated = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e12011-09-20 13:43:32 -0700159 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
160 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
161 sta->sta.addr, sta->llid, sta->plid,
162 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200163 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400164
165 if (deactivated)
166 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100167}
168
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200169static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700170 enum ieee80211_self_protected_actioncode action,
171 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200172 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700173 struct sk_buff *skb;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100174 struct ieee80211_mgmt *mgmt;
175 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700176 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700177 u8 *pos, ie_len = 4;
178 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
179 sizeof(mgmt->u.action.u.self_prot);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100180
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800181 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700182 hdr_len +
183 2 + /* capability info */
184 2 + /* AID */
185 2 + 8 + /* supported rates */
186 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
187 2 + sdata->u.mesh.mesh_id_len +
188 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700189 2 + sizeof(struct ieee80211_ht_cap) +
190 2 + sizeof(struct ieee80211_ht_info) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700191 2 + 8 + /* peering IE */
192 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100193 if (!skb)
194 return -1;
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800195 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700196 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
197 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700198 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
199 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100200 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100201 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700202 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700203 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
204 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100205
Thomas Pedersen8db09852011-08-12 20:01:00 -0700206 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
207 /* capability info */
208 pos = skb_put(skb, 2);
209 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700210 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700211 /* AID */
212 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000213 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100214 }
Arik Nemtsov768db342011-09-28 14:12:51 +0300215 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
216 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700217 mesh_add_rsn_ie(skb, sdata) ||
218 mesh_add_meshid_ie(skb, sdata) ||
219 mesh_add_meshconf_ie(skb, sdata))
220 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700221 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
222 if (mesh_add_meshid_ie(skb, sdata))
223 return -1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100224 }
225
Thomas Pedersen8db09852011-08-12 20:01:00 -0700226 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100227 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700228 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100229 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700230 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700231 ie_len += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100232 include_plid = true;
233 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700234 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700235 if (plid) {
236 ie_len += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100237 include_plid = true;
238 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700239 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100240 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700241 default:
242 return -EINVAL;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100243 }
244
Thomas Pedersen8db09852011-08-12 20:01:00 -0700245 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
246 return -ENOMEM;
247
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100248 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700249 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100250 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700251 memcpy(pos, &peering_proto, 2);
252 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100253 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700254 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100255 if (include_plid) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100256 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700257 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100258 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700259 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100260 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700261 pos += 2;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100262 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700263
264 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
265 if (mesh_add_ht_cap_ie(skb, sdata) ||
266 mesh_add_ht_info_ie(skb, sdata))
267 return -1;
268 }
269
Thomas Pedersen8db09852011-08-12 20:01:00 -0700270 if (mesh_add_vendor_ies(skb, sdata))
271 return -1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100272
Johannes Berg62ae67b2009-11-18 18:42:05 +0100273 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100274 return 0;
275}
276
Javier Cardona1570ca52011-04-07 15:08:35 -0700277void mesh_neighbour_update(u8 *hw_addr, u32 rates,
278 struct ieee80211_sub_if_data *sdata,
279 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100280{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200281 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100282 struct sta_info *sta;
283
Johannes Bergd0709a62008-02-25 16:27:46 +0100284 rcu_read_lock();
285
Johannes Bergabe60632009-11-25 17:46:18 +0100286 sta = sta_info_get(sdata, hw_addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100287 if (!sta) {
Johannes Berg34e89502010-02-03 13:59:58 +0100288 rcu_read_unlock();
Javier Cardona1570ca52011-04-07 15:08:35 -0700289 /* Userspace handles peer allocation when security is enabled
290 * */
Javier Cardonab130e5c2011-05-03 16:57:07 -0700291 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
Javier Cardona1570ca52011-04-07 15:08:35 -0700292 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
293 elems->ie_start, elems->total_len,
294 GFP_KERNEL);
295 else
Thomas Pedersen739522b2011-10-26 14:47:28 -0700296 sta = mesh_plink_alloc(sdata, hw_addr, rates, elems);
Johannes Berg34e89502010-02-03 13:59:58 +0100297 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100298 return;
Johannes Berg34e89502010-02-03 13:59:58 +0100299 if (sta_info_insert_rcu(sta)) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100300 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100301 return;
Johannes Bergd0709a62008-02-25 16:27:46 +0100302 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100303 }
304
305 sta->last_rx = jiffies;
Johannes Berg323ce792008-09-11 02:45:11 +0200306 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Javier Cardona1570ca52011-04-07 15:08:35 -0700307 if (mesh_peer_accepts_plinks(elems) &&
Javier Cardona57cf8042011-05-13 10:45:43 -0700308 sta->plink_state == NL80211_PLINK_LISTEN &&
Johannes Berg472dbc42008-09-11 00:01:49 +0200309 sdata->u.mesh.accepting_plinks &&
Ashok Nagarajan55335132012-02-28 17:04:08 -0800310 sdata->u.mesh.mshcfg.auto_open_plinks &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800311 rssi_threshold_check(sta, sdata))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100312 mesh_plink_open(sta);
313
Johannes Bergd0709a62008-02-25 16:27:46 +0100314 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100315}
316
317static void mesh_plink_timer(unsigned long data)
318{
319 struct sta_info *sta;
320 __le16 llid, plid, reason;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100321 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100322
Johannes Bergd0709a62008-02-25 16:27:46 +0100323 /*
324 * This STA is valid because sta_info_destroy() will
325 * del_timer_sync() this timer after having made sure
326 * it cannot be readded (by deleting the plink.)
327 */
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100328 sta = (struct sta_info *) data;
329
Johannes Berg5bb644a2009-05-17 11:40:42 +0200330 if (sta->sdata->local->quiescing) {
331 sta->plink_timer_was_running = true;
332 return;
333 }
334
Johannes Berg07346f812008-05-03 01:02:02 +0200335 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100336 if (sta->ignore_plink_timer) {
337 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200338 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100339 return;
340 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700341 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
342 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100343 reason = 0;
344 llid = sta->llid;
345 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100346 sdata = sta->sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100347
348 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700349 case NL80211_PLINK_OPN_RCVD:
350 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100351 /* retry timer */
352 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
353 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700354 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
355 sta->sta.addr, sta->plink_retries,
356 sta->plink_timeout);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100357 get_random_bytes(&rand, sizeof(u32));
358 sta->plink_timeout = sta->plink_timeout +
359 rand % sta->plink_timeout;
360 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100361 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200362 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700363 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
364 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100365 break;
366 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700367 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100368 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700369 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100370 /* confirm timer */
371 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700372 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700373 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100374 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200375 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700376 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
377 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100378 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700379 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100380 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100381 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100382 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200383 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100384 break;
385 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200386 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100387 break;
388 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100389}
390
Johannes Berg5bb644a2009-05-17 11:40:42 +0200391#ifdef CONFIG_PM
392void mesh_plink_quiesce(struct sta_info *sta)
393{
394 if (del_timer_sync(&sta->plink_timer))
395 sta->plink_timer_was_running = true;
396}
397
398void mesh_plink_restart(struct sta_info *sta)
399{
400 if (sta->plink_timer_was_running) {
401 add_timer(&sta->plink_timer);
402 sta->plink_timer_was_running = false;
403 }
404}
405#endif
406
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100407static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
408{
409 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
410 sta->plink_timer.data = (unsigned long) sta;
411 sta->plink_timer.function = mesh_plink_timer;
412 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100413 add_timer(&sta->plink_timer);
414}
415
416int mesh_plink_open(struct sta_info *sta)
417{
418 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100419 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100420
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200421 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700422 return -EPERM;
423
Johannes Berg07346f812008-05-03 01:02:02 +0200424 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100425 get_random_bytes(&llid, 2);
426 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700427 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200428 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100429 return -EBUSY;
430 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700431 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100432 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200433 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700434 mpl_dbg("Mesh plink: starting establishment with %pM\n",
435 sta->sta.addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100436
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700437 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200438 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100439}
440
441void mesh_plink_block(struct sta_info *sta)
442{
John W. Linvillec9370192010-06-21 17:14:07 -0400443 struct ieee80211_sub_if_data *sdata = sta->sdata;
444 bool deactivated;
445
Johannes Berg07346f812008-05-03 01:02:02 +0200446 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400447 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700448 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200449 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400450
451 if (deactivated)
452 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100453}
454
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100455
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200456void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100457 size_t len, struct ieee80211_rx_status *rx_status)
458{
Johannes Bergd0709a62008-02-25 16:27:46 +0100459 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100460 struct ieee802_11_elems elems;
461 struct sta_info *sta;
462 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700463 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100464 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200465 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100466 u8 ie_len;
467 u8 *baseaddr;
468 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000469#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
470 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700471 [NL80211_PLINK_LISTEN] = "LISTEN",
472 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
473 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
474 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
475 [NL80211_PLINK_ESTAB] = "ESTAB",
476 [NL80211_PLINK_HOLDING] = "HOLDING",
477 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000478 };
479#endif
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100480
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200481 /* need action_code, aux */
482 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
483 return;
484
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100485 if (is_multicast_ether_addr(mgmt->da)) {
486 mpl_dbg("Mesh plink: ignore frame from multicast address");
487 return;
488 }
489
Thomas Pedersen8db09852011-08-12 20:01:00 -0700490 baseaddr = mgmt->u.action.u.self_prot.variable;
491 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
492 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700493 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100494 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700495 baselen += 4;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100496 }
497 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700498 if (!elems.peering) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100499 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
500 return;
501 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700502 if (elems.rsn_len &&
503 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700504 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
505 return;
506 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100507
Thomas Pedersen8db09852011-08-12 20:01:00 -0700508 ftype = mgmt->u.action.u.self_prot.action_code;
509 ie_len = elems.peering_len;
510 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
511 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
512 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
513 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000514 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
515 ftype, ie_len);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100516 return;
517 }
518
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700519 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
520 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100521 mpl_dbg("Mesh plink: missing necessary ie\n");
522 return;
523 }
524 /* Note the lines below are correct, the llid in the frame is the plid
525 * from the point of view of this host.
526 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700527 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700528 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700529 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
530 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100531
Johannes Bergd0709a62008-02-25 16:27:46 +0100532 rcu_read_lock();
533
Johannes Bergabe60632009-11-25 17:46:18 +0100534 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700535 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100536 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100537 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100538 return;
539 }
540
Ashok Nagarajan55335132012-02-28 17:04:08 -0800541 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800542 !rssi_threshold_check(sta, sdata)) {
Ashok Nagarajan55335132012-02-28 17:04:08 -0800543 mpl_dbg("Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800544 mgmt->sa);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800545 rcu_read_unlock();
546 return;
547 }
548
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200549 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700550 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
551 rcu_read_unlock();
552 return;
553 }
554
Javier Cardona57cf8042011-05-13 10:45:43 -0700555 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100556 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100557 return;
558 }
559
560 /* Now we will figure out the appropriate event... */
561 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700562 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
563 (!mesh_matches_local(&elems, sdata))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200564 matches_local = false;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100565 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700566 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100567 event = OPN_RJCT;
568 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700569 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100570 event = CNF_RJCT;
571 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700572 default:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100573 break;
574 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200575 }
576
577 if (!sta && !matches_local) {
578 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700579 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200580 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700581 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
582 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200583 return;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100584 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700585 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg881d9482009-01-21 15:13:48 +0100586 u32 rates;
Johannes Berg34e89502010-02-03 13:59:58 +0100587
588 rcu_read_unlock();
589
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100590 if (!mesh_plink_free_count(sdata)) {
591 mpl_dbg("Mesh plink error: no more free plinks\n");
592 return;
593 }
594
595 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
Thomas Pedersen739522b2011-10-26 14:47:28 -0700596 sta = mesh_plink_alloc(sdata, mgmt->sa, rates, &elems);
Johannes Berg73651ee2008-02-25 16:27:47 +0100597 if (!sta) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100598 mpl_dbg("Mesh plink error: plink table full\n");
599 return;
600 }
Johannes Berg34e89502010-02-03 13:59:58 +0100601 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100602 rcu_read_unlock();
603 return;
604 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100605 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200606 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200607 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200608 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100609 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700610 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100611 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100612 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100613 event = OPN_IGNR;
614 else
615 event = OPN_ACPT;
616 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700617 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100618 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100619 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100620 event = CNF_IGNR;
621 else
622 event = CNF_ACPT;
623 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700624 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700625 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100626 /* Do not check for llid or plid. This does not
627 * follow the standard but since multiple plinks
628 * per sta are not supported, it is necessary in
629 * order to avoid a livelock when MP A sees an
630 * establish peer link to MP B but MP B does not
631 * see it. This can be caused by a timeout in
632 * B's peer link establishment or B beign
633 * restarted.
634 */
635 event = CLS_ACPT;
636 else if (sta->plid != plid)
637 event = CLS_IGNR;
638 else if (ie_len == 7 && sta->llid != llid)
639 event = CLS_IGNR;
640 else
641 event = CLS_ACPT;
642 break;
643 default:
644 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200645 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100646 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100647 return;
648 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200649 } else {
650 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100651 }
652
Rui Paulo1460dd12009-11-09 23:46:48 +0000653 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
654 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700655 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
656 event);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100657 reason = 0;
658 switch (sta->plink_state) {
659 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700660 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100661 switch (event) {
662 case CLS_ACPT:
663 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200664 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100665 break;
666 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700667 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100668 sta->plid = plid;
669 get_random_bytes(&llid, 2);
670 sta->llid = llid;
671 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200672 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700673 mesh_plink_frame_tx(sdata,
674 WLAN_SP_MESH_PEERING_OPEN,
675 sta->sta.addr, llid, 0, 0);
676 mesh_plink_frame_tx(sdata,
677 WLAN_SP_MESH_PEERING_CONFIRM,
678 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100679 break;
680 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200681 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100682 break;
683 }
684 break;
685
Javier Cardona57cf8042011-05-13 10:45:43 -0700686 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100687 switch (event) {
688 case OPN_RJCT:
689 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700690 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100691 case CLS_ACPT:
692 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700693 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100694 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700695 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100696 if (!mod_plink_timer(sta,
697 dot11MeshHoldingTimeout(sdata)))
698 sta->ignore_plink_timer = true;
699
700 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200701 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700702 mesh_plink_frame_tx(sdata,
703 WLAN_SP_MESH_PEERING_CLOSE,
704 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100705 break;
706 case OPN_ACPT:
707 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700708 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100709 sta->plid = plid;
710 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200711 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700712 mesh_plink_frame_tx(sdata,
713 WLAN_SP_MESH_PEERING_CONFIRM,
714 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100715 break;
716 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700717 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100718 if (!mod_plink_timer(sta,
719 dot11MeshConfirmTimeout(sdata)))
720 sta->ignore_plink_timer = true;
721
Johannes Berg07346f812008-05-03 01:02:02 +0200722 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100723 break;
724 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200725 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100726 break;
727 }
728 break;
729
Javier Cardona57cf8042011-05-13 10:45:43 -0700730 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100731 switch (event) {
732 case OPN_RJCT:
733 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700734 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100735 case CLS_ACPT:
736 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700737 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100738 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700739 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100740 if (!mod_plink_timer(sta,
741 dot11MeshHoldingTimeout(sdata)))
742 sta->ignore_plink_timer = true;
743
744 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200745 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700746 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
747 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100748 break;
749 case OPN_ACPT:
750 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200751 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700752 mesh_plink_frame_tx(sdata,
753 WLAN_SP_MESH_PEERING_CONFIRM,
754 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100755 break;
756 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100757 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700758 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200759 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400760 mesh_plink_inc_estab_count(sdata);
761 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700762 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
763 sta->sta.addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100764 break;
765 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200766 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100767 break;
768 }
769 break;
770
Javier Cardona57cf8042011-05-13 10:45:43 -0700771 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100772 switch (event) {
773 case OPN_RJCT:
774 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700775 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100776 case CLS_ACPT:
777 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700778 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100779 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700780 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100781 if (!mod_plink_timer(sta,
782 dot11MeshHoldingTimeout(sdata)))
783 sta->ignore_plink_timer = true;
784
785 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200786 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700787 mesh_plink_frame_tx(sdata,
788 WLAN_SP_MESH_PEERING_CLOSE,
789 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100790 break;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100791 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100792 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700793 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200794 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400795 mesh_plink_inc_estab_count(sdata);
796 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700797 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
798 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700799 mesh_plink_frame_tx(sdata,
800 WLAN_SP_MESH_PEERING_CONFIRM,
801 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100802 break;
803 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200804 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100805 break;
806 }
807 break;
808
Javier Cardona57cf8042011-05-13 10:45:43 -0700809 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100810 switch (event) {
811 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700812 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100813 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400814 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700815 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100816 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100817 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200818 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400819 if (deactivated)
820 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700821 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
822 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100823 break;
824 case OPN_ACPT:
825 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200826 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700827 mesh_plink_frame_tx(sdata,
828 WLAN_SP_MESH_PEERING_CONFIRM,
829 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100830 break;
831 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200832 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100833 break;
834 }
835 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700836 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100837 switch (event) {
838 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100839 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100840 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100841 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200842 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100843 break;
844 case OPN_ACPT:
845 case CNF_ACPT:
846 case OPN_RJCT:
847 case CNF_RJCT:
848 llid = sta->llid;
849 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200850 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700851 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
852 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100853 break;
854 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200855 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100856 }
857 break;
858 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800859 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800860 * beginning of the function
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100861 */
Johannes Berg07346f812008-05-03 01:02:02 +0200862 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100863 break;
864 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100865
866 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100867}