blob: 9c836e774fbd8e11cbf93707f641bebc62c46cf3 [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 Pedersenba4a14e2011-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 Pedersenba4a14e2011-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) +
Johannes Berg074d46d2012-03-15 19:45:16 +0100190 2 + sizeof(struct ieee80211_ht_operation) +
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 }
Ashok Nagarajan657c3e02012-04-02 21:21:20 -0700215 if (ieee80211_add_srates_ie(&sdata->vif, skb, true) ||
216 ieee80211_add_ext_srates_ie(&sdata->vif, skb, true) ||
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) ||
Johannes Berg074d46d2012-03-15 19:45:16 +0100266 mesh_add_ht_oper_ie(skb, sdata))
Thomas Pedersen176f3602011-10-26 14:47:27 -0700267 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;
Ashok Nagarajan9ebb61a2012-04-02 21:21:21 -0700468 u32 rates, basic_rates = 0;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100469 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000470#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
471 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700472 [NL80211_PLINK_LISTEN] = "LISTEN",
473 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
474 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
475 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
476 [NL80211_PLINK_ESTAB] = "ESTAB",
477 [NL80211_PLINK_HOLDING] = "HOLDING",
478 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000479 };
480#endif
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100481
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200482 /* need action_code, aux */
483 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
484 return;
485
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100486 if (is_multicast_ether_addr(mgmt->da)) {
487 mpl_dbg("Mesh plink: ignore frame from multicast address");
488 return;
489 }
490
Thomas Pedersen8db09852011-08-12 20:01:00 -0700491 baseaddr = mgmt->u.action.u.self_prot.variable;
492 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
493 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700494 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100495 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700496 baselen += 4;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100497 }
498 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700499 if (!elems.peering) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100500 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
501 return;
502 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700503 if (elems.rsn_len &&
504 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700505 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
506 return;
507 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100508
Thomas Pedersen8db09852011-08-12 20:01:00 -0700509 ftype = mgmt->u.action.u.self_prot.action_code;
510 ie_len = elems.peering_len;
511 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
512 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
513 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
514 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000515 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
516 ftype, ie_len);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100517 return;
518 }
519
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700520 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
521 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100522 mpl_dbg("Mesh plink: missing necessary ie\n");
523 return;
524 }
525 /* Note the lines below are correct, the llid in the frame is the plid
526 * from the point of view of this host.
527 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700528 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700529 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700530 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
531 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100532
Johannes Bergd0709a62008-02-25 16:27:46 +0100533 rcu_read_lock();
534
Johannes Bergabe60632009-11-25 17:46:18 +0100535 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700536 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100537 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100538 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100539 return;
540 }
541
Ashok Nagarajan55335132012-02-28 17:04:08 -0800542 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800543 !rssi_threshold_check(sta, sdata)) {
Ashok Nagarajan55335132012-02-28 17:04:08 -0800544 mpl_dbg("Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800545 mgmt->sa);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800546 rcu_read_unlock();
547 return;
548 }
549
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200550 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700551 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
552 rcu_read_unlock();
553 return;
554 }
555
Javier Cardona57cf8042011-05-13 10:45:43 -0700556 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100557 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100558 return;
559 }
560
561 /* Now we will figure out the appropriate event... */
562 event = PLINK_UNDEFINED;
Ashok Nagarajan9ebb61a2012-04-02 21:21:21 -0700563 rates = ieee80211_sta_get_rates(local, &elems,
564 rx_status->band, &basic_rates);
565
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700566 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Ashok Nagarajanfe40cb62012-04-02 21:21:22 -0700567 (!mesh_matches_local(&elems, sdata, basic_rates))) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200568 matches_local = false;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100569 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700570 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100571 event = OPN_RJCT;
572 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700573 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100574 event = CNF_RJCT;
575 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700576 default:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100577 break;
578 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200579 }
580
581 if (!sta && !matches_local) {
582 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700583 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200584 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700585 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
586 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200587 return;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100588 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700589 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Johannes Berg34e89502010-02-03 13:59:58 +0100590
591 rcu_read_unlock();
592
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100593 if (!mesh_plink_free_count(sdata)) {
594 mpl_dbg("Mesh plink error: no more free plinks\n");
595 return;
596 }
Thomas Pedersen739522b2011-10-26 14:47:28 -0700597 sta = mesh_plink_alloc(sdata, mgmt->sa, rates, &elems);
Johannes Berg73651ee2008-02-25 16:27:47 +0100598 if (!sta) {
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100599 mpl_dbg("Mesh plink error: plink table full\n");
600 return;
601 }
Johannes Berg34e89502010-02-03 13:59:58 +0100602 if (sta_info_insert_rcu(sta)) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100603 rcu_read_unlock();
604 return;
605 }
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100606 event = OPN_ACPT;
Johannes Berg07346f812008-05-03 01:02:02 +0200607 spin_lock_bh(&sta->lock);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200608 } else if (matches_local) {
Johannes Berg07346f812008-05-03 01:02:02 +0200609 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100610 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700611 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100612 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100613 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100614 event = OPN_IGNR;
615 else
616 event = OPN_ACPT;
617 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700618 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100619 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100620 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100621 event = CNF_IGNR;
622 else
623 event = CNF_ACPT;
624 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700625 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700626 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100627 /* Do not check for llid or plid. This does not
628 * follow the standard but since multiple plinks
629 * per sta are not supported, it is necessary in
630 * order to avoid a livelock when MP A sees an
631 * establish peer link to MP B but MP B does not
632 * see it. This can be caused by a timeout in
633 * B's peer link establishment or B beign
634 * restarted.
635 */
636 event = CLS_ACPT;
637 else if (sta->plid != plid)
638 event = CLS_IGNR;
639 else if (ie_len == 7 && sta->llid != llid)
640 event = CLS_IGNR;
641 else
642 event = CLS_ACPT;
643 break;
644 default:
645 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Berg07346f812008-05-03 01:02:02 +0200646 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +0100647 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100648 return;
649 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200650 } else {
651 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100652 }
653
Rui Paulo1460dd12009-11-09 23:46:48 +0000654 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
655 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700656 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
657 event);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100658 reason = 0;
659 switch (sta->plink_state) {
660 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700661 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100662 switch (event) {
663 case CLS_ACPT:
664 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200665 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100666 break;
667 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700668 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100669 sta->plid = plid;
670 get_random_bytes(&llid, 2);
671 sta->llid = llid;
672 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200673 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700674 mesh_plink_frame_tx(sdata,
675 WLAN_SP_MESH_PEERING_OPEN,
676 sta->sta.addr, llid, 0, 0);
677 mesh_plink_frame_tx(sdata,
678 WLAN_SP_MESH_PEERING_CONFIRM,
679 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100680 break;
681 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200682 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100683 break;
684 }
685 break;
686
Javier Cardona57cf8042011-05-13 10:45:43 -0700687 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100688 switch (event) {
689 case OPN_RJCT:
690 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700691 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100692 case CLS_ACPT:
693 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700694 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100695 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700696 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100697 if (!mod_plink_timer(sta,
698 dot11MeshHoldingTimeout(sdata)))
699 sta->ignore_plink_timer = true;
700
701 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200702 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700703 mesh_plink_frame_tx(sdata,
704 WLAN_SP_MESH_PEERING_CLOSE,
705 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100706 break;
707 case OPN_ACPT:
708 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700709 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100710 sta->plid = plid;
711 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200712 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700713 mesh_plink_frame_tx(sdata,
714 WLAN_SP_MESH_PEERING_CONFIRM,
715 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100716 break;
717 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700718 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100719 if (!mod_plink_timer(sta,
720 dot11MeshConfirmTimeout(sdata)))
721 sta->ignore_plink_timer = true;
722
Johannes Berg07346f812008-05-03 01:02:02 +0200723 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100724 break;
725 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200726 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100727 break;
728 }
729 break;
730
Javier Cardona57cf8042011-05-13 10:45:43 -0700731 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100732 switch (event) {
733 case OPN_RJCT:
734 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700735 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100736 case CLS_ACPT:
737 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700738 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100739 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700740 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100741 if (!mod_plink_timer(sta,
742 dot11MeshHoldingTimeout(sdata)))
743 sta->ignore_plink_timer = true;
744
745 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200746 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700747 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
748 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100749 break;
750 case OPN_ACPT:
751 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200752 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700753 mesh_plink_frame_tx(sdata,
754 WLAN_SP_MESH_PEERING_CONFIRM,
755 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100756 break;
757 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100758 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700759 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200760 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400761 mesh_plink_inc_estab_count(sdata);
762 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700763 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
764 sta->sta.addr);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100765 break;
766 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200767 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100768 break;
769 }
770 break;
771
Javier Cardona57cf8042011-05-13 10:45:43 -0700772 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100773 switch (event) {
774 case OPN_RJCT:
775 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700776 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100777 case CLS_ACPT:
778 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700779 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100780 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700781 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100782 if (!mod_plink_timer(sta,
783 dot11MeshHoldingTimeout(sdata)))
784 sta->ignore_plink_timer = true;
785
786 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200787 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700788 mesh_plink_frame_tx(sdata,
789 WLAN_SP_MESH_PEERING_CLOSE,
790 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100791 break;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100792 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100793 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700794 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200795 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400796 mesh_plink_inc_estab_count(sdata);
797 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700798 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
799 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700800 mesh_plink_frame_tx(sdata,
801 WLAN_SP_MESH_PEERING_CONFIRM,
802 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100803 break;
804 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200805 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100806 break;
807 }
808 break;
809
Javier Cardona57cf8042011-05-13 10:45:43 -0700810 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100811 switch (event) {
812 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700813 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100814 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400815 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700816 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100817 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100818 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200819 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400820 if (deactivated)
821 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700822 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
823 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100824 break;
825 case OPN_ACPT:
826 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200827 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700828 mesh_plink_frame_tx(sdata,
829 WLAN_SP_MESH_PEERING_CONFIRM,
830 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100831 break;
832 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200833 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100834 break;
835 }
836 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700837 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100838 switch (event) {
839 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100840 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100841 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100842 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200843 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100844 break;
845 case OPN_ACPT:
846 case CNF_ACPT:
847 case OPN_RJCT:
848 case CNF_RJCT:
849 llid = sta->llid;
850 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200851 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700852 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
853 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100854 break;
855 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200856 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100857 }
858 break;
859 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800860 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800861 * beginning of the function
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100862 */
Johannes Berg07346f812008-05-03 01:02:02 +0200863 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100864 break;
865 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100866
867 rcu_read_unlock();
Luis Carlos Coboc3896d22008-02-23 15:17:13 +0100868}