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
;
153 * mesh_sta_cleanup - clean up any mesh sta state
155 * @sta: mesh sta to clean up.
157 void mesh_sta_cleanup(struct sta_info
*sta
)
159 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
163 * maybe userspace handles peer allocation and peering, but in either
164 * case the beacon is still generated by the kernel and we might need
167 changed
= mesh_accept_plinks_update(sdata
);
168 if (sdata
->u
.mesh
.security
== IEEE80211_MESH_SEC_NONE
) {
169 changed
|= mesh_plink_deactivate(sta
);
170 del_timer_sync(&sta
->plink_timer
);
174 ieee80211_bss_info_change_notify(sdata
, changed
);
177 int mesh_rmc_init(struct ieee80211_sub_if_data
*sdata
)
181 sdata
->u
.mesh
.rmc
= kmalloc(sizeof(struct mesh_rmc
), GFP_KERNEL
);
182 if (!sdata
->u
.mesh
.rmc
)
184 sdata
->u
.mesh
.rmc
->idx_mask
= RMC_BUCKETS
- 1;
185 for (i
= 0; i
< RMC_BUCKETS
; i
++)
186 INIT_LIST_HEAD(&sdata
->u
.mesh
.rmc
->bucket
[i
]);
190 void mesh_rmc_free(struct ieee80211_sub_if_data
*sdata
)
192 struct mesh_rmc
*rmc
= sdata
->u
.mesh
.rmc
;
193 struct rmc_entry
*p
, *n
;
196 if (!sdata
->u
.mesh
.rmc
)
199 for (i
= 0; i
< RMC_BUCKETS
; i
++)
200 list_for_each_entry_safe(p
, n
, &rmc
->bucket
[i
], list
) {
202 kmem_cache_free(rm_cache
, p
);
206 sdata
->u
.mesh
.rmc
= NULL
;
210 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
212 * @sa: source address
213 * @mesh_hdr: mesh_header
215 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
217 * Checks using the source address and the mesh sequence number if we have
218 * received this frame lately. If the frame is not in the cache, it is added to
221 int mesh_rmc_check(u8
*sa
, struct ieee80211s_hdr
*mesh_hdr
,
222 struct ieee80211_sub_if_data
*sdata
)
224 struct mesh_rmc
*rmc
= sdata
->u
.mesh
.rmc
;
228 struct rmc_entry
*p
, *n
;
230 /* Don't care about endianness since only match matters */
231 memcpy(&seqnum
, &mesh_hdr
->seqnum
, sizeof(mesh_hdr
->seqnum
));
232 idx
= le32_to_cpu(mesh_hdr
->seqnum
) & rmc
->idx_mask
;
233 list_for_each_entry_safe(p
, n
, &rmc
->bucket
[idx
], list
) {
235 if (time_after(jiffies
, p
->exp_time
) ||
236 (entries
== RMC_QUEUE_MAX_LEN
)) {
238 kmem_cache_free(rm_cache
, p
);
240 } else if ((seqnum
== p
->seqnum
) &&
241 (ether_addr_equal(sa
, p
->sa
)))
245 p
= kmem_cache_alloc(rm_cache
, GFP_ATOMIC
);
250 p
->exp_time
= jiffies
+ RMC_TIMEOUT
;
251 memcpy(p
->sa
, sa
, ETH_ALEN
);
252 list_add(&p
->list
, &rmc
->bucket
[idx
]);
257 mesh_add_meshconf_ie(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
259 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
261 u8 meshconf_len
= sizeof(struct ieee80211_meshconf_ie
);
263 if (skb_tailroom(skb
) < 2 + meshconf_len
)
266 pos
= skb_put(skb
, 2 + meshconf_len
);
267 *pos
++ = WLAN_EID_MESH_CONFIG
;
268 *pos
++ = meshconf_len
;
270 /* Active path selection protocol ID */
271 *pos
++ = ifmsh
->mesh_pp_id
;
272 /* Active path selection metric ID */
273 *pos
++ = ifmsh
->mesh_pm_id
;
274 /* Congestion control mode identifier */
275 *pos
++ = ifmsh
->mesh_cc_id
;
276 /* Synchronization protocol identifier */
277 *pos
++ = ifmsh
->mesh_sp_id
;
278 /* Authentication Protocol identifier */
279 *pos
++ = ifmsh
->mesh_auth_id
;
280 /* Mesh Formation Info - number of neighbors */
281 neighbors
= atomic_read(&ifmsh
->estab_plinks
);
282 /* Number of neighbor mesh STAs or 15 whichever is smaller */
283 neighbors
= (neighbors
> 15) ? 15 : neighbors
;
284 *pos
++ = neighbors
<< 1;
285 /* Mesh capability */
286 *pos
= IEEE80211_MESHCONF_CAPAB_FORWARDING
;
287 *pos
|= ifmsh
->accepting_plinks
?
288 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS
: 0x00;
289 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
290 *pos
|= ifmsh
->ps_peers_deep_sleep
?
291 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL
: 0x00;
292 *pos
++ |= ifmsh
->adjusting_tbtt
?
293 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING
: 0x00;
300 mesh_add_meshid_ie(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
302 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
305 if (skb_tailroom(skb
) < 2 + ifmsh
->mesh_id_len
)
308 pos
= skb_put(skb
, 2 + ifmsh
->mesh_id_len
);
309 *pos
++ = WLAN_EID_MESH_ID
;
310 *pos
++ = ifmsh
->mesh_id_len
;
311 if (ifmsh
->mesh_id_len
)
312 memcpy(pos
, ifmsh
->mesh_id
, ifmsh
->mesh_id_len
);
317 int mesh_add_awake_window_ie(struct sk_buff
*skb
,
318 struct ieee80211_sub_if_data
*sdata
)
320 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
323 /* see IEEE802.11-2012 13.14.6 */
324 if (ifmsh
->ps_peers_light_sleep
== 0 &&
325 ifmsh
->ps_peers_deep_sleep
== 0 &&
326 ifmsh
->nonpeer_pm
== NL80211_MESH_POWER_ACTIVE
)
329 if (skb_tailroom(skb
) < 4)
332 pos
= skb_put(skb
, 2 + 2);
333 *pos
++ = WLAN_EID_MESH_AWAKE_WINDOW
;
335 put_unaligned_le16(ifmsh
->mshcfg
.dot11MeshAwakeWindowDuration
, pos
);
341 mesh_add_vendor_ies(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
343 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
347 if (!ifmsh
->ie
|| !ifmsh
->ie_len
)
350 /* fast-forward to vendor IEs */
351 offset
= ieee80211_ie_split_vendor(ifmsh
->ie
, ifmsh
->ie_len
, 0);
354 len
= ifmsh
->ie_len
- offset
;
355 data
= ifmsh
->ie
+ offset
;
356 if (skb_tailroom(skb
) < len
)
358 memcpy(skb_put(skb
, len
), data
, len
);
365 mesh_add_rsn_ie(struct sk_buff
*skb
, struct ieee80211_sub_if_data
*sdata
)
367 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
371 if (!ifmsh
->ie
|| !ifmsh
->ie_len
)
376 while (data
< ifmsh
->ie
+ ifmsh
->ie_len
) {
377 if (*data
== WLAN_EID_RSN
) {
385 if (skb_tailroom(skb
) < len
)
387 memcpy(skb_put(skb
, len
), data
, len
);
393 int mesh_add_ds_params_ie(struct sk_buff
*skb
,
394 struct ieee80211_sub_if_data
*sdata
)
396 struct ieee80211_chanctx_conf
*chanctx_conf
;
397 struct ieee80211_channel
*chan
;
400 if (skb_tailroom(skb
) < 3)
404 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
405 if (WARN_ON(!chanctx_conf
)) {
409 chan
= chanctx_conf
->def
.chan
;
412 pos
= skb_put(skb
, 2 + 1);
413 *pos
++ = WLAN_EID_DS_PARAMS
;
415 *pos
++ = ieee80211_frequency_to_channel(chan
->center_freq
);
420 int mesh_add_ht_cap_ie(struct sk_buff
*skb
,
421 struct ieee80211_sub_if_data
*sdata
)
423 struct ieee80211_local
*local
= sdata
->local
;
424 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
425 struct ieee80211_supported_band
*sband
;
428 sband
= local
->hw
.wiphy
->bands
[band
];
429 if (!sband
->ht_cap
.ht_supported
||
430 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
433 if (skb_tailroom(skb
) < 2 + sizeof(struct ieee80211_ht_cap
))
436 pos
= skb_put(skb
, 2 + sizeof(struct ieee80211_ht_cap
));
437 ieee80211_ie_build_ht_cap(pos
, &sband
->ht_cap
, sband
->ht_cap
.cap
);
442 int mesh_add_ht_oper_ie(struct sk_buff
*skb
,
443 struct ieee80211_sub_if_data
*sdata
)
445 struct ieee80211_local
*local
= sdata
->local
;
446 struct ieee80211_chanctx_conf
*chanctx_conf
;
447 struct ieee80211_channel
*channel
;
448 enum nl80211_channel_type channel_type
=
449 cfg80211_get_chandef_type(&sdata
->vif
.bss_conf
.chandef
);
450 struct ieee80211_supported_band
*sband
;
451 struct ieee80211_sta_ht_cap
*ht_cap
;
455 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
456 if (WARN_ON(!chanctx_conf
)) {
460 channel
= chanctx_conf
->def
.chan
;
463 sband
= local
->hw
.wiphy
->bands
[channel
->band
];
464 ht_cap
= &sband
->ht_cap
;
466 if (!ht_cap
->ht_supported
|| channel_type
== NL80211_CHAN_NO_HT
)
469 if (skb_tailroom(skb
) < 2 + sizeof(struct ieee80211_ht_operation
))
472 pos
= skb_put(skb
, 2 + sizeof(struct ieee80211_ht_operation
));
473 ieee80211_ie_build_ht_oper(pos
, ht_cap
, &sdata
->vif
.bss_conf
.chandef
,
474 sdata
->vif
.bss_conf
.ht_operation_mode
);
478 static void ieee80211_mesh_path_timer(unsigned long data
)
480 struct ieee80211_sub_if_data
*sdata
=
481 (struct ieee80211_sub_if_data
*) data
;
482 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
483 struct ieee80211_local
*local
= sdata
->local
;
485 if (local
->quiescing
) {
486 set_bit(TMR_RUNNING_MP
, &ifmsh
->timers_running
);
490 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
493 static void ieee80211_mesh_path_root_timer(unsigned long data
)
495 struct ieee80211_sub_if_data
*sdata
=
496 (struct ieee80211_sub_if_data
*) data
;
497 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
498 struct ieee80211_local
*local
= sdata
->local
;
500 set_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
);
502 if (local
->quiescing
) {
503 set_bit(TMR_RUNNING_MPR
, &ifmsh
->timers_running
);
507 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
510 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh
*ifmsh
)
512 if (ifmsh
->mshcfg
.dot11MeshHWMPRootMode
> IEEE80211_ROOTMODE_ROOT
)
513 set_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
);
515 clear_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
);
516 /* stop running timer */
517 del_timer_sync(&ifmsh
->mesh_path_root_timer
);
522 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
523 * @hdr: 802.11 frame header
524 * @fc: frame control field
525 * @meshda: destination address in the mesh
526 * @meshsa: source address address in the mesh. Same as TA, as frame is
527 * locally originated.
529 * Return the length of the 802.11 (does not include a mesh control header)
531 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr
*hdr
, __le16
*fc
,
532 const u8
*meshda
, const u8
*meshsa
)
534 if (is_multicast_ether_addr(meshda
)) {
535 *fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
537 memcpy(hdr
->addr1
, meshda
, ETH_ALEN
);
538 memcpy(hdr
->addr2
, meshsa
, ETH_ALEN
);
539 memcpy(hdr
->addr3
, meshsa
, ETH_ALEN
);
542 *fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
544 memset(hdr
->addr1
, 0, ETH_ALEN
); /* RA is resolved later */
545 memcpy(hdr
->addr2
, meshsa
, ETH_ALEN
);
546 memcpy(hdr
->addr3
, meshda
, ETH_ALEN
);
547 memcpy(hdr
->addr4
, meshsa
, ETH_ALEN
);
553 * ieee80211_new_mesh_header - create a new mesh header
554 * @meshhdr: uninitialized mesh header
555 * @sdata: mesh interface to be used
556 * @addr4or5: 1st address in the ae header, which may correspond to address 4
557 * (if addr6 is NULL) or address 5 (if addr6 is present). It may
559 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
562 * Return the header length.
564 int ieee80211_new_mesh_header(struct ieee80211s_hdr
*meshhdr
,
565 struct ieee80211_sub_if_data
*sdata
, char *addr4or5
,
569 BUG_ON(!addr4or5
&& addr6
);
570 memset(meshhdr
, 0, sizeof(*meshhdr
));
571 meshhdr
->ttl
= sdata
->u
.mesh
.mshcfg
.dot11MeshTTL
;
572 put_unaligned(cpu_to_le32(sdata
->u
.mesh
.mesh_seqnum
), &meshhdr
->seqnum
);
573 sdata
->u
.mesh
.mesh_seqnum
++;
574 if (addr4or5
&& !addr6
) {
575 meshhdr
->flags
|= MESH_FLAGS_AE_A4
;
577 memcpy(meshhdr
->eaddr1
, addr4or5
, ETH_ALEN
);
578 } else if (addr4or5
&& addr6
) {
579 meshhdr
->flags
|= MESH_FLAGS_AE_A5_A6
;
580 aelen
+= 2 * ETH_ALEN
;
581 memcpy(meshhdr
->eaddr1
, addr4or5
, ETH_ALEN
);
582 memcpy(meshhdr
->eaddr2
, addr6
, ETH_ALEN
);
587 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data
*sdata
,
588 struct ieee80211_if_mesh
*ifmsh
)
592 ieee80211_sta_expire(sdata
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
593 mesh_path_expire(sdata
);
595 changed
= mesh_accept_plinks_update(sdata
);
596 ieee80211_bss_info_change_notify(sdata
, changed
);
598 mod_timer(&ifmsh
->housekeeping_timer
,
599 round_jiffies(jiffies
+ IEEE80211_MESH_HOUSEKEEPING_INTERVAL
));
602 static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data
*sdata
)
604 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
607 mesh_path_tx_root_frame(sdata
);
609 if (ifmsh
->mshcfg
.dot11MeshHWMPRootMode
== IEEE80211_PROACTIVE_RANN
)
610 interval
= ifmsh
->mshcfg
.dot11MeshHWMPRannInterval
;
612 interval
= ifmsh
->mshcfg
.dot11MeshHWMProotInterval
;
614 mod_timer(&ifmsh
->mesh_path_root_timer
,
615 round_jiffies(TU_TO_EXP_TIME(interval
)));
619 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data
*sdata
)
621 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
623 /* use atomic bitops in case all timers fire at the same time */
625 if (del_timer_sync(&ifmsh
->housekeeping_timer
))
626 set_bit(TMR_RUNNING_HK
, &ifmsh
->timers_running
);
627 if (del_timer_sync(&ifmsh
->mesh_path_timer
))
628 set_bit(TMR_RUNNING_MP
, &ifmsh
->timers_running
);
629 if (del_timer_sync(&ifmsh
->mesh_path_root_timer
))
630 set_bit(TMR_RUNNING_MPR
, &ifmsh
->timers_running
);
633 void ieee80211_mesh_restart(struct ieee80211_sub_if_data
*sdata
)
635 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
637 if (test_and_clear_bit(TMR_RUNNING_HK
, &ifmsh
->timers_running
))
638 add_timer(&ifmsh
->housekeeping_timer
);
639 if (test_and_clear_bit(TMR_RUNNING_MP
, &ifmsh
->timers_running
))
640 add_timer(&ifmsh
->mesh_path_timer
);
641 if (test_and_clear_bit(TMR_RUNNING_MPR
, &ifmsh
->timers_running
))
642 add_timer(&ifmsh
->mesh_path_root_timer
);
643 ieee80211_mesh_root_setup(ifmsh
);
647 void ieee80211_start_mesh(struct ieee80211_sub_if_data
*sdata
)
649 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
650 struct ieee80211_local
*local
= sdata
->local
;
651 u32 changed
= BSS_CHANGED_BEACON
|
652 BSS_CHANGED_BEACON_ENABLED
|
654 BSS_CHANGED_BASIC_RATES
|
655 BSS_CHANGED_BEACON_INT
;
656 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
658 local
->fif_other_bss
++;
659 /* mesh ifaces must set allmulti to forward mcast traffic */
660 atomic_inc(&local
->iff_allmultis
);
661 ieee80211_configure_filter(local
);
663 ifmsh
->mesh_cc_id
= 0; /* Disabled */
664 ifmsh
->mesh_auth_id
= 0; /* Disabled */
665 /* register sync ops from extensible synchronization framework */
666 ifmsh
->sync_ops
= ieee80211_mesh_sync_ops_get(ifmsh
->mesh_sp_id
);
667 ifmsh
->adjusting_tbtt
= false;
668 ifmsh
->sync_offset_clockdrift_max
= 0;
669 set_bit(MESH_WORK_HOUSEKEEPING
, &ifmsh
->wrkq_flags
);
670 ieee80211_mesh_root_setup(ifmsh
);
671 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
672 sdata
->vif
.bss_conf
.ht_operation_mode
=
673 ifmsh
->mshcfg
.ht_opmode
;
674 sdata
->vif
.bss_conf
.enable_beacon
= true;
675 sdata
->vif
.bss_conf
.basic_rates
=
676 ieee80211_mandatory_rates(local
, band
);
678 ieee80211_mps_local_status_update(sdata
);
680 ieee80211_bss_info_change_notify(sdata
, changed
);
682 netif_carrier_on(sdata
->dev
);
685 void ieee80211_stop_mesh(struct ieee80211_sub_if_data
*sdata
)
687 struct ieee80211_local
*local
= sdata
->local
;
688 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
690 netif_carrier_off(sdata
->dev
);
692 /* stop the beacon */
693 ifmsh
->mesh_id_len
= 0;
694 sdata
->vif
.bss_conf
.enable_beacon
= false;
695 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED
, &sdata
->state
);
696 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
);
698 /* flush STAs and mpaths on this iface */
699 sta_info_flush(sdata
);
700 mesh_path_flush_by_iface(sdata
);
702 /* free all potentially still buffered group-addressed frames */
703 local
->total_ps_buffered
-= skb_queue_len(&ifmsh
->ps
.bc_buf
);
704 skb_queue_purge(&ifmsh
->ps
.bc_buf
);
706 del_timer_sync(&sdata
->u
.mesh
.housekeeping_timer
);
707 del_timer_sync(&sdata
->u
.mesh
.mesh_path_root_timer
);
708 del_timer_sync(&sdata
->u
.mesh
.mesh_path_timer
);
710 * If the timer fired while we waited for it, it will have
711 * requeued the work. Now the work will be running again
712 * but will not rearm the timer again because it checks
713 * whether the interface is running, which, at this point,
716 cancel_work_sync(&sdata
->work
);
718 local
->fif_other_bss
--;
719 atomic_dec(&local
->iff_allmultis
);
720 ieee80211_configure_filter(local
);
722 sdata
->u
.mesh
.timers_running
= 0;
725 static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data
*sdata
,
727 struct ieee80211_mgmt
*mgmt
,
729 struct ieee80211_rx_status
*rx_status
)
731 struct ieee80211_local
*local
= sdata
->local
;
732 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
733 struct ieee802_11_elems elems
;
734 struct ieee80211_channel
*channel
;
737 enum ieee80211_band band
= rx_status
->band
;
739 /* ignore ProbeResp to foreign address */
740 if (stype
== IEEE80211_STYPE_PROBE_RESP
&&
741 !ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
))
744 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
748 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
751 /* ignore non-mesh or secure / unsecure mismatch */
752 if ((!elems
.mesh_id
|| !elems
.mesh_config
) ||
753 (elems
.rsn
&& sdata
->u
.mesh
.security
== IEEE80211_MESH_SEC_NONE
) ||
754 (!elems
.rsn
&& sdata
->u
.mesh
.security
!= IEEE80211_MESH_SEC_NONE
))
757 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
758 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0], band
);
760 freq
= rx_status
->freq
;
762 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
764 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
767 if (mesh_matches_local(sdata
, &elems
))
768 mesh_neighbour_update(sdata
, mgmt
->sa
, &elems
);
771 ifmsh
->sync_ops
->rx_bcn_presp(sdata
,
772 stype
, mgmt
, &elems
, rx_status
);
775 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data
*sdata
,
776 struct ieee80211_mgmt
*mgmt
,
778 struct ieee80211_rx_status
*rx_status
)
780 switch (mgmt
->u
.action
.category
) {
781 case WLAN_CATEGORY_SELF_PROTECTED
:
782 switch (mgmt
->u
.action
.u
.self_prot
.action_code
) {
783 case WLAN_SP_MESH_PEERING_OPEN
:
784 case WLAN_SP_MESH_PEERING_CLOSE
:
785 case WLAN_SP_MESH_PEERING_CONFIRM
:
786 mesh_rx_plink_frame(sdata
, mgmt
, len
, rx_status
);
790 case WLAN_CATEGORY_MESH_ACTION
:
791 if (mesh_action_is_path_sel(mgmt
))
792 mesh_rx_path_sel_frame(sdata
, mgmt
, len
);
797 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
800 struct ieee80211_rx_status
*rx_status
;
801 struct ieee80211_mgmt
*mgmt
;
804 rx_status
= IEEE80211_SKB_RXCB(skb
);
805 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
806 stype
= le16_to_cpu(mgmt
->frame_control
) & IEEE80211_FCTL_STYPE
;
809 case IEEE80211_STYPE_PROBE_RESP
:
810 case IEEE80211_STYPE_BEACON
:
811 ieee80211_mesh_rx_bcn_presp(sdata
, stype
, mgmt
, skb
->len
,
814 case IEEE80211_STYPE_ACTION
:
815 ieee80211_mesh_rx_mgmt_action(sdata
, mgmt
, skb
->len
, rx_status
);
820 void ieee80211_mesh_work(struct ieee80211_sub_if_data
*sdata
)
822 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
824 if (ifmsh
->preq_queue_len
&&
826 ifmsh
->last_preq
+ msecs_to_jiffies(ifmsh
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
827 mesh_path_start_discovery(sdata
);
829 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE
, &ifmsh
->wrkq_flags
))
830 mesh_mpath_table_grow();
832 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE
, &ifmsh
->wrkq_flags
))
833 mesh_mpp_table_grow();
835 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING
, &ifmsh
->wrkq_flags
))
836 ieee80211_mesh_housekeeping(sdata
, ifmsh
);
838 if (test_and_clear_bit(MESH_WORK_ROOT
, &ifmsh
->wrkq_flags
))
839 ieee80211_mesh_rootpath(sdata
);
841 if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST
, &ifmsh
->wrkq_flags
))
842 mesh_sync_adjust_tbtt(sdata
);
845 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local
*local
)
847 struct ieee80211_sub_if_data
*sdata
;
850 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
851 if (ieee80211_vif_is_mesh(&sdata
->vif
))
852 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
856 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data
*sdata
)
858 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
859 static u8 zero_addr
[ETH_ALEN
] = {};
861 setup_timer(&ifmsh
->housekeeping_timer
,
862 ieee80211_mesh_housekeeping_timer
,
863 (unsigned long) sdata
);
865 ifmsh
->accepting_plinks
= true;
868 ifmsh
->num_gates
= 0;
869 atomic_set(&ifmsh
->mpaths
, 0);
870 mesh_rmc_init(sdata
);
871 ifmsh
->last_preq
= jiffies
;
872 ifmsh
->next_perr
= jiffies
;
873 /* Allocate all mesh structures when creating the first mesh interface. */
876 setup_timer(&ifmsh
->mesh_path_timer
,
877 ieee80211_mesh_path_timer
,
878 (unsigned long) sdata
);
879 setup_timer(&ifmsh
->mesh_path_root_timer
,
880 ieee80211_mesh_path_root_timer
,
881 (unsigned long) sdata
);
882 INIT_LIST_HEAD(&ifmsh
->preq_queue
.list
);
883 skb_queue_head_init(&ifmsh
->ps
.bc_buf
);
884 spin_lock_init(&ifmsh
->mesh_preq_queue_lock
);
885 spin_lock_init(&ifmsh
->sync_offset_lock
);
887 sdata
->vif
.bss_conf
.bssid
= zero_addr
;