blob: c2af7b3d03cd2cfe8581bcdf35dfef85e8f0589f [file] [log] [blame]
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +01003 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/gfp.h>
Johannes Berg902acc72008-02-23 15:17:19 +010010#include <linux/kernel.h>
11#include <linux/random.h>
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010012#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010014#include "mesh.h"
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010015
16#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
18#else
19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
20#endif
21
Thomas Pedersen8db09852011-08-12 20:01:00 -070022#define PLINK_GET_LLID(p) (p + 2)
23#define PLINK_GET_PLID(p) (p + 4)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010024
25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000))
27
Johannes Berg472dbc42008-09-11 00:01:49 +020028#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
29#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
30#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
31#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
32#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010033
Ashok 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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-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 Coboc3896d2c2008-02-23 15:17:13 +010082}
83
Johannes Berg93e5deb2008-04-01 15:21:00 +020084/*
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -070085 * Allocate mesh sta entry and insert into station table
Johannes Berg93e5deb2008-04-01 15:21:00 +020086 */
Johannes Berg03e44972008-02-27 09:56:40 +010087static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -070088 u8 *hw_addr)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010089{
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010090 struct sta_info *sta;
91
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -070092 if (sdata->local->num_sta >= MESH_MAX_PLINKS)
Johannes Berg73651ee2008-02-25 16:27:47 +010093 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010094
Johannes Berg34e89502010-02-03 13:59:58 +010095 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +010096 if (!sta)
97 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +010098
Johannes Berg83d5cc02012-01-12 09:31:10 +010099 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
100 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
101 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100102
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200103 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100104
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700105 if (sta_info_insert(sta))
106 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100107
108 return sta;
109}
110
111/**
John W. Linvillec9370192010-06-21 17:14:07 -0400112 * __mesh_plink_deactivate - deactivate mesh peer link
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100113 *
114 * @sta: mesh peer link to deactivate
115 *
116 * All mesh paths with this peer as next hop will be flushed
117 *
Johannes Berg07346f812008-05-03 01:02:02 +0200118 * Locking: the caller must hold sta->lock
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100119 */
John W. Linvillec9370192010-06-21 17:14:07 -0400120static bool __mesh_plink_deactivate(struct sta_info *sta)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100121{
Johannes Bergd0709a62008-02-25 16:27:46 +0100122 struct ieee80211_sub_if_data *sdata = sta->sdata;
John W. Linvillec9370192010-06-21 17:14:07 -0400123 bool deactivated = false;
Johannes Bergd0709a62008-02-25 16:27:46 +0100124
Javier Cardona57cf8042011-05-13 10:45:43 -0700125 if (sta->plink_state == NL80211_PLINK_ESTAB) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100126 mesh_plink_dec_estab_count(sdata);
John W. Linvillec9370192010-06-21 17:14:07 -0400127 deactivated = true;
128 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700129 sta->plink_state = NL80211_PLINK_BLOCKED;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100130 mesh_path_flush_by_nexthop(sta);
John W. Linvillec9370192010-06-21 17:14:07 -0400131
132 return deactivated;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100133}
134
Johannes Berg902acc72008-02-23 15:17:19 +0100135/**
John W. Linvillec9370192010-06-21 17:14:07 -0400136 * mesh_plink_deactivate - deactivate mesh peer link
Johannes Berg902acc72008-02-23 15:17:19 +0100137 *
138 * @sta: mesh peer link to deactivate
139 *
140 * All mesh paths with this peer as next hop will be flushed
141 */
142void mesh_plink_deactivate(struct sta_info *sta)
143{
John W. Linvillec9370192010-06-21 17:14:07 -0400144 struct ieee80211_sub_if_data *sdata = sta->sdata;
145 bool deactivated;
146
Johannes Berg07346f812008-05-03 01:02:02 +0200147 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400148 deactivated = __mesh_plink_deactivate(sta);
Thomas Pedersenba4a14e2011-09-20 13:43:32 -0700149 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
150 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
151 sta->sta.addr, sta->llid, sta->plid,
152 sta->reason);
Johannes Berg07346f812008-05-03 01:02:02 +0200153 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400154
155 if (deactivated)
156 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +0100157}
158
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200159static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700160 enum ieee80211_self_protected_actioncode action,
161 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200162 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700163 struct sk_buff *skb;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100164 struct ieee80211_mgmt *mgmt;
165 bool include_plid = false;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700166 u16 peering_proto = 0;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700167 u8 *pos, ie_len = 4;
168 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
169 sizeof(mgmt->u.action.u.self_prot);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100170
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800171 skb = dev_alloc_skb(local->tx_headroom +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700172 hdr_len +
173 2 + /* capability info */
174 2 + /* AID */
175 2 + 8 + /* supported rates */
176 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
177 2 + sdata->u.mesh.mesh_id_len +
178 2 + sizeof(struct ieee80211_meshconf_ie) +
Thomas Pedersen176f3602011-10-26 14:47:27 -0700179 2 + sizeof(struct ieee80211_ht_cap) +
Johannes Berg074d46d2012-03-15 19:45:16 +0100180 2 + sizeof(struct ieee80211_ht_operation) +
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700181 2 + 8 + /* peering IE */
182 sdata->u.mesh.ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100183 if (!skb)
184 return -1;
Javier Cardona65e8b0c2012-01-17 18:17:46 -0800185 skb_reserve(skb, local->tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700186 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
187 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700188 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
189 IEEE80211_STYPE_ACTION);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100190 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100191 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Javier Cardona915b5c52011-05-03 16:57:10 -0700192 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700193 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
194 mgmt->u.action.u.self_prot.action_code = action;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100195
Thomas Pedersen8db09852011-08-12 20:01:00 -0700196 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
197 /* capability info */
198 pos = skb_put(skb, 2);
199 memset(pos, 0, 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700200 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
Thomas Pedersen8db09852011-08-12 20:01:00 -0700201 /* AID */
202 pos = skb_put(skb, 2);
Rui Paulo77fa76b2009-11-09 23:46:52 +0000203 memcpy(pos + 2, &plid, 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100204 }
Ashok Nagarajan657c3e02012-04-02 21:21:20 -0700205 if (ieee80211_add_srates_ie(&sdata->vif, skb, true) ||
206 ieee80211_add_ext_srates_ie(&sdata->vif, skb, true) ||
Thomas Pedersen082ebb02011-08-11 19:35:10 -0700207 mesh_add_rsn_ie(skb, sdata) ||
208 mesh_add_meshid_ie(skb, sdata) ||
209 mesh_add_meshconf_ie(skb, sdata))
210 return -1;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700211 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
212 if (mesh_add_meshid_ie(skb, sdata))
213 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100214 }
215
Thomas Pedersen8db09852011-08-12 20:01:00 -0700216 /* Add Mesh Peering Management element */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100217 switch (action) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700218 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100219 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700220 case WLAN_SP_MESH_PEERING_CONFIRM:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700221 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100222 include_plid = true;
223 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700224 case WLAN_SP_MESH_PEERING_CLOSE:
Thomas Pedersen8db09852011-08-12 20:01:00 -0700225 if (plid) {
226 ie_len += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100227 include_plid = true;
228 }
Thomas Pedersen8db09852011-08-12 20:01:00 -0700229 ie_len += 2; /* reason code */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100230 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700231 default:
232 return -EINVAL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100233 }
234
Thomas Pedersen8db09852011-08-12 20:01:00 -0700235 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
236 return -ENOMEM;
237
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100238 pos = skb_put(skb, 2 + ie_len);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700239 *pos++ = WLAN_EID_PEER_MGMT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100240 *pos++ = ie_len;
Thomas Pedersen8db09852011-08-12 20:01:00 -0700241 memcpy(pos, &peering_proto, 2);
242 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100243 memcpy(pos, &llid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700244 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100245 if (include_plid) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100246 memcpy(pos, &plid, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700247 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100248 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700249 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100250 memcpy(pos, &reason, 2);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700251 pos += 2;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100252 }
Thomas Pedersen176f3602011-10-26 14:47:27 -0700253
254 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
255 if (mesh_add_ht_cap_ie(skb, sdata) ||
Johannes Berg074d46d2012-03-15 19:45:16 +0100256 mesh_add_ht_oper_ie(skb, sdata))
Thomas Pedersen176f3602011-10-26 14:47:27 -0700257 return -1;
258 }
259
Thomas Pedersen8db09852011-08-12 20:01:00 -0700260 if (mesh_add_vendor_ies(skb, sdata))
261 return -1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100262
Johannes Berg62ae67b2009-11-18 18:42:05 +0100263 ieee80211_tx_skb(sdata, skb);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100264 return 0;
265}
266
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700267/* mesh_peer_init - initialize new mesh peer and return resulting sta_info
268 *
269 * @sdata: local meshif
270 * @addr: peer's address
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700271 * @elems: IEs from beacon or mesh peering frame
272 *
273 * call under RCU
274 */
275static struct sta_info *mesh_peer_init(struct ieee80211_sub_if_data *sdata,
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700276 u8 *addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700277 struct ieee802_11_elems *elems)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100278{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200279 struct ieee80211_local *local = sdata->local;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700280 enum ieee80211_band band = local->oper_channel->band;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700281 struct ieee80211_supported_band *sband;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700282 u32 rates, basic_rates = 0;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100283 struct sta_info *sta;
284
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700285 sband = local->hw.wiphy->bands[band];
286 rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates);
Johannes Bergd0709a62008-02-25 16:27:46 +0100287
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700288 sta = sta_info_get(sdata, addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100289 if (!sta) {
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700290 sta = mesh_plink_alloc(sdata, addr);
Johannes Berg34e89502010-02-03 13:59:58 +0100291 if (!sta)
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700292 return NULL;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100293 }
294
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700295 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100296 sta->last_rx = jiffies;
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700297 sta->sta.supp_rates[band] = rates;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700298 if (elems->ht_cap_elem)
299 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
300 elems->ht_cap_elem,
301 &sta->sta.ht_cap);
302 else
303 memset(&sta->sta.ht_cap, 0, sizeof(sta->sta.ht_cap));
304
305 rate_control_rate_init(sta);
306 spin_unlock_bh(&sta->lock);
307
308 return sta;
309}
310
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700311void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
312 u8 *hw_addr,
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700313 struct ieee802_11_elems *elems)
314{
315 struct sta_info *sta;
316
317 /* Userspace handles peer allocation when security is enabled */
318 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) {
319 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
320 elems->ie_start,
321 elems->total_len,
322 GFP_KERNEL);
323 return;
324 }
325
326 rcu_read_lock();
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700327 sta = mesh_peer_init(sdata, hw_addr, elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700328 if (!sta)
329 goto out;
330
Javier Cardona1570ca52011-04-07 15:08:35 -0700331 if (mesh_peer_accepts_plinks(elems) &&
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700332 sta->plink_state == NL80211_PLINK_LISTEN &&
333 sdata->u.mesh.accepting_plinks &&
334 sdata->u.mesh.mshcfg.auto_open_plinks &&
335 rssi_threshold_check(sta, sdata))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100336 mesh_plink_open(sta);
337
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700338out:
Johannes Bergd0709a62008-02-25 16:27:46 +0100339 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100340}
341
342static void mesh_plink_timer(unsigned long data)
343{
344 struct sta_info *sta;
345 __le16 llid, plid, reason;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100346 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100347
Johannes Bergd0709a62008-02-25 16:27:46 +0100348 /*
349 * This STA is valid because sta_info_destroy() will
350 * del_timer_sync() this timer after having made sure
351 * it cannot be readded (by deleting the plink.)
352 */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100353 sta = (struct sta_info *) data;
354
Johannes Berg5bb644a2009-05-17 11:40:42 +0200355 if (sta->sdata->local->quiescing) {
356 sta->plink_timer_was_running = true;
357 return;
358 }
359
Johannes Berg07346f812008-05-03 01:02:02 +0200360 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100361 if (sta->ignore_plink_timer) {
362 sta->ignore_plink_timer = false;
Johannes Berg07346f812008-05-03 01:02:02 +0200363 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100364 return;
365 }
Johannes Berg0c68ae262008-10-27 15:56:10 -0700366 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
367 sta->sta.addr, sta->plink_state);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100368 reason = 0;
369 llid = sta->llid;
370 plid = sta->plid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100371 sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100372
373 switch (sta->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700374 case NL80211_PLINK_OPN_RCVD:
375 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100376 /* retry timer */
377 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
378 u32 rand;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700379 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
380 sta->sta.addr, sta->plink_retries,
381 sta->plink_timeout);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100382 get_random_bytes(&rand, sizeof(u32));
383 sta->plink_timeout = sta->plink_timeout +
384 rand % sta->plink_timeout;
385 ++sta->plink_retries;
Johannes Bergd0709a62008-02-25 16:27:46 +0100386 mod_plink_timer(sta, sta->plink_timeout);
Johannes Berg07346f812008-05-03 01:02:02 +0200387 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700388 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
389 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100390 break;
391 }
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700392 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100393 /* fall through on else */
Javier Cardona57cf8042011-05-13 10:45:43 -0700394 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100395 /* confirm timer */
396 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700397 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
Javier Cardona57cf8042011-05-13 10:45:43 -0700398 sta->plink_state = NL80211_PLINK_HOLDING;
Johannes Bergd0709a62008-02-25 16:27:46 +0100399 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200400 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700401 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
402 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100403 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700404 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100405 /* holding timer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100406 del_timer(&sta->plink_timer);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100407 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200408 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100409 break;
410 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200411 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100412 break;
413 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100414}
415
Johannes Berg5bb644a2009-05-17 11:40:42 +0200416#ifdef CONFIG_PM
417void mesh_plink_quiesce(struct sta_info *sta)
418{
419 if (del_timer_sync(&sta->plink_timer))
420 sta->plink_timer_was_running = true;
421}
422
423void mesh_plink_restart(struct sta_info *sta)
424{
425 if (sta->plink_timer_was_running) {
426 add_timer(&sta->plink_timer);
427 sta->plink_timer_was_running = false;
428 }
429}
430#endif
431
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100432static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
433{
434 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
435 sta->plink_timer.data = (unsigned long) sta;
436 sta->plink_timer.function = mesh_plink_timer;
437 sta->plink_timeout = timeout;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100438 add_timer(&sta->plink_timer);
439}
440
441int mesh_plink_open(struct sta_info *sta)
442{
443 __le16 llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100444 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100445
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200446 if (!test_sta_flag(sta, WLAN_STA_AUTH))
Javier Cardona53e80512011-04-07 15:08:32 -0700447 return -EPERM;
448
Johannes Berg07346f812008-05-03 01:02:02 +0200449 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100450 get_random_bytes(&llid, 2);
451 sta->llid = llid;
Javier Cardona57cf8042011-05-13 10:45:43 -0700452 if (sta->plink_state != NL80211_PLINK_LISTEN) {
Johannes Berg07346f812008-05-03 01:02:02 +0200453 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100454 return -EBUSY;
455 }
Javier Cardona57cf8042011-05-13 10:45:43 -0700456 sta->plink_state = NL80211_PLINK_OPN_SNT;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100457 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200458 spin_unlock_bh(&sta->lock);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700459 mpl_dbg("Mesh plink: starting establishment with %pM\n",
460 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100461
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700462 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
Johannes Berg17741cd2008-09-11 00:02:02 +0200463 sta->sta.addr, llid, 0, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100464}
465
466void mesh_plink_block(struct sta_info *sta)
467{
John W. Linvillec9370192010-06-21 17:14:07 -0400468 struct ieee80211_sub_if_data *sdata = sta->sdata;
469 bool deactivated;
470
Johannes Berg07346f812008-05-03 01:02:02 +0200471 spin_lock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400472 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700473 sta->plink_state = NL80211_PLINK_BLOCKED;
Johannes Berg07346f812008-05-03 01:02:02 +0200474 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400475
476 if (deactivated)
477 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100478}
479
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100480
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200481void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100482 size_t len, struct ieee80211_rx_status *rx_status)
483{
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100484 struct ieee802_11_elems elems;
485 struct sta_info *sta;
486 enum plink_event event;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700487 enum ieee80211_self_protected_actioncode ftype;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100488 size_t baselen;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200489 bool deactivated, matches_local = true;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100490 u8 ie_len;
491 u8 *baseaddr;
492 __le16 plid, llid, reason;
Rui Paulo1460dd12009-11-09 23:46:48 +0000493#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
494 static const char *mplstates[] = {
Javier Cardona57cf8042011-05-13 10:45:43 -0700495 [NL80211_PLINK_LISTEN] = "LISTEN",
496 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
497 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
498 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
499 [NL80211_PLINK_ESTAB] = "ESTAB",
500 [NL80211_PLINK_HOLDING] = "HOLDING",
501 [NL80211_PLINK_BLOCKED] = "BLOCKED"
Rui Paulo1460dd12009-11-09 23:46:48 +0000502 };
503#endif
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100504
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200505 /* need action_code, aux */
506 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
507 return;
508
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100509 if (is_multicast_ether_addr(mgmt->da)) {
510 mpl_dbg("Mesh plink: ignore frame from multicast address");
511 return;
512 }
513
Thomas Pedersen8db09852011-08-12 20:01:00 -0700514 baseaddr = mgmt->u.action.u.self_prot.variable;
515 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
516 if (mgmt->u.action.u.self_prot.action_code ==
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700517 WLAN_SP_MESH_PEERING_CONFIRM) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100518 baseaddr += 4;
David Woo70bdb6b2009-08-12 11:03:44 -0700519 baselen += 4;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100520 }
521 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
Thomas Pedersen8db09852011-08-12 20:01:00 -0700522 if (!elems.peering) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100523 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
524 return;
525 }
Javier Cardonab130e5c2011-05-03 16:57:07 -0700526 if (elems.rsn_len &&
527 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
Javier Cardona5cff5e02011-04-07 15:08:29 -0700528 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
529 return;
530 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100531
Thomas Pedersen8db09852011-08-12 20:01:00 -0700532 ftype = mgmt->u.action.u.self_prot.action_code;
533 ie_len = elems.peering_len;
534 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
535 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
536 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
537 && ie_len != 8)) {
Rui Paulo09383932009-11-09 23:46:43 +0000538 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
539 ftype, ie_len);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100540 return;
541 }
542
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700543 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
544 (!elems.mesh_id || !elems.mesh_config)) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100545 mpl_dbg("Mesh plink: missing necessary ie\n");
546 return;
547 }
548 /* Note the lines below are correct, the llid in the frame is the plid
549 * from the point of view of this host.
550 */
Thomas Pedersen8db09852011-08-12 20:01:00 -0700551 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700552 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
Thomas Pedersen8db09852011-08-12 20:01:00 -0700553 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
554 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100555
Johannes Bergd0709a62008-02-25 16:27:46 +0100556 rcu_read_lock();
557
Johannes Bergabe60632009-11-25 17:46:18 +0100558 sta = sta_info_get(sdata, mgmt->sa);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700559 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100560 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100561 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100562 return;
563 }
564
Ashok Nagarajan55335132012-02-28 17:04:08 -0800565 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800566 !rssi_threshold_check(sta, sdata)) {
Ashok Nagarajan55335132012-02-28 17:04:08 -0800567 mpl_dbg("Mesh plink: %pM does not meet rssi threshold\n",
Ashok Nagarajan3d4f9692012-03-06 12:48:30 -0800568 mgmt->sa);
Ashok Nagarajan55335132012-02-28 17:04:08 -0800569 rcu_read_unlock();
570 return;
571 }
572
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200573 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
Javier Cardona53e80512011-04-07 15:08:32 -0700574 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
575 rcu_read_unlock();
576 return;
577 }
578
Javier Cardona57cf8042011-05-13 10:45:43 -0700579 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100580 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100581 return;
582 }
583
584 /* Now we will figure out the appropriate event... */
585 event = PLINK_UNDEFINED;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700586 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700587 !mesh_matches_local(sdata, &elems)) {
Christian Lamparterd12c7452010-10-08 22:27:07 +0200588 matches_local = false;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100589 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700590 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100591 event = OPN_RJCT;
592 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700593 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100594 event = CNF_RJCT;
595 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700596 default:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100597 break;
598 }
Christian Lamparterd12c7452010-10-08 22:27:07 +0200599 }
600
601 if (!sta && !matches_local) {
602 rcu_read_unlock();
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700603 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200604 llid = 0;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700605 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
606 mgmt->sa, llid, plid, reason);
Christian Lamparterd12c7452010-10-08 22:27:07 +0200607 return;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100608 } else if (!sta) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700609 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100610 if (!mesh_plink_free_count(sdata)) {
611 mpl_dbg("Mesh plink error: no more free plinks\n");
Johannes Berg73651ee2008-02-25 16:27:47 +0100612 rcu_read_unlock();
613 return;
614 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100615 event = OPN_ACPT;
Christian Lamparterd12c7452010-10-08 22:27:07 +0200616 } else if (matches_local) {
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100617 switch (ftype) {
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700618 case WLAN_SP_MESH_PEERING_OPEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100619 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100620 (sta->plid && sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100621 event = OPN_IGNR;
622 else
623 event = OPN_ACPT;
624 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700625 case WLAN_SP_MESH_PEERING_CONFIRM:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100626 if (!mesh_plink_free_count(sdata) ||
Johannes Bergd0709a62008-02-25 16:27:46 +0100627 (sta->llid != llid || sta->plid != plid))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100628 event = CNF_IGNR;
629 else
630 event = CNF_ACPT;
631 break;
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700632 case WLAN_SP_MESH_PEERING_CLOSE:
Javier Cardona57cf8042011-05-13 10:45:43 -0700633 if (sta->plink_state == NL80211_PLINK_ESTAB)
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100634 /* Do not check for llid or plid. This does not
635 * follow the standard but since multiple plinks
636 * per sta are not supported, it is necessary in
637 * order to avoid a livelock when MP A sees an
638 * establish peer link to MP B but MP B does not
639 * see it. This can be caused by a timeout in
640 * B's peer link establishment or B beign
641 * restarted.
642 */
643 event = CLS_ACPT;
644 else if (sta->plid != plid)
645 event = CLS_IGNR;
646 else if (ie_len == 7 && sta->llid != llid)
647 event = CLS_IGNR;
648 else
649 event = CLS_ACPT;
650 break;
651 default:
652 mpl_dbg("Mesh plink: unknown frame subtype\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100653 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100654 return;
655 }
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700656 }
657
658 if (event == OPN_ACPT) {
659 /* allocate sta entry if necessary and update info */
Thomas Pedersenf743ff42012-04-18 19:23:43 -0700660 sta = mesh_peer_init(sdata, mgmt->sa, &elems);
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700661 if (!sta) {
662 mpl_dbg("Mesh plink: failed to init peer!\n");
663 rcu_read_unlock();
664 return;
665 }
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100666 }
667
Rui Paulo1460dd12009-11-09 23:46:48 +0000668 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
669 mgmt->sa, mplstates[sta->plink_state],
Johannes Berg0c68ae262008-10-27 15:56:10 -0700670 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
671 event);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100672 reason = 0;
Thomas Pedersen54ab1ff2012-04-18 19:23:42 -0700673 spin_lock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100674 switch (sta->plink_state) {
675 /* spin_unlock as soon as state is updated at each case */
Javier Cardona57cf8042011-05-13 10:45:43 -0700676 case NL80211_PLINK_LISTEN:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100677 switch (event) {
678 case CLS_ACPT:
679 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200680 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100681 break;
682 case OPN_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700683 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100684 sta->plid = plid;
685 get_random_bytes(&llid, 2);
686 sta->llid = llid;
687 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200688 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700689 mesh_plink_frame_tx(sdata,
690 WLAN_SP_MESH_PEERING_OPEN,
691 sta->sta.addr, llid, 0, 0);
692 mesh_plink_frame_tx(sdata,
693 WLAN_SP_MESH_PEERING_CONFIRM,
694 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100695 break;
696 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200697 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100698 break;
699 }
700 break;
701
Javier Cardona57cf8042011-05-13 10:45:43 -0700702 case NL80211_PLINK_OPN_SNT:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100703 switch (event) {
704 case OPN_RJCT:
705 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700706 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100707 case CLS_ACPT:
708 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700709 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100710 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700711 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100712 if (!mod_plink_timer(sta,
713 dot11MeshHoldingTimeout(sdata)))
714 sta->ignore_plink_timer = true;
715
716 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200717 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700718 mesh_plink_frame_tx(sdata,
719 WLAN_SP_MESH_PEERING_CLOSE,
720 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100721 break;
722 case OPN_ACPT:
723 /* retry timer is left untouched */
Javier Cardona57cf8042011-05-13 10:45:43 -0700724 sta->plink_state = NL80211_PLINK_OPN_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100725 sta->plid = plid;
726 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200727 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700728 mesh_plink_frame_tx(sdata,
729 WLAN_SP_MESH_PEERING_CONFIRM,
730 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100731 break;
732 case CNF_ACPT:
Javier Cardona57cf8042011-05-13 10:45:43 -0700733 sta->plink_state = NL80211_PLINK_CNF_RCVD;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100734 if (!mod_plink_timer(sta,
735 dot11MeshConfirmTimeout(sdata)))
736 sta->ignore_plink_timer = true;
737
Johannes Berg07346f812008-05-03 01:02:02 +0200738 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100739 break;
740 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200741 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100742 break;
743 }
744 break;
745
Javier Cardona57cf8042011-05-13 10:45:43 -0700746 case NL80211_PLINK_OPN_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100747 switch (event) {
748 case OPN_RJCT:
749 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700750 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100751 case CLS_ACPT:
752 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700753 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100754 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700755 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100756 if (!mod_plink_timer(sta,
757 dot11MeshHoldingTimeout(sdata)))
758 sta->ignore_plink_timer = true;
759
760 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200761 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700762 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
763 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100764 break;
765 case OPN_ACPT:
766 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200767 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700768 mesh_plink_frame_tx(sdata,
769 WLAN_SP_MESH_PEERING_CONFIRM,
770 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100771 break;
772 case CNF_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100773 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700774 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200775 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400776 mesh_plink_inc_estab_count(sdata);
777 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700778 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
779 sta->sta.addr);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100780 break;
781 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200782 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100783 break;
784 }
785 break;
786
Javier Cardona57cf8042011-05-13 10:45:43 -0700787 case NL80211_PLINK_CNF_RCVD:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100788 switch (event) {
789 case OPN_RJCT:
790 case CNF_RJCT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700791 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100792 case CLS_ACPT:
793 if (!reason)
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700794 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100795 sta->reason = reason;
Javier Cardona57cf8042011-05-13 10:45:43 -0700796 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100797 if (!mod_plink_timer(sta,
798 dot11MeshHoldingTimeout(sdata)))
799 sta->ignore_plink_timer = true;
800
801 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200802 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700803 mesh_plink_frame_tx(sdata,
804 WLAN_SP_MESH_PEERING_CLOSE,
805 sta->sta.addr, llid, plid, reason);
Johannes Bergff59dc72008-02-25 10:11:50 +0100806 break;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100807 case OPN_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100808 del_timer(&sta->plink_timer);
Javier Cardona57cf8042011-05-13 10:45:43 -0700809 sta->plink_state = NL80211_PLINK_ESTAB;
Johannes Berg07346f812008-05-03 01:02:02 +0200810 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400811 mesh_plink_inc_estab_count(sdata);
812 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Johannes Berg0c68ae262008-10-27 15:56:10 -0700813 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
814 sta->sta.addr);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700815 mesh_plink_frame_tx(sdata,
816 WLAN_SP_MESH_PEERING_CONFIRM,
817 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100818 break;
819 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200820 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100821 break;
822 }
823 break;
824
Javier Cardona57cf8042011-05-13 10:45:43 -0700825 case NL80211_PLINK_ESTAB:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100826 switch (event) {
827 case CLS_ACPT:
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700828 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100829 sta->reason = reason;
John W. Linvillec9370192010-06-21 17:14:07 -0400830 deactivated = __mesh_plink_deactivate(sta);
Javier Cardona57cf8042011-05-13 10:45:43 -0700831 sta->plink_state = NL80211_PLINK_HOLDING;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100832 llid = sta->llid;
Johannes Bergd0709a62008-02-25 16:27:46 +0100833 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
Johannes Berg07346f812008-05-03 01:02:02 +0200834 spin_unlock_bh(&sta->lock);
John W. Linvillec9370192010-06-21 17:14:07 -0400835 if (deactivated)
836 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700837 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
838 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100839 break;
840 case OPN_ACPT:
841 llid = sta->llid;
Johannes Berg07346f812008-05-03 01:02:02 +0200842 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700843 mesh_plink_frame_tx(sdata,
844 WLAN_SP_MESH_PEERING_CONFIRM,
845 sta->sta.addr, llid, plid, 0);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100846 break;
847 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200848 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100849 break;
850 }
851 break;
Javier Cardona57cf8042011-05-13 10:45:43 -0700852 case NL80211_PLINK_HOLDING:
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100853 switch (event) {
854 case CLS_ACPT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100855 if (del_timer(&sta->plink_timer))
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100856 sta->ignore_plink_timer = 1;
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100857 mesh_plink_fsm_restart(sta);
Johannes Berg07346f812008-05-03 01:02:02 +0200858 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100859 break;
860 case OPN_ACPT:
861 case CNF_ACPT:
862 case OPN_RJCT:
863 case CNF_RJCT:
864 llid = sta->llid;
865 reason = sta->reason;
Johannes Berg07346f812008-05-03 01:02:02 +0200866 spin_unlock_bh(&sta->lock);
Thomas Pedersen54ef6562011-08-11 19:35:12 -0700867 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
868 sta->sta.addr, llid, plid, reason);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100869 break;
870 default:
Johannes Berg07346f812008-05-03 01:02:02 +0200871 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100872 }
873 break;
874 default:
Luis Carlos Cobob4e08ea2008-02-29 15:46:08 -0800875 /* should not get here, PLINK_BLOCKED is dealt with at the
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800876 * beginning of the function
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100877 */
Johannes Berg07346f812008-05-03 01:02:02 +0200878 spin_unlock_bh(&sta->lock);
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100879 break;
880 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100881
882 rcu_read_unlock();
Luis Carlos Coboc3896d2c2008-02-23 15:17:13 +0100883}