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