2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com>
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.
11 #include <linux/slab.h>
12 #include <asm/unaligned.h>
13 #include "ieee80211_i.h"
16 #define TMR_RUNNING_HK 0
17 #define TMR_RUNNING_MP 1
18 #define TMR_RUNNING_MPR 2
21 static struct kmem_cache
*rm_cache
;
23 bool mesh_action_is_path_sel(struct ieee80211_mgmt
*mgmt
)
25 return (mgmt
->u
.action
.u
.mesh_action
.action_code
==
26 WLAN_MESH_ACTION_HWMP_PATH_SELECTION
);
29 void ieee80211s_init(void)
33 rm_cache
= kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry
),
37 void ieee80211s_stop(void)
39 mesh_pathtbl_unregister();
40 kmem_cache_destroy(rm_cache
);
43 static void ieee80211_mesh_housekeeping_timer(unsigned long data
)
45 struct ieee80211_sub_if_data
*sdata
= (void *) data
;
46 struct ieee80211_local
*local
= sdata
->local
;
47 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
49 set_bit(MESH_WORK_HOUSEKEEPING
, &ifmsh
->wrkq_flags
);
51 if (local
->quiescing
) {
52 set_bit(TMR_RUNNING_HK
, &ifmsh
->timers_running
);
56 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
60 * mesh_matches_local - check if the config of a mesh point matches ours
62 * @sdata: local mesh subif
63 * @ie: information elements of a management frame from the mesh peer
65 * This function checks if the mesh configuration of a mesh point matches the
66 * local mesh configuration, i.e. if both nodes belong to the same mesh network.
68 bool mesh_matches_local(struct ieee80211_sub_if_data
*sdata
,
69 struct ieee802_11_elems
*ie
)
71 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
72 struct ieee80211_local
*local
= sdata
->local
;
74 struct cfg80211_chan_def sta_chan_def
;
77 * As support for each feature is added, check for matching
78 * - On mesh config capabilities
79 * - Power Save Support En
80 * - Sync support enabled
81 * - Sync support active
82 * - Sync support required from peer
84 * - Power management control on fc
86 if (!(ifmsh
->mesh_id_len
== ie
->mesh_id_len
&&
87 memcmp(ifmsh
->mesh_id
, ie
->mesh_id
, ie
->mesh_id_len
) == 0 &&
88 (ifmsh
->mesh_pp_id
== ie
->mesh_config
->meshconf_psel
) &&
89 (ifmsh
->mesh_pm_id
== ie
->mesh_config
->meshconf_pmetric
) &&
90 (ifmsh
->mesh_cc_id
== ie
->mesh_config
->meshconf_congest
) &&
91 (ifmsh
->mesh_sp_id
== ie
->mesh_config
->meshconf_synch
) &&
92 (ifmsh
->mesh_auth_id
== ie
->mesh_config
->meshconf_auth
)))
95 ieee80211_sta_get_rates(local
, ie
, ieee80211_get_sdata_band(sdata
),
98 if (sdata
->vif
.bss_conf
.basic_rates
!= basic_rates
)
101 ieee80211_ht_oper_to_chandef(sdata
->vif
.bss_conf
.chandef
.chan
,
102 ie
->ht_operation
, &sta_chan_def
);
104 if (!cfg80211_chandef_compatible(&sdata
->vif
.bss_conf
.chandef
,
114 * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
116 * @ie: information elements of a management frame from the mesh peer
118 bool mesh_peer_accepts_plinks(struct ieee802_11_elems
*ie
)
120 return (ie
->mesh_config
->meshconf_cap
&
121 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS
) != 0;
125 * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
127 * @sdata: mesh interface in which mesh beacons are going to be updated
129 * Returns: beacon changed flag if the beacon content changed.
131 u32
mesh_accept_plinks_update(struct ieee80211_sub_if_data
*sdata
)
136 /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
137 * the mesh interface might be able to establish plinks with peers that
138 * are already on the table but are not on PLINK_ESTAB state. However,
139 * in general the mesh interface is not accepting peer link requests
140 * from new peers, and that must be reflected in the beacon
142 free_plinks
= mesh_plink_availables(sdata
);
144 if (free_plinks
!= sdata
->u
.mesh
.accepting_plinks
) {
145 sdata
->u
.mesh
.accepting_plinks
= free_plinks
;
146 changed
= BSS_CHANGED_BEACON
;
152 int mesh_rmc_init(struct ieee80211_sub_if_data
*sdata
)
156 sdata
->u
.mesh
.rmc
= kmalloc(sizeof(struct mesh_rmc
), GFP_KERNEL
);
157 if (!sdata
->u
.mesh
.rmc
)
159 sdata
->u
.mesh
.rmc
->idx_mask
= RMC_BUCKETS
- 1;
160 for (i
= 0; i
< RMC_BUCKETS
; i
++)
161 INIT_LIST_HEAD(&sdata
->u
.mesh
.rmc
->bucket
[i
]);
165 void mesh_rmc_free(struct ieee80211_sub_if_data
*sdata
)
167 struct mesh_rmc
*rmc
= sdata
->u
.mesh
.rmc
;
168 struct rmc_entry
*p
, *n
;
171 if (!sdata
->u
.mesh
.rmc
)
174 for (i
= 0; i
< RMC_BUCKETS
; i
++)
175 list_for_each_entry_safe(p
, n
, &rmc
->bucket
[i
], list
) {
177 kmem_cache_free(rm_cache
, p
);
181 sdata
->u
.mesh
.rmc
= NULL
;
185 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
187 * @sa: source address
188 * @mesh_hdr: mesh_header
190 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
192 * Checks using the source address and the mesh sequence number if we have
193 * received this frame lately. If the frame is not in the cache, it is added to
196 int mesh_rmc_check(u8
*sa
, struct ieee80211s_hdr
*mesh_hdr
,
197 struct ieee80211_sub_if_data
*sdata
)
199 struct mesh_rmc
*rmc
= sdata
->u
.mesh
.rmc
;
203 struct rmc_entry
*p
, *n
;
205 /* Don't care about endianness since only match matters */
206 memcpy(&seqnum
, &mesh_hdr
->seqnum
, sizeof(mesh_hdr
->seqnum
));
207 idx
= le32_to_cpu(mesh_hdr
->seqnum
) & rmc
->idx_mask
;
208 list_for_each_entry_safe(p
, n
, &rmc
->bucket
[idx
], list
) {
210 if (time_after(jiffies
, p
->exp_time
) ||
211 (entries
== RMC_QUEUE_MAX_LEN
)) {
213 kmem_cache_free(rm_cache
, p
);
215 } else if ((seqnum
== p
->seqnum
) &&
216 (ether_addr_equal(sa
, p
->sa
)))
220 p
= kmem_cache_alloc(rm_cache
, GFP_ATOMIC
);
225 p
->exp_time
= jiffies
+ RMC_TIMEOUT
;
226 memcpy(p
->sa
, sa
, ETH_ALEN
);
227 list_add(&p
->list
, &rmc
->bucket
[idx
]);
232 mesh_add_meshconf_ie(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
234 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
236 u8 meshconf_len
= sizeof(struct ieee80211_meshconf_ie
);
238 if (skb_tailroom(skb
) < 2 + meshconf_len
)
241 pos
= skb_put(skb
, 2 + meshconf_len
);
242 *pos
++ = WLAN_EID_MESH_CONFIG
;
243 *pos
++ = meshconf_len
;
245 /* Active path selection protocol ID */
246 *pos
++ = ifmsh
->mesh_pp_id
;
247 /* Active path selection metric ID */
248 *pos
++ = ifmsh
->mesh_pm_id
;
249 /* Congestion control mode identifier */
250 *pos
++ = ifmsh
->mesh_cc_id
;
251 /* Synchronization protocol identifier */
252 *pos
++ = ifmsh
->mesh_sp_id
;
253 /* Authentication Protocol identifier */
254 *pos
++ = ifmsh
->mesh_auth_id
;
255 /* Mesh Formation Info - number of neighbors */
256 neighbors
= atomic_read(&ifmsh
->estab_plinks
);
257 /* Number of neighbor mesh STAs or 15 whichever is smaller */
258 neighbors
= (neighbors
> 15) ? 15 : neighbors
;
259 *pos
++ = neighbors
<< 1;
260 /* Mesh capability */
261 *pos
= IEEE80211_MESHCONF_CAPAB_FORWARDING
;
262 *pos
|= ifmsh
->accepting_plinks
?
263 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS
: 0x00;
264 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
265 *pos
|= ifmsh
->ps_peers_deep_sleep
?
266 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL
: 0x00;
267 *pos
++ |= ifmsh
->adjusting_tbtt
?
268 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING
: 0x00;
275 mesh_add_meshid_ie(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
277 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
280 if (skb_tailroom(skb
) < 2 + ifmsh
->mesh_id_len
)
283 pos
= skb_put(skb
, 2 + ifmsh
->mesh_id_len
);
284 *pos
++ = WLAN_EID_MESH_ID
;
285 *pos
++ = ifmsh
->mesh_id_len
;
286 if (ifmsh
->mesh_id_len
)
287 memcpy(pos
, ifmsh
->mesh_id
, ifmsh
->mesh_id_len
);
292 int mesh_add_awake_window_ie(struct sk_buff
*skb
,
293 struct ieee80211_sub_if_data
*sdata
)
295 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
298 /* see IEEE802.11-2012 13.14.6 */
299 if (ifmsh
->ps_peers_light_sleep
== 0 &&
300 ifmsh
->ps_peers_deep_sleep
== 0 &&
301 ifmsh
->nonpeer_pm
== NL80211_MESH_POWER_ACTIVE
)
304 if (skb_tailroom(skb
) < 4)
307 pos
= skb_put(skb
, 2 + 2);
308 *pos
++ = WLAN_EID_MESH_AWAKE_WINDOW
;
310 put_unaligned_le16(ifmsh
->mshcfg
.dot11MeshAwakeWindowDuration
, pos
);
316 mesh_add_vendor_ies(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
318 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
322 if (!ifmsh
->ie
|| !ifmsh
->ie_len
)
325 /* fast-forward to vendor IEs */
326 offset
= ieee80211_ie_split_vendor(ifmsh
->ie
, ifmsh
->ie_len
, 0);
329 len
= ifmsh
->ie_len
- offset
;
330 data
= ifmsh
->ie
+ offset
;
331 if (skb_tailroom(skb
) < len
)
333 memcpy(skb_put(skb
, len
), data
, len
);
340 mesh_add_rsn_ie(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
342 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
346 if (!ifmsh
->ie
|| !ifmsh
->ie_len
)
351 while (data
< ifmsh
->ie
+ ifmsh
->ie_len
) {
352 if (*data
== WLAN_EID_RSN
) {
360 if (skb_tailroom(skb
) < len
)
362 memcpy(skb_put(skb
, len
), data
, len
);
368 int mesh_add_ds_params_ie(struct sk_buff
*skb
,
369 struct ieee80211_sub_if_data
*sdata
)
371 struct ieee80211_local
*local
= sdata
->local
;
372 struct ieee80211_supported_band
*sband
;
373 struct ieee80211_chanctx_conf
*chanctx_conf
;
374 struct ieee80211_channel
*chan
;
377 if (skb_tailroom(skb
) < 3)
381 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
382 if (WARN_ON(!chanctx_conf
)) {
386 chan
= chanctx_conf
->def
.chan
;
389 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
390 if (sband
->band
== IEEE80211_BAND_2GHZ
) {
391 pos
= skb_put(skb
, 2 + 1);
392 *pos
++ = WLAN_EID_DS_PARAMS
;
394 *pos
++ = ieee80211_frequency_to_channel(chan
->center_freq
);
400 int mesh_add_ht_cap_ie(struct sk_buff
*skb
,
401 struct ieee80211_sub_if_data
*sdata
)
403 struct ieee80211_local
*local
= sdata
->local
;
404 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
405 struct ieee80211_supported_band
*sband
;
408 sband
= local
->hw
.wiphy
->bands
[band
];
409 if (!sband
->ht_cap
.ht_supported
||
410 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
413 if (skb_tailroom(skb
) < 2 + sizeof(struct ieee80211_ht_cap
))
416 pos
= skb_put(skb
, 2 + sizeof(struct ieee80211_ht_cap
));
417 ieee80211_ie_build_ht_cap(pos
, &sband
->ht_cap
, sband
->ht_cap
.cap
);
422 int mesh_add_ht_oper_ie(struct sk_buff
*skb
,
423 struct ieee80211_sub_if_data
*sdata
)
425 struct ieee80211_local
*local
= sdata
->local
;
426 struct ieee80211_chanctx_conf
*chanctx_conf
;
427 struct ieee80211_channel
*channel
;
428 enum nl80211_channel_type channel_type
=
429 cfg80211_get_chandef_type(&sdata
->vif
.bss_conf
.chandef
);
430 struct ieee80211_supported_band
*sband
;
431 struct ieee80211_sta_ht_cap
*ht_cap
;
435 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
436 if (WARN_ON(!chanctx_conf
)) {
440 channel
= chanctx_conf
->def
.chan
;
443 sband
= local
->hw
.wiphy
->bands
[channel
->band
];
444 ht_cap
= &sband
->ht_cap
;
446 if (!ht_cap
->ht_supported
|| channel_type
== NL80211_CHAN_NO_HT
)
449 if (skb_tailroom(skb
) < 2 + sizeof(struct ieee80211_ht_operation
))
452 pos
= skb_put(skb
, 2 + sizeof(struct ieee80211_ht_operation
));
453 ieee80211_ie_build_ht_oper(pos
, ht_cap
, &sdata
->vif
.bss_conf
.chandef
,
454 sdata
->vif
.bss_conf
.ht_operation_mode
);
458 static void ieee80211_mesh_path_timer(unsigned long data
)
460 struct ieee80211_sub_if_data
*sdata
=
461 (struct ieee80211_sub_if_data
*) data
;
462 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
463 struct ieee80211_local
*local
= sdata
->local
;
465 if (local
->quiescing
) {
466 set_bit(TMR_RUNNING_MP
, &ifmsh
->timers_running
);
470 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
473 static void ieee80211_mesh_path_root_timer(unsigned long data
)
475 struct ieee80211_sub_if_data
*sdata
=
476 (struct ieee80211_sub_if_data
*) data
;
477 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
478 struct ieee80211_local
*local
= sdata
->local
;
480 set_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
);
482 if (local
->quiescing
) {
483 set_bit(TMR_RUNNING_MPR
, &ifmsh
->timers_running
);
487 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
490 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh
*ifmsh
)
492 if (ifmsh
->mshcfg
.dot11MeshHWMPRootMode
> IEEE80211_ROOTMODE_ROOT
)
493 set_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
);
495 clear_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
);
496 /* stop running timer */
497 del_timer_sync(&ifmsh
->mesh_path_root_timer
);
502 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
503 * @hdr: 802.11 frame header
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.
509 * Return the length of the 802.11 (does not include a mesh control header)
511 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr
*hdr
, __le16
*fc
,
512 const u8
*meshda
, const u8
*meshsa
)
514 if (is_multicast_ether_addr(meshda
)) {
515 *fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
517 memcpy(hdr
->addr1
, meshda
, ETH_ALEN
);
518 memcpy(hdr
->addr2
, meshsa
, ETH_ALEN
);
519 memcpy(hdr
->addr3
, meshsa
, ETH_ALEN
);
522 *fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
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
);
533 * ieee80211_new_mesh_header - create a new mesh header
534 * @meshhdr: uninitialized mesh header
535 * @sdata: mesh interface to be used
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
539 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
542 * Return the header length.
544 int ieee80211_new_mesh_header(struct ieee80211s_hdr
*meshhdr
,
545 struct ieee80211_sub_if_data
*sdata
, char *addr4or5
,
549 BUG_ON(!addr4or5
&& addr6
);
550 memset(meshhdr
, 0, sizeof(*meshhdr
));
551 meshhdr
->ttl
= sdata
->u
.mesh
.mshcfg
.dot11MeshTTL
;
552 put_unaligned(cpu_to_le32(sdata
->u
.mesh
.mesh_seqnum
), &meshhdr
->seqnum
);
553 sdata
->u
.mesh
.mesh_seqnum
++;
554 if (addr4or5
&& !addr6
) {
555 meshhdr
->flags
|= MESH_FLAGS_AE_A4
;
557 memcpy(meshhdr
->eaddr1
, addr4or5
, ETH_ALEN
);
558 } else if (addr4or5
&& addr6
) {
559 meshhdr
->flags
|= MESH_FLAGS_AE_A5_A6
;
560 aelen
+= 2 * ETH_ALEN
;
561 memcpy(meshhdr
->eaddr1
, addr4or5
, ETH_ALEN
);
562 memcpy(meshhdr
->eaddr2
, addr6
, ETH_ALEN
);
567 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data
*sdata
,
568 struct ieee80211_if_mesh
*ifmsh
)
572 ieee80211_sta_expire(sdata
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
573 mesh_path_expire(sdata
);
575 changed
= mesh_accept_plinks_update(sdata
);
576 ieee80211_bss_info_change_notify(sdata
, changed
);
578 mod_timer(&ifmsh
->housekeeping_timer
,
579 round_jiffies(jiffies
+ IEEE80211_MESH_HOUSEKEEPING_INTERVAL
));
582 static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data
*sdata
)
584 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
587 mesh_path_tx_root_frame(sdata
);
589 if (ifmsh
->mshcfg
.dot11MeshHWMPRootMode
== IEEE80211_PROACTIVE_RANN
)
590 interval
= ifmsh
->mshcfg
.dot11MeshHWMPRannInterval
;
592 interval
= ifmsh
->mshcfg
.dot11MeshHWMProotInterval
;
594 mod_timer(&ifmsh
->mesh_path_root_timer
,
595 round_jiffies(TU_TO_EXP_TIME(interval
)));
599 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data
*sdata
)
601 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
603 /* use atomic bitops in case all timers fire at the same time */
605 if (del_timer_sync(&ifmsh
->housekeeping_timer
))
606 set_bit(TMR_RUNNING_HK
, &ifmsh
->timers_running
);
607 if (del_timer_sync(&ifmsh
->mesh_path_timer
))
608 set_bit(TMR_RUNNING_MP
, &ifmsh
->timers_running
);
609 if (del_timer_sync(&ifmsh
->mesh_path_root_timer
))
610 set_bit(TMR_RUNNING_MPR
, &ifmsh
->timers_running
);
613 void ieee80211_mesh_restart(struct ieee80211_sub_if_data
*sdata
)
615 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
617 if (test_and_clear_bit(TMR_RUNNING_HK
, &ifmsh
->timers_running
))
618 add_timer(&ifmsh
->housekeeping_timer
);
619 if (test_and_clear_bit(TMR_RUNNING_MP
, &ifmsh
->timers_running
))
620 add_timer(&ifmsh
->mesh_path_timer
);
621 if (test_and_clear_bit(TMR_RUNNING_MPR
, &ifmsh
->timers_running
))
622 add_timer(&ifmsh
->mesh_path_root_timer
);
623 ieee80211_mesh_root_setup(ifmsh
);
627 void ieee80211_start_mesh(struct ieee80211_sub_if_data
*sdata
)
629 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
630 struct ieee80211_local
*local
= sdata
->local
;
631 u32 changed
= BSS_CHANGED_BEACON
|
632 BSS_CHANGED_BEACON_ENABLED
|
634 BSS_CHANGED_BASIC_RATES
|
635 BSS_CHANGED_BEACON_INT
;
636 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
638 local
->fif_other_bss
++;
639 /* mesh ifaces must set allmulti to forward mcast traffic */
640 atomic_inc(&local
->iff_allmultis
);
641 ieee80211_configure_filter(local
);
643 ifmsh
->mesh_cc_id
= 0; /* Disabled */
644 ifmsh
->mesh_auth_id
= 0; /* Disabled */
645 /* register sync ops from extensible synchronization framework */
646 ifmsh
->sync_ops
= ieee80211_mesh_sync_ops_get(ifmsh
->mesh_sp_id
);
647 ifmsh
->adjusting_tbtt
= false;
648 ifmsh
->sync_offset_clockdrift_max
= 0;
649 set_bit(MESH_WORK_HOUSEKEEPING
, &ifmsh
->wrkq_flags
);
650 ieee80211_mesh_root_setup(ifmsh
);
651 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
652 sdata
->vif
.bss_conf
.ht_operation_mode
=
653 ifmsh
->mshcfg
.ht_opmode
;
654 sdata
->vif
.bss_conf
.enable_beacon
= true;
655 sdata
->vif
.bss_conf
.basic_rates
=
656 ieee80211_mandatory_rates(local
, band
);
658 ieee80211_mps_local_status_update(sdata
);
660 ieee80211_bss_info_change_notify(sdata
, changed
);
662 netif_carrier_on(sdata
->dev
);
665 void ieee80211_stop_mesh(struct ieee80211_sub_if_data
*sdata
)
667 struct ieee80211_local
*local
= sdata
->local
;
668 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
670 netif_carrier_off(sdata
->dev
);
672 /* stop the beacon */
673 ifmsh
->mesh_id_len
= 0;
674 sdata
->vif
.bss_conf
.enable_beacon
= false;
675 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED
, &sdata
->state
);
676 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
);
678 /* flush STAs and mpaths on this iface */
679 sta_info_flush(sdata
);
680 mesh_path_flush_by_iface(sdata
);
682 /* free all potentially still buffered group-addressed frames */
683 local
->total_ps_buffered
-= skb_queue_len(&ifmsh
->ps
.bc_buf
);
684 skb_queue_purge(&ifmsh
->ps
.bc_buf
);
686 del_timer_sync(&sdata
->u
.mesh
.housekeeping_timer
);
687 del_timer_sync(&sdata
->u
.mesh
.mesh_path_root_timer
);
688 del_timer_sync(&sdata
->u
.mesh
.mesh_path_timer
);
690 * If the timer fired while we waited for it, it will have
691 * requeued the work. Now the work will be running again
692 * but will not rearm the timer again because it checks
693 * whether the interface is running, which, at this point,
696 cancel_work_sync(&sdata
->work
);
698 local
->fif_other_bss
--;
699 atomic_dec(&local
->iff_allmultis
);
700 ieee80211_configure_filter(local
);
702 sdata
->u
.mesh
.timers_running
= 0;
705 static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data
*sdata
,
707 struct ieee80211_mgmt
*mgmt
,
709 struct ieee80211_rx_status
*rx_status
)
711 struct ieee80211_local
*local
= sdata
->local
;
712 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
713 struct ieee802_11_elems elems
;
714 struct ieee80211_channel
*channel
;
717 enum ieee80211_band band
= rx_status
->band
;
719 /* ignore ProbeResp to foreign address */
720 if (stype
== IEEE80211_STYPE_PROBE_RESP
&&
721 !ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
))
724 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
728 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
731 /* ignore non-mesh or secure / unsecure mismatch */
732 if ((!elems
.mesh_id
|| !elems
.mesh_config
) ||
733 (elems
.rsn
&& sdata
->u
.mesh
.security
== IEEE80211_MESH_SEC_NONE
) ||
734 (!elems
.rsn
&& sdata
->u
.mesh
.security
!= IEEE80211_MESH_SEC_NONE
))
737 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
738 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0], band
);
740 freq
= rx_status
->freq
;
742 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
744 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
747 if (mesh_matches_local(sdata
, &elems
))
748 mesh_neighbour_update(sdata
, mgmt
->sa
, &elems
);
751 ifmsh
->sync_ops
->rx_bcn_presp(sdata
,
752 stype
, mgmt
, &elems
, rx_status
);
755 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data
*sdata
,
756 struct ieee80211_mgmt
*mgmt
,
758 struct ieee80211_rx_status
*rx_status
)
760 switch (mgmt
->u
.action
.category
) {
761 case WLAN_CATEGORY_SELF_PROTECTED
:
762 switch (mgmt
->u
.action
.u
.self_prot
.action_code
) {
763 case WLAN_SP_MESH_PEERING_OPEN
:
764 case WLAN_SP_MESH_PEERING_CLOSE
:
765 case WLAN_SP_MESH_PEERING_CONFIRM
:
766 mesh_rx_plink_frame(sdata
, mgmt
, len
, rx_status
);
770 case WLAN_CATEGORY_MESH_ACTION
:
771 if (mesh_action_is_path_sel(mgmt
))
772 mesh_rx_path_sel_frame(sdata
, mgmt
, len
);
777 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
780 struct ieee80211_rx_status
*rx_status
;
781 struct ieee80211_mgmt
*mgmt
;
784 rx_status
= IEEE80211_SKB_RXCB(skb
);
785 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
786 stype
= le16_to_cpu(mgmt
->frame_control
) & IEEE80211_FCTL_STYPE
;
789 case IEEE80211_STYPE_PROBE_RESP
:
790 case IEEE80211_STYPE_BEACON
:
791 ieee80211_mesh_rx_bcn_presp(sdata
, stype
, mgmt
, skb
->len
,
794 case IEEE80211_STYPE_ACTION
:
795 ieee80211_mesh_rx_mgmt_action(sdata
, mgmt
, skb
->len
, rx_status
);
800 void ieee80211_mesh_work(struct ieee80211_sub_if_data
*sdata
)
802 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
804 if (ifmsh
->preq_queue_len
&&
806 ifmsh
->last_preq
+ msecs_to_jiffies(ifmsh
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
807 mesh_path_start_discovery(sdata
);
809 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE
, &ifmsh
->wrkq_flags
))
810 mesh_mpath_table_grow();
812 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE
, &ifmsh
->wrkq_flags
))
813 mesh_mpp_table_grow();
815 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING
, &ifmsh
->wrkq_flags
))
816 ieee80211_mesh_housekeeping(sdata
, ifmsh
);
818 if (test_and_clear_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
))
819 ieee80211_mesh_rootpath(sdata
);
821 if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST
, &ifmsh
->wrkq_flags
))
822 mesh_sync_adjust_tbtt(sdata
);
825 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local
*local
)
827 struct ieee80211_sub_if_data
*sdata
;
830 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
831 if (ieee80211_vif_is_mesh(&sdata
->vif
))
832 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
836 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data
*sdata
)
838 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
839 static u8 zero_addr
[ETH_ALEN
] = {};
841 setup_timer(&ifmsh
->housekeeping_timer
,
842 ieee80211_mesh_housekeeping_timer
,
843 (unsigned long) sdata
);
845 ifmsh
->accepting_plinks
= true;
848 ifmsh
->num_gates
= 0;
849 atomic_set(&ifmsh
->mpaths
, 0);
850 mesh_rmc_init(sdata
);
851 ifmsh
->last_preq
= jiffies
;
852 ifmsh
->next_perr
= jiffies
;
853 /* Allocate all mesh structures when creating the first mesh interface. */
856 setup_timer(&ifmsh
->mesh_path_timer
,
857 ieee80211_mesh_path_timer
,
858 (unsigned long) sdata
);
859 setup_timer(&ifmsh
->mesh_path_root_timer
,
860 ieee80211_mesh_path_root_timer
,
861 (unsigned long) sdata
);
862 INIT_LIST_HEAD(&ifmsh
->preq_queue
.list
);
863 skb_queue_head_init(&ifmsh
->ps
.bc_buf
);
864 spin_lock_init(&ifmsh
->mesh_preq_queue_lock
);
865 spin_lock_init(&ifmsh
->sync_offset_lock
);
867 sdata
->vif
.bss_conf
.bssid
= zero_addr
;