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