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