{nl,cfg,mac}80211: enable the triggering of CSA frame in mesh
[deliverable/linux.git] / net / mac80211 / mesh.c
CommitLineData
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"
15
bf7cd94d 16static int mesh_allocated;
2e3c8736
LCC
17static struct kmem_cache *rm_cache;
18
25d49e4d
TP
19bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
20{
21 return (mgmt->u.action.u.mesh_action.action_code ==
22 WLAN_MESH_ACTION_HWMP_PATH_SELECTION);
23}
25d49e4d 24
2e3c8736
LCC
25void ieee80211s_init(void)
26{
27 mesh_pathtbl_init();
28 mesh_allocated = 1;
29 rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
30 0, 0, NULL);
31}
32
33void ieee80211s_stop(void)
34{
bf7cd94d
JB
35 if (!mesh_allocated)
36 return;
2e3c8736
LCC
37 mesh_pathtbl_unregister();
38 kmem_cache_destroy(rm_cache);
39}
40
472dbc45
JB
41static void ieee80211_mesh_housekeeping_timer(unsigned long data)
42{
43 struct ieee80211_sub_if_data *sdata = (void *) data;
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
64592c8f 49 ieee80211_queue_work(&local->hw, &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.
60 */
f743ff49
TP
61bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
62 struct ieee802_11_elems *ie)
2e3c8736 63{
472dbc45 64 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
f743ff49 65 u32 basic_rates = 0;
4bf88530 66 struct cfg80211_chan_def sta_chan_def;
2e3c8736 67
2e3c8736
LCC
68 /*
69 * As support for each feature is added, check for matching
70 * - On mesh config capabilities
71 * - Power Save Support En
72 * - Sync support enabled
73 * - Sync support active
74 * - Sync support required from peer
75 * - MDA enabled
76 * - Power management control on fc
77 */
739522ba
TP
78 if (!(ifmsh->mesh_id_len == ie->mesh_id_len &&
79 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
80 (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
81 (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
82 (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
83 (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
84 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)))
bf7cd94d 85 return false;
739522ba 86
2103dec1 87 ieee80211_sta_get_rates(sdata, ie, ieee80211_get_sdata_band(sdata),
f743ff49
TP
88 &basic_rates);
89
fe40cb62 90 if (sdata->vif.bss_conf.basic_rates != basic_rates)
bf7cd94d 91 return false;
fe40cb62 92
4bf88530
JB
93 ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan,
94 ie->ht_operation, &sta_chan_def);
95
96 if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef,
97 &sta_chan_def))
bf7cd94d 98 return false;
2e3c8736 99
739522ba 100 return true;
2e3c8736
LCC
101}
102
103/**
104 * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
105 *
106 * @ie: information elements of a management frame from the mesh peer
2e3c8736 107 */
f698d856 108bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
2e3c8736 109{
136cfa28 110 return (ie->mesh_config->meshconf_cap &
bf7cd94d 111 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
2e3c8736
LCC
112}
113
114/**
2c53040f 115 * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
2e3c8736 116 *
d0709a65 117 * @sdata: mesh interface in which mesh beacons are going to be updated
df323818
MP
118 *
119 * Returns: beacon changed flag if the beacon content changed.
2e3c8736 120 */
df323818 121u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
2e3c8736 122{
2e3c8736 123 bool free_plinks;
df323818 124 u32 changed = 0;
2e3c8736
LCC
125
126 /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
127 * the mesh interface might be able to establish plinks with peers that
b4e08ea1
LCC
128 * are already on the table but are not on PLINK_ESTAB state. However,
129 * in general the mesh interface is not accepting peer link requests
130 * from new peers, and that must be reflected in the beacon
2e3c8736
LCC
131 */
132 free_plinks = mesh_plink_availables(sdata);
133
df323818
MP
134 if (free_plinks != sdata->u.mesh.accepting_plinks) {
135 sdata->u.mesh.accepting_plinks = free_plinks;
136 changed = BSS_CHANGED_BEACON;
137 }
138
139 return changed;
2e3c8736
LCC
140}
141
45b5028e
TP
142/*
143 * mesh_sta_cleanup - clean up any mesh sta state
144 *
145 * @sta: mesh sta to clean up.
146 */
147void mesh_sta_cleanup(struct sta_info *sta)
148{
149 struct ieee80211_sub_if_data *sdata = sta->sdata;
150 u32 changed;
151
152 /*
153 * maybe userspace handles peer allocation and peering, but in either
154 * case the beacon is still generated by the kernel and we might need
155 * an update.
156 */
157 changed = mesh_accept_plinks_update(sdata);
a6dad6a2 158 if (!sdata->u.mesh.user_mpm) {
45b5028e
TP
159 changed |= mesh_plink_deactivate(sta);
160 del_timer_sync(&sta->plink_timer);
161 }
162
f81a9ded 163 if (changed)
2b5e1967 164 ieee80211_mbss_info_change_notify(sdata, changed);
45b5028e
TP
165}
166
f698d856 167int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
2e3c8736 168{
2e3c8736
LCC
169 int i;
170
472dbc45
JB
171 sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
172 if (!sdata->u.mesh.rmc)
2e3c8736 173 return -ENOMEM;
472dbc45 174 sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
2e3c8736 175 for (i = 0; i < RMC_BUCKETS; i++)
b7cfcd11 176 INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i]);
2e3c8736
LCC
177 return 0;
178}
179
f698d856 180void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
2e3c8736 181{
472dbc45 182 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
2e3c8736
LCC
183 struct rmc_entry *p, *n;
184 int i;
185
472dbc45 186 if (!sdata->u.mesh.rmc)
2e3c8736
LCC
187 return;
188
bf7cd94d 189 for (i = 0; i < RMC_BUCKETS; i++) {
b7cfcd11 190 list_for_each_entry_safe(p, n, &rmc->bucket[i], list) {
2e3c8736
LCC
191 list_del(&p->list);
192 kmem_cache_free(rm_cache, p);
193 }
bf7cd94d 194 }
2e3c8736
LCC
195
196 kfree(rmc);
472dbc45 197 sdata->u.mesh.rmc = NULL;
2e3c8736
LCC
198}
199
200/**
201 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
202 *
bf7cd94d 203 * @sdata: interface
2e3c8736
LCC
204 * @sa: source address
205 * @mesh_hdr: mesh_header
206 *
207 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
208 *
209 * Checks using the source address and the mesh sequence number if we have
210 * received this frame lately. If the frame is not in the cache, it is added to
211 * it.
212 */
bf7cd94d
JB
213int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
214 const u8 *sa, struct ieee80211s_hdr *mesh_hdr)
2e3c8736 215{
472dbc45 216 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
2e3c8736
LCC
217 u32 seqnum = 0;
218 int entries = 0;
219 u8 idx;
220 struct rmc_entry *p, *n;
221
222 /* Don't care about endianness since only match matters */
51ceddad
LCC
223 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
224 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
b7cfcd11 225 list_for_each_entry_safe(p, n, &rmc->bucket[idx], list) {
2e3c8736
LCC
226 ++entries;
227 if (time_after(jiffies, p->exp_time) ||
bf7cd94d 228 entries == RMC_QUEUE_MAX_LEN) {
2e3c8736
LCC
229 list_del(&p->list);
230 kmem_cache_free(rm_cache, p);
231 --entries;
bf7cd94d 232 } else if ((seqnum == p->seqnum) && ether_addr_equal(sa, p->sa))
2e3c8736
LCC
233 return -1;
234 }
235
236 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
d15b8459 237 if (!p)
2e3c8736 238 return 0;
d15b8459 239
2e3c8736
LCC
240 p->seqnum = seqnum;
241 p->exp_time = jiffies + RMC_TIMEOUT;
242 memcpy(p->sa, sa, ETH_ALEN);
b7cfcd11 243 list_add(&p->list, &rmc->bucket[idx]);
2e3c8736
LCC
244 return 0;
245}
246
bf7cd94d
JB
247int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
248 struct sk_buff *skb)
082ebb0c
TP
249{
250 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
251 u8 *pos, neighbors;
252 u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie);
253
254 if (skb_tailroom(skb) < 2 + meshconf_len)
255 return -ENOMEM;
256
257 pos = skb_put(skb, 2 + meshconf_len);
258 *pos++ = WLAN_EID_MESH_CONFIG;
259 *pos++ = meshconf_len;
260
261 /* Active path selection protocol ID */
262 *pos++ = ifmsh->mesh_pp_id;
263 /* Active path selection metric ID */
264 *pos++ = ifmsh->mesh_pm_id;
265 /* Congestion control mode identifier */
266 *pos++ = ifmsh->mesh_cc_id;
267 /* Synchronization protocol identifier */
268 *pos++ = ifmsh->mesh_sp_id;
269 /* Authentication Protocol identifier */
270 *pos++ = ifmsh->mesh_auth_id;
271 /* Mesh Formation Info - number of neighbors */
1258d976 272 neighbors = atomic_read(&ifmsh->estab_plinks);
e05ecccd 273 neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS);
082ebb0c
TP
274 *pos++ = neighbors << 1;
275 /* Mesh capability */
b60e527a
CYY
276 *pos = 0x00;
277 *pos |= ifmsh->mshcfg.dot11MeshForwarding ?
278 IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00;
dbf498fb 279 *pos |= ifmsh->accepting_plinks ?
bf7cd94d 280 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
3f52b7e3
MP
281 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
282 *pos |= ifmsh->ps_peers_deep_sleep ?
bf7cd94d 283 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00;
dbf498fb 284 *pos++ |= ifmsh->adjusting_tbtt ?
bf7cd94d 285 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING : 0x00;
082ebb0c
TP
286 *pos++ = 0x00;
287
288 return 0;
289}
290
bf7cd94d 291int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
082ebb0c
TP
292{
293 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
294 u8 *pos;
295
296 if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
297 return -ENOMEM;
298
299 pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
300 *pos++ = WLAN_EID_MESH_ID;
301 *pos++ = ifmsh->mesh_id_len;
302 if (ifmsh->mesh_id_len)
303 memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
304
305 return 0;
306}
307
bf7cd94d
JB
308static int mesh_add_awake_window_ie(struct ieee80211_sub_if_data *sdata,
309 struct sk_buff *skb)
3f52b7e3
MP
310{
311 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
312 u8 *pos;
313
314 /* see IEEE802.11-2012 13.14.6 */
315 if (ifmsh->ps_peers_light_sleep == 0 &&
316 ifmsh->ps_peers_deep_sleep == 0 &&
317 ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE)
318 return 0;
319
320 if (skb_tailroom(skb) < 4)
321 return -ENOMEM;
322
323 pos = skb_put(skb, 2 + 2);
324 *pos++ = WLAN_EID_MESH_AWAKE_WINDOW;
325 *pos++ = 2;
326 put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos);
327
328 return 0;
329}
330
bf7cd94d
JB
331int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
332 struct sk_buff *skb)
082ebb0c
TP
333{
334 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
335 u8 offset, len;
336 const u8 *data;
337
338 if (!ifmsh->ie || !ifmsh->ie_len)
339 return 0;
340
341 /* fast-forward to vendor IEs */
342 offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
343
344 if (offset) {
345 len = ifmsh->ie_len - offset;
346 data = ifmsh->ie + offset;
347 if (skb_tailroom(skb) < len)
348 return -ENOMEM;
349 memcpy(skb_put(skb, len), data, len);
350 }
351
352 return 0;
353}
354
bf7cd94d 355int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
082ebb0c
TP
356{
357 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
358 u8 len = 0;
359 const u8 *data;
360
361 if (!ifmsh->ie || !ifmsh->ie_len)
362 return 0;
363
364 /* find RSN IE */
365 data = ifmsh->ie;
366 while (data < ifmsh->ie + ifmsh->ie_len) {
367 if (*data == WLAN_EID_RSN) {
368 len = data[1] + 2;
369 break;
370 }
371 data++;
372 }
373
374 if (len) {
375 if (skb_tailroom(skb) < len)
376 return -ENOMEM;
377 memcpy(skb_put(skb, len), data, len);
378 }
379
380 return 0;
381}
382
bf7cd94d
JB
383static int mesh_add_ds_params_ie(struct ieee80211_sub_if_data *sdata,
384 struct sk_buff *skb)
082ebb0c 385{
55de908a
JB
386 struct ieee80211_chanctx_conf *chanctx_conf;
387 struct ieee80211_channel *chan;
082ebb0c 388 u8 *pos;
2e3c8736 389
082ebb0c
TP
390 if (skb_tailroom(skb) < 3)
391 return -ENOMEM;
392
55de908a
JB
393 rcu_read_lock();
394 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
395 if (WARN_ON(!chanctx_conf)) {
396 rcu_read_unlock();
397 return -EINVAL;
398 }
4bf88530 399 chan = chanctx_conf->def.chan;
55de908a
JB
400 rcu_read_unlock();
401
601513aa
ET
402 pos = skb_put(skb, 2 + 1);
403 *pos++ = WLAN_EID_DS_PARAMS;
404 *pos++ = 1;
405 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
be125c60 406
082ebb0c 407 return 0;
2e3c8736
LCC
408}
409
bf7cd94d
JB
410int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
411 struct sk_buff *skb)
176f3608
TP
412{
413 struct ieee80211_local *local = sdata->local;
55de908a 414 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
176f3608
TP
415 struct ieee80211_supported_band *sband;
416 u8 *pos;
417
55de908a 418 sband = local->hw.wiphy->bands[band];
176f3608 419 if (!sband->ht_cap.ht_supported ||
0418a445
SW
420 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
421 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
422 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
176f3608
TP
423 return 0;
424
425 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
426 return -ENOMEM;
427
428 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
ef96a842 429 ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
176f3608
TP
430
431 return 0;
432}
433
bf7cd94d
JB
434int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
435 struct sk_buff *skb)
176f3608
TP
436{
437 struct ieee80211_local *local = sdata->local;
55de908a
JB
438 struct ieee80211_chanctx_conf *chanctx_conf;
439 struct ieee80211_channel *channel;
466f310d 440 enum nl80211_channel_type channel_type =
4bf88530 441 cfg80211_get_chandef_type(&sdata->vif.bss_conf.chandef);
55de908a
JB
442 struct ieee80211_supported_band *sband;
443 struct ieee80211_sta_ht_cap *ht_cap;
176f3608
TP
444 u8 *pos;
445
55de908a
JB
446 rcu_read_lock();
447 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
448 if (WARN_ON(!chanctx_conf)) {
449 rcu_read_unlock();
450 return -EINVAL;
451 }
4bf88530 452 channel = chanctx_conf->def.chan;
55de908a
JB
453 rcu_read_unlock();
454
455 sband = local->hw.wiphy->bands[channel->band];
456 ht_cap = &sband->ht_cap;
457
176f3608
TP
458 if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
459 return 0;
460
074d46d1 461 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
176f3608
TP
462 return -ENOMEM;
463
074d46d1 464 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
4bf88530 465 ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef,
431e3154 466 sdata->vif.bss_conf.ht_operation_mode);
176f3608
TP
467
468 return 0;
469}
bf7cd94d 470
2e3c8736
LCC
471static void ieee80211_mesh_path_timer(unsigned long data)
472{
473 struct ieee80211_sub_if_data *sdata =
474 (struct ieee80211_sub_if_data *) data;
5bb644a0 475
690205f1 476 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2e3c8736
LCC
477}
478
e304bfd3
RP
479static void ieee80211_mesh_path_root_timer(unsigned long data)
480{
481 struct ieee80211_sub_if_data *sdata =
482 (struct ieee80211_sub_if_data *) data;
483 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
e304bfd3
RP
484
485 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
486
690205f1 487 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
e304bfd3
RP
488}
489
63c5723b
RP
490void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
491{
dbb912cd 492 if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
63c5723b
RP
493 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
494 else {
495 clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
496 /* stop running timer */
497 del_timer_sync(&ifmsh->mesh_path_root_timer);
498 }
499}
500
3c5772a5
JC
501/**
502 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
bf7cd94d 503 * @hdr: 802.11 frame header
3c5772a5
JC
504 * @fc: frame control field
505 * @meshda: destination address in the mesh
506 * @meshsa: source address address in the mesh. Same as TA, as frame is
507 * locally originated.
508 *
509 * Return the length of the 802.11 (does not include a mesh control header)
510 */
15ff6365
JB
511int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
512 const u8 *meshda, const u8 *meshsa)
513{
3c5772a5
JC
514 if (is_multicast_ether_addr(meshda)) {
515 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
516 /* DA TA SA */
517 memcpy(hdr->addr1, meshda, ETH_ALEN);
518 memcpy(hdr->addr2, meshsa, ETH_ALEN);
519 memcpy(hdr->addr3, meshsa, ETH_ALEN);
520 return 24;
521 } else {
2154c81c 522 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
3c5772a5
JC
523 /* RA TA DA SA */
524 memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
525 memcpy(hdr->addr2, meshsa, ETH_ALEN);
526 memcpy(hdr->addr3, meshda, ETH_ALEN);
527 memcpy(hdr->addr4, meshsa, ETH_ALEN);
528 return 30;
529 }
530}
531
902acc78
JB
532/**
533 * ieee80211_new_mesh_header - create a new mesh header
902acc78 534 * @sdata: mesh interface to be used
bf7cd94d 535 * @meshhdr: uninitialized mesh header
61ad5394
JC
536 * @addr4or5: 1st address in the ae header, which may correspond to address 4
537 * (if addr6 is NULL) or address 5 (if addr6 is present). It may
538 * be NULL.
539 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
540 * mesh frame
902acc78
JB
541 *
542 * Return the header length.
543 */
bf7cd94d
JB
544int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
545 struct ieee80211s_hdr *meshhdr,
546 const char *addr4or5, const char *addr6)
902acc78 547{
bf7cd94d
JB
548 if (WARN_ON(!addr4or5 && addr6))
549 return 0;
550
0c3cee72 551 memset(meshhdr, 0, sizeof(*meshhdr));
bf7cd94d 552
472dbc45 553 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
bf7cd94d
JB
554
555 /* FIXME: racy -- TX on multiple queues can be concurrent */
472dbc45
JB
556 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
557 sdata->u.mesh.mesh_seqnum++;
bf7cd94d 558
61ad5394 559 if (addr4or5 && !addr6) {
3c5772a5 560 meshhdr->flags |= MESH_FLAGS_AE_A4;
61ad5394 561 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
bf7cd94d 562 return 2 * ETH_ALEN;
61ad5394 563 } else if (addr4or5 && addr6) {
3c5772a5 564 meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
61ad5394
JC
565 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
566 memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
bf7cd94d 567 return 3 * ETH_ALEN;
3c5772a5 568 }
bf7cd94d
JB
569
570 return ETH_ALEN;
902acc78
JB
571}
572
bf7cd94d 573static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata)
472dbc45 574{
bf7cd94d 575 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
df323818 576 u32 changed;
472dbc45 577
66de6713 578 ieee80211_sta_expire(sdata, ifmsh->mshcfg.plink_timeout * HZ);
472dbc45
JB
579 mesh_path_expire(sdata);
580
df323818 581 changed = mesh_accept_plinks_update(sdata);
2b5e1967 582 ieee80211_mbss_info_change_notify(sdata, changed);
472dbc45 583
472dbc45 584 mod_timer(&ifmsh->housekeeping_timer,
bf7cd94d
JB
585 round_jiffies(jiffies +
586 IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
472dbc45
JB
587}
588
e304bfd3
RP
589static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
590{
591 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
a69cc44f 592 u32 interval;
e304bfd3
RP
593
594 mesh_path_tx_root_frame(sdata);
a69cc44f
CYY
595
596 if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
597 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
598 else
599 interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
600
e304bfd3 601 mod_timer(&ifmsh->mesh_path_root_timer,
a69cc44f 602 round_jiffies(TU_TO_EXP_TIME(interval)));
e304bfd3
RP
603}
604
2b5e1967
TP
605static int
606ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
607{
608 struct beacon_data *bcn;
609 int head_len, tail_len;
610 struct sk_buff *skb;
611 struct ieee80211_mgmt *mgmt;
612 struct ieee80211_chanctx_conf *chanctx_conf;
613 enum ieee80211_band band;
614 u8 *pos;
615 struct ieee80211_sub_if_data *sdata;
616 int hdr_len = offsetof(struct ieee80211_mgmt, u.beacon) +
617 sizeof(mgmt->u.beacon);
618
619 sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh);
620 rcu_read_lock();
621 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
622 band = chanctx_conf->def.chan->band;
623 rcu_read_unlock();
624
625 head_len = hdr_len +
626 2 + /* NULL SSID */
627 2 + 8 + /* supported rates */
628 2 + 3; /* DS params */
629 tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
630 2 + sizeof(struct ieee80211_ht_cap) +
631 2 + sizeof(struct ieee80211_ht_operation) +
632 2 + ifmsh->mesh_id_len +
633 2 + sizeof(struct ieee80211_meshconf_ie) +
634 2 + sizeof(__le16) + /* awake window */
635 ifmsh->ie_len;
636
637 bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
638 /* need an skb for IE builders to operate on */
639 skb = dev_alloc_skb(max(head_len, tail_len));
640
641 if (!bcn || !skb)
642 goto out_free;
643
644 /*
645 * pointers go into the block we allocated,
646 * memory is | beacon_data | head | tail |
647 */
648 bcn->head = ((u8 *) bcn) + sizeof(*bcn);
649
650 /* fill in the head */
651 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
652 memset(mgmt, 0, hdr_len);
653 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
654 IEEE80211_STYPE_BEACON);
655 eth_broadcast_addr(mgmt->da);
656 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
657 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
658 ieee80211_mps_set_frame_flags(sdata, NULL, (void *) mgmt);
659 mgmt->u.beacon.beacon_int =
660 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
661 mgmt->u.beacon.capab_info |= cpu_to_le16(
662 sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
663
664 pos = skb_put(skb, 2);
665 *pos++ = WLAN_EID_SSID;
666 *pos++ = 0x0;
667
668 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
bf7cd94d 669 mesh_add_ds_params_ie(sdata, skb))
2b5e1967
TP
670 goto out_free;
671
672 bcn->head_len = skb->len;
673 memcpy(bcn->head, skb->data, bcn->head_len);
674
675 /* now the tail */
676 skb_trim(skb, 0);
677 bcn->tail = bcn->head + bcn->head_len;
678
679 if (ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
bf7cd94d
JB
680 mesh_add_rsn_ie(sdata, skb) ||
681 mesh_add_ht_cap_ie(sdata, skb) ||
682 mesh_add_ht_oper_ie(sdata, skb) ||
683 mesh_add_meshid_ie(sdata, skb) ||
684 mesh_add_meshconf_ie(sdata, skb) ||
685 mesh_add_awake_window_ie(sdata, skb) ||
686 mesh_add_vendor_ies(sdata, skb))
2b5e1967
TP
687 goto out_free;
688
689 bcn->tail_len = skb->len;
690 memcpy(bcn->tail, skb->data, bcn->tail_len);
691
692 dev_kfree_skb(skb);
693 rcu_assign_pointer(ifmsh->beacon, bcn);
694 return 0;
695out_free:
696 kfree(bcn);
697 dev_kfree_skb(skb);
698 return -ENOMEM;
699}
700
701static int
8d61ffa5 702ieee80211_mesh_rebuild_beacon(struct ieee80211_sub_if_data *sdata)
2b5e1967 703{
2b5e1967
TP
704 struct beacon_data *old_bcn;
705 int ret;
2b5e1967 706
8d61ffa5
JB
707 old_bcn = rcu_dereference_protected(sdata->u.mesh.beacon,
708 lockdep_is_held(&sdata->wdev.mtx));
709 ret = ieee80211_mesh_build_beacon(&sdata->u.mesh);
2b5e1967
TP
710 if (ret)
711 /* just reuse old beacon */
8d61ffa5 712 return ret;
2b5e1967
TP
713
714 if (old_bcn)
715 kfree_rcu(old_bcn, rcu_head);
8d61ffa5 716 return 0;
2b5e1967
TP
717}
718
719void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
720 u32 changed)
721{
f81a9ded
TP
722 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
723 unsigned long bits = changed;
724 u32 bit;
725
726 if (!bits)
727 return;
728
729 /* if we race with running work, worst case this work becomes a noop */
730 for_each_set_bit(bit, &bits, sizeof(changed) * BITS_PER_BYTE)
731 set_bit(bit, &ifmsh->mbss_changed);
732 set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags);
733 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2b5e1967
TP
734}
735
736int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
472dbc45
JB
737{
738 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
739 struct ieee80211_local *local = sdata->local;
f4eabc91
CYY
740 u32 changed = BSS_CHANGED_BEACON |
741 BSS_CHANGED_BEACON_ENABLED |
742 BSS_CHANGED_HT |
743 BSS_CHANGED_BASIC_RATES |
744 BSS_CHANGED_BEACON_INT;
472dbc45 745
09b17470
JB
746 local->fif_other_bss++;
747 /* mesh ifaces must set allmulti to forward mcast traffic */
748 atomic_inc(&local->iff_allmultis);
749 ieee80211_configure_filter(local);
750
c7108a71 751 ifmsh->mesh_cc_id = 0; /* Disabled */
dbf498fb
JC
752 /* register sync ops from extensible synchronization framework */
753 ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id);
754 ifmsh->adjusting_tbtt = false;
755 ifmsh->sync_offset_clockdrift_max = 0;
6b9ac442 756 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
63c5723b 757 ieee80211_mesh_root_setup(ifmsh);
64592c8f 758 ieee80211_queue_work(&local->hw, &sdata->work);
70c33eaa
AN
759 sdata->vif.bss_conf.ht_operation_mode =
760 ifmsh->mshcfg.ht_opmode;
d6a83228 761 sdata->vif.bss_conf.enable_beacon = true;
f4eabc91 762
39886b61 763 changed |= ieee80211_mps_local_status_update(sdata);
3f52b7e3 764
2b5e1967
TP
765 if (ieee80211_mesh_build_beacon(ifmsh)) {
766 ieee80211_stop_mesh(sdata);
767 return -ENOMEM;
768 }
769
f4eabc91 770 ieee80211_bss_info_change_notify(sdata, changed);
c405c629
JB
771
772 netif_carrier_on(sdata->dev);
2b5e1967 773 return 0;
472dbc45
JB
774}
775
776void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
777{
09b17470 778 struct ieee80211_local *local = sdata->local;
29cbe68c 779 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2b5e1967 780 struct beacon_data *bcn;
29cbe68c 781
c405c629
JB
782 netif_carrier_off(sdata->dev);
783
0d466b9c 784 /* stop the beacon */
29cbe68c 785 ifmsh->mesh_id_len = 0;
d6a83228
JB
786 sdata->vif.bss_conf.enable_beacon = false;
787 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
29cbe68c 788 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
2b5e1967 789 bcn = rcu_dereference_protected(ifmsh->beacon,
8d61ffa5 790 lockdep_is_held(&sdata->wdev.mtx));
2b5e1967
TP
791 rcu_assign_pointer(ifmsh->beacon, NULL);
792 kfree_rcu(bcn, rcu_head);
0d466b9c
TP
793
794 /* flush STAs and mpaths on this iface */
b998e8bb 795 sta_info_flush(sdata);
0d466b9c 796 mesh_path_flush_by_iface(sdata);
09b17470 797
3f52b7e3
MP
798 /* free all potentially still buffered group-addressed frames */
799 local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf);
800 skb_queue_purge(&ifmsh->ps.bc_buf);
801
472dbc45 802 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
e304bfd3 803 del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
dd4c9260 804 del_timer_sync(&sdata->u.mesh.mesh_path_timer);
09b17470 805
f81a9ded
TP
806 /* clear any mesh work (for next join) we may have accrued */
807 ifmsh->wrkq_flags = 0;
808 ifmsh->mbss_changed = 0;
809
09b17470
JB
810 local->fif_other_bss--;
811 atomic_dec(&local->iff_allmultis);
812 ieee80211_configure_filter(local);
472dbc45
JB
813}
814
9fb04b50
TP
815static void
816ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata,
817 struct ieee80211_mgmt *mgmt, size_t len)
818{
819 struct ieee80211_local *local = sdata->local;
820 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
821 struct sk_buff *presp;
822 struct beacon_data *bcn;
823 struct ieee80211_mgmt *hdr;
824 struct ieee802_11_elems elems;
825 size_t baselen;
511044ea 826 u8 *pos;
9fb04b50 827
9fb04b50
TP
828 pos = mgmt->u.probe_req.variable;
829 baselen = (u8 *) pos - (u8 *) mgmt;
830 if (baselen > len)
831 return;
832
b2e506bf 833 ieee802_11_parse_elems(pos, len - baselen, false, &elems);
9fb04b50 834
a4ef66a9
CYY
835 if (!elems.mesh_id)
836 return;
837
9fb04b50
TP
838 /* 802.11-2012 10.1.4.3.2 */
839 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
840 !is_broadcast_ether_addr(mgmt->da)) ||
841 elems.ssid_len != 0)
842 return;
843
844 if (elems.mesh_id_len != 0 &&
845 (elems.mesh_id_len != ifmsh->mesh_id_len ||
846 memcmp(elems.mesh_id, ifmsh->mesh_id, ifmsh->mesh_id_len)))
847 return;
848
849 rcu_read_lock();
850 bcn = rcu_dereference(ifmsh->beacon);
851
852 if (!bcn)
853 goto out;
854
855 presp = dev_alloc_skb(local->tx_headroom +
856 bcn->head_len + bcn->tail_len);
857 if (!presp)
858 goto out;
859
860 skb_reserve(presp, local->tx_headroom);
861 memcpy(skb_put(presp, bcn->head_len), bcn->head, bcn->head_len);
862 memcpy(skb_put(presp, bcn->tail_len), bcn->tail, bcn->tail_len);
863 hdr = (struct ieee80211_mgmt *) presp->data;
864 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
865 IEEE80211_STYPE_PROBE_RESP);
866 memcpy(hdr->da, mgmt->sa, ETH_ALEN);
9fb04b50
TP
867 IEEE80211_SKB_CB(presp)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
868 ieee80211_tx_skb(sdata, presp);
869out:
870 rcu_read_unlock();
871}
872
472dbc45
JB
873static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
874 u16 stype,
875 struct ieee80211_mgmt *mgmt,
876 size_t len,
877 struct ieee80211_rx_status *rx_status)
878{
c6a1fa12 879 struct ieee80211_local *local = sdata->local;
dbf498fb 880 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
472dbc45
JB
881 struct ieee802_11_elems elems;
882 struct ieee80211_channel *channel;
472dbc45
JB
883 size_t baselen;
884 int freq;
885 enum ieee80211_band band = rx_status->band;
886
887 /* ignore ProbeResp to foreign address */
888 if (stype == IEEE80211_STYPE_PROBE_RESP &&
b203ca39 889 !ether_addr_equal(mgmt->da, sdata->vif.addr))
472dbc45
JB
890 return;
891
892 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
893 if (baselen > len)
894 return;
895
896 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
b2e506bf 897 false, &elems);
472dbc45 898
9a90bc81
TP
899 /* ignore non-mesh or secure / unsecure mismatch */
900 if ((!elems.mesh_id || !elems.mesh_config) ||
901 (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
902 (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
5cff5e01
JC
903 return;
904
1cd8e88e 905 if (elems.ds_params)
59eb21a6 906 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
472dbc45
JB
907 else
908 freq = rx_status->freq;
909
910 channel = ieee80211_get_channel(local->hw.wiphy, freq);
911
912 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
913 return;
914
9a90bc81 915 if (mesh_matches_local(sdata, &elems))
f743ff49 916 mesh_neighbour_update(sdata, mgmt->sa, &elems);
dbf498fb
JC
917
918 if (ifmsh->sync_ops)
919 ifmsh->sync_ops->rx_bcn_presp(sdata,
920 stype, mgmt, &elems, rx_status);
472dbc45
JB
921}
922
8f2535b9
CYY
923static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
924 struct ieee80211_mgmt *mgmt, size_t len)
925{
926 struct ieee80211_mgmt *mgmt_fwd;
927 struct sk_buff *skb;
928 struct ieee80211_local *local = sdata->local;
929 u8 *pos = mgmt->u.action.u.chan_switch.variable;
930 size_t offset_ttl;
931
932 skb = dev_alloc_skb(local->tx_headroom + len);
933 if (!skb)
934 return -ENOMEM;
935 skb_reserve(skb, local->tx_headroom);
936 mgmt_fwd = (struct ieee80211_mgmt *) skb_put(skb, len);
937
938 /* offset_ttl is based on whether the secondary channel
939 * offset is available or not. Substract 1 from the mesh TTL
940 * and disable the initiator flag before forwarding.
941 */
942 offset_ttl = (len < 42) ? 7 : 10;
943 *(pos + offset_ttl) -= 1;
944 *(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
945
946 memcpy(mgmt_fwd, mgmt, len);
947 eth_broadcast_addr(mgmt_fwd->da);
948 memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN);
949 memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN);
950
951 ieee80211_tx_skb(sdata, skb);
952 return 0;
953}
954
955static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
956 struct ieee80211_mgmt *mgmt, size_t len)
957{
958 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
959 struct ieee802_11_elems elems;
960 u16 pre_value;
961 bool block_tx, fwd_csa = true;
962 size_t baselen;
963 u8 *pos, ttl;
964
965 if (mgmt->u.action.u.measurement.action_code !=
966 WLAN_ACTION_SPCT_CHL_SWITCH)
967 return;
968
969 pos = mgmt->u.action.u.chan_switch.variable;
970 baselen = offsetof(struct ieee80211_mgmt,
971 u.action.u.chan_switch.variable);
972 ieee802_11_parse_elems(pos, len - baselen, false, &elems);
973
974 ttl = elems.mesh_chansw_params_ie->mesh_ttl;
975 if (!--ttl)
976 fwd_csa = false;
977
978 pre_value = le16_to_cpu(elems.mesh_chansw_params_ie->mesh_pre_value);
979 if (ifmsh->pre_value >= pre_value)
980 return;
981
982 ifmsh->pre_value = pre_value;
983
984 /* forward or re-broadcast the CSA frame */
985 if (fwd_csa) {
986 if (mesh_fwd_csa_frame(sdata, mgmt, len) < 0)
987 mcsa_dbg(sdata, "Failed to forward the CSA frame");
988 }
989
990 /* block the Tx only after forwarding the CSA frame if required */
991 block_tx = elems.mesh_chansw_params_ie->mesh_flags &
992 WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT;
993 if (block_tx)
994 ieee80211_stop_queues_by_reason(&sdata->local->hw,
995 IEEE80211_MAX_QUEUE_MAP,
996 IEEE80211_QUEUE_STOP_REASON_CSA);
997}
998
472dbc45
JB
999static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
1000 struct ieee80211_mgmt *mgmt,
1001 size_t len,
1002 struct ieee80211_rx_status *rx_status)
1003{
1004 switch (mgmt->u.action.category) {
8db09850
TP
1005 case WLAN_CATEGORY_SELF_PROTECTED:
1006 switch (mgmt->u.action.u.self_prot.action_code) {
1007 case WLAN_SP_MESH_PEERING_OPEN:
1008 case WLAN_SP_MESH_PEERING_CLOSE:
1009 case WLAN_SP_MESH_PEERING_CONFIRM:
1010 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
1011 break;
1012 }
472dbc45 1013 break;
25d49e4d
TP
1014 case WLAN_CATEGORY_MESH_ACTION:
1015 if (mesh_action_is_path_sel(mgmt))
1016 mesh_rx_path_sel_frame(sdata, mgmt, len);
472dbc45 1017 break;
8f2535b9
CYY
1018 case WLAN_CATEGORY_SPECTRUM_MGMT:
1019 mesh_rx_csa_frame(sdata, mgmt, len);
1020 break;
472dbc45
JB
1021 }
1022}
1023
1fa57d01
JB
1024void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1025 struct sk_buff *skb)
472dbc45
JB
1026{
1027 struct ieee80211_rx_status *rx_status;
472dbc45
JB
1028 struct ieee80211_mgmt *mgmt;
1029 u16 stype;
1030
ecccd072
TP
1031 sdata_lock(sdata);
1032
1033 /* mesh already went down */
1034 if (!sdata->wdev.mesh_id_len)
1035 goto out;
1036
f1d58c25 1037 rx_status = IEEE80211_SKB_RXCB(skb);
472dbc45
JB
1038 mgmt = (struct ieee80211_mgmt *) skb->data;
1039 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1040
1041 switch (stype) {
1042 case IEEE80211_STYPE_PROBE_RESP:
1043 case IEEE80211_STYPE_BEACON:
1044 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
1045 rx_status);
1046 break;
9fb04b50
TP
1047 case IEEE80211_STYPE_PROBE_REQ:
1048 ieee80211_mesh_rx_probe_req(sdata, mgmt, skb->len);
1049 break;
472dbc45
JB
1050 case IEEE80211_STYPE_ACTION:
1051 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
1052 break;
1053 }
ecccd072
TP
1054out:
1055 sdata_unlock(sdata);
472dbc45
JB
1056}
1057
f81a9ded
TP
1058static void mesh_bss_info_changed(struct ieee80211_sub_if_data *sdata)
1059{
1060 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1061 u32 bit, changed = 0;
1062
1063 for_each_set_bit(bit, &ifmsh->mbss_changed,
1064 sizeof(changed) * BITS_PER_BYTE) {
1065 clear_bit(bit, &ifmsh->mbss_changed);
1066 changed |= BIT(bit);
1067 }
1068
1069 if (sdata->vif.bss_conf.enable_beacon &&
1070 (changed & (BSS_CHANGED_BEACON |
1071 BSS_CHANGED_HT |
1072 BSS_CHANGED_BASIC_RATES |
1073 BSS_CHANGED_BEACON_INT)))
1074 if (ieee80211_mesh_rebuild_beacon(sdata))
1075 return;
1076
1077 ieee80211_bss_info_change_notify(sdata, changed);
1078}
1079
1fa57d01 1080void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
472dbc45 1081{
472dbc45 1082 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
472dbc45 1083
ecccd072
TP
1084 sdata_lock(sdata);
1085
1086 /* mesh already went down */
1087 if (!sdata->wdev.mesh_id_len)
1088 goto out;
1089
472dbc45
JB
1090 if (ifmsh->preq_queue_len &&
1091 time_after(jiffies,
1092 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
1093 mesh_path_start_discovery(sdata);
1094
18889231
JC
1095 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
1096 mesh_mpath_table_grow();
1097
dcac908b 1098 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
18889231
JC
1099 mesh_mpp_table_grow();
1100
1101 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
bf7cd94d 1102 ieee80211_mesh_housekeeping(sdata);
e304bfd3
RP
1103
1104 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
1105 ieee80211_mesh_rootpath(sdata);
dbf498fb
JC
1106
1107 if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
1108 mesh_sync_adjust_tbtt(sdata);
ecccd072 1109
f81a9ded
TP
1110 if (test_and_clear_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags))
1111 mesh_bss_info_changed(sdata);
ecccd072
TP
1112out:
1113 sdata_unlock(sdata);
472dbc45
JB
1114}
1115
1116void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
1117{
1118 struct ieee80211_sub_if_data *sdata;
1119
1120 rcu_read_lock();
1121 list_for_each_entry_rcu(sdata, &local->interfaces, list)
370bd005
BG
1122 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1123 ieee80211_sdata_running(sdata))
64592c8f 1124 ieee80211_queue_work(&local->hw, &sdata->work);
472dbc45
JB
1125 rcu_read_unlock();
1126}
1127
902acc78
JB
1128void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
1129{
472dbc45 1130 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
ad2d223a 1131 static u8 zero_addr[ETH_ALEN] = {};
472dbc45 1132
472dbc45
JB
1133 setup_timer(&ifmsh->housekeeping_timer,
1134 ieee80211_mesh_housekeeping_timer,
1135 (unsigned long) sdata);
472dbc45 1136
472dbc45 1137 ifmsh->accepting_plinks = true;
472dbc45 1138 atomic_set(&ifmsh->mpaths, 0);
f698d856 1139 mesh_rmc_init(sdata);
472dbc45 1140 ifmsh->last_preq = jiffies;
dca7e943 1141 ifmsh->next_perr = jiffies;
8f2535b9 1142 ifmsh->chsw_init = false;
902acc78
JB
1143 /* Allocate all mesh structures when creating the first mesh interface. */
1144 if (!mesh_allocated)
1145 ieee80211s_init();
472dbc45 1146 setup_timer(&ifmsh->mesh_path_timer,
902acc78
JB
1147 ieee80211_mesh_path_timer,
1148 (unsigned long) sdata);
e304bfd3
RP
1149 setup_timer(&ifmsh->mesh_path_root_timer,
1150 ieee80211_mesh_path_root_timer,
1151 (unsigned long) sdata);
472dbc45 1152 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
3f52b7e3 1153 skb_queue_head_init(&ifmsh->ps.bc_buf);
472dbc45 1154 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
dbf498fb 1155 spin_lock_init(&ifmsh->sync_offset_lock);
2b5e1967 1156 RCU_INIT_POINTER(ifmsh->beacon, NULL);
ad2d223a
JB
1157
1158 sdata->vif.bss_conf.bssid = zero_addr;
472dbc45 1159}
This page took 0.556403 seconds and 5 git commands to generate.