]>
Commit | Line | Data |
---|---|---|
2e3c8736 | 1 | /* |
264d9b7d | 2 | * Copyright (c) 2008, 2009 open80211s Ltd. |
2e3c8736 LCC |
3 | * Authors: Luis Carlos Cobo <luisca@cozybit.com> |
4 | * Javier Cardona <javier@cozybit.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
5a0e3ad6 | 11 | #include <linux/slab.h> |
51ceddad | 12 | #include <asm/unaligned.h> |
2e3c8736 LCC |
13 | #include "ieee80211_i.h" |
14 | #include "mesh.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 | { | |
28 | mesh_pathtbl_init(); | |
29 | mesh_allocated = 1; | |
30 | rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry), | |
31 | 0, 0, NULL); | |
32 | } | |
33 | ||
34 | void ieee80211s_stop(void) | |
35 | { | |
bf7cd94d JB |
36 | if (!mesh_allocated) |
37 | return; | |
2e3c8736 LCC |
38 | mesh_pathtbl_unregister(); |
39 | kmem_cache_destroy(rm_cache); | |
40 | } | |
41 | ||
472dbc45 JB |
42 | static void ieee80211_mesh_housekeeping_timer(unsigned long data) |
43 | { | |
44 | struct ieee80211_sub_if_data *sdata = (void *) data; | |
45 | struct ieee80211_local *local = sdata->local; | |
46 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
47 | ||
6b9ac442 | 48 | set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); |
5bb644a0 | 49 | |
64592c8f | 50 | ieee80211_queue_work(&local->hw, &sdata->work); |
472dbc45 JB |
51 | } |
52 | ||
2e3c8736 LCC |
53 | /** |
54 | * mesh_matches_local - check if the config of a mesh point matches ours | |
55 | * | |
f698d856 | 56 | * @sdata: local mesh subif |
f743ff49 | 57 | * @ie: information elements of a management frame from the mesh peer |
2e3c8736 LCC |
58 | * |
59 | * This function checks if the mesh configuration of a mesh point matches the | |
60 | * local mesh configuration, i.e. if both nodes belong to the same mesh network. | |
61 | */ | |
f743ff49 TP |
62 | bool mesh_matches_local(struct ieee80211_sub_if_data *sdata, |
63 | struct ieee802_11_elems *ie) | |
2e3c8736 | 64 | { |
472dbc45 | 65 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
f743ff49 | 66 | u32 basic_rates = 0; |
4bf88530 | 67 | struct cfg80211_chan_def sta_chan_def; |
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 | |
2103dec1 | 88 | ieee80211_sta_get_rates(sdata, ie, ieee80211_get_sdata_band(sdata), |
f743ff49 TP |
89 | &basic_rates); |
90 | ||
fe40cb62 | 91 | if (sdata->vif.bss_conf.basic_rates != basic_rates) |
bf7cd94d | 92 | return false; |
fe40cb62 | 93 | |
4bf88530 JB |
94 | ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan, |
95 | ie->ht_operation, &sta_chan_def); | |
96 | ||
c85fb53c BC |
97 | ieee80211_vht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan, |
98 | ie->vht_operation, &sta_chan_def); | |
99 | ||
4bf88530 JB |
100 | if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef, |
101 | &sta_chan_def)) | |
bf7cd94d | 102 | return false; |
2e3c8736 | 103 | |
739522ba | 104 | return true; |
2e3c8736 LCC |
105 | } |
106 | ||
107 | /** | |
108 | * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links | |
109 | * | |
110 | * @ie: information elements of a management frame from the mesh peer | |
2e3c8736 | 111 | */ |
f698d856 | 112 | bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie) |
2e3c8736 | 113 | { |
136cfa28 | 114 | return (ie->mesh_config->meshconf_cap & |
bf7cd94d | 115 | IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0; |
2e3c8736 LCC |
116 | } |
117 | ||
118 | /** | |
2c53040f | 119 | * mesh_accept_plinks_update - update accepting_plink in local mesh beacons |
2e3c8736 | 120 | * |
d0709a65 | 121 | * @sdata: mesh interface in which mesh beacons are going to be updated |
df323818 MP |
122 | * |
123 | * Returns: beacon changed flag if the beacon content changed. | |
2e3c8736 | 124 | */ |
df323818 | 125 | u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 126 | { |
2e3c8736 | 127 | bool free_plinks; |
df323818 | 128 | u32 changed = 0; |
2e3c8736 LCC |
129 | |
130 | /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0, | |
131 | * the mesh interface might be able to establish plinks with peers that | |
b4e08ea1 LCC |
132 | * are already on the table but are not on PLINK_ESTAB state. However, |
133 | * in general the mesh interface is not accepting peer link requests | |
134 | * from new peers, and that must be reflected in the beacon | |
2e3c8736 LCC |
135 | */ |
136 | free_plinks = mesh_plink_availables(sdata); | |
137 | ||
df323818 MP |
138 | if (free_plinks != sdata->u.mesh.accepting_plinks) { |
139 | sdata->u.mesh.accepting_plinks = free_plinks; | |
140 | changed = BSS_CHANGED_BEACON; | |
141 | } | |
142 | ||
143 | return changed; | |
2e3c8736 LCC |
144 | } |
145 | ||
45b5028e TP |
146 | /* |
147 | * mesh_sta_cleanup - clean up any mesh sta state | |
148 | * | |
149 | * @sta: mesh sta to clean up. | |
150 | */ | |
151 | void mesh_sta_cleanup(struct sta_info *sta) | |
152 | { | |
153 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
252d75f4 | 154 | u32 changed = 0; |
45b5028e TP |
155 | |
156 | /* | |
157 | * maybe userspace handles peer allocation and peering, but in either | |
158 | * case the beacon is still generated by the kernel and we might need | |
159 | * an update. | |
160 | */ | |
252d75f4 JM |
161 | if (sdata->u.mesh.user_mpm && |
162 | sta->mesh->plink_state == NL80211_PLINK_ESTAB) | |
163 | changed |= mesh_plink_dec_estab_count(sdata); | |
164 | changed |= mesh_accept_plinks_update(sdata); | |
a6dad6a2 | 165 | if (!sdata->u.mesh.user_mpm) { |
45b5028e | 166 | changed |= mesh_plink_deactivate(sta); |
433f5bc1 | 167 | del_timer_sync(&sta->mesh->plink_timer); |
45b5028e TP |
168 | } |
169 | ||
b40b5399 BC |
170 | /* make sure no readers can access nexthop sta from here on */ |
171 | mesh_path_flush_by_nexthop(sta); | |
172 | synchronize_net(); | |
173 | ||
f81a9ded | 174 | if (changed) |
2b5e1967 | 175 | ieee80211_mbss_info_change_notify(sdata, changed); |
45b5028e TP |
176 | } |
177 | ||
f698d856 | 178 | int mesh_rmc_init(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 179 | { |
2e3c8736 LCC |
180 | int i; |
181 | ||
472dbc45 JB |
182 | sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL); |
183 | if (!sdata->u.mesh.rmc) | |
2e3c8736 | 184 | return -ENOMEM; |
472dbc45 | 185 | sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1; |
2e3c8736 | 186 | for (i = 0; i < RMC_BUCKETS; i++) |
b7cfcd11 | 187 | INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i]); |
2e3c8736 LCC |
188 | return 0; |
189 | } | |
190 | ||
f698d856 | 191 | void mesh_rmc_free(struct ieee80211_sub_if_data *sdata) |
2e3c8736 | 192 | { |
472dbc45 | 193 | struct mesh_rmc *rmc = sdata->u.mesh.rmc; |
2e3c8736 LCC |
194 | struct rmc_entry *p, *n; |
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++) { |
b7cfcd11 | 201 | list_for_each_entry_safe(p, n, &rmc->bucket[i], list) { |
2e3c8736 LCC |
202 | list_del(&p->list); |
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; | |
231 | struct rmc_entry *p, *n; | |
232 | ||
233 | /* Don't care about endianness since only match matters */ | |
51ceddad LCC |
234 | memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum)); |
235 | idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask; | |
b7cfcd11 | 236 | list_for_each_entry_safe(p, n, &rmc->bucket[idx], list) { |
2e3c8736 LCC |
237 | ++entries; |
238 | if (time_after(jiffies, p->exp_time) || | |
bf7cd94d | 239 | entries == RMC_QUEUE_MAX_LEN) { |
2e3c8736 LCC |
240 | list_del(&p->list); |
241 | kmem_cache_free(rm_cache, p); | |
242 | --entries; | |
bf7cd94d | 243 | } else if ((seqnum == p->seqnum) && ether_addr_equal(sa, p->sa)) |
2e3c8736 LCC |
244 | return -1; |
245 | } | |
246 | ||
247 | p = kmem_cache_alloc(rm_cache, GFP_ATOMIC); | |
d15b8459 | 248 | if (!p) |
2e3c8736 | 249 | return 0; |
d15b8459 | 250 | |
2e3c8736 LCC |
251 | p->seqnum = seqnum; |
252 | p->exp_time = jiffies + RMC_TIMEOUT; | |
253 | memcpy(p->sa, sa, ETH_ALEN); | |
b7cfcd11 | 254 | list_add(&p->list, &rmc->bucket[idx]); |
2e3c8736 LCC |
255 | return 0; |
256 | } | |
257 | ||
bf7cd94d JB |
258 | int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata, |
259 | struct sk_buff *skb) | |
082ebb0c TP |
260 | { |
261 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
262 | u8 *pos, neighbors; | |
263 | u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie); | |
264 | ||
265 | if (skb_tailroom(skb) < 2 + meshconf_len) | |
266 | return -ENOMEM; | |
267 | ||
268 | pos = skb_put(skb, 2 + meshconf_len); | |
269 | *pos++ = WLAN_EID_MESH_CONFIG; | |
270 | *pos++ = meshconf_len; | |
271 | ||
43552be1 TP |
272 | /* save a pointer for quick updates in pre-tbtt */ |
273 | ifmsh->meshconf_offset = pos - skb->data; | |
274 | ||
082ebb0c TP |
275 | /* Active path selection protocol ID */ |
276 | *pos++ = ifmsh->mesh_pp_id; | |
277 | /* Active path selection metric ID */ | |
278 | *pos++ = ifmsh->mesh_pm_id; | |
279 | /* Congestion control mode identifier */ | |
280 | *pos++ = ifmsh->mesh_cc_id; | |
281 | /* Synchronization protocol identifier */ | |
282 | *pos++ = ifmsh->mesh_sp_id; | |
283 | /* Authentication Protocol identifier */ | |
284 | *pos++ = ifmsh->mesh_auth_id; | |
285 | /* Mesh Formation Info - number of neighbors */ | |
1258d976 | 286 | neighbors = atomic_read(&ifmsh->estab_plinks); |
e05ecccd | 287 | neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS); |
082ebb0c TP |
288 | *pos++ = neighbors << 1; |
289 | /* Mesh capability */ | |
b60e527a CYY |
290 | *pos = 0x00; |
291 | *pos |= ifmsh->mshcfg.dot11MeshForwarding ? | |
292 | IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00; | |
dbf498fb | 293 | *pos |= ifmsh->accepting_plinks ? |
bf7cd94d | 294 | IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00; |
3f52b7e3 MP |
295 | /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */ |
296 | *pos |= ifmsh->ps_peers_deep_sleep ? | |
bf7cd94d | 297 | IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00; |
082ebb0c TP |
298 | return 0; |
299 | } | |
300 | ||
bf7cd94d | 301 | int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) |
082ebb0c TP |
302 | { |
303 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
304 | u8 *pos; | |
305 | ||
306 | if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len) | |
307 | return -ENOMEM; | |
308 | ||
309 | pos = skb_put(skb, 2 + ifmsh->mesh_id_len); | |
310 | *pos++ = WLAN_EID_MESH_ID; | |
311 | *pos++ = ifmsh->mesh_id_len; | |
312 | if (ifmsh->mesh_id_len) | |
313 | memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len); | |
314 | ||
315 | return 0; | |
316 | } | |
317 | ||
bf7cd94d JB |
318 | static int mesh_add_awake_window_ie(struct ieee80211_sub_if_data *sdata, |
319 | struct sk_buff *skb) | |
3f52b7e3 MP |
320 | { |
321 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
322 | u8 *pos; | |
323 | ||
324 | /* see IEEE802.11-2012 13.14.6 */ | |
325 | if (ifmsh->ps_peers_light_sleep == 0 && | |
326 | ifmsh->ps_peers_deep_sleep == 0 && | |
327 | ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE) | |
328 | return 0; | |
329 | ||
330 | if (skb_tailroom(skb) < 4) | |
331 | return -ENOMEM; | |
332 | ||
333 | pos = skb_put(skb, 2 + 2); | |
334 | *pos++ = WLAN_EID_MESH_AWAKE_WINDOW; | |
335 | *pos++ = 2; | |
336 | put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos); | |
337 | ||
338 | return 0; | |
339 | } | |
340 | ||
bf7cd94d JB |
341 | int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata, |
342 | struct sk_buff *skb) | |
082ebb0c TP |
343 | { |
344 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
345 | u8 offset, len; | |
346 | const u8 *data; | |
347 | ||
348 | if (!ifmsh->ie || !ifmsh->ie_len) | |
349 | return 0; | |
350 | ||
351 | /* fast-forward to vendor IEs */ | |
352 | offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0); | |
353 | ||
72212eec | 354 | if (offset < ifmsh->ie_len) { |
082ebb0c TP |
355 | len = ifmsh->ie_len - offset; |
356 | data = ifmsh->ie + offset; | |
357 | if (skb_tailroom(skb) < len) | |
358 | return -ENOMEM; | |
359 | memcpy(skb_put(skb, len), data, len); | |
360 | } | |
361 | ||
362 | return 0; | |
363 | } | |
364 | ||
bf7cd94d | 365 | int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) |
082ebb0c TP |
366 | { |
367 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
368 | u8 len = 0; | |
369 | const u8 *data; | |
370 | ||
371 | if (!ifmsh->ie || !ifmsh->ie_len) | |
372 | return 0; | |
373 | ||
374 | /* find RSN IE */ | |
a40a8c17 BC |
375 | data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len); |
376 | if (!data) | |
377 | return 0; | |
082ebb0c | 378 | |
a40a8c17 BC |
379 | len = data[1] + 2; |
380 | ||
381 | if (skb_tailroom(skb) < len) | |
382 | return -ENOMEM; | |
383 | memcpy(skb_put(skb, len), data, len); | |
082ebb0c TP |
384 | |
385 | return 0; | |
386 | } | |
387 | ||
bf7cd94d JB |
388 | static int mesh_add_ds_params_ie(struct ieee80211_sub_if_data *sdata, |
389 | struct sk_buff *skb) | |
082ebb0c | 390 | { |
55de908a JB |
391 | struct ieee80211_chanctx_conf *chanctx_conf; |
392 | struct ieee80211_channel *chan; | |
082ebb0c | 393 | u8 *pos; |
2e3c8736 | 394 | |
082ebb0c TP |
395 | if (skb_tailroom(skb) < 3) |
396 | return -ENOMEM; | |
397 | ||
55de908a JB |
398 | rcu_read_lock(); |
399 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
400 | if (WARN_ON(!chanctx_conf)) { | |
401 | rcu_read_unlock(); | |
402 | return -EINVAL; | |
403 | } | |
4bf88530 | 404 | chan = chanctx_conf->def.chan; |
55de908a JB |
405 | rcu_read_unlock(); |
406 | ||
601513aa ET |
407 | pos = skb_put(skb, 2 + 1); |
408 | *pos++ = WLAN_EID_DS_PARAMS; | |
409 | *pos++ = 1; | |
410 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); | |
be125c60 | 411 | |
082ebb0c | 412 | return 0; |
2e3c8736 LCC |
413 | } |
414 | ||
bf7cd94d JB |
415 | int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata, |
416 | struct sk_buff *skb) | |
176f3608 TP |
417 | { |
418 | struct ieee80211_local *local = sdata->local; | |
55de908a | 419 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
176f3608 TP |
420 | struct ieee80211_supported_band *sband; |
421 | u8 *pos; | |
422 | ||
55de908a | 423 | sband = local->hw.wiphy->bands[band]; |
176f3608 | 424 | if (!sband->ht_cap.ht_supported || |
0418a445 SW |
425 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || |
426 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
427 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
176f3608 TP |
428 | return 0; |
429 | ||
430 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap)) | |
431 | return -ENOMEM; | |
432 | ||
433 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap)); | |
ef96a842 | 434 | ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap); |
176f3608 TP |
435 | |
436 | return 0; | |
437 | } | |
438 | ||
bf7cd94d JB |
439 | int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata, |
440 | struct sk_buff *skb) | |
176f3608 TP |
441 | { |
442 | struct ieee80211_local *local = sdata->local; | |
55de908a JB |
443 | struct ieee80211_chanctx_conf *chanctx_conf; |
444 | struct ieee80211_channel *channel; | |
55de908a JB |
445 | struct ieee80211_supported_band *sband; |
446 | struct ieee80211_sta_ht_cap *ht_cap; | |
176f3608 TP |
447 | u8 *pos; |
448 | ||
55de908a JB |
449 | rcu_read_lock(); |
450 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
451 | if (WARN_ON(!chanctx_conf)) { | |
452 | rcu_read_unlock(); | |
453 | return -EINVAL; | |
454 | } | |
4bf88530 | 455 | channel = chanctx_conf->def.chan; |
55de908a JB |
456 | rcu_read_unlock(); |
457 | ||
458 | sband = local->hw.wiphy->bands[channel->band]; | |
459 | ht_cap = &sband->ht_cap; | |
460 | ||
c85fb53c BC |
461 | if (!ht_cap->ht_supported || |
462 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
463 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
464 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
176f3608 TP |
465 | return 0; |
466 | ||
074d46d1 | 467 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation)) |
176f3608 TP |
468 | return -ENOMEM; |
469 | ||
074d46d1 | 470 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation)); |
4bf88530 | 471 | ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef, |
57f255f5 AN |
472 | sdata->vif.bss_conf.ht_operation_mode, |
473 | false); | |
176f3608 TP |
474 | |
475 | return 0; | |
476 | } | |
bf7cd94d | 477 | |
c85fb53c BC |
478 | int mesh_add_vht_cap_ie(struct ieee80211_sub_if_data *sdata, |
479 | struct sk_buff *skb) | |
480 | { | |
481 | struct ieee80211_local *local = sdata->local; | |
482 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); | |
483 | struct ieee80211_supported_band *sband; | |
484 | u8 *pos; | |
485 | ||
486 | sband = local->hw.wiphy->bands[band]; | |
487 | if (!sband->vht_cap.vht_supported || | |
488 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
489 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
490 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
491 | return 0; | |
492 | ||
493 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_cap)) | |
494 | return -ENOMEM; | |
495 | ||
496 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_cap)); | |
497 | ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, sband->vht_cap.cap); | |
498 | ||
499 | return 0; | |
500 | } | |
501 | ||
502 | int mesh_add_vht_oper_ie(struct ieee80211_sub_if_data *sdata, | |
503 | struct sk_buff *skb) | |
504 | { | |
505 | struct ieee80211_local *local = sdata->local; | |
506 | struct ieee80211_chanctx_conf *chanctx_conf; | |
507 | struct ieee80211_channel *channel; | |
508 | struct ieee80211_supported_band *sband; | |
509 | struct ieee80211_sta_vht_cap *vht_cap; | |
510 | u8 *pos; | |
511 | ||
512 | rcu_read_lock(); | |
513 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
514 | if (WARN_ON(!chanctx_conf)) { | |
515 | rcu_read_unlock(); | |
516 | return -EINVAL; | |
517 | } | |
518 | channel = chanctx_conf->def.chan; | |
519 | rcu_read_unlock(); | |
520 | ||
521 | sband = local->hw.wiphy->bands[channel->band]; | |
522 | vht_cap = &sband->vht_cap; | |
523 | ||
524 | if (!vht_cap->vht_supported || | |
525 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT || | |
526 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 || | |
527 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10) | |
528 | return 0; | |
529 | ||
530 | if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_operation)) | |
531 | return -ENOMEM; | |
532 | ||
533 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_operation)); | |
534 | ieee80211_ie_build_vht_oper(pos, vht_cap, | |
535 | &sdata->vif.bss_conf.chandef); | |
536 | ||
537 | return 0; | |
538 | } | |
539 | ||
2e3c8736 LCC |
540 | static void ieee80211_mesh_path_timer(unsigned long data) |
541 | { | |
542 | struct ieee80211_sub_if_data *sdata = | |
543 | (struct ieee80211_sub_if_data *) data; | |
5bb644a0 | 544 | |
690205f1 | 545 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
2e3c8736 LCC |
546 | } |
547 | ||
e304bfd3 RP |
548 | static void ieee80211_mesh_path_root_timer(unsigned long data) |
549 | { | |
550 | struct ieee80211_sub_if_data *sdata = | |
551 | (struct ieee80211_sub_if_data *) data; | |
552 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
e304bfd3 RP |
553 | |
554 | set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); | |
555 | ||
690205f1 | 556 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
e304bfd3 RP |
557 | } |
558 | ||
63c5723b RP |
559 | void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh) |
560 | { | |
dbb912cd | 561 | if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT) |
63c5723b RP |
562 | set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); |
563 | else { | |
564 | clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); | |
565 | /* stop running timer */ | |
566 | del_timer_sync(&ifmsh->mesh_path_root_timer); | |
567 | } | |
568 | } | |
569 | ||
3c5772a5 JC |
570 | /** |
571 | * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame | |
bf7cd94d | 572 | * @hdr: 802.11 frame header |
3c5772a5 JC |
573 | * @fc: frame control field |
574 | * @meshda: destination address in the mesh | |
575 | * @meshsa: source address address in the mesh. Same as TA, as frame is | |
576 | * locally originated. | |
577 | * | |
578 | * Return the length of the 802.11 (does not include a mesh control header) | |
579 | */ | |
15ff6365 JB |
580 | int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, |
581 | const u8 *meshda, const u8 *meshsa) | |
582 | { | |
3c5772a5 JC |
583 | if (is_multicast_ether_addr(meshda)) { |
584 | *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); | |
585 | /* DA TA SA */ | |
586 | memcpy(hdr->addr1, meshda, ETH_ALEN); | |
587 | memcpy(hdr->addr2, meshsa, ETH_ALEN); | |
588 | memcpy(hdr->addr3, meshsa, ETH_ALEN); | |
589 | return 24; | |
590 | } else { | |
2154c81c | 591 | *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
3c5772a5 | 592 | /* RA TA DA SA */ |
c84a67a2 | 593 | eth_zero_addr(hdr->addr1); /* RA is resolved later */ |
3c5772a5 JC |
594 | memcpy(hdr->addr2, meshsa, ETH_ALEN); |
595 | memcpy(hdr->addr3, meshda, ETH_ALEN); | |
596 | memcpy(hdr->addr4, meshsa, ETH_ALEN); | |
597 | return 30; | |
598 | } | |
599 | } | |
600 | ||
902acc78 JB |
601 | /** |
602 | * ieee80211_new_mesh_header - create a new mesh header | |
902acc78 | 603 | * @sdata: mesh interface to be used |
bf7cd94d | 604 | * @meshhdr: uninitialized mesh header |
61ad5394 JC |
605 | * @addr4or5: 1st address in the ae header, which may correspond to address 4 |
606 | * (if addr6 is NULL) or address 5 (if addr6 is present). It may | |
607 | * be NULL. | |
608 | * @addr6: 2nd address in the ae header, which corresponds to addr6 of the | |
609 | * mesh frame | |
902acc78 JB |
610 | * |
611 | * Return the header length. | |
612 | */ | |
5edfcee5 AH |
613 | unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata, |
614 | struct ieee80211s_hdr *meshhdr, | |
615 | const char *addr4or5, const char *addr6) | |
902acc78 | 616 | { |
bf7cd94d JB |
617 | if (WARN_ON(!addr4or5 && addr6)) |
618 | return 0; | |
619 | ||
0c3cee72 | 620 | memset(meshhdr, 0, sizeof(*meshhdr)); |
bf7cd94d | 621 | |
472dbc45 | 622 | meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; |
bf7cd94d JB |
623 | |
624 | /* FIXME: racy -- TX on multiple queues can be concurrent */ | |
472dbc45 JB |
625 | put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum); |
626 | sdata->u.mesh.mesh_seqnum++; | |
bf7cd94d | 627 | |
61ad5394 | 628 | if (addr4or5 && !addr6) { |
3c5772a5 | 629 | meshhdr->flags |= MESH_FLAGS_AE_A4; |
61ad5394 | 630 | memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); |
bf7cd94d | 631 | return 2 * ETH_ALEN; |
61ad5394 | 632 | } else if (addr4or5 && addr6) { |
3c5772a5 | 633 | meshhdr->flags |= MESH_FLAGS_AE_A5_A6; |
61ad5394 JC |
634 | memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); |
635 | memcpy(meshhdr->eaddr2, addr6, ETH_ALEN); | |
bf7cd94d | 636 | return 3 * ETH_ALEN; |
3c5772a5 | 637 | } |
bf7cd94d JB |
638 | |
639 | return ETH_ALEN; | |
902acc78 JB |
640 | } |
641 | ||
bf7cd94d | 642 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata) |
472dbc45 | 643 | { |
bf7cd94d | 644 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
df323818 | 645 | u32 changed; |
472dbc45 | 646 | |
31f909a2 MH |
647 | if (ifmsh->mshcfg.plink_timeout > 0) |
648 | ieee80211_sta_expire(sdata, ifmsh->mshcfg.plink_timeout * HZ); | |
472dbc45 JB |
649 | mesh_path_expire(sdata); |
650 | ||
df323818 | 651 | changed = mesh_accept_plinks_update(sdata); |
2b5e1967 | 652 | ieee80211_mbss_info_change_notify(sdata, changed); |
472dbc45 | 653 | |
472dbc45 | 654 | mod_timer(&ifmsh->housekeeping_timer, |
bf7cd94d JB |
655 | round_jiffies(jiffies + |
656 | IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); | |
472dbc45 JB |
657 | } |
658 | ||
e304bfd3 RP |
659 | static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata) |
660 | { | |
661 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
a69cc44f | 662 | u32 interval; |
e304bfd3 RP |
663 | |
664 | mesh_path_tx_root_frame(sdata); | |
a69cc44f CYY |
665 | |
666 | if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN) | |
667 | interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval; | |
668 | else | |
669 | interval = ifmsh->mshcfg.dot11MeshHWMProotInterval; | |
670 | ||
e304bfd3 | 671 | mod_timer(&ifmsh->mesh_path_root_timer, |
a69cc44f | 672 | round_jiffies(TU_TO_EXP_TIME(interval))); |
e304bfd3 RP |
673 | } |
674 | ||
2b5e1967 TP |
675 | static int |
676 | ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh) | |
677 | { | |
678 | struct beacon_data *bcn; | |
679 | int head_len, tail_len; | |
680 | struct sk_buff *skb; | |
681 | struct ieee80211_mgmt *mgmt; | |
682 | struct ieee80211_chanctx_conf *chanctx_conf; | |
b8456a14 | 683 | struct mesh_csa_settings *csa; |
2b5e1967 TP |
684 | enum ieee80211_band band; |
685 | u8 *pos; | |
686 | struct ieee80211_sub_if_data *sdata; | |
687 | int hdr_len = offsetof(struct ieee80211_mgmt, u.beacon) + | |
688 | sizeof(mgmt->u.beacon); | |
689 | ||
690 | sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh); | |
691 | rcu_read_lock(); | |
692 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
693 | band = chanctx_conf->def.chan->band; | |
694 | rcu_read_unlock(); | |
695 | ||
696 | head_len = hdr_len + | |
697 | 2 + /* NULL SSID */ | |
b8456a14 CYY |
698 | /* Channel Switch Announcement */ |
699 | 2 + sizeof(struct ieee80211_channel_sw_ie) + | |
700 | /* Mesh Channel Swith Parameters */ | |
701 | 2 + sizeof(struct ieee80211_mesh_chansw_params_ie) + | |
2b5e1967 TP |
702 | 2 + 8 + /* supported rates */ |
703 | 2 + 3; /* DS params */ | |
704 | tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) + | |
705 | 2 + sizeof(struct ieee80211_ht_cap) + | |
706 | 2 + sizeof(struct ieee80211_ht_operation) + | |
707 | 2 + ifmsh->mesh_id_len + | |
708 | 2 + sizeof(struct ieee80211_meshconf_ie) + | |
709 | 2 + sizeof(__le16) + /* awake window */ | |
c85fb53c BC |
710 | 2 + sizeof(struct ieee80211_vht_cap) + |
711 | 2 + sizeof(struct ieee80211_vht_operation) + | |
2b5e1967 TP |
712 | ifmsh->ie_len; |
713 | ||
714 | bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL); | |
715 | /* need an skb for IE builders to operate on */ | |
716 | skb = dev_alloc_skb(max(head_len, tail_len)); | |
717 | ||
718 | if (!bcn || !skb) | |
719 | goto out_free; | |
720 | ||
721 | /* | |
722 | * pointers go into the block we allocated, | |
723 | * memory is | beacon_data | head | tail | | |
724 | */ | |
725 | bcn->head = ((u8 *) bcn) + sizeof(*bcn); | |
726 | ||
727 | /* fill in the head */ | |
728 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); | |
729 | memset(mgmt, 0, hdr_len); | |
730 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
731 | IEEE80211_STYPE_BEACON); | |
732 | eth_broadcast_addr(mgmt->da); | |
733 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); | |
734 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); | |
735 | ieee80211_mps_set_frame_flags(sdata, NULL, (void *) mgmt); | |
736 | mgmt->u.beacon.beacon_int = | |
737 | cpu_to_le16(sdata->vif.bss_conf.beacon_int); | |
738 | mgmt->u.beacon.capab_info |= cpu_to_le16( | |
739 | sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0); | |
740 | ||
741 | pos = skb_put(skb, 2); | |
742 | *pos++ = WLAN_EID_SSID; | |
743 | *pos++ = 0x0; | |
744 | ||
b8456a14 CYY |
745 | rcu_read_lock(); |
746 | csa = rcu_dereference(ifmsh->csa); | |
747 | if (csa) { | |
b8456a14 CYY |
748 | pos = skb_put(skb, 13); |
749 | memset(pos, 0, 13); | |
750 | *pos++ = WLAN_EID_CHANNEL_SWITCH; | |
751 | *pos++ = 3; | |
752 | *pos++ = 0x0; | |
753 | *pos++ = ieee80211_frequency_to_channel( | |
754 | csa->settings.chandef.chan->center_freq); | |
8df734e8 | 755 | bcn->csa_current_counter = csa->settings.count; |
af296bdb | 756 | bcn->csa_counter_offsets[0] = hdr_len + 6; |
b8456a14 CYY |
757 | *pos++ = csa->settings.count; |
758 | *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; | |
759 | *pos++ = 6; | |
0cb4d4dc | 760 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) { |
b8456a14 CYY |
761 | *pos++ = ifmsh->mshcfg.dot11MeshTTL; |
762 | *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR; | |
763 | } else { | |
764 | *pos++ = ifmsh->chsw_ttl; | |
765 | } | |
766 | *pos++ |= csa->settings.block_tx ? | |
767 | WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00; | |
768 | put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); | |
769 | pos += 2; | |
ca91dc97 | 770 | put_unaligned_le16(ifmsh->pre_value, pos); |
b8456a14 CYY |
771 | pos += 2; |
772 | } | |
773 | rcu_read_unlock(); | |
774 | ||
2b5e1967 | 775 | if (ieee80211_add_srates_ie(sdata, skb, true, band) || |
bf7cd94d | 776 | mesh_add_ds_params_ie(sdata, skb)) |
2b5e1967 TP |
777 | goto out_free; |
778 | ||
779 | bcn->head_len = skb->len; | |
780 | memcpy(bcn->head, skb->data, bcn->head_len); | |
781 | ||
782 | /* now the tail */ | |
783 | skb_trim(skb, 0); | |
784 | bcn->tail = bcn->head + bcn->head_len; | |
785 | ||
786 | if (ieee80211_add_ext_srates_ie(sdata, skb, true, band) || | |
bf7cd94d JB |
787 | mesh_add_rsn_ie(sdata, skb) || |
788 | mesh_add_ht_cap_ie(sdata, skb) || | |
789 | mesh_add_ht_oper_ie(sdata, skb) || | |
790 | mesh_add_meshid_ie(sdata, skb) || | |
791 | mesh_add_meshconf_ie(sdata, skb) || | |
792 | mesh_add_awake_window_ie(sdata, skb) || | |
c85fb53c BC |
793 | mesh_add_vht_cap_ie(sdata, skb) || |
794 | mesh_add_vht_oper_ie(sdata, skb) || | |
bf7cd94d | 795 | mesh_add_vendor_ies(sdata, skb)) |
2b5e1967 TP |
796 | goto out_free; |
797 | ||
798 | bcn->tail_len = skb->len; | |
799 | memcpy(bcn->tail, skb->data, bcn->tail_len); | |
43552be1 TP |
800 | bcn->meshconf = (struct ieee80211_meshconf_ie *) |
801 | (bcn->tail + ifmsh->meshconf_offset); | |
2b5e1967 TP |
802 | |
803 | dev_kfree_skb(skb); | |
804 | rcu_assign_pointer(ifmsh->beacon, bcn); | |
805 | return 0; | |
806 | out_free: | |
807 | kfree(bcn); | |
808 | dev_kfree_skb(skb); | |
809 | return -ENOMEM; | |
810 | } | |
811 | ||
812 | static int | |
8d61ffa5 | 813 | ieee80211_mesh_rebuild_beacon(struct ieee80211_sub_if_data *sdata) |
2b5e1967 | 814 | { |
2b5e1967 TP |
815 | struct beacon_data *old_bcn; |
816 | int ret; | |
2b5e1967 | 817 | |
8d61ffa5 JB |
818 | old_bcn = rcu_dereference_protected(sdata->u.mesh.beacon, |
819 | lockdep_is_held(&sdata->wdev.mtx)); | |
820 | ret = ieee80211_mesh_build_beacon(&sdata->u.mesh); | |
2b5e1967 TP |
821 | if (ret) |
822 | /* just reuse old beacon */ | |
8d61ffa5 | 823 | return ret; |
2b5e1967 TP |
824 | |
825 | if (old_bcn) | |
826 | kfree_rcu(old_bcn, rcu_head); | |
8d61ffa5 | 827 | return 0; |
2b5e1967 TP |
828 | } |
829 | ||
830 | void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata, | |
831 | u32 changed) | |
832 | { | |
f81a9ded TP |
833 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
834 | unsigned long bits = changed; | |
835 | u32 bit; | |
836 | ||
837 | if (!bits) | |
838 | return; | |
839 | ||
840 | /* if we race with running work, worst case this work becomes a noop */ | |
841 | for_each_set_bit(bit, &bits, sizeof(changed) * BITS_PER_BYTE) | |
842 | set_bit(bit, &ifmsh->mbss_changed); | |
843 | set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags); | |
844 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); | |
2b5e1967 TP |
845 | } |
846 | ||
847 | int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) | |
472dbc45 JB |
848 | { |
849 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
850 | struct ieee80211_local *local = sdata->local; | |
f4eabc91 CYY |
851 | u32 changed = BSS_CHANGED_BEACON | |
852 | BSS_CHANGED_BEACON_ENABLED | | |
853 | BSS_CHANGED_HT | | |
854 | BSS_CHANGED_BASIC_RATES | | |
855 | BSS_CHANGED_BEACON_INT; | |
472dbc45 | 856 | |
09b17470 JB |
857 | local->fif_other_bss++; |
858 | /* mesh ifaces must set allmulti to forward mcast traffic */ | |
859 | atomic_inc(&local->iff_allmultis); | |
860 | ieee80211_configure_filter(local); | |
861 | ||
c7108a71 | 862 | ifmsh->mesh_cc_id = 0; /* Disabled */ |
dbf498fb JC |
863 | /* register sync ops from extensible synchronization framework */ |
864 | ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id); | |
dbf498fb | 865 | ifmsh->sync_offset_clockdrift_max = 0; |
6b9ac442 | 866 | set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); |
63c5723b | 867 | ieee80211_mesh_root_setup(ifmsh); |
64592c8f | 868 | ieee80211_queue_work(&local->hw, &sdata->work); |
70c33eaa AN |
869 | sdata->vif.bss_conf.ht_operation_mode = |
870 | ifmsh->mshcfg.ht_opmode; | |
d6a83228 | 871 | sdata->vif.bss_conf.enable_beacon = true; |
f4eabc91 | 872 | |
39886b61 | 873 | changed |= ieee80211_mps_local_status_update(sdata); |
3f52b7e3 | 874 | |
2b5e1967 TP |
875 | if (ieee80211_mesh_build_beacon(ifmsh)) { |
876 | ieee80211_stop_mesh(sdata); | |
877 | return -ENOMEM; | |
878 | } | |
879 | ||
057d5f4b | 880 | ieee80211_recalc_dtim(local, sdata); |
f4eabc91 | 881 | ieee80211_bss_info_change_notify(sdata, changed); |
c405c629 JB |
882 | |
883 | netif_carrier_on(sdata->dev); | |
2b5e1967 | 884 | return 0; |
472dbc45 JB |
885 | } |
886 | ||
887 | void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) | |
888 | { | |
09b17470 | 889 | struct ieee80211_local *local = sdata->local; |
29cbe68c | 890 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
2b5e1967 | 891 | struct beacon_data *bcn; |
29cbe68c | 892 | |
c405c629 JB |
893 | netif_carrier_off(sdata->dev); |
894 | ||
0d466b9c | 895 | /* stop the beacon */ |
29cbe68c | 896 | ifmsh->mesh_id_len = 0; |
d6a83228 JB |
897 | sdata->vif.bss_conf.enable_beacon = false; |
898 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); | |
29cbe68c | 899 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
2b5e1967 | 900 | bcn = rcu_dereference_protected(ifmsh->beacon, |
8d61ffa5 | 901 | lockdep_is_held(&sdata->wdev.mtx)); |
0c2bef46 | 902 | RCU_INIT_POINTER(ifmsh->beacon, NULL); |
2b5e1967 | 903 | kfree_rcu(bcn, rcu_head); |
0d466b9c TP |
904 | |
905 | /* flush STAs and mpaths on this iface */ | |
b998e8bb | 906 | sta_info_flush(sdata); |
0d466b9c | 907 | mesh_path_flush_by_iface(sdata); |
09b17470 | 908 | |
3f52b7e3 MP |
909 | /* free all potentially still buffered group-addressed frames */ |
910 | local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf); | |
911 | skb_queue_purge(&ifmsh->ps.bc_buf); | |
912 | ||
472dbc45 | 913 | del_timer_sync(&sdata->u.mesh.housekeeping_timer); |
e304bfd3 | 914 | del_timer_sync(&sdata->u.mesh.mesh_path_root_timer); |
dd4c9260 | 915 | del_timer_sync(&sdata->u.mesh.mesh_path_timer); |
09b17470 | 916 | |
f81a9ded TP |
917 | /* clear any mesh work (for next join) we may have accrued */ |
918 | ifmsh->wrkq_flags = 0; | |
919 | ifmsh->mbss_changed = 0; | |
920 | ||
09b17470 JB |
921 | local->fif_other_bss--; |
922 | atomic_dec(&local->iff_allmultis); | |
923 | ieee80211_configure_filter(local); | |
472dbc45 JB |
924 | } |
925 | ||
33a45867 CYY |
926 | static bool |
927 | ieee80211_mesh_process_chnswitch(struct ieee80211_sub_if_data *sdata, | |
928 | struct ieee802_11_elems *elems, bool beacon) | |
929 | { | |
930 | struct cfg80211_csa_settings params; | |
931 | struct ieee80211_csa_ie csa_ie; | |
33a45867 CYY |
932 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
933 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); | |
0cb4d4dc | 934 | int err; |
33a45867 CYY |
935 | u32 sta_flags; |
936 | ||
dbd72850 MK |
937 | sdata_assert_lock(sdata); |
938 | ||
33a45867 CYY |
939 | sta_flags = IEEE80211_STA_DISABLE_VHT; |
940 | switch (sdata->vif.bss_conf.chandef.width) { | |
941 | case NL80211_CHAN_WIDTH_20_NOHT: | |
942 | sta_flags |= IEEE80211_STA_DISABLE_HT; | |
943 | case NL80211_CHAN_WIDTH_20: | |
944 | sta_flags |= IEEE80211_STA_DISABLE_40MHZ; | |
945 | break; | |
946 | default: | |
947 | break; | |
948 | } | |
949 | ||
950 | memset(¶ms, 0, sizeof(params)); | |
951 | memset(&csa_ie, 0, sizeof(csa_ie)); | |
84469a45 | 952 | err = ieee80211_parse_ch_switch_ie(sdata, elems, band, |
33a45867 CYY |
953 | sta_flags, sdata->vif.addr, |
954 | &csa_ie); | |
955 | if (err < 0) | |
956 | return false; | |
957 | if (err) | |
958 | return false; | |
959 | ||
960 | params.chandef = csa_ie.chandef; | |
961 | params.count = csa_ie.count; | |
962 | ||
33a45867 CYY |
963 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, ¶ms.chandef, |
964 | IEEE80211_CHAN_DISABLED)) { | |
965 | sdata_info(sdata, | |
966 | "mesh STA %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n", | |
967 | sdata->vif.addr, | |
968 | params.chandef.chan->center_freq, | |
969 | params.chandef.width, | |
970 | params.chandef.center_freq1, | |
971 | params.chandef.center_freq2); | |
972 | return false; | |
973 | } | |
974 | ||
975 | err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy, | |
2beb6dab LC |
976 | ¶ms.chandef, |
977 | NL80211_IFTYPE_MESH_POINT); | |
33a45867 CYY |
978 | if (err < 0) |
979 | return false; | |
2beb6dab | 980 | if (err > 0) |
33a45867 CYY |
981 | /* TODO: DFS not (yet) supported */ |
982 | return false; | |
2beb6dab LC |
983 | |
984 | params.radar_required = err; | |
33a45867 | 985 | |
0cb4d4dc LC |
986 | if (cfg80211_chandef_identical(¶ms.chandef, |
987 | &sdata->vif.bss_conf.chandef)) { | |
988 | mcsa_dbg(sdata, | |
989 | "received csa with an identical chandef, ignoring\n"); | |
990 | return true; | |
991 | } | |
33a45867 CYY |
992 | |
993 | mcsa_dbg(sdata, | |
994 | "received channel switch announcement to go to channel %d MHz\n", | |
995 | params.chandef.chan->center_freq); | |
996 | ||
997 | params.block_tx = csa_ie.mode & WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT; | |
3f718fd8 | 998 | if (beacon) { |
33a45867 | 999 | ifmsh->chsw_ttl = csa_ie.ttl - 1; |
3f718fd8 CYY |
1000 | if (ifmsh->pre_value >= csa_ie.pre_value) |
1001 | return false; | |
1002 | ifmsh->pre_value = csa_ie.pre_value; | |
1003 | } | |
33a45867 | 1004 | |
0cb4d4dc | 1005 | if (ifmsh->chsw_ttl >= ifmsh->mshcfg.dot11MeshTTL) |
3f718fd8 | 1006 | return false; |
33a45867 | 1007 | |
0cb4d4dc | 1008 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_REPEATER; |
33a45867 | 1009 | |
0cb4d4dc LC |
1010 | if (ieee80211_channel_switch(sdata->local->hw.wiphy, sdata->dev, |
1011 | ¶ms) < 0) | |
1012 | return false; | |
33a45867 CYY |
1013 | |
1014 | return true; | |
33a45867 CYY |
1015 | } |
1016 | ||
9fb04b50 TP |
1017 | static void |
1018 | ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata, | |
1019 | struct ieee80211_mgmt *mgmt, size_t len) | |
1020 | { | |
1021 | struct ieee80211_local *local = sdata->local; | |
1022 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1023 | struct sk_buff *presp; | |
1024 | struct beacon_data *bcn; | |
1025 | struct ieee80211_mgmt *hdr; | |
1026 | struct ieee802_11_elems elems; | |
1027 | size_t baselen; | |
511044ea | 1028 | u8 *pos; |
9fb04b50 | 1029 | |
9fb04b50 TP |
1030 | pos = mgmt->u.probe_req.variable; |
1031 | baselen = (u8 *) pos - (u8 *) mgmt; | |
1032 | if (baselen > len) | |
1033 | return; | |
1034 | ||
b2e506bf | 1035 | ieee802_11_parse_elems(pos, len - baselen, false, &elems); |
9fb04b50 | 1036 | |
a4ef66a9 CYY |
1037 | if (!elems.mesh_id) |
1038 | return; | |
1039 | ||
9fb04b50 TP |
1040 | /* 802.11-2012 10.1.4.3.2 */ |
1041 | if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) && | |
1042 | !is_broadcast_ether_addr(mgmt->da)) || | |
1043 | elems.ssid_len != 0) | |
1044 | return; | |
1045 | ||
1046 | if (elems.mesh_id_len != 0 && | |
1047 | (elems.mesh_id_len != ifmsh->mesh_id_len || | |
1048 | memcmp(elems.mesh_id, ifmsh->mesh_id, ifmsh->mesh_id_len))) | |
1049 | return; | |
1050 | ||
1051 | rcu_read_lock(); | |
1052 | bcn = rcu_dereference(ifmsh->beacon); | |
1053 | ||
1054 | if (!bcn) | |
1055 | goto out; | |
1056 | ||
1057 | presp = dev_alloc_skb(local->tx_headroom + | |
1058 | bcn->head_len + bcn->tail_len); | |
1059 | if (!presp) | |
1060 | goto out; | |
1061 | ||
1062 | skb_reserve(presp, local->tx_headroom); | |
1063 | memcpy(skb_put(presp, bcn->head_len), bcn->head, bcn->head_len); | |
1064 | memcpy(skb_put(presp, bcn->tail_len), bcn->tail, bcn->tail_len); | |
1065 | hdr = (struct ieee80211_mgmt *) presp->data; | |
1066 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
1067 | IEEE80211_STYPE_PROBE_RESP); | |
1068 | memcpy(hdr->da, mgmt->sa, ETH_ALEN); | |
9fb04b50 TP |
1069 | IEEE80211_SKB_CB(presp)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
1070 | ieee80211_tx_skb(sdata, presp); | |
1071 | out: | |
1072 | rcu_read_unlock(); | |
1073 | } | |
1074 | ||
472dbc45 JB |
1075 | static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, |
1076 | u16 stype, | |
1077 | struct ieee80211_mgmt *mgmt, | |
1078 | size_t len, | |
1079 | struct ieee80211_rx_status *rx_status) | |
1080 | { | |
c6a1fa12 | 1081 | struct ieee80211_local *local = sdata->local; |
dbf498fb | 1082 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
472dbc45 JB |
1083 | struct ieee802_11_elems elems; |
1084 | struct ieee80211_channel *channel; | |
472dbc45 JB |
1085 | size_t baselen; |
1086 | int freq; | |
1087 | enum ieee80211_band band = rx_status->band; | |
1088 | ||
1089 | /* ignore ProbeResp to foreign address */ | |
1090 | if (stype == IEEE80211_STYPE_PROBE_RESP && | |
b203ca39 | 1091 | !ether_addr_equal(mgmt->da, sdata->vif.addr)) |
472dbc45 JB |
1092 | return; |
1093 | ||
1094 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; | |
1095 | if (baselen > len) | |
1096 | return; | |
1097 | ||
1098 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
b2e506bf | 1099 | false, &elems); |
472dbc45 | 1100 | |
9a90bc81 TP |
1101 | /* ignore non-mesh or secure / unsecure mismatch */ |
1102 | if ((!elems.mesh_id || !elems.mesh_config) || | |
1103 | (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) || | |
1104 | (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)) | |
5cff5e01 JC |
1105 | return; |
1106 | ||
1cd8e88e | 1107 | if (elems.ds_params) |
59eb21a6 | 1108 | freq = ieee80211_channel_to_frequency(elems.ds_params[0], band); |
472dbc45 JB |
1109 | else |
1110 | freq = rx_status->freq; | |
1111 | ||
1112 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
1113 | ||
1114 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
1115 | return; | |
1116 | ||
9a90bc81 | 1117 | if (mesh_matches_local(sdata, &elems)) |
f743ff49 | 1118 | mesh_neighbour_update(sdata, mgmt->sa, &elems); |
dbf498fb JC |
1119 | |
1120 | if (ifmsh->sync_ops) | |
1121 | ifmsh->sync_ops->rx_bcn_presp(sdata, | |
1122 | stype, mgmt, &elems, rx_status); | |
33a45867 | 1123 | |
0cb4d4dc LC |
1124 | if (ifmsh->csa_role != IEEE80211_MESH_CSA_ROLE_INIT && |
1125 | !sdata->vif.csa_active) | |
33a45867 | 1126 | ieee80211_mesh_process_chnswitch(sdata, &elems, true); |
472dbc45 JB |
1127 | } |
1128 | ||
b8456a14 CYY |
1129 | int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata) |
1130 | { | |
1131 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1132 | struct mesh_csa_settings *tmp_csa_settings; | |
1133 | int ret = 0; | |
faf046e7 | 1134 | int changed = 0; |
b8456a14 CYY |
1135 | |
1136 | /* Reset the TTL value and Initiator flag */ | |
0cb4d4dc | 1137 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; |
b8456a14 CYY |
1138 | ifmsh->chsw_ttl = 0; |
1139 | ||
1140 | /* Remove the CSA and MCSP elements from the beacon */ | |
1141 | tmp_csa_settings = rcu_dereference(ifmsh->csa); | |
0c2bef46 | 1142 | RCU_INIT_POINTER(ifmsh->csa, NULL); |
66e01cf9 LC |
1143 | if (tmp_csa_settings) |
1144 | kfree_rcu(tmp_csa_settings, rcu_head); | |
b8456a14 CYY |
1145 | ret = ieee80211_mesh_rebuild_beacon(sdata); |
1146 | if (ret) | |
1147 | return -EINVAL; | |
1148 | ||
faf046e7 | 1149 | changed |= BSS_CHANGED_BEACON; |
b8456a14 CYY |
1150 | |
1151 | mcsa_dbg(sdata, "complete switching to center freq %d MHz", | |
1152 | sdata->vif.bss_conf.chandef.chan->center_freq); | |
faf046e7 | 1153 | return changed; |
b8456a14 CYY |
1154 | } |
1155 | ||
1156 | int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata, | |
66e01cf9 | 1157 | struct cfg80211_csa_settings *csa_settings) |
b8456a14 CYY |
1158 | { |
1159 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1160 | struct mesh_csa_settings *tmp_csa_settings; | |
1161 | int ret = 0; | |
1162 | ||
1163 | tmp_csa_settings = kmalloc(sizeof(*tmp_csa_settings), | |
1164 | GFP_ATOMIC); | |
1165 | if (!tmp_csa_settings) | |
1166 | return -ENOMEM; | |
1167 | ||
1168 | memcpy(&tmp_csa_settings->settings, csa_settings, | |
1169 | sizeof(struct cfg80211_csa_settings)); | |
1170 | ||
1171 | rcu_assign_pointer(ifmsh->csa, tmp_csa_settings); | |
1172 | ||
1173 | ret = ieee80211_mesh_rebuild_beacon(sdata); | |
1174 | if (ret) { | |
1175 | tmp_csa_settings = rcu_dereference(ifmsh->csa); | |
0c2bef46 | 1176 | RCU_INIT_POINTER(ifmsh->csa, NULL); |
b8456a14 CYY |
1177 | kfree_rcu(tmp_csa_settings, rcu_head); |
1178 | return ret; | |
1179 | } | |
1180 | ||
b58e81e9 | 1181 | return BSS_CHANGED_BEACON; |
b8456a14 CYY |
1182 | } |
1183 | ||
8f2535b9 CYY |
1184 | static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata, |
1185 | struct ieee80211_mgmt *mgmt, size_t len) | |
1186 | { | |
1187 | struct ieee80211_mgmt *mgmt_fwd; | |
1188 | struct sk_buff *skb; | |
1189 | struct ieee80211_local *local = sdata->local; | |
1190 | u8 *pos = mgmt->u.action.u.chan_switch.variable; | |
1191 | size_t offset_ttl; | |
1192 | ||
1193 | skb = dev_alloc_skb(local->tx_headroom + len); | |
1194 | if (!skb) | |
1195 | return -ENOMEM; | |
1196 | skb_reserve(skb, local->tx_headroom); | |
1197 | mgmt_fwd = (struct ieee80211_mgmt *) skb_put(skb, len); | |
1198 | ||
1199 | /* offset_ttl is based on whether the secondary channel | |
b314c669 | 1200 | * offset is available or not. Subtract 1 from the mesh TTL |
8f2535b9 CYY |
1201 | * and disable the initiator flag before forwarding. |
1202 | */ | |
1203 | offset_ttl = (len < 42) ? 7 : 10; | |
1204 | *(pos + offset_ttl) -= 1; | |
1205 | *(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR; | |
1206 | ||
1207 | memcpy(mgmt_fwd, mgmt, len); | |
1208 | eth_broadcast_addr(mgmt_fwd->da); | |
1209 | memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN); | |
1210 | memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN); | |
1211 | ||
1212 | ieee80211_tx_skb(sdata, skb); | |
1213 | return 0; | |
1214 | } | |
1215 | ||
1216 | static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata, | |
1217 | struct ieee80211_mgmt *mgmt, size_t len) | |
1218 | { | |
1219 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1220 | struct ieee802_11_elems elems; | |
1221 | u16 pre_value; | |
33a45867 | 1222 | bool fwd_csa = true; |
8f2535b9 | 1223 | size_t baselen; |
3f718fd8 | 1224 | u8 *pos; |
8f2535b9 CYY |
1225 | |
1226 | if (mgmt->u.action.u.measurement.action_code != | |
1227 | WLAN_ACTION_SPCT_CHL_SWITCH) | |
1228 | return; | |
1229 | ||
1230 | pos = mgmt->u.action.u.chan_switch.variable; | |
1231 | baselen = offsetof(struct ieee80211_mgmt, | |
1232 | u.action.u.chan_switch.variable); | |
1233 | ieee802_11_parse_elems(pos, len - baselen, false, &elems); | |
1234 | ||
3f718fd8 CYY |
1235 | ifmsh->chsw_ttl = elems.mesh_chansw_params_ie->mesh_ttl; |
1236 | if (!--ifmsh->chsw_ttl) | |
8f2535b9 CYY |
1237 | fwd_csa = false; |
1238 | ||
1239 | pre_value = le16_to_cpu(elems.mesh_chansw_params_ie->mesh_pre_value); | |
1240 | if (ifmsh->pre_value >= pre_value) | |
1241 | return; | |
1242 | ||
1243 | ifmsh->pre_value = pre_value; | |
1244 | ||
0cb4d4dc LC |
1245 | if (!sdata->vif.csa_active && |
1246 | !ieee80211_mesh_process_chnswitch(sdata, &elems, false)) { | |
33a45867 CYY |
1247 | mcsa_dbg(sdata, "Failed to process CSA action frame"); |
1248 | return; | |
1249 | } | |
1250 | ||
8f2535b9 CYY |
1251 | /* forward or re-broadcast the CSA frame */ |
1252 | if (fwd_csa) { | |
1253 | if (mesh_fwd_csa_frame(sdata, mgmt, len) < 0) | |
1254 | mcsa_dbg(sdata, "Failed to forward the CSA frame"); | |
1255 | } | |
8f2535b9 CYY |
1256 | } |
1257 | ||
472dbc45 JB |
1258 | static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, |
1259 | struct ieee80211_mgmt *mgmt, | |
1260 | size_t len, | |
1261 | struct ieee80211_rx_status *rx_status) | |
1262 | { | |
1263 | switch (mgmt->u.action.category) { | |
8db09850 TP |
1264 | case WLAN_CATEGORY_SELF_PROTECTED: |
1265 | switch (mgmt->u.action.u.self_prot.action_code) { | |
1266 | case WLAN_SP_MESH_PEERING_OPEN: | |
1267 | case WLAN_SP_MESH_PEERING_CLOSE: | |
1268 | case WLAN_SP_MESH_PEERING_CONFIRM: | |
1269 | mesh_rx_plink_frame(sdata, mgmt, len, rx_status); | |
1270 | break; | |
1271 | } | |
472dbc45 | 1272 | break; |
25d49e4d TP |
1273 | case WLAN_CATEGORY_MESH_ACTION: |
1274 | if (mesh_action_is_path_sel(mgmt)) | |
1275 | mesh_rx_path_sel_frame(sdata, mgmt, len); | |
472dbc45 | 1276 | break; |
8f2535b9 CYY |
1277 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
1278 | mesh_rx_csa_frame(sdata, mgmt, len); | |
1279 | break; | |
472dbc45 JB |
1280 | } |
1281 | } | |
1282 | ||
1fa57d01 JB |
1283 | void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
1284 | struct sk_buff *skb) | |
472dbc45 JB |
1285 | { |
1286 | struct ieee80211_rx_status *rx_status; | |
472dbc45 JB |
1287 | struct ieee80211_mgmt *mgmt; |
1288 | u16 stype; | |
1289 | ||
ecccd072 TP |
1290 | sdata_lock(sdata); |
1291 | ||
1292 | /* mesh already went down */ | |
1693d344 | 1293 | if (!sdata->u.mesh.mesh_id_len) |
ecccd072 TP |
1294 | goto out; |
1295 | ||
f1d58c25 | 1296 | rx_status = IEEE80211_SKB_RXCB(skb); |
472dbc45 JB |
1297 | mgmt = (struct ieee80211_mgmt *) skb->data; |
1298 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; | |
1299 | ||
1300 | switch (stype) { | |
1301 | case IEEE80211_STYPE_PROBE_RESP: | |
1302 | case IEEE80211_STYPE_BEACON: | |
1303 | ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len, | |
1304 | rx_status); | |
1305 | break; | |
9fb04b50 TP |
1306 | case IEEE80211_STYPE_PROBE_REQ: |
1307 | ieee80211_mesh_rx_probe_req(sdata, mgmt, skb->len); | |
1308 | break; | |
472dbc45 JB |
1309 | case IEEE80211_STYPE_ACTION: |
1310 | ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status); | |
1311 | break; | |
1312 | } | |
ecccd072 TP |
1313 | out: |
1314 | sdata_unlock(sdata); | |
472dbc45 JB |
1315 | } |
1316 | ||
f81a9ded TP |
1317 | static void mesh_bss_info_changed(struct ieee80211_sub_if_data *sdata) |
1318 | { | |
1319 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
1320 | u32 bit, changed = 0; | |
1321 | ||
1322 | for_each_set_bit(bit, &ifmsh->mbss_changed, | |
1323 | sizeof(changed) * BITS_PER_BYTE) { | |
1324 | clear_bit(bit, &ifmsh->mbss_changed); | |
1325 | changed |= BIT(bit); | |
1326 | } | |
1327 | ||
1328 | if (sdata->vif.bss_conf.enable_beacon && | |
1329 | (changed & (BSS_CHANGED_BEACON | | |
1330 | BSS_CHANGED_HT | | |
1331 | BSS_CHANGED_BASIC_RATES | | |
1332 | BSS_CHANGED_BEACON_INT))) | |
1333 | if (ieee80211_mesh_rebuild_beacon(sdata)) | |
1334 | return; | |
1335 | ||
1336 | ieee80211_bss_info_change_notify(sdata, changed); | |
1337 | } | |
1338 | ||
1fa57d01 | 1339 | void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata) |
472dbc45 | 1340 | { |
472dbc45 | 1341 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
472dbc45 | 1342 | |
ecccd072 TP |
1343 | sdata_lock(sdata); |
1344 | ||
1345 | /* mesh already went down */ | |
1693d344 | 1346 | if (!sdata->u.mesh.mesh_id_len) |
ecccd072 TP |
1347 | goto out; |
1348 | ||
472dbc45 JB |
1349 | if (ifmsh->preq_queue_len && |
1350 | time_after(jiffies, | |
1351 | ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval))) | |
1352 | mesh_path_start_discovery(sdata); | |
1353 | ||
18889231 JC |
1354 | if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags)) |
1355 | mesh_mpath_table_grow(); | |
1356 | ||
dcac908b | 1357 | if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags)) |
18889231 JC |
1358 | mesh_mpp_table_grow(); |
1359 | ||
1360 | if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags)) | |
bf7cd94d | 1361 | ieee80211_mesh_housekeeping(sdata); |
e304bfd3 RP |
1362 | |
1363 | if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags)) | |
1364 | ieee80211_mesh_rootpath(sdata); | |
dbf498fb JC |
1365 | |
1366 | if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags)) | |
1367 | mesh_sync_adjust_tbtt(sdata); | |
ecccd072 | 1368 | |
f81a9ded TP |
1369 | if (test_and_clear_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags)) |
1370 | mesh_bss_info_changed(sdata); | |
ecccd072 TP |
1371 | out: |
1372 | sdata_unlock(sdata); | |
472dbc45 JB |
1373 | } |
1374 | ||
472dbc45 | 1375 | |
902acc78 JB |
1376 | void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) |
1377 | { | |
472dbc45 | 1378 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
ad2d223a | 1379 | static u8 zero_addr[ETH_ALEN] = {}; |
472dbc45 | 1380 | |
472dbc45 JB |
1381 | setup_timer(&ifmsh->housekeeping_timer, |
1382 | ieee80211_mesh_housekeeping_timer, | |
1383 | (unsigned long) sdata); | |
472dbc45 | 1384 | |
472dbc45 | 1385 | ifmsh->accepting_plinks = true; |
472dbc45 | 1386 | atomic_set(&ifmsh->mpaths, 0); |
f698d856 | 1387 | mesh_rmc_init(sdata); |
472dbc45 | 1388 | ifmsh->last_preq = jiffies; |
dca7e943 | 1389 | ifmsh->next_perr = jiffies; |
0cb4d4dc | 1390 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; |
902acc78 JB |
1391 | /* Allocate all mesh structures when creating the first mesh interface. */ |
1392 | if (!mesh_allocated) | |
1393 | ieee80211s_init(); | |
472dbc45 | 1394 | setup_timer(&ifmsh->mesh_path_timer, |
902acc78 JB |
1395 | ieee80211_mesh_path_timer, |
1396 | (unsigned long) sdata); | |
e304bfd3 RP |
1397 | setup_timer(&ifmsh->mesh_path_root_timer, |
1398 | ieee80211_mesh_path_root_timer, | |
1399 | (unsigned long) sdata); | |
472dbc45 | 1400 | INIT_LIST_HEAD(&ifmsh->preq_queue.list); |
3f52b7e3 | 1401 | skb_queue_head_init(&ifmsh->ps.bc_buf); |
472dbc45 | 1402 | spin_lock_init(&ifmsh->mesh_preq_queue_lock); |
dbf498fb | 1403 | spin_lock_init(&ifmsh->sync_offset_lock); |
2b5e1967 | 1404 | RCU_INIT_POINTER(ifmsh->beacon, NULL); |
ad2d223a JB |
1405 | |
1406 | sdata->vif.bss_conf.bssid = zero_addr; | |
472dbc45 | 1407 | } |