Commit | Line | Data |
---|---|---|
c3896d2c | 1 | /* |
264d9b7d | 2 | * Copyright (c) 2008, 2009 open80211s Ltd. |
c3896d2c LCC |
3 | * 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 | */ | |
5a0e3ad6 | 9 | #include <linux/gfp.h> |
902acc78 JB |
10 | #include <linux/kernel.h> |
11 | #include <linux/random.h> | |
c3896d2c | 12 | #include "ieee80211_i.h" |
2c8dccc7 | 13 | #include "rate.h" |
c3896d2c | 14 | #include "mesh.h" |
c3896d2c | 15 | |
8db09850 TP |
16 | #define PLINK_GET_LLID(p) (p + 2) |
17 | #define PLINK_GET_PLID(p) (p + 4) | |
c3896d2c LCC |
18 | |
19 | #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \ | |
20 | jiffies + HZ * t / 1000)) | |
21 | ||
3d4f9699 AN |
22 | /* We only need a valid sta if user configured a minimum rssi_threshold. */ |
23 | #define rssi_threshold_check(sta, sdata) \ | |
55335137 | 24 | (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\ |
3d4f9699 AN |
25 | (sta && (s8) -ewma_read(&sta->avg_signal) > \ |
26 | sdata->u.mesh.mshcfg.rssi_threshold)) | |
55335137 | 27 | |
c3896d2c LCC |
28 | enum plink_event { |
29 | PLINK_UNDEFINED, | |
30 | OPN_ACPT, | |
31 | OPN_RJCT, | |
32 | OPN_IGNR, | |
33 | CNF_ACPT, | |
34 | CNF_RJCT, | |
35 | CNF_IGNR, | |
36 | CLS_ACPT, | |
37 | CLS_IGNR | |
38 | }; | |
39 | ||
ba4a14e1 TP |
40 | static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, |
41 | enum ieee80211_self_protected_actioncode action, | |
42 | u8 *da, __le16 llid, __le16 plid, __le16 reason); | |
43 | ||
c3896d2c LCC |
44 | /** |
45 | * mesh_plink_fsm_restart - restart a mesh peer link finite state machine | |
46 | * | |
23c7a29c | 47 | * @sta: mesh peer link to restart |
c3896d2c | 48 | * |
07346f81 | 49 | * Locking: this function must be called holding sta->lock |
c3896d2c LCC |
50 | */ |
51 | static inline void mesh_plink_fsm_restart(struct sta_info *sta) | |
52 | { | |
57cf8043 | 53 | sta->plink_state = NL80211_PLINK_LISTEN; |
37659ff8 LCC |
54 | sta->llid = sta->plid = sta->reason = 0; |
55 | sta->plink_retries = 0; | |
c3896d2c LCC |
56 | } |
57 | ||
2c53040f | 58 | /** |
cbf9322e | 59 | * mesh_set_ht_prot_mode - set correct HT protection mode |
57aac7c5 | 60 | * |
cbf9322e AN |
61 | * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT |
62 | * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT | |
63 | * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is | |
64 | * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode | |
65 | * is selected if all peers in our 20/40MHz MBSS support HT and atleast one | |
66 | * HT20 peer is present. Otherwise no-protection mode is selected. | |
57aac7c5 AN |
67 | */ |
68 | static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata) | |
69 | { | |
70 | struct ieee80211_local *local = sdata->local; | |
71 | struct sta_info *sta; | |
72 | u32 changed = 0; | |
73 | u16 ht_opmode; | |
74 | bool non_ht_sta = false, ht20_sta = false; | |
75 | ||
4bf88530 | 76 | if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) |
57aac7c5 AN |
77 | return 0; |
78 | ||
79 | rcu_read_lock(); | |
80 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | |
cbf9322e AN |
81 | if (sdata != sta->sdata || |
82 | sta->plink_state != NL80211_PLINK_ESTAB) | |
83 | continue; | |
84 | ||
4bf88530 JB |
85 | switch (sta->ch_width) { |
86 | case NL80211_CHAN_WIDTH_20_NOHT: | |
bdcbd8e0 JB |
87 | mpl_dbg(sdata, |
88 | "mesh_plink %pM: nonHT sta (%pM) is present\n", | |
cbf9322e AN |
89 | sdata->vif.addr, sta->sta.addr); |
90 | non_ht_sta = true; | |
91 | goto out; | |
4bf88530 | 92 | case NL80211_CHAN_WIDTH_20: |
bdcbd8e0 JB |
93 | mpl_dbg(sdata, |
94 | "mesh_plink %pM: HT20 sta (%pM) is present\n", | |
cbf9322e AN |
95 | sdata->vif.addr, sta->sta.addr); |
96 | ht20_sta = true; | |
97 | default: | |
98 | break; | |
57aac7c5 AN |
99 | } |
100 | } | |
101 | out: | |
102 | rcu_read_unlock(); | |
103 | ||
104 | if (non_ht_sta) | |
105 | ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED; | |
466f310d | 106 | else if (ht20_sta && |
4bf88530 | 107 | sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20) |
57aac7c5 AN |
108 | ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ; |
109 | else | |
110 | ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; | |
111 | ||
112 | if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { | |
113 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; | |
70c33eaa | 114 | sdata->u.mesh.mshcfg.ht_opmode = ht_opmode; |
57aac7c5 | 115 | changed = BSS_CHANGED_HT; |
bdcbd8e0 JB |
116 | mpl_dbg(sdata, |
117 | "mesh_plink %pM: protection mode changed to %d\n", | |
57aac7c5 AN |
118 | sdata->vif.addr, ht_opmode); |
119 | } | |
120 | ||
121 | return changed; | |
122 | } | |
123 | ||
c3896d2c | 124 | /** |
c9370197 | 125 | * __mesh_plink_deactivate - deactivate mesh peer link |
c3896d2c LCC |
126 | * |
127 | * @sta: mesh peer link to deactivate | |
128 | * | |
129 | * All mesh paths with this peer as next hop will be flushed | |
df323818 | 130 | * Returns beacon changed flag if the beacon content changed. |
c3896d2c | 131 | * |
07346f81 | 132 | * Locking: the caller must hold sta->lock |
c3896d2c | 133 | */ |
df323818 | 134 | static u32 __mesh_plink_deactivate(struct sta_info *sta) |
c3896d2c | 135 | { |
d0709a65 | 136 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
df323818 | 137 | u32 changed = 0; |
d0709a65 | 138 | |
df323818 MP |
139 | if (sta->plink_state == NL80211_PLINK_ESTAB) |
140 | changed = mesh_plink_dec_estab_count(sdata); | |
57cf8043 | 141 | sta->plink_state = NL80211_PLINK_BLOCKED; |
c3896d2c | 142 | mesh_path_flush_by_nexthop(sta); |
c9370197 | 143 | |
df323818 | 144 | return changed; |
c3896d2c LCC |
145 | } |
146 | ||
902acc78 | 147 | /** |
c9370197 | 148 | * mesh_plink_deactivate - deactivate mesh peer link |
902acc78 JB |
149 | * |
150 | * @sta: mesh peer link to deactivate | |
151 | * | |
152 | * All mesh paths with this peer as next hop will be flushed | |
153 | */ | |
154 | void mesh_plink_deactivate(struct sta_info *sta) | |
155 | { | |
c9370197 | 156 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
df323818 | 157 | u32 changed; |
c9370197 | 158 | |
07346f81 | 159 | spin_lock_bh(&sta->lock); |
df323818 | 160 | changed = __mesh_plink_deactivate(sta); |
ba4a14e1 TP |
161 | sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED); |
162 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, | |
163 | sta->sta.addr, sta->llid, sta->plid, | |
164 | sta->reason); | |
07346f81 | 165 | spin_unlock_bh(&sta->lock); |
c9370197 | 166 | |
df323818 | 167 | ieee80211_bss_info_change_notify(sdata, changed); |
902acc78 JB |
168 | } |
169 | ||
f698d856 | 170 | static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, |
54ef656b TP |
171 | enum ieee80211_self_protected_actioncode action, |
172 | u8 *da, __le16 llid, __le16 plid, __le16 reason) { | |
f698d856 | 173 | struct ieee80211_local *local = sdata->local; |
3b69a9c5 | 174 | struct sk_buff *skb; |
e7570dfb | 175 | struct ieee80211_tx_info *info; |
c3896d2c LCC |
176 | struct ieee80211_mgmt *mgmt; |
177 | bool include_plid = false; | |
8db09850 | 178 | u16 peering_proto = 0; |
3b69a9c5 TP |
179 | u8 *pos, ie_len = 4; |
180 | int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) + | |
181 | sizeof(mgmt->u.action.u.self_prot); | |
f609a43d | 182 | int err = -ENOMEM; |
3b69a9c5 | 183 | |
65e8b0cc | 184 | skb = dev_alloc_skb(local->tx_headroom + |
3b69a9c5 TP |
185 | hdr_len + |
186 | 2 + /* capability info */ | |
187 | 2 + /* AID */ | |
188 | 2 + 8 + /* supported rates */ | |
189 | 2 + (IEEE80211_MAX_SUPP_RATES - 8) + | |
190 | 2 + sdata->u.mesh.mesh_id_len + | |
191 | 2 + sizeof(struct ieee80211_meshconf_ie) + | |
176f3608 | 192 | 2 + sizeof(struct ieee80211_ht_cap) + |
074d46d1 | 193 | 2 + sizeof(struct ieee80211_ht_operation) + |
3b69a9c5 TP |
194 | 2 + 8 + /* peering IE */ |
195 | sdata->u.mesh.ie_len); | |
c3896d2c LCC |
196 | if (!skb) |
197 | return -1; | |
e7570dfb | 198 | info = IEEE80211_SKB_CB(skb); |
65e8b0cc | 199 | skb_reserve(skb, local->tx_headroom); |
3b69a9c5 TP |
200 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); |
201 | memset(mgmt, 0, hdr_len); | |
e7827a70 HH |
202 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
203 | IEEE80211_STYPE_ACTION); | |
c3896d2c | 204 | memcpy(mgmt->da, da, ETH_ALEN); |
47846c9b | 205 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
915b5c50 | 206 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); |
8db09850 TP |
207 | mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED; |
208 | mgmt->u.action.u.self_prot.action_code = action; | |
c3896d2c | 209 | |
8db09850 | 210 | if (action != WLAN_SP_MESH_PEERING_CLOSE) { |
55de908a JB |
211 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
212 | ||
8db09850 TP |
213 | /* capability info */ |
214 | pos = skb_put(skb, 2); | |
215 | memset(pos, 0, 2); | |
54ef656b | 216 | if (action == WLAN_SP_MESH_PEERING_CONFIRM) { |
8db09850 TP |
217 | /* AID */ |
218 | pos = skb_put(skb, 2); | |
77fa76bb | 219 | memcpy(pos + 2, &plid, 2); |
c3896d2c | 220 | } |
55de908a JB |
221 | if (ieee80211_add_srates_ie(sdata, skb, true, band) || |
222 | ieee80211_add_ext_srates_ie(sdata, skb, true, band) || | |
082ebb0c TP |
223 | mesh_add_rsn_ie(skb, sdata) || |
224 | mesh_add_meshid_ie(skb, sdata) || | |
225 | mesh_add_meshconf_ie(skb, sdata)) | |
f609a43d | 226 | goto free; |
8db09850 | 227 | } else { /* WLAN_SP_MESH_PEERING_CLOSE */ |
e7570dfb | 228 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
8db09850 | 229 | if (mesh_add_meshid_ie(skb, sdata)) |
f609a43d | 230 | goto free; |
c3896d2c LCC |
231 | } |
232 | ||
8db09850 | 233 | /* Add Mesh Peering Management element */ |
c3896d2c | 234 | switch (action) { |
54ef656b | 235 | case WLAN_SP_MESH_PEERING_OPEN: |
c3896d2c | 236 | break; |
54ef656b | 237 | case WLAN_SP_MESH_PEERING_CONFIRM: |
8db09850 | 238 | ie_len += 2; |
c3896d2c LCC |
239 | include_plid = true; |
240 | break; | |
54ef656b | 241 | case WLAN_SP_MESH_PEERING_CLOSE: |
8db09850 TP |
242 | if (plid) { |
243 | ie_len += 2; | |
c3896d2c LCC |
244 | include_plid = true; |
245 | } | |
8db09850 | 246 | ie_len += 2; /* reason code */ |
c3896d2c | 247 | break; |
8db09850 | 248 | default: |
f609a43d TP |
249 | err = -EINVAL; |
250 | goto free; | |
c3896d2c LCC |
251 | } |
252 | ||
8db09850 | 253 | if (WARN_ON(skb_tailroom(skb) < 2 + ie_len)) |
f609a43d | 254 | goto free; |
8db09850 | 255 | |
c3896d2c | 256 | pos = skb_put(skb, 2 + ie_len); |
8db09850 | 257 | *pos++ = WLAN_EID_PEER_MGMT; |
c3896d2c | 258 | *pos++ = ie_len; |
8db09850 TP |
259 | memcpy(pos, &peering_proto, 2); |
260 | pos += 2; | |
c3896d2c | 261 | memcpy(pos, &llid, 2); |
8db09850 | 262 | pos += 2; |
c3896d2c | 263 | if (include_plid) { |
c3896d2c | 264 | memcpy(pos, &plid, 2); |
8db09850 | 265 | pos += 2; |
c3896d2c | 266 | } |
54ef656b | 267 | if (action == WLAN_SP_MESH_PEERING_CLOSE) { |
c3896d2c | 268 | memcpy(pos, &reason, 2); |
8db09850 | 269 | pos += 2; |
c3896d2c | 270 | } |
176f3608 TP |
271 | |
272 | if (action != WLAN_SP_MESH_PEERING_CLOSE) { | |
273 | if (mesh_add_ht_cap_ie(skb, sdata) || | |
074d46d1 | 274 | mesh_add_ht_oper_ie(skb, sdata)) |
f609a43d | 275 | goto free; |
176f3608 TP |
276 | } |
277 | ||
8db09850 | 278 | if (mesh_add_vendor_ies(skb, sdata)) |
f609a43d | 279 | goto free; |
c3896d2c | 280 | |
62ae67be | 281 | ieee80211_tx_skb(sdata, skb); |
c3896d2c | 282 | return 0; |
f609a43d TP |
283 | free: |
284 | kfree_skb(skb); | |
285 | return err; | |
c3896d2c LCC |
286 | } |
287 | ||
296fcba3 TP |
288 | static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata, |
289 | struct sta_info *sta, | |
290 | struct ieee802_11_elems *elems, bool insert) | |
c3896d2c | 291 | { |
f698d856 | 292 | struct ieee80211_local *local = sdata->local; |
55de908a | 293 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
54ab1ffb | 294 | struct ieee80211_supported_band *sband; |
f68d776a | 295 | u32 rates, basic_rates = 0, changed = 0; |
c3896d2c | 296 | |
f743ff49 TP |
297 | sband = local->hw.wiphy->bands[band]; |
298 | rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates); | |
d0709a65 | 299 | |
54ab1ffb | 300 | spin_lock_bh(&sta->lock); |
c3896d2c | 301 | sta->last_rx = jiffies; |
296fcba3 TP |
302 | |
303 | /* rates and capabilities don't change during peering */ | |
304 | if (sta->plink_state == NL80211_PLINK_ESTAB) | |
305 | goto out; | |
bae35d92 | 306 | |
f68d776a TP |
307 | if (sta->sta.supp_rates[band] != rates) |
308 | changed |= IEEE80211_RC_SUPP_RATES_CHANGED; | |
f743ff49 | 309 | sta->sta.supp_rates[band] = rates; |
e76781e4 | 310 | if (elems->ht_cap_elem && |
4bf88530 | 311 | sdata->vif.bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) |
54ab1ffb TP |
312 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
313 | elems->ht_cap_elem, | |
314 | &sta->sta.ht_cap); | |
315 | else | |
316 | memset(&sta->sta.ht_cap, 0, sizeof(sta->sta.ht_cap)); | |
317 | ||
57aac7c5 | 318 | if (elems->ht_operation) { |
4bf88530 JB |
319 | struct cfg80211_chan_def chandef; |
320 | ||
c7d25828 TP |
321 | if (!(elems->ht_operation->ht_param & |
322 | IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) | |
323 | sta->sta.ht_cap.cap &= | |
324 | ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
4bf88530 JB |
325 | ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan, |
326 | elems->ht_operation, &chandef); | |
f68d776a TP |
327 | if (sta->ch_width != chandef.width) |
328 | changed |= IEEE80211_RC_BW_CHANGED; | |
4bf88530 | 329 | sta->ch_width = chandef.width; |
57aac7c5 | 330 | } |
c7d25828 | 331 | |
59cf1d65 HS |
332 | if (insert) |
333 | rate_control_rate_init(sta); | |
f68d776a TP |
334 | else |
335 | rate_control_rate_update(local, sband, sta, changed); | |
296fcba3 | 336 | out: |
54ab1ffb | 337 | spin_unlock_bh(&sta->lock); |
296fcba3 TP |
338 | } |
339 | ||
340 | static struct sta_info * | |
341 | __mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr) | |
342 | { | |
343 | struct sta_info *sta; | |
54ab1ffb | 344 | |
296fcba3 | 345 | if (sdata->local->num_sta >= MESH_MAX_PLINKS) |
e87278e7 TP |
346 | return NULL; |
347 | ||
296fcba3 TP |
348 | sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL); |
349 | if (!sta) | |
350 | return NULL; | |
351 | ||
352 | sta->plink_state = NL80211_PLINK_LISTEN; | |
353 | init_timer(&sta->plink_timer); | |
354 | ||
355 | sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); | |
356 | sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); | |
357 | sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED); | |
358 | ||
359 | set_sta_flag(sta, WLAN_STA_WME); | |
360 | ||
361 | return sta; | |
362 | } | |
363 | ||
364 | static struct sta_info * | |
365 | mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr, | |
366 | struct ieee802_11_elems *elems) | |
367 | { | |
368 | struct sta_info *sta = NULL; | |
369 | ||
370 | /* Userspace handles peer allocation when security is enabled */ | |
371 | if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) | |
372 | cfg80211_notify_new_peer_candidate(sdata->dev, addr, | |
373 | elems->ie_start, | |
374 | elems->total_len, | |
375 | GFP_KERNEL); | |
376 | else | |
377 | sta = __mesh_sta_info_alloc(sdata, addr); | |
378 | ||
54ab1ffb TP |
379 | return sta; |
380 | } | |
381 | ||
296fcba3 TP |
382 | /* |
383 | * mesh_sta_info_get - return mesh sta info entry for @addr. | |
384 | * | |
385 | * @sdata: local meshif | |
386 | * @addr: peer's address | |
387 | * @elems: IEs from beacon or mesh peering frame. | |
388 | * | |
389 | * Return existing or newly allocated sta_info under RCU read lock. | |
390 | * (re)initialize with given IEs. | |
391 | */ | |
392 | static struct sta_info * | |
393 | mesh_sta_info_get(struct ieee80211_sub_if_data *sdata, | |
394 | u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU) | |
395 | { | |
396 | struct sta_info *sta = NULL; | |
397 | ||
398 | rcu_read_lock(); | |
399 | sta = sta_info_get(sdata, addr); | |
400 | if (sta) { | |
401 | mesh_sta_info_init(sdata, sta, elems, false); | |
402 | } else { | |
403 | rcu_read_unlock(); | |
404 | /* can't run atomic */ | |
405 | sta = mesh_sta_info_alloc(sdata, addr, elems); | |
406 | if (!sta) { | |
407 | rcu_read_lock(); | |
408 | return NULL; | |
409 | } | |
410 | ||
3b4797bc TP |
411 | mesh_sta_info_init(sdata, sta, elems, true); |
412 | ||
296fcba3 TP |
413 | if (sta_info_insert_rcu(sta)) |
414 | return NULL; | |
415 | } | |
416 | ||
417 | return sta; | |
418 | } | |
419 | ||
420 | /* | |
421 | * mesh_neighbour_update - update or initialize new mesh neighbor. | |
422 | * | |
423 | * @sdata: local meshif | |
424 | * @addr: peer's address | |
425 | * @elems: IEs from beacon or mesh peering frame | |
426 | * | |
427 | * Initiates peering if appropriate. | |
428 | */ | |
f743ff49 TP |
429 | void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata, |
430 | u8 *hw_addr, | |
54ab1ffb TP |
431 | struct ieee802_11_elems *elems) |
432 | { | |
433 | struct sta_info *sta; | |
434 | ||
296fcba3 | 435 | sta = mesh_sta_info_get(sdata, hw_addr, elems); |
54ab1ffb TP |
436 | if (!sta) |
437 | goto out; | |
438 | ||
1570ca59 | 439 | if (mesh_peer_accepts_plinks(elems) && |
54ab1ffb TP |
440 | sta->plink_state == NL80211_PLINK_LISTEN && |
441 | sdata->u.mesh.accepting_plinks && | |
442 | sdata->u.mesh.mshcfg.auto_open_plinks && | |
443 | rssi_threshold_check(sta, sdata)) | |
c3896d2c LCC |
444 | mesh_plink_open(sta); |
445 | ||
54ab1ffb | 446 | out: |
d0709a65 | 447 | rcu_read_unlock(); |
c3896d2c LCC |
448 | } |
449 | ||
450 | static void mesh_plink_timer(unsigned long data) | |
451 | { | |
452 | struct sta_info *sta; | |
453 | __le16 llid, plid, reason; | |
c3896d2c | 454 | struct ieee80211_sub_if_data *sdata; |
453e66f2 | 455 | struct mesh_config *mshcfg; |
c3896d2c | 456 | |
d0709a65 JB |
457 | /* |
458 | * This STA is valid because sta_info_destroy() will | |
459 | * del_timer_sync() this timer after having made sure | |
460 | * it cannot be readded (by deleting the plink.) | |
461 | */ | |
c3896d2c LCC |
462 | sta = (struct sta_info *) data; |
463 | ||
5bb644a0 JB |
464 | if (sta->sdata->local->quiescing) { |
465 | sta->plink_timer_was_running = true; | |
466 | return; | |
467 | } | |
468 | ||
07346f81 | 469 | spin_lock_bh(&sta->lock); |
c3896d2c LCC |
470 | if (sta->ignore_plink_timer) { |
471 | sta->ignore_plink_timer = false; | |
07346f81 | 472 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
473 | return; |
474 | } | |
bdcbd8e0 JB |
475 | mpl_dbg(sta->sdata, |
476 | "Mesh plink timer for %pM fired on state %d\n", | |
0c68ae26 | 477 | sta->sta.addr, sta->plink_state); |
c3896d2c LCC |
478 | reason = 0; |
479 | llid = sta->llid; | |
480 | plid = sta->plid; | |
d0709a65 | 481 | sdata = sta->sdata; |
453e66f2 | 482 | mshcfg = &sdata->u.mesh.mshcfg; |
c3896d2c LCC |
483 | |
484 | switch (sta->plink_state) { | |
57cf8043 JC |
485 | case NL80211_PLINK_OPN_RCVD: |
486 | case NL80211_PLINK_OPN_SNT: | |
c3896d2c | 487 | /* retry timer */ |
453e66f2 | 488 | if (sta->plink_retries < mshcfg->dot11MeshMaxRetries) { |
c3896d2c | 489 | u32 rand; |
bdcbd8e0 JB |
490 | mpl_dbg(sta->sdata, |
491 | "Mesh plink for %pM (retry, timeout): %d %d\n", | |
0c68ae26 JB |
492 | sta->sta.addr, sta->plink_retries, |
493 | sta->plink_timeout); | |
c3896d2c LCC |
494 | get_random_bytes(&rand, sizeof(u32)); |
495 | sta->plink_timeout = sta->plink_timeout + | |
496 | rand % sta->plink_timeout; | |
497 | ++sta->plink_retries; | |
d0709a65 | 498 | mod_plink_timer(sta, sta->plink_timeout); |
07346f81 | 499 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
500 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, |
501 | sta->sta.addr, llid, 0, 0); | |
c3896d2c LCC |
502 | break; |
503 | } | |
54ef656b | 504 | reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES); |
c3896d2c | 505 | /* fall through on else */ |
57cf8043 | 506 | case NL80211_PLINK_CNF_RCVD: |
c3896d2c LCC |
507 | /* confirm timer */ |
508 | if (!reason) | |
54ef656b | 509 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT); |
57cf8043 | 510 | sta->plink_state = NL80211_PLINK_HOLDING; |
453e66f2 | 511 | mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout); |
07346f81 | 512 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
513 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
514 | sta->sta.addr, llid, plid, reason); | |
c3896d2c | 515 | break; |
57cf8043 | 516 | case NL80211_PLINK_HOLDING: |
c3896d2c | 517 | /* holding timer */ |
d0709a65 | 518 | del_timer(&sta->plink_timer); |
c3896d2c | 519 | mesh_plink_fsm_restart(sta); |
07346f81 | 520 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
521 | break; |
522 | default: | |
07346f81 | 523 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
524 | break; |
525 | } | |
c3896d2c LCC |
526 | } |
527 | ||
5bb644a0 JB |
528 | #ifdef CONFIG_PM |
529 | void mesh_plink_quiesce(struct sta_info *sta) | |
530 | { | |
531 | if (del_timer_sync(&sta->plink_timer)) | |
532 | sta->plink_timer_was_running = true; | |
533 | } | |
534 | ||
535 | void mesh_plink_restart(struct sta_info *sta) | |
536 | { | |
537 | if (sta->plink_timer_was_running) { | |
538 | add_timer(&sta->plink_timer); | |
539 | sta->plink_timer_was_running = false; | |
540 | } | |
541 | } | |
542 | #endif | |
543 | ||
c3896d2c LCC |
544 | static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) |
545 | { | |
546 | sta->plink_timer.expires = jiffies + (HZ * timeout / 1000); | |
547 | sta->plink_timer.data = (unsigned long) sta; | |
548 | sta->plink_timer.function = mesh_plink_timer; | |
549 | sta->plink_timeout = timeout; | |
c3896d2c LCC |
550 | add_timer(&sta->plink_timer); |
551 | } | |
552 | ||
553 | int mesh_plink_open(struct sta_info *sta) | |
554 | { | |
555 | __le16 llid; | |
d0709a65 | 556 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
c3896d2c | 557 | |
c2c98fde | 558 | if (!test_sta_flag(sta, WLAN_STA_AUTH)) |
53e80511 JC |
559 | return -EPERM; |
560 | ||
07346f81 | 561 | spin_lock_bh(&sta->lock); |
c3896d2c LCC |
562 | get_random_bytes(&llid, 2); |
563 | sta->llid = llid; | |
9385d04f CYY |
564 | if (sta->plink_state != NL80211_PLINK_LISTEN && |
565 | sta->plink_state != NL80211_PLINK_BLOCKED) { | |
07346f81 | 566 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
567 | return -EBUSY; |
568 | } | |
57cf8043 | 569 | sta->plink_state = NL80211_PLINK_OPN_SNT; |
453e66f2 | 570 | mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout); |
07346f81 | 571 | spin_unlock_bh(&sta->lock); |
bdcbd8e0 JB |
572 | mpl_dbg(sdata, |
573 | "Mesh plink: starting establishment with %pM\n", | |
0c68ae26 | 574 | sta->sta.addr); |
c3896d2c | 575 | |
54ef656b | 576 | return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, |
17741cdc | 577 | sta->sta.addr, llid, 0, 0); |
c3896d2c LCC |
578 | } |
579 | ||
580 | void mesh_plink_block(struct sta_info *sta) | |
581 | { | |
c9370197 | 582 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
df323818 | 583 | u32 changed; |
c9370197 | 584 | |
07346f81 | 585 | spin_lock_bh(&sta->lock); |
df323818 | 586 | changed = __mesh_plink_deactivate(sta); |
57cf8043 | 587 | sta->plink_state = NL80211_PLINK_BLOCKED; |
07346f81 | 588 | spin_unlock_bh(&sta->lock); |
c9370197 | 589 | |
df323818 | 590 | ieee80211_bss_info_change_notify(sdata, changed); |
c3896d2c LCC |
591 | } |
592 | ||
c3896d2c | 593 | |
f698d856 | 594 | void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt, |
c3896d2c LCC |
595 | size_t len, struct ieee80211_rx_status *rx_status) |
596 | { | |
453e66f2 | 597 | struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg; |
c3896d2c LCC |
598 | struct ieee802_11_elems elems; |
599 | struct sta_info *sta; | |
600 | enum plink_event event; | |
54ef656b | 601 | enum ieee80211_self_protected_actioncode ftype; |
c3896d2c | 602 | size_t baselen; |
57aac7c5 | 603 | bool matches_local = true; |
c3896d2c LCC |
604 | u8 ie_len; |
605 | u8 *baseaddr; | |
57aac7c5 | 606 | u32 changed = 0; |
c3896d2c | 607 | __le16 plid, llid, reason; |
1460dd15 | 608 | static const char *mplstates[] = { |
57cf8043 JC |
609 | [NL80211_PLINK_LISTEN] = "LISTEN", |
610 | [NL80211_PLINK_OPN_SNT] = "OPN-SNT", | |
611 | [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD", | |
612 | [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD", | |
613 | [NL80211_PLINK_ESTAB] = "ESTAB", | |
614 | [NL80211_PLINK_HOLDING] = "HOLDING", | |
615 | [NL80211_PLINK_BLOCKED] = "BLOCKED" | |
1460dd15 | 616 | }; |
c3896d2c | 617 | |
9c80d3dc JB |
618 | /* need action_code, aux */ |
619 | if (len < IEEE80211_MIN_ACTION_SIZE + 3) | |
620 | return; | |
621 | ||
c3896d2c | 622 | if (is_multicast_ether_addr(mgmt->da)) { |
bdcbd8e0 JB |
623 | mpl_dbg(sdata, |
624 | "Mesh plink: ignore frame from multicast address\n"); | |
c3896d2c LCC |
625 | return; |
626 | } | |
627 | ||
8db09850 TP |
628 | baseaddr = mgmt->u.action.u.self_prot.variable; |
629 | baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt; | |
630 | if (mgmt->u.action.u.self_prot.action_code == | |
54ef656b | 631 | WLAN_SP_MESH_PEERING_CONFIRM) { |
c3896d2c | 632 | baseaddr += 4; |
70bdb6b2 | 633 | baselen += 4; |
c3896d2c LCC |
634 | } |
635 | ieee802_11_parse_elems(baseaddr, len - baselen, &elems); | |
8db09850 | 636 | if (!elems.peering) { |
bdcbd8e0 JB |
637 | mpl_dbg(sdata, |
638 | "Mesh plink: missing necessary peer link ie\n"); | |
c3896d2c LCC |
639 | return; |
640 | } | |
b130e5ce JC |
641 | if (elems.rsn_len && |
642 | sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) { | |
bdcbd8e0 JB |
643 | mpl_dbg(sdata, |
644 | "Mesh plink: can't establish link with secure peer\n"); | |
5cff5e01 JC |
645 | return; |
646 | } | |
c3896d2c | 647 | |
8db09850 TP |
648 | ftype = mgmt->u.action.u.self_prot.action_code; |
649 | ie_len = elems.peering_len; | |
650 | if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) || | |
651 | (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) || | |
652 | (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6 | |
653 | && ie_len != 8)) { | |
bdcbd8e0 JB |
654 | mpl_dbg(sdata, |
655 | "Mesh plink: incorrect plink ie length %d %d\n", | |
656 | ftype, ie_len); | |
c3896d2c LCC |
657 | return; |
658 | } | |
659 | ||
54ef656b TP |
660 | if (ftype != WLAN_SP_MESH_PEERING_CLOSE && |
661 | (!elems.mesh_id || !elems.mesh_config)) { | |
bdcbd8e0 | 662 | mpl_dbg(sdata, "Mesh plink: missing necessary ie\n"); |
c3896d2c LCC |
663 | return; |
664 | } | |
665 | /* Note the lines below are correct, the llid in the frame is the plid | |
666 | * from the point of view of this host. | |
667 | */ | |
8db09850 | 668 | memcpy(&plid, PLINK_GET_LLID(elems.peering), 2); |
54ef656b | 669 | if (ftype == WLAN_SP_MESH_PEERING_CONFIRM || |
8db09850 TP |
670 | (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8)) |
671 | memcpy(&llid, PLINK_GET_PLID(elems.peering), 2); | |
c3896d2c | 672 | |
296fcba3 | 673 | /* WARNING: Only for sta pointer, is dropped & re-acquired */ |
d0709a65 JB |
674 | rcu_read_lock(); |
675 | ||
abe60632 | 676 | sta = sta_info_get(sdata, mgmt->sa); |
54ef656b | 677 | if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) { |
bdcbd8e0 | 678 | mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n"); |
d0709a65 | 679 | rcu_read_unlock(); |
c3896d2c LCC |
680 | return; |
681 | } | |
682 | ||
55335137 | 683 | if (ftype == WLAN_SP_MESH_PEERING_OPEN && |
3d4f9699 | 684 | !rssi_threshold_check(sta, sdata)) { |
bdcbd8e0 | 685 | mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n", |
3d4f9699 | 686 | mgmt->sa); |
55335137 AN |
687 | rcu_read_unlock(); |
688 | return; | |
689 | } | |
690 | ||
c2c98fde | 691 | if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) { |
bdcbd8e0 | 692 | mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n"); |
53e80511 JC |
693 | rcu_read_unlock(); |
694 | return; | |
695 | } | |
696 | ||
57cf8043 | 697 | if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) { |
d0709a65 | 698 | rcu_read_unlock(); |
c3896d2c LCC |
699 | return; |
700 | } | |
701 | ||
702 | /* Now we will figure out the appropriate event... */ | |
703 | event = PLINK_UNDEFINED; | |
54ef656b | 704 | if (ftype != WLAN_SP_MESH_PEERING_CLOSE && |
f743ff49 | 705 | !mesh_matches_local(sdata, &elems)) { |
d12c7452 | 706 | matches_local = false; |
c3896d2c | 707 | switch (ftype) { |
54ef656b | 708 | case WLAN_SP_MESH_PEERING_OPEN: |
c3896d2c LCC |
709 | event = OPN_RJCT; |
710 | break; | |
54ef656b | 711 | case WLAN_SP_MESH_PEERING_CONFIRM: |
c3896d2c LCC |
712 | event = CNF_RJCT; |
713 | break; | |
54ef656b | 714 | default: |
c3896d2c LCC |
715 | break; |
716 | } | |
d12c7452 CL |
717 | } |
718 | ||
719 | if (!sta && !matches_local) { | |
720 | rcu_read_unlock(); | |
54ef656b | 721 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
d12c7452 | 722 | llid = 0; |
54ef656b TP |
723 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
724 | mgmt->sa, llid, plid, reason); | |
d12c7452 | 725 | return; |
c3896d2c | 726 | } else if (!sta) { |
54ef656b | 727 | /* ftype == WLAN_SP_MESH_PEERING_OPEN */ |
c3896d2c | 728 | if (!mesh_plink_free_count(sdata)) { |
bdcbd8e0 | 729 | mpl_dbg(sdata, "Mesh plink error: no more free plinks\n"); |
73651ee6 JB |
730 | rcu_read_unlock(); |
731 | return; | |
732 | } | |
c3896d2c | 733 | event = OPN_ACPT; |
d12c7452 | 734 | } else if (matches_local) { |
c3896d2c | 735 | switch (ftype) { |
54ef656b | 736 | case WLAN_SP_MESH_PEERING_OPEN: |
c3896d2c | 737 | if (!mesh_plink_free_count(sdata) || |
d0709a65 | 738 | (sta->plid && sta->plid != plid)) |
c3896d2c LCC |
739 | event = OPN_IGNR; |
740 | else | |
741 | event = OPN_ACPT; | |
742 | break; | |
54ef656b | 743 | case WLAN_SP_MESH_PEERING_CONFIRM: |
c3896d2c | 744 | if (!mesh_plink_free_count(sdata) || |
d0709a65 | 745 | (sta->llid != llid || sta->plid != plid)) |
c3896d2c LCC |
746 | event = CNF_IGNR; |
747 | else | |
748 | event = CNF_ACPT; | |
749 | break; | |
54ef656b | 750 | case WLAN_SP_MESH_PEERING_CLOSE: |
57cf8043 | 751 | if (sta->plink_state == NL80211_PLINK_ESTAB) |
c3896d2c LCC |
752 | /* Do not check for llid or plid. This does not |
753 | * follow the standard but since multiple plinks | |
754 | * per sta are not supported, it is necessary in | |
755 | * order to avoid a livelock when MP A sees an | |
756 | * establish peer link to MP B but MP B does not | |
757 | * see it. This can be caused by a timeout in | |
758 | * B's peer link establishment or B beign | |
759 | * restarted. | |
760 | */ | |
761 | event = CLS_ACPT; | |
762 | else if (sta->plid != plid) | |
763 | event = CLS_IGNR; | |
764 | else if (ie_len == 7 && sta->llid != llid) | |
765 | event = CLS_IGNR; | |
766 | else | |
767 | event = CLS_ACPT; | |
768 | break; | |
769 | default: | |
bdcbd8e0 | 770 | mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n"); |
d0709a65 | 771 | rcu_read_unlock(); |
c3896d2c LCC |
772 | return; |
773 | } | |
54ab1ffb TP |
774 | } |
775 | ||
776 | if (event == OPN_ACPT) { | |
296fcba3 | 777 | rcu_read_unlock(); |
54ab1ffb | 778 | /* allocate sta entry if necessary and update info */ |
296fcba3 | 779 | sta = mesh_sta_info_get(sdata, mgmt->sa, &elems); |
54ab1ffb | 780 | if (!sta) { |
bdcbd8e0 | 781 | mpl_dbg(sdata, "Mesh plink: failed to init peer!\n"); |
54ab1ffb TP |
782 | rcu_read_unlock(); |
783 | return; | |
784 | } | |
c3896d2c LCC |
785 | } |
786 | ||
bdcbd8e0 JB |
787 | mpl_dbg(sdata, |
788 | "Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n", | |
1460dd15 | 789 | mgmt->sa, mplstates[sta->plink_state], |
0c68ae26 JB |
790 | le16_to_cpu(sta->llid), le16_to_cpu(sta->plid), |
791 | event); | |
c3896d2c | 792 | reason = 0; |
54ab1ffb | 793 | spin_lock_bh(&sta->lock); |
c3896d2c LCC |
794 | switch (sta->plink_state) { |
795 | /* spin_unlock as soon as state is updated at each case */ | |
57cf8043 | 796 | case NL80211_PLINK_LISTEN: |
c3896d2c LCC |
797 | switch (event) { |
798 | case CLS_ACPT: | |
799 | mesh_plink_fsm_restart(sta); | |
07346f81 | 800 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
801 | break; |
802 | case OPN_ACPT: | |
57cf8043 | 803 | sta->plink_state = NL80211_PLINK_OPN_RCVD; |
c3896d2c LCC |
804 | sta->plid = plid; |
805 | get_random_bytes(&llid, 2); | |
806 | sta->llid = llid; | |
453e66f2 MP |
807 | mesh_plink_timer_set(sta, |
808 | mshcfg->dot11MeshRetryTimeout); | |
07346f81 | 809 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
810 | mesh_plink_frame_tx(sdata, |
811 | WLAN_SP_MESH_PEERING_OPEN, | |
812 | sta->sta.addr, llid, 0, 0); | |
813 | mesh_plink_frame_tx(sdata, | |
814 | WLAN_SP_MESH_PEERING_CONFIRM, | |
815 | sta->sta.addr, llid, plid, 0); | |
c3896d2c LCC |
816 | break; |
817 | default: | |
07346f81 | 818 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
819 | break; |
820 | } | |
821 | break; | |
822 | ||
57cf8043 | 823 | case NL80211_PLINK_OPN_SNT: |
c3896d2c LCC |
824 | switch (event) { |
825 | case OPN_RJCT: | |
826 | case CNF_RJCT: | |
54ef656b | 827 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
c3896d2c LCC |
828 | case CLS_ACPT: |
829 | if (!reason) | |
54ef656b | 830 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
c3896d2c | 831 | sta->reason = reason; |
57cf8043 | 832 | sta->plink_state = NL80211_PLINK_HOLDING; |
c3896d2c | 833 | if (!mod_plink_timer(sta, |
453e66f2 | 834 | mshcfg->dot11MeshHoldingTimeout)) |
c3896d2c LCC |
835 | sta->ignore_plink_timer = true; |
836 | ||
837 | llid = sta->llid; | |
07346f81 | 838 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
839 | mesh_plink_frame_tx(sdata, |
840 | WLAN_SP_MESH_PEERING_CLOSE, | |
841 | sta->sta.addr, llid, plid, reason); | |
c3896d2c LCC |
842 | break; |
843 | case OPN_ACPT: | |
844 | /* retry timer is left untouched */ | |
57cf8043 | 845 | sta->plink_state = NL80211_PLINK_OPN_RCVD; |
c3896d2c LCC |
846 | sta->plid = plid; |
847 | llid = sta->llid; | |
07346f81 | 848 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
849 | mesh_plink_frame_tx(sdata, |
850 | WLAN_SP_MESH_PEERING_CONFIRM, | |
851 | sta->sta.addr, llid, plid, 0); | |
c3896d2c LCC |
852 | break; |
853 | case CNF_ACPT: | |
57cf8043 | 854 | sta->plink_state = NL80211_PLINK_CNF_RCVD; |
c3896d2c | 855 | if (!mod_plink_timer(sta, |
453e66f2 | 856 | mshcfg->dot11MeshConfirmTimeout)) |
c3896d2c LCC |
857 | sta->ignore_plink_timer = true; |
858 | ||
07346f81 | 859 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
860 | break; |
861 | default: | |
07346f81 | 862 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
863 | break; |
864 | } | |
865 | break; | |
866 | ||
57cf8043 | 867 | case NL80211_PLINK_OPN_RCVD: |
c3896d2c LCC |
868 | switch (event) { |
869 | case OPN_RJCT: | |
870 | case CNF_RJCT: | |
54ef656b | 871 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
c3896d2c LCC |
872 | case CLS_ACPT: |
873 | if (!reason) | |
54ef656b | 874 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
c3896d2c | 875 | sta->reason = reason; |
57cf8043 | 876 | sta->plink_state = NL80211_PLINK_HOLDING; |
c3896d2c | 877 | if (!mod_plink_timer(sta, |
453e66f2 | 878 | mshcfg->dot11MeshHoldingTimeout)) |
c3896d2c LCC |
879 | sta->ignore_plink_timer = true; |
880 | ||
881 | llid = sta->llid; | |
07346f81 | 882 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
883 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
884 | sta->sta.addr, llid, plid, reason); | |
c3896d2c LCC |
885 | break; |
886 | case OPN_ACPT: | |
887 | llid = sta->llid; | |
07346f81 | 888 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
889 | mesh_plink_frame_tx(sdata, |
890 | WLAN_SP_MESH_PEERING_CONFIRM, | |
891 | sta->sta.addr, llid, plid, 0); | |
c3896d2c LCC |
892 | break; |
893 | case CNF_ACPT: | |
d0709a65 | 894 | del_timer(&sta->plink_timer); |
57cf8043 | 895 | sta->plink_state = NL80211_PLINK_ESTAB; |
07346f81 | 896 | spin_unlock_bh(&sta->lock); |
df323818 | 897 | changed |= mesh_plink_inc_estab_count(sdata); |
57aac7c5 | 898 | changed |= mesh_set_ht_prot_mode(sdata); |
bdcbd8e0 | 899 | mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", |
0c68ae26 | 900 | sta->sta.addr); |
c3896d2c LCC |
901 | break; |
902 | default: | |
07346f81 | 903 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
904 | break; |
905 | } | |
906 | break; | |
907 | ||
57cf8043 | 908 | case NL80211_PLINK_CNF_RCVD: |
c3896d2c LCC |
909 | switch (event) { |
910 | case OPN_RJCT: | |
911 | case CNF_RJCT: | |
54ef656b | 912 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
c3896d2c LCC |
913 | case CLS_ACPT: |
914 | if (!reason) | |
54ef656b | 915 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
c3896d2c | 916 | sta->reason = reason; |
57cf8043 | 917 | sta->plink_state = NL80211_PLINK_HOLDING; |
c3896d2c | 918 | if (!mod_plink_timer(sta, |
453e66f2 | 919 | mshcfg->dot11MeshHoldingTimeout)) |
c3896d2c LCC |
920 | sta->ignore_plink_timer = true; |
921 | ||
922 | llid = sta->llid; | |
07346f81 | 923 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
924 | mesh_plink_frame_tx(sdata, |
925 | WLAN_SP_MESH_PEERING_CLOSE, | |
926 | sta->sta.addr, llid, plid, reason); | |
ff59dc76 | 927 | break; |
c3896d2c | 928 | case OPN_ACPT: |
d0709a65 | 929 | del_timer(&sta->plink_timer); |
57cf8043 | 930 | sta->plink_state = NL80211_PLINK_ESTAB; |
07346f81 | 931 | spin_unlock_bh(&sta->lock); |
df323818 | 932 | changed |= mesh_plink_inc_estab_count(sdata); |
57aac7c5 | 933 | changed |= mesh_set_ht_prot_mode(sdata); |
bdcbd8e0 | 934 | mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", |
0c68ae26 | 935 | sta->sta.addr); |
54ef656b TP |
936 | mesh_plink_frame_tx(sdata, |
937 | WLAN_SP_MESH_PEERING_CONFIRM, | |
938 | sta->sta.addr, llid, plid, 0); | |
c3896d2c LCC |
939 | break; |
940 | default: | |
07346f81 | 941 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
942 | break; |
943 | } | |
944 | break; | |
945 | ||
57cf8043 | 946 | case NL80211_PLINK_ESTAB: |
c3896d2c LCC |
947 | switch (event) { |
948 | case CLS_ACPT: | |
54ef656b | 949 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
c3896d2c | 950 | sta->reason = reason; |
df323818 | 951 | changed |= __mesh_plink_deactivate(sta); |
57cf8043 | 952 | sta->plink_state = NL80211_PLINK_HOLDING; |
c3896d2c | 953 | llid = sta->llid; |
453e66f2 | 954 | mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout); |
07346f81 | 955 | spin_unlock_bh(&sta->lock); |
57aac7c5 | 956 | changed |= mesh_set_ht_prot_mode(sdata); |
54ef656b TP |
957 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
958 | sta->sta.addr, llid, plid, reason); | |
c3896d2c LCC |
959 | break; |
960 | case OPN_ACPT: | |
961 | llid = sta->llid; | |
07346f81 | 962 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
963 | mesh_plink_frame_tx(sdata, |
964 | WLAN_SP_MESH_PEERING_CONFIRM, | |
965 | sta->sta.addr, llid, plid, 0); | |
c3896d2c LCC |
966 | break; |
967 | default: | |
07346f81 | 968 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
969 | break; |
970 | } | |
971 | break; | |
57cf8043 | 972 | case NL80211_PLINK_HOLDING: |
c3896d2c LCC |
973 | switch (event) { |
974 | case CLS_ACPT: | |
d0709a65 | 975 | if (del_timer(&sta->plink_timer)) |
c3896d2c | 976 | sta->ignore_plink_timer = 1; |
c3896d2c | 977 | mesh_plink_fsm_restart(sta); |
07346f81 | 978 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
979 | break; |
980 | case OPN_ACPT: | |
981 | case CNF_ACPT: | |
982 | case OPN_RJCT: | |
983 | case CNF_RJCT: | |
984 | llid = sta->llid; | |
985 | reason = sta->reason; | |
07346f81 | 986 | spin_unlock_bh(&sta->lock); |
54ef656b TP |
987 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
988 | sta->sta.addr, llid, plid, reason); | |
c3896d2c LCC |
989 | break; |
990 | default: | |
07346f81 | 991 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
992 | } |
993 | break; | |
994 | default: | |
b4e08ea1 | 995 | /* should not get here, PLINK_BLOCKED is dealt with at the |
3ad2f3fb | 996 | * beginning of the function |
c3896d2c | 997 | */ |
07346f81 | 998 | spin_unlock_bh(&sta->lock); |
c3896d2c LCC |
999 | break; |
1000 | } | |
d0709a65 JB |
1001 | |
1002 | rcu_read_unlock(); | |
57aac7c5 AN |
1003 | |
1004 | if (changed) | |
1005 | ieee80211_bss_info_change_notify(sdata, changed); | |
c3896d2c | 1006 | } |