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