Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
2e3c8736 | 2 | /* |
264d9b7d | 3 | * Copyright (c) 2008, 2009 open80211s Ltd. |
15ddba5f | 4 | * Copyright (C) 2018 - 2023 Intel Corporation |
2e3c8736 LCC |
5 | * Authors: Luis Carlos Cobo <luisca@cozybit.com> |
6 | * Javier Cardona <javier@cozybit.com> | |
2e3c8736 LCC |
7 | */ |
8 | ||
5a0e3ad6 | 9 | #include <linux/slab.h> |
51ceddad | 10 | #include <asm/unaligned.h> |
2e3c8736 LCC |
11 | #include "ieee80211_i.h" |
12 | #include "mesh.h" | |
d5edb9ae | 13 | #include "wme.h" |
b8456a14 | 14 | #include "driver-ops.h" |
2e3c8736 | 15 | |
bf7cd94d | 16 | static int mesh_allocated; |
2e3c8736 LCC |
17 | static struct kmem_cache *rm_cache; |
18 | ||
25d49e4d TP |
19 | bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt) |
20 | { | |
21 | return (mgmt->u.action.u.mesh_action.action_code == | |
22 | WLAN_MESH_ACTION_HWMP_PATH_SELECTION); | |
23 | } | |
25d49e4d | 24 | |
2e3c8736 LCC |
25 | void ieee80211s_init(void) |
26 | { | |
2e3c8736 LCC |
27 | mesh_allocated = 1; |
28 | rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry), | |
29 | 0, 0, NULL); | |
30 | } | |
31 | ||
32 | void ieee80211s_stop(void) | |
33 | { | |
bf7cd94d JB |
34 | if (!mesh_allocated) |
35 | return; | |
2e3c8736 LCC |
36 | kmem_cache_destroy(rm_cache); |
37 | } | |
38 | ||
34f11cd3 | 39 | static void ieee80211_mesh_housekeeping_timer(struct timer_list *t) |
472dbc45 | 40 | { |
34f11cd3 KC |
41 | struct ieee80211_sub_if_data *sdata = |
42 | from_timer(sdata, t, u.mesh.housekeeping_timer); | |
472dbc45 JB |
43 | struct ieee80211_local *local = sdata->local; |
44 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
45 | ||
6b9ac442 | 46 | set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); |
5bb644a0 | 47 | |
16114496 | 48 | wiphy_work_queue(local->hw.wiphy, &sdata->work); |
472dbc45 JB |
49 | } |
50 | ||
2e3c8736 LCC |
51 | /** |
52 | * mesh_matches_local - check if the config of a mesh point matches ours | |
53 | * | |
f698d856 | 54 | * @sdata: local mesh subif |
f743ff49 | 55 | * @ie: information elements of a management frame from the mesh peer |
2e3c8736 LCC |
56 | * |
57 | * This function checks if the mesh configuration of a mesh point matches the | |
58 | * local mesh configuration, i.e. if both nodes belong to the same mesh network. | |
59 | */ | |
f743ff49 TP |
60 | bool mesh_matches_local(struct ieee80211_sub_if_data *sdata, |
61 | struct ieee802_11_elems *ie) | |
2e3c8736 | 62 | { |
472dbc45 | 63 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
f743ff49 | 64 | u32 basic_rates = 0; |
4bf88530 | 65 | struct cfg80211_chan_def sta_chan_def; |
21a8e9dd | 66 | struct ieee80211_supported_band *sband; |
2a333a0d | 67 | u32 vht_cap_info = 0; |
2e3c8736 | 68 | |
2e3c8736 LCC |
69 | /* |
70 | * As support for each feature is added, check for matching | |
71 | * - On mesh config capabilities | |
72 | * - Power Save Support En | |
73 | * - Sync support enabled | |
74 | * - Sync support active | |
75 | * - Sync support required from peer | |
76 | * - MDA enabled | |
77 | * - Power management control on fc | |
78 | */ | |
739522ba TP |
79 | if (!(ifmsh->mesh_id_len == ie->mesh_id_len && |
80 | memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 && | |
81 | (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) && | |
82 | (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) && | |
83 | (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) && | |
84 | (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) && | |
85 | (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))) | |
bf7cd94d | 86 | return false; |
739522ba | 87 | |
21a8e9dd MSS |
88 | sband = ieee80211_get_sband(sdata); |
89 | if (!sband) | |
90 | return false; | |
91 | ||
92 | ieee80211_sta_get_rates(sdata, ie, sband->band, | |
f743ff49 TP |
93 | &basic_rates); |
94 | ||
fe40cb62 | 95 | if (sdata->vif.bss_conf.basic_rates != basic_rates) |
bf7cd94d | 96 | return false; |
fe40cb62 | 97 | |
8ac3c704 JB |
98 | cfg80211_chandef_create(&sta_chan_def, sdata->vif.bss_conf.chandef.chan, |
99 | NL80211_CHAN_NO_HT); | |
100 | ieee80211_chandef_ht_oper(ie->ht_operation, &sta_chan_def); | |
2a333a0d JB |
101 | |
102 | if (ie->vht_cap_elem) | |
103 | vht_cap_info = le32_to_cpu(ie->vht_cap_elem->vht_cap_info); | |
104 | ||
105 | ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info, | |
7eb26df2 JB |
106 | ie->vht_operation, ie->ht_operation, |
107 | &sta_chan_def); | |
df1875c4 | 108 | ieee80211_chandef_he_6ghz_oper(sdata, ie->he_operation, ie->eht_operation, |
5dca295d | 109 | &sta_chan_def); |
c85fb53c | 110 | |
4bf88530 JB |
111 | if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef, |
112 | &sta_chan_def)) | |
bf7cd94d | 113 | return false; |
2e3c8736 | 114 | |
739522ba | 115 | return true; |
2e3c8736 LCC |
116 | } |
117 | ||
118 | /** | |
119 | * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links | |
120 | * | |
121 | * @ie: information elements of a management frame from the mesh peer | |
2e3c8736 | 122 | */ |
f698d856 | 123 | bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie) |
2e3c8736 | 124 | { |
136cfa28 | 125 | return (ie->mesh_config->meshconf_cap & |
bf7cd94d | 126 | IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0; |
2e3c8736 LCC |
127 | } |
128 | ||
129 | /** | |
2c53040f | 130 | * mesh_accept_plinks_update - update accepting_plink in local mesh beacons |
2e3c8736 | 131 | * |
d0709a65 | 132 | * @sdata: mesh interface in which mesh beacons are going to be updated |
df323818 MP |
133 | * |
134 | * Returns: beacon changed flag if the beacon content changed. | |
2e3c8736 | 135 | */ |
15ddba5f | 136 | u64 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 137 | { |
2e3c8736 | 138 | bool free_plinks; |
15ddba5f | 139 | u64 changed = 0; |
2e3c8736 LCC |
140 | |
141 | /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0, | |
142 | * the mesh interface might be able to establish plinks with peers that | |
b4e08ea1 LCC |
143 | * are already on the table but are not on PLINK_ESTAB state. However, |
144 | * in general the mesh interface is not accepting peer link requests | |
145 | * from new peers, and that must be reflected in the beacon | |
2e3c8736 LCC |
146 | */ |
147 | free_plinks = mesh_plink_availables(sdata); | |
148 | ||
df323818 MP |
149 | if (free_plinks != sdata->u.mesh.accepting_plinks) { |
150 | sdata->u.mesh.accepting_plinks = free_plinks; | |
151 | changed = BSS_CHANGED_BEACON; | |
152 | } | |
153 | ||
154 | return changed; | |
2e3c8736 LCC |
155 | } |
156 | ||
45b5028e TP |
157 | /* |
158 | * mesh_sta_cleanup - clean up any mesh sta state | |
159 | * | |
160 | * @sta: mesh sta to clean up. | |
161 | */ | |
162 | void mesh_sta_cleanup(struct sta_info *sta) | |
163 | { | |
164 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
15ddba5f | 165 | u64 changed = mesh_plink_deactivate(sta); |
fe7a7c57 | 166 | |
f81a9ded | 167 | if (changed) |
2b5e1967 | 168 | ieee80211_mbss_info_change_notify(sdata, changed); |
45b5028e TP |
169 | } |
170 | ||
f698d856 | 171 | int mesh_rmc_init(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 172 | { |
2e3c8736 LCC |
173 | int i; |
174 | ||
472dbc45 JB |
175 | sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL); |
176 | if (!sdata->u.mesh.rmc) | |
2e3c8736 | 177 | return -ENOMEM; |
472dbc45 | 178 | sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1; |
2e3c8736 | 179 | for (i = 0; i < RMC_BUCKETS; i++) |
47a0489c | 180 | INIT_HLIST_HEAD(&sdata->u.mesh.rmc->bucket[i]); |
2e3c8736 LCC |
181 | return 0; |
182 | } | |
183 | ||
f698d856 | 184 | void mesh_rmc_free(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 185 | { |
472dbc45 | 186 | struct mesh_rmc *rmc = sdata->u.mesh.rmc; |
47a0489c BC |
187 | struct rmc_entry *p; |
188 | struct hlist_node *n; | |
2e3c8736 LCC |
189 | int i; |
190 | ||
472dbc45 | 191 | if (!sdata->u.mesh.rmc) |
2e3c8736 LCC |
192 | return; |
193 | ||
bf7cd94d | 194 | for (i = 0; i < RMC_BUCKETS; i++) { |
47a0489c BC |
195 | hlist_for_each_entry_safe(p, n, &rmc->bucket[i], list) { |
196 | hlist_del(&p->list); | |
2e3c8736 LCC |
197 | kmem_cache_free(rm_cache, p); |
198 | } | |
bf7cd94d | 199 | } |
2e3c8736 LCC |
200 | |
201 | kfree(rmc); | |
472dbc45 | 202 | sdata->u.mesh.rmc = NULL; |
2e3c8736 LCC |
203 | } |
204 | ||
205 | /** | |
206 | * mesh_rmc_check - Check frame in recent multicast cache and add if absent. | |
207 | * | |
bf7cd94d | 208 | * @sdata: interface |
2e3c8736 LCC |
209 | * @sa: source address |
210 | * @mesh_hdr: mesh_header | |
211 | * | |
212 | * Returns: 0 if the frame is not in the cache, nonzero otherwise. | |
213 | * | |
214 | * Checks using the source address and the mesh sequence number if we have | |
215 | * received this frame lately. If the frame is not in the cache, it is added to | |
216 | * it. | |
217 | */ | |
bf7cd94d JB |
218 | int mesh_rmc_check(struct ieee80211_sub_if_data *sdata, |
219 | const u8 *sa, struct ieee80211s_hdr *mesh_hdr) | |
2e3c8736 | 220 | { |
472dbc45 | 221 | struct mesh_rmc *rmc = sdata->u.mesh.rmc; |
2e3c8736 LCC |
222 | u32 seqnum = 0; |
223 | int entries = 0; | |
224 | u8 idx; | |
47a0489c BC |
225 | struct rmc_entry *p; |
226 | struct hlist_node *n; | |
2e3c8736 | 227 | |
0aa7fabb BC |
228 | if (!rmc) |
229 | return -1; | |
230 | ||
2e3c8736 | 231 | /* Don't care about endianness since only match matters */ |
51ceddad LCC |
232 | memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum)); |
233 | idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask; | |
47a0489c | 234 | hlist_for_each_entry_safe(p, n, &rmc->bucket[idx], list) { |
2e3c8736 LCC |
235 | ++entries; |
236 | if (time_after(jiffies, p->exp_time) || | |
bf7cd94d | 237 | entries == RMC_QUEUE_MAX_LEN) { |
47a0489c | 238 | hlist_del(&p->list); |
2e3c8736 LCC |
239 | kmem_cache_free(rm_cache, p); |
240 | --entries; | |
bf7cd94d | 241 | } else if ((seqnum == p->seqnum) && ether_addr_equal(sa, p->sa)) |
2e3c8736 LCC |
242 | return -1; |
243 | } | |
244 | ||
245 | p = kmem_cache_alloc(rm_cache, GFP_ATOMIC); | |
d15b8459 | 246 | if (!p) |
2e3c8736 | 247 | return 0; |
d15b8459 | 248 | |
2e3c8736 LCC |
249 | p->seqnum = seqnum; |
250 | p->exp_time = jiffies + RMC_TIMEOUT; | |
251 | memcpy(p->sa, sa, ETH_ALEN); | |
47a0489c | 252 | hlist_add_head(&p->list, &rmc->bucket[idx]); |
2e3c8736 LCC |
253 | return 0; |
254 | } | |
255 | ||
bf7cd94d JB |
256 | int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata, |
257 | struct sk_buff *skb) | |
082ebb0c TP |
258 | { |
259 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
260 | u8 *pos, neighbors; | |
261 | u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie); | |
4a6ecd35 | 262 | bool is_connected_to_gate = ifmsh->num_gates > 0 || |
01d66fbd BC |
263 | ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol || |
264 | ifmsh->mshcfg.dot11MeshConnectedToMeshGate; | |
184eebe6 | 265 | bool is_connected_to_as = ifmsh->mshcfg.dot11MeshConnectedToAuthServer; |
082ebb0c TP |
266 | |
267 | if (skb_tailroom(skb) < 2 + meshconf_len) | |
268 | return -ENOMEM; | |
269 | ||
270 | pos = skb_put(skb, 2 + meshconf_len); | |
271 | *pos++ = WLAN_EID_MESH_CONFIG; | |
272 | *pos++ = meshconf_len; | |
273 | ||
43552be1 TP |
274 | /* save a pointer for quick updates in pre-tbtt */ |
275 | ifmsh->meshconf_offset = pos - skb->data; | |
276 | ||
082ebb0c TP |
277 | /* Active path selection protocol ID */ |
278 | *pos++ = ifmsh->mesh_pp_id; | |
279 | /* Active path selection metric ID */ | |
280 | *pos++ = ifmsh->mesh_pm_id; | |
281 | /* Congestion control mode identifier */ | |
282 | *pos++ = ifmsh->mesh_cc_id; | |
283 | /* Synchronization protocol identifier */ | |
284 | *pos++ = ifmsh->mesh_sp_id; | |
285 | /* Authentication Protocol identifier */ | |
286 | *pos++ = ifmsh->mesh_auth_id; | |
287 | /* Mesh Formation Info - number of neighbors */ | |
1258d976 | 288 | neighbors = atomic_read(&ifmsh->estab_plinks); |
e05ecccd | 289 | neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS); |
184eebe6 MT |
290 | *pos++ = (is_connected_to_as << 7) | |
291 | (neighbors << 1) | | |
292 | is_connected_to_gate; | |
082ebb0c | 293 | /* Mesh capability */ |
b60e527a CYY |
294 | *pos = 0x00; |
295 | *pos |= ifmsh->mshcfg.dot11MeshForwarding ? | |
296 | IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00; | |
dbf498fb | 297 | *pos |= ifmsh->accepting_plinks ? |
bf7cd94d | 298 | IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00; |
3f52b7e3 MP |
299 | /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */ |
300 | *pos |= ifmsh->ps_peers_deep_sleep ? | |
bf7cd94d | 301 | IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00; |
082ebb0c TP |
302 | return 0; |
303 | } | |
304 | ||
bf7cd94d | 305 | int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) |
082ebb0c TP |
306 | { |
307 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
308 | u8 *pos; | |
309 | ||
310 | if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len) | |
311 | return -ENOMEM; | |
312 | ||
313 | pos = skb_put(skb, 2 + ifmsh->mesh_id_len); | |
314 | *pos++ = WLAN_EID_MESH_ID; | |
315 | *pos++ = ifmsh->mesh_id_len; | |
316 | if (ifmsh->mesh_id_len) | |
317 | memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len); | |
318 | ||
319 | return 0; | |
320 | } | |
321 | ||
bf7cd94d JB |
322 | static int mesh_add_awake_window_ie(struct ieee80211_sub_if_data *sdata, |
323 | struct sk_buff *skb) | |
3f52b7e3 MP |
324 | { |
325 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
326 | u8 *pos; | |
327 | ||
328 | /* see IEEE802.11-2012 13.14.6 */ | |
329 | if (ifmsh->ps_peers_light_sleep == 0 && | |
330 | ifmsh->ps_peers_deep_sleep == 0 && | |
331 | ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE) | |
332 | return 0; | |
333 | ||
334 | if (skb_tailroom(skb) < 4) | |
335 | return -ENOMEM; | |
336 | ||
337 | pos = skb_put(skb, 2 + 2); | |
338 | *pos++ = WLAN_EID_MESH_AWAKE_WINDOW; | |
339 | *pos++ = 2; | |
340 | put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos); | |
341 | ||
342 | return 0; | |
343 | } | |
344 | ||
bf7cd94d JB |
345 | int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata, |
346 | struct sk_buff *skb) | |
082ebb0c TP |
347 | { |
348 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
349 | u8 offset, len; | |
350 | const u8 *data; | |
351 | ||
352 | if (!ifmsh->ie || !ifmsh->ie_len) | |
353 | return 0; | |
354 | ||
355 | /* fast-forward to vendor IEs */ | |
356 | offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0); | |
357 | ||
da7061c8 | 358 | if (offset < ifmsh->ie_len) { |
082ebb0c TP |
359 | len = ifmsh->ie_len - offset; |
360 | data = ifmsh->ie + offset; | |
361 | if (skb_tailroom(skb) < len) | |
362 | return -ENOMEM; | |
59ae1d12 | 363 | skb_put_data(skb, data, len); |
082ebb0c TP |
364 | } |
365 | ||
366 | return 0; | |
367 | } | |
368 | ||
bf7cd94d | 369 | int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) |
082ebb0c TP |
370 | { |
371 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
372 | u8 len = 0; | |
373 | const u8 *data; | |
374 | ||
375 | if (!ifmsh->ie || !ifmsh->ie_len) | |
376 | return 0; | |
377 | ||
378 | /* find RSN IE */ | |
a40a8c17 BC |
379 | data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len); |
380 | if (!data) | |
381 | return 0; | |
082ebb0c | 382 | |
a40a8c17 BC |
383 | len = data[1] + 2; |
384 | ||
385 | if (skb_tailroom(skb) < len) | |
386 | return -ENOMEM; | |
59ae1d12 | 387 | skb_put_data(skb, data, len); |
082ebb0c TP |
388 | |
389 | return 0; | |
390 | } | |
391 | ||
bf7cd94d JB |
392 | static int mesh_add_ds_params_ie(struct ieee80211_sub_if_data *sdata, |
393 | struct sk_buff *skb) | |
082ebb0c | 394 | { |
55de908a JB |
395 | struct ieee80211_chanctx_conf *chanctx_conf; |
396 | struct ieee80211_channel *chan; | |
082ebb0c | 397 | u8 *pos; |
2e3c8736 | 398 | |
082ebb0c TP |
399 | if (skb_tailroom(skb) < 3) |
400 | return -ENOMEM; | |
401 | ||
55de908a | 402 | rcu_read_lock(); |
d0a9123e | 403 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
55de908a JB |
404 | if (WARN_ON(!chanctx_conf)) { |
405 | rcu_read_unlock(); | |
406 | return -EINVAL; | |
407 | } | |
4bf88530 | 408 | chan = chanctx_conf->def.chan; |
55de908a JB |
409 | rcu_read_unlock(); |
410 | ||
601513aa ET |
411 | pos = skb_put(skb, 2 + 1); |
412 | *pos++ = WLAN_EID_DS_PARAMS; | |
413 | *pos++ = 1; | |
414 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); | |
be125c60 | 415 | |
082ebb0c | 416 | return 0; |
2e3c8736 LCC |
417 | } |
418 | ||
bf7cd94d JB |
419 | int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata, |
420 | struct sk_buff *skb) | |
176f3608 | 421 | { |
176f3608 TP |
422 | struct ieee80211_supported_band *sband; |
423 | u8 *pos; | |
424 | ||
21a8e9dd MSS |
425 | sband = ieee80211_get_sband(sdata); |
426 | if (!sband) | |
427 | return -EINVAL; | |
428 | ||
607ca9ea RM |
429 | /* HT not allowed in 6 GHz */ |
430 | if (sband->band == NL80211_BAND_6GHZ) | |
431 | return 0; | |
432 | ||
176f3608 | 433 | if (!sband->ht_cap.ht_supported || |
0418a445 SW |
434 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || |
435 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
436 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
176f3608 TP |
437 | return 0; |
438 | ||
439 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap)) | |
440 | return -ENOMEM; | |
441 | ||
442 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap)); | |
ef96a842 | 443 | ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap); |
176f3608 TP |
444 | |
445 | return 0; | |
446 | } | |
447 | ||
bf7cd94d JB |
448 | int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata, |
449 | struct sk_buff *skb) | |
176f3608 TP |
450 | { |
451 | struct ieee80211_local *local = sdata->local; | |
55de908a JB |
452 | struct ieee80211_chanctx_conf *chanctx_conf; |
453 | struct ieee80211_channel *channel; | |
55de908a JB |
454 | struct ieee80211_supported_band *sband; |
455 | struct ieee80211_sta_ht_cap *ht_cap; | |
176f3608 TP |
456 | u8 *pos; |
457 | ||
55de908a | 458 | rcu_read_lock(); |
d0a9123e | 459 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
55de908a JB |
460 | if (WARN_ON(!chanctx_conf)) { |
461 | rcu_read_unlock(); | |
462 | return -EINVAL; | |
463 | } | |
4bf88530 | 464 | channel = chanctx_conf->def.chan; |
55de908a JB |
465 | rcu_read_unlock(); |
466 | ||
467 | sband = local->hw.wiphy->bands[channel->band]; | |
468 | ht_cap = &sband->ht_cap; | |
469 | ||
607ca9ea RM |
470 | /* HT not allowed in 6 GHz */ |
471 | if (sband->band == NL80211_BAND_6GHZ) | |
472 | return 0; | |
473 | ||
c85fb53c BC |
474 | if (!ht_cap->ht_supported || |
475 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
476 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
477 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
176f3608 TP |
478 | return 0; |
479 | ||
074d46d1 | 480 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation)) |
176f3608 TP |
481 | return -ENOMEM; |
482 | ||
074d46d1 | 483 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation)); |
4bf88530 | 484 | ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef, |
57f255f5 AN |
485 | sdata->vif.bss_conf.ht_operation_mode, |
486 | false); | |
176f3608 TP |
487 | |
488 | return 0; | |
489 | } | |
bf7cd94d | 490 | |
c85fb53c BC |
491 | int mesh_add_vht_cap_ie(struct ieee80211_sub_if_data *sdata, |
492 | struct sk_buff *skb) | |
493 | { | |
c85fb53c BC |
494 | struct ieee80211_supported_band *sband; |
495 | u8 *pos; | |
496 | ||
21a8e9dd MSS |
497 | sband = ieee80211_get_sband(sdata); |
498 | if (!sband) | |
499 | return -EINVAL; | |
500 | ||
607ca9ea RM |
501 | /* VHT not allowed in 6 GHz */ |
502 | if (sband->band == NL80211_BAND_6GHZ) | |
503 | return 0; | |
504 | ||
c85fb53c BC |
505 | if (!sband->vht_cap.vht_supported || |
506 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
507 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
508 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
509 | return 0; | |
510 | ||
511 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_cap)) | |
512 | return -ENOMEM; | |
513 | ||
514 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_cap)); | |
515 | ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, sband->vht_cap.cap); | |
516 | ||
517 | return 0; | |
518 | } | |
519 | ||
520 | int mesh_add_vht_oper_ie(struct ieee80211_sub_if_data *sdata, | |
521 | struct sk_buff *skb) | |
522 | { | |
523 | struct ieee80211_local *local = sdata->local; | |
524 | struct ieee80211_chanctx_conf *chanctx_conf; | |
525 | struct ieee80211_channel *channel; | |
526 | struct ieee80211_supported_band *sband; | |
527 | struct ieee80211_sta_vht_cap *vht_cap; | |
528 | u8 *pos; | |
529 | ||
530 | rcu_read_lock(); | |
d0a9123e | 531 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
c85fb53c BC |
532 | if (WARN_ON(!chanctx_conf)) { |
533 | rcu_read_unlock(); | |
534 | return -EINVAL; | |
535 | } | |
536 | channel = chanctx_conf->def.chan; | |
537 | rcu_read_unlock(); | |
538 | ||
539 | sband = local->hw.wiphy->bands[channel->band]; | |
540 | vht_cap = &sband->vht_cap; | |
541 | ||
607ca9ea RM |
542 | /* VHT not allowed in 6 GHz */ |
543 | if (sband->band == NL80211_BAND_6GHZ) | |
544 | return 0; | |
545 | ||
c85fb53c BC |
546 | if (!vht_cap->vht_supported || |
547 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
548 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
549 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
550 | return 0; | |
551 | ||
552 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_operation)) | |
553 | return -ENOMEM; | |
554 | ||
555 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_operation)); | |
556 | ieee80211_ie_build_vht_oper(pos, vht_cap, | |
557 | &sdata->vif.bss_conf.chandef); | |
558 | ||
559 | return 0; | |
560 | } | |
561 | ||
60ad72da SE |
562 | int mesh_add_he_cap_ie(struct ieee80211_sub_if_data *sdata, |
563 | struct sk_buff *skb, u8 ie_len) | |
564 | { | |
565 | const struct ieee80211_sta_he_cap *he_cap; | |
566 | struct ieee80211_supported_band *sband; | |
567 | u8 *pos; | |
568 | ||
569 | sband = ieee80211_get_sband(sdata); | |
570 | if (!sband) | |
571 | return -EINVAL; | |
572 | ||
573 | he_cap = ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT); | |
574 | ||
575 | if (!he_cap || | |
576 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
577 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
578 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
579 | return 0; | |
580 | ||
581 | if (skb_tailroom(skb) < ie_len) | |
582 | return -ENOMEM; | |
583 | ||
584 | pos = skb_put(skb, ie_len); | |
1f2c1044 | 585 | ieee80211_ie_build_he_cap(0, pos, he_cap, pos + ie_len); |
60ad72da SE |
586 | |
587 | return 0; | |
588 | } | |
589 | ||
590 | int mesh_add_he_oper_ie(struct ieee80211_sub_if_data *sdata, | |
591 | struct sk_buff *skb) | |
592 | { | |
593 | const struct ieee80211_sta_he_cap *he_cap; | |
594 | struct ieee80211_supported_band *sband; | |
d1b7524b | 595 | u32 len; |
60ad72da SE |
596 | u8 *pos; |
597 | ||
598 | sband = ieee80211_get_sband(sdata); | |
599 | if (!sband) | |
600 | return -EINVAL; | |
601 | ||
602 | he_cap = ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT); | |
603 | if (!he_cap || | |
604 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
605 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
606 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
607 | return 0; | |
608 | ||
d1b7524b RM |
609 | len = 2 + 1 + sizeof(struct ieee80211_he_operation); |
610 | if (sdata->vif.bss_conf.chandef.chan->band == NL80211_BAND_6GHZ) | |
611 | len += sizeof(struct ieee80211_he_6ghz_oper); | |
612 | ||
613 | if (skb_tailroom(skb) < len) | |
60ad72da SE |
614 | return -ENOMEM; |
615 | ||
d1b7524b RM |
616 | pos = skb_put(skb, len); |
617 | ieee80211_ie_build_he_oper(pos, &sdata->vif.bss_conf.chandef); | |
60ad72da SE |
618 | |
619 | return 0; | |
620 | } | |
621 | ||
24a2042c RM |
622 | int mesh_add_he_6ghz_cap_ie(struct ieee80211_sub_if_data *sdata, |
623 | struct sk_buff *skb) | |
624 | { | |
65ad3ef9 RM |
625 | struct ieee80211_supported_band *sband; |
626 | const struct ieee80211_sband_iftype_data *iftd; | |
627 | ||
628 | sband = ieee80211_get_sband(sdata); | |
629 | if (!sband) | |
630 | return -EINVAL; | |
631 | ||
632 | iftd = ieee80211_get_sband_iftype_data(sband, | |
633 | NL80211_IFTYPE_MESH_POINT); | |
634 | /* The device doesn't support HE in mesh mode or at all */ | |
635 | if (!iftd) | |
636 | return 0; | |
637 | ||
abd27d06 | 638 | ieee80211_ie_build_he_6ghz_cap(sdata, sdata->deflink.smps_mode, skb); |
24a2042c RM |
639 | return 0; |
640 | } | |
641 | ||
df1875c4 RL |
642 | int mesh_add_eht_cap_ie(struct ieee80211_sub_if_data *sdata, |
643 | struct sk_buff *skb, u8 ie_len) | |
644 | { | |
645 | const struct ieee80211_sta_he_cap *he_cap; | |
646 | const struct ieee80211_sta_eht_cap *eht_cap; | |
647 | struct ieee80211_supported_band *sband; | |
648 | u8 *pos; | |
649 | ||
650 | sband = ieee80211_get_sband(sdata); | |
651 | if (!sband) | |
652 | return -EINVAL; | |
653 | ||
654 | he_cap = ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT); | |
655 | eht_cap = ieee80211_get_eht_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT); | |
656 | if (!he_cap || !eht_cap || | |
657 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
658 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
659 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
660 | return 0; | |
661 | ||
662 | if (skb_tailroom(skb) < ie_len) | |
663 | return -ENOMEM; | |
664 | ||
665 | pos = skb_put(skb, ie_len); | |
666 | ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + ie_len, false); | |
667 | ||
668 | return 0; | |
669 | } | |
670 | ||
671 | int mesh_add_eht_oper_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) | |
672 | { | |
673 | const struct ieee80211_sta_eht_cap *eht_cap; | |
674 | struct ieee80211_supported_band *sband; | |
675 | u32 len; | |
676 | u8 *pos; | |
677 | ||
678 | sband = ieee80211_get_sband(sdata); | |
679 | if (!sband) | |
680 | return -EINVAL; | |
681 | ||
682 | eht_cap = ieee80211_get_eht_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT); | |
683 | if (!eht_cap || | |
684 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
685 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
686 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
687 | return 0; | |
688 | ||
689 | len = 2 + 1 + offsetof(struct ieee80211_eht_operation, optional) + | |
690 | offsetof(struct ieee80211_eht_operation_info, optional); | |
691 | ||
692 | if (skb_tailroom(skb) < len) | |
693 | return -ENOMEM; | |
694 | ||
695 | pos = skb_put(skb, len); | |
696 | ieee80211_ie_build_eht_oper(pos, &sdata->vif.bss_conf.chandef, eht_cap); | |
697 | ||
698 | return 0; | |
699 | } | |
700 | ||
34f11cd3 | 701 | static void ieee80211_mesh_path_timer(struct timer_list *t) |
2e3c8736 LCC |
702 | { |
703 | struct ieee80211_sub_if_data *sdata = | |
34f11cd3 | 704 | from_timer(sdata, t, u.mesh.mesh_path_timer); |
5bb644a0 | 705 | |
16114496 | 706 | wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); |
2e3c8736 LCC |
707 | } |
708 | ||
34f11cd3 | 709 | static void ieee80211_mesh_path_root_timer(struct timer_list *t) |
e304bfd3 RP |
710 | { |
711 | struct ieee80211_sub_if_data *sdata = | |
34f11cd3 | 712 | from_timer(sdata, t, u.mesh.mesh_path_root_timer); |
e304bfd3 | 713 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
e304bfd3 RP |
714 | |
715 | set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); | |
716 | ||
16114496 | 717 | wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); |
e304bfd3 RP |
718 | } |
719 | ||
63c5723b RP |
720 | void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh) |
721 | { | |
dbb912cd | 722 | if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT) |
63c5723b RP |
723 | set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); |
724 | else { | |
725 | clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); | |
726 | /* stop running timer */ | |
727 | del_timer_sync(&ifmsh->mesh_path_root_timer); | |
728 | } | |
729 | } | |
730 | ||
70debba3 PKC |
731 | static void |
732 | ieee80211_mesh_update_bss_params(struct ieee80211_sub_if_data *sdata, | |
733 | u8 *ie, u8 ie_len) | |
734 | { | |
735 | struct ieee80211_supported_band *sband; | |
636707e5 | 736 | const struct element *cap; |
70debba3 PKC |
737 | const struct ieee80211_he_operation *he_oper = NULL; |
738 | ||
739 | sband = ieee80211_get_sband(sdata); | |
740 | if (!sband) | |
741 | return; | |
742 | ||
743 | if (!ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT) || | |
744 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
745 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
746 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
747 | return; | |
748 | ||
749 | sdata->vif.bss_conf.he_support = true; | |
750 | ||
636707e5 JB |
751 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ie, ie_len); |
752 | if (cap && cap->datalen >= 1 + sizeof(*he_oper) && | |
753 | cap->datalen >= 1 + ieee80211_he_oper_size(cap->data + 1)) | |
754 | he_oper = (void *)(cap->data + 1); | |
70debba3 PKC |
755 | |
756 | if (he_oper) | |
757 | sdata->vif.bss_conf.he_oper.params = | |
758 | __le32_to_cpu(he_oper->he_oper_params); | |
df1875c4 RL |
759 | |
760 | sdata->vif.bss_conf.eht_support = | |
761 | !!ieee80211_get_eht_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT); | |
70debba3 PKC |
762 | } |
763 | ||
d5edb9ae FF |
764 | bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata, |
765 | struct sk_buff *skb, u32 ctrl_flags) | |
766 | { | |
767 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
768 | struct ieee80211_mesh_fast_tx *entry; | |
769 | struct ieee80211s_hdr *meshhdr; | |
770 | u8 sa[ETH_ALEN] __aligned(2); | |
771 | struct tid_ampdu_tx *tid_tx; | |
772 | struct sta_info *sta; | |
773 | bool copy_sa = false; | |
774 | u16 ethertype; | |
775 | u8 tid; | |
776 | ||
777 | if (ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) | |
778 | return false; | |
779 | ||
780 | if (ifmsh->mshcfg.dot11MeshNolearn) | |
781 | return false; | |
782 | ||
783 | /* Add support for these cases later */ | |
784 | if (ifmsh->ps_peers_light_sleep || ifmsh->ps_peers_deep_sleep) | |
785 | return false; | |
786 | ||
787 | if (is_multicast_ether_addr(skb->data)) | |
788 | return false; | |
789 | ||
790 | ethertype = (skb->data[12] << 8) | skb->data[13]; | |
791 | if (ethertype < ETH_P_802_3_MIN) | |
792 | return false; | |
793 | ||
794 | if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) | |
795 | return false; | |
796 | ||
797 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
798 | skb_set_transport_header(skb, skb_checksum_start_offset(skb)); | |
799 | if (skb_checksum_help(skb)) | |
800 | return false; | |
801 | } | |
802 | ||
803 | entry = mesh_fast_tx_get(sdata, skb->data); | |
804 | if (!entry) | |
805 | return false; | |
806 | ||
807 | if (skb_headroom(skb) < entry->hdrlen + entry->fast_tx.hdr_len) | |
808 | return false; | |
809 | ||
810 | sta = rcu_dereference(entry->mpath->next_hop); | |
811 | if (!sta) | |
812 | return false; | |
813 | ||
814 | tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; | |
815 | tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]); | |
816 | if (tid_tx) { | |
817 | if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) | |
818 | return false; | |
819 | if (tid_tx->timeout) | |
820 | tid_tx->last_tx = jiffies; | |
821 | } | |
822 | ||
823 | skb = skb_share_check(skb, GFP_ATOMIC); | |
824 | if (!skb) | |
825 | return true; | |
826 | ||
827 | skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb)); | |
828 | ||
829 | meshhdr = (struct ieee80211s_hdr *)entry->hdr; | |
830 | if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) { | |
831 | /* preserve SA from eth header for 6-addr frames */ | |
832 | ether_addr_copy(sa, skb->data + ETH_ALEN); | |
833 | copy_sa = true; | |
834 | } | |
835 | ||
836 | memcpy(skb_push(skb, entry->hdrlen - 2 * ETH_ALEN), entry->hdr, | |
837 | entry->hdrlen); | |
838 | ||
839 | meshhdr = (struct ieee80211s_hdr *)skb->data; | |
840 | put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum), | |
841 | &meshhdr->seqnum); | |
842 | meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; | |
843 | if (copy_sa) | |
844 | ether_addr_copy(meshhdr->eaddr2, sa); | |
845 | ||
846 | skb_push(skb, 2 * ETH_ALEN); | |
847 | __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx, | |
848 | entry->mpath->dst, sdata->vif.addr); | |
849 | ||
850 | return true; | |
851 | } | |
852 | ||
3c5772a5 JC |
853 | /** |
854 | * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame | |
bf7cd94d | 855 | * @hdr: 802.11 frame header |
3c5772a5 JC |
856 | * @fc: frame control field |
857 | * @meshda: destination address in the mesh | |
13880a3b | 858 | * @meshsa: source address in the mesh. Same as TA, as frame is |
3c5772a5 JC |
859 | * locally originated. |
860 | * | |
861 | * Return the length of the 802.11 (does not include a mesh control header) | |
862 | */ | |
15ff6365 JB |
863 | int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, |
864 | const u8 *meshda, const u8 *meshsa) | |
865 | { | |
3c5772a5 JC |
866 | if (is_multicast_ether_addr(meshda)) { |
867 | *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); | |
868 | /* DA TA SA */ | |
869 | memcpy(hdr->addr1, meshda, ETH_ALEN); | |
870 | memcpy(hdr->addr2, meshsa, ETH_ALEN); | |
871 | memcpy(hdr->addr3, meshsa, ETH_ALEN); | |
872 | return 24; | |
873 | } else { | |
2154c81c | 874 | *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
3c5772a5 | 875 | /* RA TA DA SA */ |
c84a67a2 | 876 | eth_zero_addr(hdr->addr1); /* RA is resolved later */ |
3c5772a5 JC |
877 | memcpy(hdr->addr2, meshsa, ETH_ALEN); |
878 | memcpy(hdr->addr3, meshda, ETH_ALEN); | |
879 | memcpy(hdr->addr4, meshsa, ETH_ALEN); | |
880 | return 30; | |
881 | } | |
882 | } | |
883 | ||
902acc78 JB |
884 | /** |
885 | * ieee80211_new_mesh_header - create a new mesh header | |
902acc78 | 886 | * @sdata: mesh interface to be used |
bf7cd94d | 887 | * @meshhdr: uninitialized mesh header |
61ad5394 JC |
888 | * @addr4or5: 1st address in the ae header, which may correspond to address 4 |
889 | * (if addr6 is NULL) or address 5 (if addr6 is present). It may | |
890 | * be NULL. | |
891 | * @addr6: 2nd address in the ae header, which corresponds to addr6 of the | |
892 | * mesh frame | |
902acc78 JB |
893 | * |
894 | * Return the header length. | |
895 | */ | |
5edfcee5 AH |
896 | unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata, |
897 | struct ieee80211s_hdr *meshhdr, | |
898 | const char *addr4or5, const char *addr6) | |
902acc78 | 899 | { |
bf7cd94d JB |
900 | if (WARN_ON(!addr4or5 && addr6)) |
901 | return 0; | |
902 | ||
0c3cee72 | 903 | memset(meshhdr, 0, sizeof(*meshhdr)); |
bf7cd94d | 904 | |
472dbc45 | 905 | meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; |
bf7cd94d | 906 | |
e626dad9 FF |
907 | put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum), |
908 | &meshhdr->seqnum); | |
61ad5394 | 909 | if (addr4or5 && !addr6) { |
3c5772a5 | 910 | meshhdr->flags |= MESH_FLAGS_AE_A4; |
61ad5394 | 911 | memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); |
bf7cd94d | 912 | return 2 * ETH_ALEN; |
61ad5394 | 913 | } else if (addr4or5 && addr6) { |
3c5772a5 | 914 | meshhdr->flags |= MESH_FLAGS_AE_A5_A6; |
61ad5394 JC |
915 | memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); |
916 | memcpy(meshhdr->eaddr2, addr6, ETH_ALEN); | |
bf7cd94d | 917 | return 3 * ETH_ALEN; |
3c5772a5 | 918 | } |
bf7cd94d JB |
919 | |
920 | return ETH_ALEN; | |
902acc78 JB |
921 | } |
922 | ||
bf7cd94d | 923 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata) |
472dbc45 | 924 | { |
bf7cd94d | 925 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
15ddba5f | 926 | u64 changed; |
472dbc45 | 927 | |
31f909a2 MH |
928 | if (ifmsh->mshcfg.plink_timeout > 0) |
929 | ieee80211_sta_expire(sdata, ifmsh->mshcfg.plink_timeout * HZ); | |
472dbc45 JB |
930 | mesh_path_expire(sdata); |
931 | ||
df323818 | 932 | changed = mesh_accept_plinks_update(sdata); |
2b5e1967 | 933 | ieee80211_mbss_info_change_notify(sdata, changed); |
472dbc45 | 934 | |
d5edb9ae FF |
935 | mesh_fast_tx_gc(sdata); |
936 | ||
472dbc45 | 937 | mod_timer(&ifmsh->housekeeping_timer, |
bf7cd94d JB |
938 | round_jiffies(jiffies + |
939 | IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); | |
472dbc45 JB |
940 | } |
941 | ||
e304bfd3 RP |
942 | static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata) |
943 | { | |
944 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
a69cc44f | 945 | u32 interval; |
e304bfd3 RP |
946 | |
947 | mesh_path_tx_root_frame(sdata); | |
a69cc44f CYY |
948 | |
949 | if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN) | |
950 | interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval; | |
951 | else | |
952 | interval = ifmsh->mshcfg.dot11MeshHWMProotInterval; | |
953 | ||
e304bfd3 | 954 | mod_timer(&ifmsh->mesh_path_root_timer, |
a69cc44f | 955 | round_jiffies(TU_TO_EXP_TIME(interval))); |
e304bfd3 RP |
956 | } |
957 | ||
2b5e1967 TP |
958 | static int |
959 | ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh) | |
960 | { | |
961 | struct beacon_data *bcn; | |
962 | int head_len, tail_len; | |
963 | struct sk_buff *skb; | |
964 | struct ieee80211_mgmt *mgmt; | |
965 | struct ieee80211_chanctx_conf *chanctx_conf; | |
b8456a14 | 966 | struct mesh_csa_settings *csa; |
57fbcce3 | 967 | enum nl80211_band band; |
df1875c4 | 968 | u8 ie_len_he_cap, ie_len_eht_cap; |
2b5e1967 TP |
969 | u8 *pos; |
970 | struct ieee80211_sub_if_data *sdata; | |
4c121fd6 | 971 | int hdr_len = offsetofend(struct ieee80211_mgmt, u.beacon); |
2b5e1967 TP |
972 | |
973 | sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh); | |
974 | rcu_read_lock(); | |
d0a9123e | 975 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
2b5e1967 TP |
976 | band = chanctx_conf->def.chan->band; |
977 | rcu_read_unlock(); | |
978 | ||
60ad72da SE |
979 | ie_len_he_cap = ieee80211_ie_len_he_cap(sdata, |
980 | NL80211_IFTYPE_MESH_POINT); | |
df1875c4 RL |
981 | ie_len_eht_cap = ieee80211_ie_len_eht_cap(sdata, |
982 | NL80211_IFTYPE_MESH_POINT); | |
2b5e1967 TP |
983 | head_len = hdr_len + |
984 | 2 + /* NULL SSID */ | |
b8456a14 CYY |
985 | /* Channel Switch Announcement */ |
986 | 2 + sizeof(struct ieee80211_channel_sw_ie) + | |
08a7e621 | 987 | /* Mesh Channel Switch Parameters */ |
b8456a14 | 988 | 2 + sizeof(struct ieee80211_mesh_chansw_params_ie) + |
75d627d5 SW |
989 | /* Channel Switch Wrapper + Wide Bandwidth CSA IE */ |
990 | 2 + 2 + sizeof(struct ieee80211_wide_bw_chansw_ie) + | |
991 | 2 + sizeof(struct ieee80211_sec_chan_offs_ie) + | |
2b5e1967 TP |
992 | 2 + 8 + /* supported rates */ |
993 | 2 + 3; /* DS params */ | |
994 | tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) + | |
995 | 2 + sizeof(struct ieee80211_ht_cap) + | |
996 | 2 + sizeof(struct ieee80211_ht_operation) + | |
997 | 2 + ifmsh->mesh_id_len + | |
998 | 2 + sizeof(struct ieee80211_meshconf_ie) + | |
999 | 2 + sizeof(__le16) + /* awake window */ | |
c85fb53c BC |
1000 | 2 + sizeof(struct ieee80211_vht_cap) + |
1001 | 2 + sizeof(struct ieee80211_vht_operation) + | |
60ad72da SE |
1002 | ie_len_he_cap + |
1003 | 2 + 1 + sizeof(struct ieee80211_he_operation) + | |
d1b7524b | 1004 | sizeof(struct ieee80211_he_6ghz_oper) + |
24a2042c | 1005 | 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) + |
df1875c4 RL |
1006 | ie_len_eht_cap + |
1007 | 2 + 1 + offsetof(struct ieee80211_eht_operation, optional) + | |
1008 | offsetof(struct ieee80211_eht_operation_info, optional) + | |
2b5e1967 TP |
1009 | ifmsh->ie_len; |
1010 | ||
1011 | bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL); | |
1012 | /* need an skb for IE builders to operate on */ | |
60df54f8 | 1013 | skb = __dev_alloc_skb(max(head_len, tail_len), GFP_KERNEL); |
2b5e1967 TP |
1014 | |
1015 | if (!bcn || !skb) | |
1016 | goto out_free; | |
1017 | ||
1018 | /* | |
1019 | * pointers go into the block we allocated, | |
1020 | * memory is | beacon_data | head | tail | | |
1021 | */ | |
1022 | bcn->head = ((u8 *) bcn) + sizeof(*bcn); | |
1023 | ||
1024 | /* fill in the head */ | |
b080db58 | 1025 | mgmt = skb_put_zero(skb, hdr_len); |
2b5e1967 TP |
1026 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1027 | IEEE80211_STYPE_BEACON); | |
1028 | eth_broadcast_addr(mgmt->da); | |
1029 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); | |
1030 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); | |
1031 | ieee80211_mps_set_frame_flags(sdata, NULL, (void *) mgmt); | |
1032 | mgmt->u.beacon.beacon_int = | |
1033 | cpu_to_le16(sdata->vif.bss_conf.beacon_int); | |
1034 | mgmt->u.beacon.capab_info |= cpu_to_le16( | |
1035 | sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0); | |
1036 | ||
1037 | pos = skb_put(skb, 2); | |
1038 | *pos++ = WLAN_EID_SSID; | |
1039 | *pos++ = 0x0; | |
1040 | ||
b8456a14 CYY |
1041 | rcu_read_lock(); |
1042 | csa = rcu_dereference(ifmsh->csa); | |
1043 | if (csa) { | |
75d627d5 SW |
1044 | enum nl80211_channel_type ct; |
1045 | struct cfg80211_chan_def *chandef; | |
1046 | int ie_len = 2 + sizeof(struct ieee80211_channel_sw_ie) + | |
1047 | 2 + sizeof(struct ieee80211_mesh_chansw_params_ie); | |
1048 | ||
e45a79da | 1049 | pos = skb_put_zero(skb, ie_len); |
b8456a14 CYY |
1050 | *pos++ = WLAN_EID_CHANNEL_SWITCH; |
1051 | *pos++ = 3; | |
1052 | *pos++ = 0x0; | |
1053 | *pos++ = ieee80211_frequency_to_channel( | |
1054 | csa->settings.chandef.chan->center_freq); | |
8552a434 JC |
1055 | bcn->cntdwn_current_counter = csa->settings.count; |
1056 | bcn->cntdwn_counter_offsets[0] = hdr_len + 6; | |
b8456a14 CYY |
1057 | *pos++ = csa->settings.count; |
1058 | *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; | |
1059 | *pos++ = 6; | |
0cb4d4dc | 1060 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) { |
b8456a14 CYY |
1061 | *pos++ = ifmsh->mshcfg.dot11MeshTTL; |
1062 | *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR; | |
1063 | } else { | |
1064 | *pos++ = ifmsh->chsw_ttl; | |
1065 | } | |
1066 | *pos++ |= csa->settings.block_tx ? | |
1067 | WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00; | |
1068 | put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); | |
1069 | pos += 2; | |
ca91dc97 | 1070 | put_unaligned_le16(ifmsh->pre_value, pos); |
b8456a14 | 1071 | pos += 2; |
75d627d5 SW |
1072 | |
1073 | switch (csa->settings.chandef.width) { | |
1074 | case NL80211_CHAN_WIDTH_40: | |
1075 | ie_len = 2 + sizeof(struct ieee80211_sec_chan_offs_ie); | |
e45a79da | 1076 | pos = skb_put_zero(skb, ie_len); |
75d627d5 SW |
1077 | |
1078 | *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */ | |
1079 | *pos++ = 1; /* len */ | |
1080 | ct = cfg80211_get_chandef_type(&csa->settings.chandef); | |
1081 | if (ct == NL80211_CHAN_HT40PLUS) | |
1082 | *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
1083 | else | |
1084 | *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
1085 | break; | |
1086 | case NL80211_CHAN_WIDTH_80: | |
1087 | case NL80211_CHAN_WIDTH_80P80: | |
1088 | case NL80211_CHAN_WIDTH_160: | |
1089 | /* Channel Switch Wrapper + Wide Bandwidth CSA IE */ | |
1090 | ie_len = 2 + 2 + | |
1091 | sizeof(struct ieee80211_wide_bw_chansw_ie); | |
e45a79da | 1092 | pos = skb_put_zero(skb, ie_len); |
75d627d5 SW |
1093 | |
1094 | *pos++ = WLAN_EID_CHANNEL_SWITCH_WRAPPER; /* EID */ | |
1095 | *pos++ = 5; /* len */ | |
1096 | /* put sub IE */ | |
1097 | chandef = &csa->settings.chandef; | |
1098 | ieee80211_ie_build_wide_bw_cs(pos, chandef); | |
1099 | break; | |
1100 | default: | |
1101 | break; | |
1102 | } | |
b8456a14 CYY |
1103 | } |
1104 | rcu_read_unlock(); | |
1105 | ||
2b5e1967 | 1106 | if (ieee80211_add_srates_ie(sdata, skb, true, band) || |
bf7cd94d | 1107 | mesh_add_ds_params_ie(sdata, skb)) |
2b5e1967 TP |
1108 | goto out_free; |
1109 | ||
1110 | bcn->head_len = skb->len; | |
1111 | memcpy(bcn->head, skb->data, bcn->head_len); | |
1112 | ||
1113 | /* now the tail */ | |
1114 | skb_trim(skb, 0); | |
1115 | bcn->tail = bcn->head + bcn->head_len; | |
1116 | ||
1117 | if (ieee80211_add_ext_srates_ie(sdata, skb, true, band) || | |
bf7cd94d JB |
1118 | mesh_add_rsn_ie(sdata, skb) || |
1119 | mesh_add_ht_cap_ie(sdata, skb) || | |
1120 | mesh_add_ht_oper_ie(sdata, skb) || | |
1121 | mesh_add_meshid_ie(sdata, skb) || | |
1122 | mesh_add_meshconf_ie(sdata, skb) || | |
1123 | mesh_add_awake_window_ie(sdata, skb) || | |
c85fb53c BC |
1124 | mesh_add_vht_cap_ie(sdata, skb) || |
1125 | mesh_add_vht_oper_ie(sdata, skb) || | |
60ad72da SE |
1126 | mesh_add_he_cap_ie(sdata, skb, ie_len_he_cap) || |
1127 | mesh_add_he_oper_ie(sdata, skb) || | |
24a2042c | 1128 | mesh_add_he_6ghz_cap_ie(sdata, skb) || |
df1875c4 RL |
1129 | mesh_add_eht_cap_ie(sdata, skb, ie_len_eht_cap) || |
1130 | mesh_add_eht_oper_ie(sdata, skb) || | |
bf7cd94d | 1131 | mesh_add_vendor_ies(sdata, skb)) |
2b5e1967 TP |
1132 | goto out_free; |
1133 | ||
1134 | bcn->tail_len = skb->len; | |
1135 | memcpy(bcn->tail, skb->data, bcn->tail_len); | |
70debba3 | 1136 | ieee80211_mesh_update_bss_params(sdata, bcn->tail, bcn->tail_len); |
43552be1 TP |
1137 | bcn->meshconf = (struct ieee80211_meshconf_ie *) |
1138 | (bcn->tail + ifmsh->meshconf_offset); | |
2b5e1967 TP |
1139 | |
1140 | dev_kfree_skb(skb); | |
1141 | rcu_assign_pointer(ifmsh->beacon, bcn); | |
1142 | return 0; | |
1143 | out_free: | |
1144 | kfree(bcn); | |
1145 | dev_kfree_skb(skb); | |
1146 | return -ENOMEM; | |
1147 | } | |
1148 | ||
1149 | static int | |
8d61ffa5 | 1150 | ieee80211_mesh_rebuild_beacon(struct ieee80211_sub_if_data *sdata) |
2b5e1967 | 1151 | { |
2b5e1967 TP |
1152 | struct beacon_data *old_bcn; |
1153 | int ret; | |
2b5e1967 | 1154 | |
6858ad75 | 1155 | old_bcn = sdata_dereference(sdata->u.mesh.beacon, sdata); |
8d61ffa5 | 1156 | ret = ieee80211_mesh_build_beacon(&sdata->u.mesh); |
2b5e1967 TP |
1157 | if (ret) |
1158 | /* just reuse old beacon */ | |
8d61ffa5 | 1159 | return ret; |
2b5e1967 TP |
1160 | |
1161 | if (old_bcn) | |
1162 | kfree_rcu(old_bcn, rcu_head); | |
8d61ffa5 | 1163 | return 0; |
2b5e1967 TP |
1164 | } |
1165 | ||
1166 | void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata, | |
15ddba5f | 1167 | u64 changed) |
2b5e1967 | 1168 | { |
f81a9ded TP |
1169 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
1170 | unsigned long bits = changed; | |
1171 | u32 bit; | |
1172 | ||
1173 | if (!bits) | |
1174 | return; | |
1175 | ||
1176 | /* if we race with running work, worst case this work becomes a noop */ | |
1177 | for_each_set_bit(bit, &bits, sizeof(changed) * BITS_PER_BYTE) | |
1178 | set_bit(bit, &ifmsh->mbss_changed); | |
1179 | set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags); | |
16114496 | 1180 | wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); |
2b5e1967 TP |
1181 | } |
1182 | ||
1183 | int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) | |
472dbc45 JB |
1184 | { |
1185 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1186 | struct ieee80211_local *local = sdata->local; | |
15ddba5f | 1187 | u64 changed = BSS_CHANGED_BEACON | |
f4eabc91 CYY |
1188 | BSS_CHANGED_BEACON_ENABLED | |
1189 | BSS_CHANGED_HT | | |
1190 | BSS_CHANGED_BASIC_RATES | | |
dcbe73ca PKC |
1191 | BSS_CHANGED_BEACON_INT | |
1192 | BSS_CHANGED_MCAST_RATE; | |
472dbc45 | 1193 | |
09b17470 JB |
1194 | local->fif_other_bss++; |
1195 | /* mesh ifaces must set allmulti to forward mcast traffic */ | |
1196 | atomic_inc(&local->iff_allmultis); | |
1197 | ieee80211_configure_filter(local); | |
1198 | ||
c7108a71 | 1199 | ifmsh->mesh_cc_id = 0; /* Disabled */ |
dbf498fb JC |
1200 | /* register sync ops from extensible synchronization framework */ |
1201 | ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id); | |
dbf498fb | 1202 | ifmsh->sync_offset_clockdrift_max = 0; |
6b9ac442 | 1203 | set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); |
63c5723b | 1204 | ieee80211_mesh_root_setup(ifmsh); |
16114496 | 1205 | wiphy_work_queue(local->hw.wiphy, &sdata->work); |
70c33eaa AN |
1206 | sdata->vif.bss_conf.ht_operation_mode = |
1207 | ifmsh->mshcfg.ht_opmode; | |
d6a83228 | 1208 | sdata->vif.bss_conf.enable_beacon = true; |
f4eabc91 | 1209 | |
39886b61 | 1210 | changed |= ieee80211_mps_local_status_update(sdata); |
3f52b7e3 | 1211 | |
2b5e1967 TP |
1212 | if (ieee80211_mesh_build_beacon(ifmsh)) { |
1213 | ieee80211_stop_mesh(sdata); | |
1214 | return -ENOMEM; | |
1215 | } | |
1216 | ||
057d5f4b | 1217 | ieee80211_recalc_dtim(local, sdata); |
d8675a63 | 1218 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); |
c405c629 JB |
1219 | |
1220 | netif_carrier_on(sdata->dev); | |
2b5e1967 | 1221 | return 0; |
472dbc45 JB |
1222 | } |
1223 | ||
1224 | void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) | |
1225 | { | |
09b17470 | 1226 | struct ieee80211_local *local = sdata->local; |
29cbe68c | 1227 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
2b5e1967 | 1228 | struct beacon_data *bcn; |
29cbe68c | 1229 | |
c405c629 JB |
1230 | netif_carrier_off(sdata->dev); |
1231 | ||
c37a54ac MH |
1232 | /* flush STAs and mpaths on this iface */ |
1233 | sta_info_flush(sdata); | |
0112fa55 | 1234 | ieee80211_free_keys(sdata, true); |
c37a54ac MH |
1235 | mesh_path_flush_by_iface(sdata); |
1236 | ||
0d466b9c | 1237 | /* stop the beacon */ |
29cbe68c | 1238 | ifmsh->mesh_id_len = 0; |
d6a83228 | 1239 | sdata->vif.bss_conf.enable_beacon = false; |
08fad438 | 1240 | sdata->beacon_rate_set = false; |
d6a83228 | 1241 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); |
d8675a63 JB |
1242 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
1243 | BSS_CHANGED_BEACON_ENABLED); | |
c37a54ac MH |
1244 | |
1245 | /* remove beacon */ | |
6858ad75 | 1246 | bcn = sdata_dereference(ifmsh->beacon, sdata); |
0c2bef46 | 1247 | RCU_INIT_POINTER(ifmsh->beacon, NULL); |
2b5e1967 | 1248 | kfree_rcu(bcn, rcu_head); |
0d466b9c | 1249 | |
3f52b7e3 MP |
1250 | /* free all potentially still buffered group-addressed frames */ |
1251 | local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf); | |
1252 | skb_queue_purge(&ifmsh->ps.bc_buf); | |
1253 | ||
472dbc45 | 1254 | del_timer_sync(&sdata->u.mesh.housekeeping_timer); |
e304bfd3 | 1255 | del_timer_sync(&sdata->u.mesh.mesh_path_root_timer); |
dd4c9260 | 1256 | del_timer_sync(&sdata->u.mesh.mesh_path_timer); |
09b17470 | 1257 | |
f81a9ded TP |
1258 | /* clear any mesh work (for next join) we may have accrued */ |
1259 | ifmsh->wrkq_flags = 0; | |
1260 | ifmsh->mbss_changed = 0; | |
1261 | ||
09b17470 JB |
1262 | local->fif_other_bss--; |
1263 | atomic_dec(&local->iff_allmultis); | |
1264 | ieee80211_configure_filter(local); | |
472dbc45 JB |
1265 | } |
1266 | ||
5d55371b BB |
1267 | static void ieee80211_mesh_csa_mark_radar(struct ieee80211_sub_if_data *sdata) |
1268 | { | |
1269 | int err; | |
1270 | ||
1271 | /* if the current channel is a DFS channel, mark the channel as | |
1272 | * unavailable. | |
1273 | */ | |
1274 | err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy, | |
1275 | &sdata->vif.bss_conf.chandef, | |
1276 | NL80211_IFTYPE_MESH_POINT); | |
1277 | if (err > 0) | |
1278 | cfg80211_radar_event(sdata->local->hw.wiphy, | |
1279 | &sdata->vif.bss_conf.chandef, GFP_ATOMIC); | |
1280 | } | |
1281 | ||
33a45867 CYY |
1282 | static bool |
1283 | ieee80211_mesh_process_chnswitch(struct ieee80211_sub_if_data *sdata, | |
1284 | struct ieee802_11_elems *elems, bool beacon) | |
1285 | { | |
1286 | struct cfg80211_csa_settings params; | |
1287 | struct ieee80211_csa_ie csa_ie; | |
33a45867 | 1288 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
21a8e9dd | 1289 | struct ieee80211_supported_band *sband; |
0cb4d4dc | 1290 | int err; |
ba323e29 JB |
1291 | ieee80211_conn_flags_t conn_flags = 0; |
1292 | u32 vht_cap_info = 0; | |
33a45867 | 1293 | |
dbd72850 MK |
1294 | sdata_assert_lock(sdata); |
1295 | ||
21a8e9dd MSS |
1296 | sband = ieee80211_get_sband(sdata); |
1297 | if (!sband) | |
1298 | return false; | |
1299 | ||
33a45867 CYY |
1300 | switch (sdata->vif.bss_conf.chandef.width) { |
1301 | case NL80211_CHAN_WIDTH_20_NOHT: | |
ba323e29 | 1302 | conn_flags |= IEEE80211_CONN_DISABLE_HT; |
fc0561dc | 1303 | fallthrough; |
33a45867 | 1304 | case NL80211_CHAN_WIDTH_20: |
ba323e29 | 1305 | conn_flags |= IEEE80211_CONN_DISABLE_40MHZ; |
fc0561dc | 1306 | fallthrough; |
71ec289e | 1307 | case NL80211_CHAN_WIDTH_40: |
ba323e29 | 1308 | conn_flags |= IEEE80211_CONN_DISABLE_VHT; |
33a45867 CYY |
1309 | break; |
1310 | default: | |
1311 | break; | |
1312 | } | |
1313 | ||
2a333a0d JB |
1314 | if (elems->vht_cap_elem) |
1315 | vht_cap_info = | |
1316 | le32_to_cpu(elems->vht_cap_elem->vht_cap_info); | |
1317 | ||
33a45867 | 1318 | memset(¶ms, 0, sizeof(params)); |
21a8e9dd | 1319 | err = ieee80211_parse_ch_switch_ie(sdata, elems, sband->band, |
2a333a0d | 1320 | vht_cap_info, |
ba323e29 | 1321 | conn_flags, sdata->vif.addr, |
33a45867 CYY |
1322 | &csa_ie); |
1323 | if (err < 0) | |
1324 | return false; | |
1325 | if (err) | |
1326 | return false; | |
1327 | ||
5d55371b BB |
1328 | /* Mark the channel unavailable if the reason for the switch is |
1329 | * regulatory. | |
1330 | */ | |
1331 | if (csa_ie.reason_code == WLAN_REASON_MESH_CHAN_REGULATORY) | |
1332 | ieee80211_mesh_csa_mark_radar(sdata); | |
1333 | ||
33a45867 CYY |
1334 | params.chandef = csa_ie.chandef; |
1335 | params.count = csa_ie.count; | |
1336 | ||
33a45867 | 1337 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, ¶ms.chandef, |
0ab2e55d BB |
1338 | IEEE80211_CHAN_DISABLED) || |
1339 | !cfg80211_reg_can_beacon(sdata->local->hw.wiphy, ¶ms.chandef, | |
1340 | NL80211_IFTYPE_MESH_POINT)) { | |
33a45867 CYY |
1341 | sdata_info(sdata, |
1342 | "mesh STA %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n", | |
1343 | sdata->vif.addr, | |
1344 | params.chandef.chan->center_freq, | |
1345 | params.chandef.width, | |
1346 | params.chandef.center_freq1, | |
1347 | params.chandef.center_freq2); | |
1348 | return false; | |
1349 | } | |
1350 | ||
1351 | err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy, | |
2beb6dab LC |
1352 | ¶ms.chandef, |
1353 | NL80211_IFTYPE_MESH_POINT); | |
33a45867 CYY |
1354 | if (err < 0) |
1355 | return false; | |
0ab2e55d BB |
1356 | if (err > 0 && !ifmsh->userspace_handles_dfs) { |
1357 | sdata_info(sdata, | |
1358 | "mesh STA %pM switches to channel requiring DFS (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n", | |
1359 | sdata->vif.addr, | |
1360 | params.chandef.chan->center_freq, | |
1361 | params.chandef.width, | |
1362 | params.chandef.center_freq1, | |
1363 | params.chandef.center_freq2); | |
33a45867 | 1364 | return false; |
0ab2e55d | 1365 | } |
2beb6dab LC |
1366 | |
1367 | params.radar_required = err; | |
33a45867 | 1368 | |
0cb4d4dc LC |
1369 | if (cfg80211_chandef_identical(¶ms.chandef, |
1370 | &sdata->vif.bss_conf.chandef)) { | |
1371 | mcsa_dbg(sdata, | |
1372 | "received csa with an identical chandef, ignoring\n"); | |
1373 | return true; | |
1374 | } | |
33a45867 CYY |
1375 | |
1376 | mcsa_dbg(sdata, | |
1377 | "received channel switch announcement to go to channel %d MHz\n", | |
1378 | params.chandef.chan->center_freq); | |
1379 | ||
1380 | params.block_tx = csa_ie.mode & WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT; | |
3f718fd8 | 1381 | if (beacon) { |
33a45867 | 1382 | ifmsh->chsw_ttl = csa_ie.ttl - 1; |
3f718fd8 CYY |
1383 | if (ifmsh->pre_value >= csa_ie.pre_value) |
1384 | return false; | |
1385 | ifmsh->pre_value = csa_ie.pre_value; | |
1386 | } | |
33a45867 | 1387 | |
0cb4d4dc | 1388 | if (ifmsh->chsw_ttl >= ifmsh->mshcfg.dot11MeshTTL) |
3f718fd8 | 1389 | return false; |
33a45867 | 1390 | |
0cb4d4dc | 1391 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_REPEATER; |
33a45867 | 1392 | |
0cb4d4dc LC |
1393 | if (ieee80211_channel_switch(sdata->local->hw.wiphy, sdata->dev, |
1394 | ¶ms) < 0) | |
1395 | return false; | |
33a45867 CYY |
1396 | |
1397 | return true; | |
33a45867 CYY |
1398 | } |
1399 | ||
9fb04b50 TP |
1400 | static void |
1401 | ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata, | |
1402 | struct ieee80211_mgmt *mgmt, size_t len) | |
1403 | { | |
1404 | struct ieee80211_local *local = sdata->local; | |
1405 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1406 | struct sk_buff *presp; | |
1407 | struct beacon_data *bcn; | |
1408 | struct ieee80211_mgmt *hdr; | |
5d24828d | 1409 | struct ieee802_11_elems *elems; |
9fb04b50 | 1410 | size_t baselen; |
511044ea | 1411 | u8 *pos; |
9fb04b50 | 1412 | |
9fb04b50 TP |
1413 | pos = mgmt->u.probe_req.variable; |
1414 | baselen = (u8 *) pos - (u8 *) mgmt; | |
1415 | if (baselen > len) | |
1416 | return; | |
1417 | ||
38c6aa29 | 1418 | elems = ieee802_11_parse_elems(pos, len - baselen, false, NULL); |
5d24828d | 1419 | if (!elems) |
a4ef66a9 CYY |
1420 | return; |
1421 | ||
5d24828d JB |
1422 | if (!elems->mesh_id) |
1423 | goto free; | |
1424 | ||
9fb04b50 TP |
1425 | /* 802.11-2012 10.1.4.3.2 */ |
1426 | if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) && | |
1427 | !is_broadcast_ether_addr(mgmt->da)) || | |
5d24828d JB |
1428 | elems->ssid_len != 0) |
1429 | goto free; | |
9fb04b50 | 1430 | |
5d24828d JB |
1431 | if (elems->mesh_id_len != 0 && |
1432 | (elems->mesh_id_len != ifmsh->mesh_id_len || | |
1433 | memcmp(elems->mesh_id, ifmsh->mesh_id, ifmsh->mesh_id_len))) | |
1434 | goto free; | |
9fb04b50 TP |
1435 | |
1436 | rcu_read_lock(); | |
1437 | bcn = rcu_dereference(ifmsh->beacon); | |
1438 | ||
1439 | if (!bcn) | |
1440 | goto out; | |
1441 | ||
1442 | presp = dev_alloc_skb(local->tx_headroom + | |
1443 | bcn->head_len + bcn->tail_len); | |
1444 | if (!presp) | |
1445 | goto out; | |
1446 | ||
1447 | skb_reserve(presp, local->tx_headroom); | |
59ae1d12 JB |
1448 | skb_put_data(presp, bcn->head, bcn->head_len); |
1449 | skb_put_data(presp, bcn->tail, bcn->tail_len); | |
9fb04b50 TP |
1450 | hdr = (struct ieee80211_mgmt *) presp->data; |
1451 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
1452 | IEEE80211_STYPE_PROBE_RESP); | |
1453 | memcpy(hdr->da, mgmt->sa, ETH_ALEN); | |
9fb04b50 TP |
1454 | IEEE80211_SKB_CB(presp)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
1455 | ieee80211_tx_skb(sdata, presp); | |
1456 | out: | |
1457 | rcu_read_unlock(); | |
5d24828d JB |
1458 | free: |
1459 | kfree(elems); | |
9fb04b50 TP |
1460 | } |
1461 | ||
472dbc45 JB |
1462 | static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, |
1463 | u16 stype, | |
1464 | struct ieee80211_mgmt *mgmt, | |
1465 | size_t len, | |
1466 | struct ieee80211_rx_status *rx_status) | |
1467 | { | |
c6a1fa12 | 1468 | struct ieee80211_local *local = sdata->local; |
dbf498fb | 1469 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
5d24828d | 1470 | struct ieee802_11_elems *elems; |
472dbc45 | 1471 | struct ieee80211_channel *channel; |
472dbc45 JB |
1472 | size_t baselen; |
1473 | int freq; | |
57fbcce3 | 1474 | enum nl80211_band band = rx_status->band; |
472dbc45 JB |
1475 | |
1476 | /* ignore ProbeResp to foreign address */ | |
1477 | if (stype == IEEE80211_STYPE_PROBE_RESP && | |
b203ca39 | 1478 | !ether_addr_equal(mgmt->da, sdata->vif.addr)) |
472dbc45 JB |
1479 | return; |
1480 | ||
1481 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; | |
1482 | if (baselen > len) | |
1483 | return; | |
1484 | ||
5d24828d JB |
1485 | elems = ieee802_11_parse_elems(mgmt->u.probe_resp.variable, |
1486 | len - baselen, | |
38c6aa29 | 1487 | false, NULL); |
5d24828d JB |
1488 | if (!elems) |
1489 | return; | |
472dbc45 | 1490 | |
9a90bc81 | 1491 | /* ignore non-mesh or secure / unsecure mismatch */ |
5d24828d JB |
1492 | if ((!elems->mesh_id || !elems->mesh_config) || |
1493 | (elems->rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) || | |
1494 | (!elems->rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)) | |
1495 | goto free; | |
5cff5e01 | 1496 | |
5d24828d JB |
1497 | if (elems->ds_params) |
1498 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], band); | |
472dbc45 JB |
1499 | else |
1500 | freq = rx_status->freq; | |
1501 | ||
1502 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
1503 | ||
1504 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
5d24828d | 1505 | goto free; |
472dbc45 | 1506 | |
5d24828d | 1507 | if (mesh_matches_local(sdata, elems)) { |
ed92a9b5 MH |
1508 | mpl_dbg(sdata, "rssi_threshold=%d,rx_status->signal=%d\n", |
1509 | sdata->u.mesh.mshcfg.rssi_threshold, rx_status->signal); | |
1510 | if (!sdata->u.mesh.user_mpm || | |
1511 | sdata->u.mesh.mshcfg.rssi_threshold == 0 || | |
1512 | sdata->u.mesh.mshcfg.rssi_threshold < rx_status->signal) | |
5d24828d | 1513 | mesh_neighbour_update(sdata, mgmt->sa, elems, |
ecbc12ad | 1514 | rx_status); |
93e2d04a T |
1515 | |
1516 | if (ifmsh->csa_role != IEEE80211_MESH_CSA_ROLE_INIT && | |
d0a9123e | 1517 | !sdata->vif.bss_conf.csa_active) |
5d24828d | 1518 | ieee80211_mesh_process_chnswitch(sdata, elems, true); |
ed92a9b5 | 1519 | } |
dbf498fb JC |
1520 | |
1521 | if (ifmsh->sync_ops) | |
a5b983c6 | 1522 | ifmsh->sync_ops->rx_bcn_presp(sdata, stype, mgmt, len, |
5d24828d JB |
1523 | elems->mesh_config, rx_status); |
1524 | free: | |
1525 | kfree(elems); | |
472dbc45 JB |
1526 | } |
1527 | ||
15ddba5f | 1528 | int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata, u64 *changed) |
b8456a14 CYY |
1529 | { |
1530 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1531 | struct mesh_csa_settings *tmp_csa_settings; | |
1532 | int ret = 0; | |
1533 | ||
1534 | /* Reset the TTL value and Initiator flag */ | |
0cb4d4dc | 1535 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; |
b8456a14 CYY |
1536 | ifmsh->chsw_ttl = 0; |
1537 | ||
1538 | /* Remove the CSA and MCSP elements from the beacon */ | |
6858ad75 | 1539 | tmp_csa_settings = sdata_dereference(ifmsh->csa, sdata); |
0c2bef46 | 1540 | RCU_INIT_POINTER(ifmsh->csa, NULL); |
66e01cf9 LC |
1541 | if (tmp_csa_settings) |
1542 | kfree_rcu(tmp_csa_settings, rcu_head); | |
b8456a14 CYY |
1543 | ret = ieee80211_mesh_rebuild_beacon(sdata); |
1544 | if (ret) | |
1545 | return -EINVAL; | |
1546 | ||
15ddba5f | 1547 | *changed |= BSS_CHANGED_BEACON; |
b8456a14 CYY |
1548 | |
1549 | mcsa_dbg(sdata, "complete switching to center freq %d MHz", | |
1550 | sdata->vif.bss_conf.chandef.chan->center_freq); | |
15ddba5f | 1551 | return 0; |
b8456a14 CYY |
1552 | } |
1553 | ||
1554 | int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata, | |
15ddba5f A |
1555 | struct cfg80211_csa_settings *csa_settings, |
1556 | u64 *changed) | |
b8456a14 CYY |
1557 | { |
1558 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1559 | struct mesh_csa_settings *tmp_csa_settings; | |
1560 | int ret = 0; | |
1561 | ||
55184244 TP |
1562 | lockdep_assert_held(&sdata->wdev.mtx); |
1563 | ||
b8456a14 CYY |
1564 | tmp_csa_settings = kmalloc(sizeof(*tmp_csa_settings), |
1565 | GFP_ATOMIC); | |
1566 | if (!tmp_csa_settings) | |
1567 | return -ENOMEM; | |
1568 | ||
1569 | memcpy(&tmp_csa_settings->settings, csa_settings, | |
1570 | sizeof(struct cfg80211_csa_settings)); | |
1571 | ||
1572 | rcu_assign_pointer(ifmsh->csa, tmp_csa_settings); | |
1573 | ||
1574 | ret = ieee80211_mesh_rebuild_beacon(sdata); | |
1575 | if (ret) { | |
1576 | tmp_csa_settings = rcu_dereference(ifmsh->csa); | |
0c2bef46 | 1577 | RCU_INIT_POINTER(ifmsh->csa, NULL); |
b8456a14 CYY |
1578 | kfree_rcu(tmp_csa_settings, rcu_head); |
1579 | return ret; | |
1580 | } | |
1581 | ||
15ddba5f A |
1582 | *changed |= BSS_CHANGED_BEACON; |
1583 | return 0; | |
b8456a14 CYY |
1584 | } |
1585 | ||
8f2535b9 | 1586 | static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata, |
c4de37ee PO |
1587 | struct ieee80211_mgmt *mgmt, size_t len, |
1588 | struct ieee802_11_elems *elems) | |
8f2535b9 CYY |
1589 | { |
1590 | struct ieee80211_mgmt *mgmt_fwd; | |
1591 | struct sk_buff *skb; | |
1592 | struct ieee80211_local *local = sdata->local; | |
8f2535b9 CYY |
1593 | |
1594 | skb = dev_alloc_skb(local->tx_headroom + len); | |
1595 | if (!skb) | |
1596 | return -ENOMEM; | |
1597 | skb_reserve(skb, local->tx_headroom); | |
4df864c1 | 1598 | mgmt_fwd = skb_put(skb, len); |
8f2535b9 | 1599 | |
c4de37ee PO |
1600 | elems->mesh_chansw_params_ie->mesh_ttl--; |
1601 | elems->mesh_chansw_params_ie->mesh_flags &= | |
1602 | ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR; | |
8f2535b9 CYY |
1603 | |
1604 | memcpy(mgmt_fwd, mgmt, len); | |
1605 | eth_broadcast_addr(mgmt_fwd->da); | |
1606 | memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN); | |
1607 | memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN); | |
1608 | ||
1609 | ieee80211_tx_skb(sdata, skb); | |
1610 | return 0; | |
1611 | } | |
1612 | ||
1613 | static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata, | |
1614 | struct ieee80211_mgmt *mgmt, size_t len) | |
1615 | { | |
1616 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
5d24828d | 1617 | struct ieee802_11_elems *elems; |
8f2535b9 | 1618 | u16 pre_value; |
33a45867 | 1619 | bool fwd_csa = true; |
8f2535b9 | 1620 | size_t baselen; |
3f718fd8 | 1621 | u8 *pos; |
8f2535b9 CYY |
1622 | |
1623 | if (mgmt->u.action.u.measurement.action_code != | |
1624 | WLAN_ACTION_SPCT_CHL_SWITCH) | |
1625 | return; | |
1626 | ||
1627 | pos = mgmt->u.action.u.chan_switch.variable; | |
1628 | baselen = offsetof(struct ieee80211_mgmt, | |
1629 | u.action.u.chan_switch.variable); | |
38c6aa29 | 1630 | elems = ieee802_11_parse_elems(pos, len - baselen, true, NULL); |
5d24828d | 1631 | if (!elems) |
93e2d04a T |
1632 | return; |
1633 | ||
5d24828d JB |
1634 | if (!mesh_matches_local(sdata, elems)) |
1635 | goto free; | |
1636 | ||
1637 | ifmsh->chsw_ttl = elems->mesh_chansw_params_ie->mesh_ttl; | |
3f718fd8 | 1638 | if (!--ifmsh->chsw_ttl) |
8f2535b9 CYY |
1639 | fwd_csa = false; |
1640 | ||
5d24828d | 1641 | pre_value = le16_to_cpu(elems->mesh_chansw_params_ie->mesh_pre_value); |
8f2535b9 | 1642 | if (ifmsh->pre_value >= pre_value) |
5d24828d | 1643 | goto free; |
8f2535b9 CYY |
1644 | |
1645 | ifmsh->pre_value = pre_value; | |
1646 | ||
d0a9123e | 1647 | if (!sdata->vif.bss_conf.csa_active && |
5d24828d | 1648 | !ieee80211_mesh_process_chnswitch(sdata, elems, false)) { |
33a45867 | 1649 | mcsa_dbg(sdata, "Failed to process CSA action frame"); |
5d24828d | 1650 | goto free; |
33a45867 CYY |
1651 | } |
1652 | ||
8f2535b9 CYY |
1653 | /* forward or re-broadcast the CSA frame */ |
1654 | if (fwd_csa) { | |
5d24828d | 1655 | if (mesh_fwd_csa_frame(sdata, mgmt, len, elems) < 0) |
8f2535b9 CYY |
1656 | mcsa_dbg(sdata, "Failed to forward the CSA frame"); |
1657 | } | |
5d24828d JB |
1658 | free: |
1659 | kfree(elems); | |
8f2535b9 CYY |
1660 | } |
1661 | ||
472dbc45 JB |
1662 | static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, |
1663 | struct ieee80211_mgmt *mgmt, | |
1664 | size_t len, | |
1665 | struct ieee80211_rx_status *rx_status) | |
1666 | { | |
1667 | switch (mgmt->u.action.category) { | |
8db09850 TP |
1668 | case WLAN_CATEGORY_SELF_PROTECTED: |
1669 | switch (mgmt->u.action.u.self_prot.action_code) { | |
1670 | case WLAN_SP_MESH_PEERING_OPEN: | |
1671 | case WLAN_SP_MESH_PEERING_CLOSE: | |
1672 | case WLAN_SP_MESH_PEERING_CONFIRM: | |
1673 | mesh_rx_plink_frame(sdata, mgmt, len, rx_status); | |
1674 | break; | |
1675 | } | |
472dbc45 | 1676 | break; |
25d49e4d TP |
1677 | case WLAN_CATEGORY_MESH_ACTION: |
1678 | if (mesh_action_is_path_sel(mgmt)) | |
1679 | mesh_rx_path_sel_frame(sdata, mgmt, len); | |
472dbc45 | 1680 | break; |
8f2535b9 CYY |
1681 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
1682 | mesh_rx_csa_frame(sdata, mgmt, len); | |
1683 | break; | |
472dbc45 JB |
1684 | } |
1685 | } | |
1686 | ||
1fa57d01 JB |
1687 | void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
1688 | struct sk_buff *skb) | |
472dbc45 JB |
1689 | { |
1690 | struct ieee80211_rx_status *rx_status; | |
472dbc45 JB |
1691 | struct ieee80211_mgmt *mgmt; |
1692 | u16 stype; | |
1693 | ||
ecccd072 TP |
1694 | sdata_lock(sdata); |
1695 | ||
1696 | /* mesh already went down */ | |
1693d344 | 1697 | if (!sdata->u.mesh.mesh_id_len) |
ecccd072 TP |
1698 | goto out; |
1699 | ||
f1d58c25 | 1700 | rx_status = IEEE80211_SKB_RXCB(skb); |
472dbc45 JB |
1701 | mgmt = (struct ieee80211_mgmt *) skb->data; |
1702 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; | |
1703 | ||
1704 | switch (stype) { | |
1705 | case IEEE80211_STYPE_PROBE_RESP: | |
1706 | case IEEE80211_STYPE_BEACON: | |
1707 | ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len, | |
1708 | rx_status); | |
1709 | break; | |
9fb04b50 TP |
1710 | case IEEE80211_STYPE_PROBE_REQ: |
1711 | ieee80211_mesh_rx_probe_req(sdata, mgmt, skb->len); | |
1712 | break; | |
472dbc45 JB |
1713 | case IEEE80211_STYPE_ACTION: |
1714 | ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status); | |
1715 | break; | |
1716 | } | |
ecccd072 TP |
1717 | out: |
1718 | sdata_unlock(sdata); | |
472dbc45 JB |
1719 | } |
1720 | ||
f81a9ded TP |
1721 | static void mesh_bss_info_changed(struct ieee80211_sub_if_data *sdata) |
1722 | { | |
1723 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
15ddba5f A |
1724 | u32 bit; |
1725 | u64 changed = 0; | |
f81a9ded TP |
1726 | |
1727 | for_each_set_bit(bit, &ifmsh->mbss_changed, | |
1728 | sizeof(changed) * BITS_PER_BYTE) { | |
1729 | clear_bit(bit, &ifmsh->mbss_changed); | |
1730 | changed |= BIT(bit); | |
1731 | } | |
1732 | ||
1733 | if (sdata->vif.bss_conf.enable_beacon && | |
1734 | (changed & (BSS_CHANGED_BEACON | | |
1735 | BSS_CHANGED_HT | | |
1736 | BSS_CHANGED_BASIC_RATES | | |
1737 | BSS_CHANGED_BEACON_INT))) | |
1738 | if (ieee80211_mesh_rebuild_beacon(sdata)) | |
1739 | return; | |
1740 | ||
d8675a63 | 1741 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); |
f81a9ded TP |
1742 | } |
1743 | ||
1fa57d01 | 1744 | void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata) |
472dbc45 | 1745 | { |
472dbc45 | 1746 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
472dbc45 | 1747 | |
ecccd072 TP |
1748 | sdata_lock(sdata); |
1749 | ||
1750 | /* mesh already went down */ | |
1693d344 | 1751 | if (!sdata->u.mesh.mesh_id_len) |
ecccd072 TP |
1752 | goto out; |
1753 | ||
472dbc45 JB |
1754 | if (ifmsh->preq_queue_len && |
1755 | time_after(jiffies, | |
1756 | ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval))) | |
1757 | mesh_path_start_discovery(sdata); | |
1758 | ||
18889231 | 1759 | if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags)) |
bf7cd94d | 1760 | ieee80211_mesh_housekeeping(sdata); |
e304bfd3 RP |
1761 | |
1762 | if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags)) | |
1763 | ieee80211_mesh_rootpath(sdata); | |
dbf498fb JC |
1764 | |
1765 | if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags)) | |
445cd452 | 1766 | mesh_sync_adjust_tsf(sdata); |
ecccd072 | 1767 | |
f81a9ded TP |
1768 | if (test_and_clear_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags)) |
1769 | mesh_bss_info_changed(sdata); | |
ecccd072 TP |
1770 | out: |
1771 | sdata_unlock(sdata); | |
472dbc45 JB |
1772 | } |
1773 | ||
472dbc45 | 1774 | |
902acc78 JB |
1775 | void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) |
1776 | { | |
472dbc45 | 1777 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
ad2d223a | 1778 | static u8 zero_addr[ETH_ALEN] = {}; |
472dbc45 | 1779 | |
34f11cd3 KC |
1780 | timer_setup(&ifmsh->housekeeping_timer, |
1781 | ieee80211_mesh_housekeeping_timer, 0); | |
472dbc45 | 1782 | |
472dbc45 | 1783 | ifmsh->accepting_plinks = true; |
472dbc45 | 1784 | atomic_set(&ifmsh->mpaths, 0); |
f698d856 | 1785 | mesh_rmc_init(sdata); |
472dbc45 | 1786 | ifmsh->last_preq = jiffies; |
dca7e943 | 1787 | ifmsh->next_perr = jiffies; |
0cb4d4dc | 1788 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; |
902acc78 JB |
1789 | /* Allocate all mesh structures when creating the first mesh interface. */ |
1790 | if (!mesh_allocated) | |
1791 | ieee80211s_init(); | |
2bdaf386 BC |
1792 | |
1793 | mesh_pathtbl_init(sdata); | |
1794 | ||
34f11cd3 KC |
1795 | timer_setup(&ifmsh->mesh_path_timer, ieee80211_mesh_path_timer, 0); |
1796 | timer_setup(&ifmsh->mesh_path_root_timer, | |
1797 | ieee80211_mesh_path_root_timer, 0); | |
472dbc45 | 1798 | INIT_LIST_HEAD(&ifmsh->preq_queue.list); |
3f52b7e3 | 1799 | skb_queue_head_init(&ifmsh->ps.bc_buf); |
472dbc45 | 1800 | spin_lock_init(&ifmsh->mesh_preq_queue_lock); |
dbf498fb | 1801 | spin_lock_init(&ifmsh->sync_offset_lock); |
2b5e1967 | 1802 | RCU_INIT_POINTER(ifmsh->beacon, NULL); |
ad2d223a JB |
1803 | |
1804 | sdata->vif.bss_conf.bssid = zero_addr; | |
472dbc45 | 1805 | } |
0371a08f BC |
1806 | |
1807 | void ieee80211_mesh_teardown_sdata(struct ieee80211_sub_if_data *sdata) | |
1808 | { | |
1809 | mesh_rmc_free(sdata); | |
1810 | mesh_pathtbl_unregister(sdata); | |
1811 | } |