1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2008, 2009 open80211s Ltd.
4 * Copyright (C) 2018 - 2024 Intel Corporation
5 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
6 * Javier Cardona <javier@cozybit.com>
9 #include <linux/slab.h>
10 #include <linux/unaligned.h>
12 #include "ieee80211_i.h"
15 #include "driver-ops.h"
17 static int mesh_allocated;
18 static struct kmem_cache *rm_cache;
20 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
22 return (mgmt->u.action.u.mesh_action.action_code ==
23 WLAN_MESH_ACTION_HWMP_PATH_SELECTION);
26 void ieee80211s_init(void)
29 rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
33 void ieee80211s_stop(void)
37 kmem_cache_destroy(rm_cache);
40 static void ieee80211_mesh_housekeeping_timer(struct timer_list *t)
42 struct ieee80211_sub_if_data *sdata =
43 timer_container_of(sdata, t, u.mesh.housekeeping_timer);
44 struct ieee80211_local *local = sdata->local;
45 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
47 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
49 wiphy_work_queue(local->hw.wiphy, &sdata->work);
53 * mesh_matches_local - check if the config of a mesh point matches ours
55 * @sdata: local mesh subif
56 * @ie: information elements of a management frame from the mesh peer
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.
61 * Returns: %true if both nodes belong to the same mesh
63 bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
64 struct ieee802_11_elems *ie)
66 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
68 struct cfg80211_chan_def sta_chan_def;
69 struct ieee80211_supported_band *sband;
73 * As support for each feature is added, check for matching
74 * - On mesh config capabilities
75 * - Power Save Support En
76 * - Sync support enabled
77 * - Sync support active
78 * - Sync support required from peer
80 * - Power management control on fc
82 if (!(ifmsh->mesh_id_len == ie->mesh_id_len &&
83 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
84 (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
85 (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
86 (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
87 (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
88 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)))
91 sband = ieee80211_get_sband(sdata);
95 ieee80211_sta_get_rates(sdata, ie, sband->band,
98 if (sdata->vif.bss_conf.basic_rates != basic_rates)
101 cfg80211_chandef_create(&sta_chan_def, sdata->vif.bss_conf.chanreq.oper.chan,
103 ieee80211_chandef_ht_oper(ie->ht_operation, &sta_chan_def);
105 if (ie->vht_cap_elem)
106 vht_cap_info = le32_to_cpu(ie->vht_cap_elem->vht_cap_info);
108 ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
109 ie->vht_operation, ie->ht_operation,
111 ieee80211_chandef_he_6ghz_oper(sdata->local, ie->he_operation,
115 if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chanreq.oper,
123 * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
125 * @ie: information elements of a management frame from the mesh peer
127 * Returns: %true if the mesh peer is willing to establish peer links
129 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
131 return (ie->mesh_config->meshconf_cap &
132 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
136 * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
138 * @sdata: mesh interface in which mesh beacons are going to be updated
140 * Returns: beacon changed flag if the beacon content changed.
142 u64 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
147 /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
148 * the mesh interface might be able to establish plinks with peers that
149 * are already on the table but are not on PLINK_ESTAB state. However,
150 * in general the mesh interface is not accepting peer link requests
151 * from new peers, and that must be reflected in the beacon
153 free_plinks = mesh_plink_availables(sdata);
155 if (free_plinks != sdata->u.mesh.accepting_plinks) {
156 sdata->u.mesh.accepting_plinks = free_plinks;
157 changed = BSS_CHANGED_BEACON;
164 * mesh_sta_cleanup - clean up any mesh sta state
166 * @sta: mesh sta to clean up.
168 void mesh_sta_cleanup(struct sta_info *sta)
170 struct ieee80211_sub_if_data *sdata = sta->sdata;
171 u64 changed = mesh_plink_deactivate(sta);
174 ieee80211_mbss_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_HLIST_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;
194 struct hlist_node *n;
197 if (!sdata->u.mesh.rmc)
200 for (i = 0; i < RMC_BUCKETS; i++) {
201 hlist_for_each_entry_safe(p, n, &rmc->bucket[i], list) {
203 kmem_cache_free(rm_cache, p);
208 sdata->u.mesh.rmc = NULL;
212 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
215 * @sa: source address
216 * @mesh_hdr: mesh_header
218 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
220 * Checks using the source address and the mesh sequence number if we have
221 * received this frame lately. If the frame is not in the cache, it is added to
224 int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
225 const u8 *sa, struct ieee80211s_hdr *mesh_hdr)
227 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
232 struct hlist_node *n;
237 /* Don't care about endianness since only match matters */
238 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
239 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
240 hlist_for_each_entry_safe(p, n, &rmc->bucket[idx], list) {
242 if (time_after(jiffies, p->exp_time) ||
243 entries == RMC_QUEUE_MAX_LEN) {
245 kmem_cache_free(rm_cache, p);
247 } else if ((seqnum == p->seqnum) && ether_addr_equal(sa, p->sa))
251 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
256 p->exp_time = jiffies + RMC_TIMEOUT;
257 memcpy(p->sa, sa, ETH_ALEN);
258 hlist_add_head(&p->list, &rmc->bucket[idx]);
262 int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
265 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
267 u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie);
268 bool is_connected_to_gate = ifmsh->num_gates > 0 ||
269 ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol ||
270 ifmsh->mshcfg.dot11MeshConnectedToMeshGate;
271 bool is_connected_to_as = ifmsh->mshcfg.dot11MeshConnectedToAuthServer;
273 if (skb_tailroom(skb) < 2 + meshconf_len)
276 pos = skb_put(skb, 2 + meshconf_len);
277 *pos++ = WLAN_EID_MESH_CONFIG;
278 *pos++ = meshconf_len;
280 /* save a pointer for quick updates in pre-tbtt */
281 ifmsh->meshconf_offset = pos - skb->data;
283 /* Active path selection protocol ID */
284 *pos++ = ifmsh->mesh_pp_id;
285 /* Active path selection metric ID */
286 *pos++ = ifmsh->mesh_pm_id;
287 /* Congestion control mode identifier */
288 *pos++ = ifmsh->mesh_cc_id;
289 /* Synchronization protocol identifier */
290 *pos++ = ifmsh->mesh_sp_id;
291 /* Authentication Protocol identifier */
292 *pos++ = ifmsh->mesh_auth_id;
293 /* Mesh Formation Info - number of neighbors */
294 neighbors = atomic_read(&ifmsh->estab_plinks);
295 neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS);
296 *pos++ = (is_connected_to_as << 7) |
298 is_connected_to_gate;
299 /* Mesh capability */
301 *pos |= ifmsh->mshcfg.dot11MeshForwarding ?
302 IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00;
303 *pos |= ifmsh->accepting_plinks ?
304 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
305 /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
306 *pos |= ifmsh->ps_peers_deep_sleep ?
307 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00;
311 int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
313 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
316 if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
319 pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
320 *pos++ = WLAN_EID_MESH_ID;
321 *pos++ = ifmsh->mesh_id_len;
322 if (ifmsh->mesh_id_len)
323 memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
328 static int mesh_add_awake_window_ie(struct ieee80211_sub_if_data *sdata,
331 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
334 /* see IEEE802.11-2012 13.14.6 */
335 if (ifmsh->ps_peers_light_sleep == 0 &&
336 ifmsh->ps_peers_deep_sleep == 0 &&
337 ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE)
340 if (skb_tailroom(skb) < 4)
343 pos = skb_put(skb, 2 + 2);
344 *pos++ = WLAN_EID_MESH_AWAKE_WINDOW;
346 put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos);
351 int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
354 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
358 if (!ifmsh->ie || !ifmsh->ie_len)
361 /* fast-forward to vendor IEs */
362 offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
364 if (offset < ifmsh->ie_len) {
365 len = ifmsh->ie_len - offset;
366 data = ifmsh->ie + offset;
367 if (skb_tailroom(skb) < len)
369 skb_put_data(skb, data, len);
375 int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
377 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
381 if (!ifmsh->ie || !ifmsh->ie_len)
385 data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
391 if (skb_tailroom(skb) < len)
393 skb_put_data(skb, data, len);
398 static int mesh_add_ds_params_ie(struct ieee80211_sub_if_data *sdata,
401 struct ieee80211_chanctx_conf *chanctx_conf;
402 struct ieee80211_channel *chan;
405 if (skb_tailroom(skb) < 3)
409 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
410 if (WARN_ON(!chanctx_conf)) {
414 chan = chanctx_conf->def.chan;
417 pos = skb_put(skb, 2 + 1);
418 *pos++ = WLAN_EID_DS_PARAMS;
420 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
425 int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
428 struct ieee80211_supported_band *sband;
431 sband = ieee80211_get_sband(sdata);
435 /* HT not allowed in 6 GHz */
436 if (sband->band == NL80211_BAND_6GHZ)
439 if (!sband->ht_cap.ht_supported ||
440 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
441 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
442 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
445 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
448 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
449 ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
454 int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
457 struct ieee80211_local *local = sdata->local;
458 struct ieee80211_chanctx_conf *chanctx_conf;
459 struct ieee80211_channel *channel;
460 struct ieee80211_supported_band *sband;
461 struct ieee80211_sta_ht_cap *ht_cap;
465 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
466 if (WARN_ON(!chanctx_conf)) {
470 channel = chanctx_conf->def.chan;
473 sband = local->hw.wiphy->bands[channel->band];
474 ht_cap = &sband->ht_cap;
476 /* HT not allowed in 6 GHz */
477 if (sband->band == NL80211_BAND_6GHZ)
480 if (!ht_cap->ht_supported ||
481 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
482 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
483 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
486 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
489 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
490 ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chanreq.oper,
491 sdata->vif.bss_conf.ht_operation_mode,
497 int mesh_add_vht_cap_ie(struct ieee80211_sub_if_data *sdata,
500 struct ieee80211_supported_band *sband;
503 sband = ieee80211_get_sband(sdata);
507 /* VHT not allowed in 6 GHz */
508 if (sband->band == NL80211_BAND_6GHZ)
511 if (!sband->vht_cap.vht_supported ||
512 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
513 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
514 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
517 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_cap))
520 pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_cap));
521 ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, sband->vht_cap.cap);
526 int mesh_add_vht_oper_ie(struct ieee80211_sub_if_data *sdata,
529 struct ieee80211_local *local = sdata->local;
530 struct ieee80211_chanctx_conf *chanctx_conf;
531 struct ieee80211_channel *channel;
532 struct ieee80211_supported_band *sband;
533 struct ieee80211_sta_vht_cap *vht_cap;
537 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
538 if (WARN_ON(!chanctx_conf)) {
542 channel = chanctx_conf->def.chan;
545 sband = local->hw.wiphy->bands[channel->band];
546 vht_cap = &sband->vht_cap;
548 /* VHT not allowed in 6 GHz */
549 if (sband->band == NL80211_BAND_6GHZ)
552 if (!vht_cap->vht_supported ||
553 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
554 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
555 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
558 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_operation))
561 pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_operation));
562 ieee80211_ie_build_vht_oper(pos, vht_cap,
563 &sdata->vif.bss_conf.chanreq.oper);
568 int mesh_add_he_cap_ie(struct ieee80211_sub_if_data *sdata,
569 struct sk_buff *skb, u8 ie_len)
571 struct ieee80211_supported_band *sband;
573 sband = ieee80211_get_sband(sdata);
577 if (sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
578 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
579 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
582 return ieee80211_put_he_cap(skb, sdata, sband, NULL);
585 int mesh_add_he_oper_ie(struct ieee80211_sub_if_data *sdata,
588 const struct ieee80211_sta_he_cap *he_cap;
589 struct ieee80211_supported_band *sband;
593 sband = ieee80211_get_sband(sdata);
597 he_cap = ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT);
599 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
600 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
601 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
604 len = 2 + 1 + sizeof(struct ieee80211_he_operation);
605 if (sdata->vif.bss_conf.chanreq.oper.chan->band == NL80211_BAND_6GHZ)
606 len += sizeof(struct ieee80211_he_6ghz_oper);
608 if (skb_tailroom(skb) < len)
611 pos = skb_put(skb, len);
612 ieee80211_ie_build_he_oper(pos, &sdata->vif.bss_conf.chanreq.oper);
617 int mesh_add_he_6ghz_cap_ie(struct ieee80211_sub_if_data *sdata,
620 struct ieee80211_supported_band *sband;
621 const struct ieee80211_sband_iftype_data *iftd;
623 sband = ieee80211_get_sband(sdata);
627 iftd = ieee80211_get_sband_iftype_data(sband,
628 NL80211_IFTYPE_MESH_POINT);
629 /* The device doesn't support HE in mesh mode or at all */
633 ieee80211_put_he_6ghz_cap(skb, sdata, sdata->deflink.smps_mode);
637 int mesh_add_eht_cap_ie(struct ieee80211_sub_if_data *sdata,
638 struct sk_buff *skb, u8 ie_len)
640 struct ieee80211_supported_band *sband;
642 sband = ieee80211_get_sband(sdata);
646 if (sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
647 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
648 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
651 return ieee80211_put_eht_cap(skb, sdata, sband, NULL);
654 int mesh_add_eht_oper_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
656 const struct ieee80211_sta_eht_cap *eht_cap;
657 struct ieee80211_supported_band *sband;
661 sband = ieee80211_get_sband(sdata);
665 eht_cap = ieee80211_get_eht_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT);
667 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
668 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
669 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
672 len = 2 + 1 + offsetof(struct ieee80211_eht_operation, optional) +
673 offsetof(struct ieee80211_eht_operation_info, optional);
675 if (skb_tailroom(skb) < len)
678 pos = skb_put(skb, len);
679 ieee80211_ie_build_eht_oper(pos, &sdata->vif.bss_conf.chanreq.oper, eht_cap);
684 static void ieee80211_mesh_path_timer(struct timer_list *t)
686 struct ieee80211_sub_if_data *sdata =
687 timer_container_of(sdata, t, u.mesh.mesh_path_timer);
689 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
692 static void ieee80211_mesh_path_root_timer(struct timer_list *t)
694 struct ieee80211_sub_if_data *sdata =
695 timer_container_of(sdata, t, u.mesh.mesh_path_root_timer);
696 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
698 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
700 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
703 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
705 if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
706 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
708 clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
709 /* stop running timer */
710 timer_delete_sync(&ifmsh->mesh_path_root_timer);
715 ieee80211_mesh_update_bss_params(struct ieee80211_sub_if_data *sdata,
718 struct ieee80211_supported_band *sband;
719 const struct element *cap;
720 const struct ieee80211_he_operation *he_oper = NULL;
722 sband = ieee80211_get_sband(sdata);
726 if (!ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT) ||
727 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT ||
728 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
729 sdata->vif.bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_10)
732 sdata->vif.bss_conf.he_support = true;
734 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ie, ie_len);
735 if (cap && cap->datalen >= 1 + sizeof(*he_oper) &&
736 cap->datalen >= 1 + ieee80211_he_oper_size(cap->data + 1))
737 he_oper = (void *)(cap->data + 1);
740 sdata->vif.bss_conf.he_oper.params =
741 __le32_to_cpu(he_oper->he_oper_params);
743 sdata->vif.bss_conf.eht_support =
744 !!ieee80211_get_eht_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT);
747 bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
748 struct sk_buff *skb, u32 ctrl_flags)
750 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
751 struct ieee80211_mesh_fast_tx_key key = {
752 .type = MESH_FAST_TX_TYPE_LOCAL
754 struct ieee80211_mesh_fast_tx *entry;
755 struct ieee80211s_hdr *meshhdr;
756 u8 sa[ETH_ALEN] __aligned(2);
757 struct tid_ampdu_tx *tid_tx;
758 struct sta_info *sta;
759 bool copy_sa = false;
763 if (ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
766 if (ifmsh->mshcfg.dot11MeshNolearn)
769 /* Add support for these cases later */
770 if (ifmsh->ps_peers_light_sleep || ifmsh->ps_peers_deep_sleep)
773 if (is_multicast_ether_addr(skb->data))
776 ethertype = (skb->data[12] << 8) | skb->data[13];
777 if (ethertype < ETH_P_802_3_MIN)
780 if (sk_requests_wifi_status(skb->sk))
783 if (skb->ip_summed == CHECKSUM_PARTIAL) {
784 skb_set_transport_header(skb, skb_checksum_start_offset(skb));
785 if (skb_checksum_help(skb))
789 ether_addr_copy(key.addr, skb->data);
790 if (!ether_addr_equal(skb->data + ETH_ALEN, sdata->vif.addr))
791 key.type = MESH_FAST_TX_TYPE_PROXIED;
792 entry = mesh_fast_tx_get(sdata, &key);
796 if (skb_headroom(skb) < entry->hdrlen + entry->fast_tx.hdr_len)
799 sta = rcu_dereference(entry->mpath->next_hop);
803 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
804 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
806 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
809 tid_tx->last_tx = jiffies;
812 skb = skb_share_check(skb, GFP_ATOMIC);
816 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
818 meshhdr = (struct ieee80211s_hdr *)entry->hdr;
819 if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
820 /* preserve SA from eth header for 6-addr frames */
821 ether_addr_copy(sa, skb->data + ETH_ALEN);
825 memcpy(skb_push(skb, entry->hdrlen - 2 * ETH_ALEN), entry->hdr,
828 meshhdr = (struct ieee80211s_hdr *)skb->data;
829 put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum),
831 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
833 ether_addr_copy(meshhdr->eaddr2, sa);
835 skb_push(skb, 2 * ETH_ALEN);
836 __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
837 entry->mpath->dst, sdata->vif.addr);
843 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
844 * @hdr: 802.11 frame header
845 * @fc: frame control field
846 * @meshda: destination address in the mesh
847 * @meshsa: source address in the mesh. Same as TA, as frame is
848 * locally originated.
850 * Returns: the length of the 802.11 frame header (excludes mesh control header)
852 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
853 const u8 *meshda, const u8 *meshsa)
855 if (is_multicast_ether_addr(meshda)) {
856 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
858 memcpy(hdr->addr1, meshda, ETH_ALEN);
859 memcpy(hdr->addr2, meshsa, ETH_ALEN);
860 memcpy(hdr->addr3, meshsa, ETH_ALEN);
863 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
865 eth_zero_addr(hdr->addr1); /* RA is resolved later */
866 memcpy(hdr->addr2, meshsa, ETH_ALEN);
867 memcpy(hdr->addr3, meshda, ETH_ALEN);
868 memcpy(hdr->addr4, meshsa, ETH_ALEN);
874 * ieee80211_new_mesh_header - create a new mesh header
875 * @sdata: mesh interface to be used
876 * @meshhdr: uninitialized mesh header
877 * @addr4or5: 1st address in the ae header, which may correspond to address 4
878 * (if addr6 is NULL) or address 5 (if addr6 is present). It may
880 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
883 * Returns: the header length
885 unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
886 struct ieee80211s_hdr *meshhdr,
887 const char *addr4or5, const char *addr6)
889 if (WARN_ON(!addr4or5 && addr6))
892 memset(meshhdr, 0, sizeof(*meshhdr));
894 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
896 put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum),
898 if (addr4or5 && !addr6) {
899 meshhdr->flags |= MESH_FLAGS_AE_A4;
900 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
902 } else if (addr4or5 && addr6) {
903 meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
904 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
905 memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
912 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata)
914 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
917 if (ifmsh->mshcfg.plink_timeout > 0)
918 ieee80211_sta_expire(sdata, ifmsh->mshcfg.plink_timeout * HZ);
919 mesh_path_expire(sdata);
921 changed = mesh_accept_plinks_update(sdata);
922 ieee80211_mbss_info_change_notify(sdata, changed);
924 mesh_fast_tx_gc(sdata);
926 mod_timer(&ifmsh->housekeeping_timer,
927 round_jiffies(jiffies +
928 IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
931 static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
933 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
936 mesh_path_tx_root_frame(sdata);
938 if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
939 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
941 interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
943 mod_timer(&ifmsh->mesh_path_root_timer,
944 round_jiffies(TU_TO_EXP_TIME(interval)));
948 ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
950 struct beacon_data *bcn;
951 int head_len, tail_len;
953 struct ieee80211_mgmt *mgmt;
954 struct mesh_csa_settings *csa;
955 const struct ieee80211_supported_band *sband;
956 u8 ie_len_he_cap, ie_len_eht_cap;
958 struct ieee80211_sub_if_data *sdata;
959 int hdr_len = offsetofend(struct ieee80211_mgmt, u.beacon);
961 sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh);
963 sband = ieee80211_get_sband(sdata);
965 ie_len_he_cap = ieee80211_ie_len_he_cap(sdata);
966 ie_len_eht_cap = ieee80211_ie_len_eht_cap(sdata);
969 /* Channel Switch Announcement */
970 2 + sizeof(struct ieee80211_channel_sw_ie) +
971 /* Mesh Channel Switch Parameters */
972 2 + sizeof(struct ieee80211_mesh_chansw_params_ie) +
973 /* Channel Switch Wrapper + Wide Bandwidth CSA IE */
974 2 + 2 + sizeof(struct ieee80211_wide_bw_chansw_ie) +
975 2 + sizeof(struct ieee80211_sec_chan_offs_ie) +
976 2 + 8 + /* supported rates */
977 2 + 3; /* DS params */
978 tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
979 2 + sizeof(struct ieee80211_ht_cap) +
980 2 + sizeof(struct ieee80211_ht_operation) +
981 2 + ifmsh->mesh_id_len +
982 2 + sizeof(struct ieee80211_meshconf_ie) +
983 2 + sizeof(__le16) + /* awake window */
984 2 + sizeof(struct ieee80211_vht_cap) +
985 2 + sizeof(struct ieee80211_vht_operation) +
987 2 + 1 + sizeof(struct ieee80211_he_operation) +
988 sizeof(struct ieee80211_he_6ghz_oper) +
989 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
991 2 + 1 + offsetof(struct ieee80211_eht_operation, optional) +
992 offsetof(struct ieee80211_eht_operation_info, optional) +
995 bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
996 /* need an skb for IE builders to operate on */
997 skb = __dev_alloc_skb(max(head_len, tail_len), GFP_KERNEL);
1003 * pointers go into the block we allocated,
1004 * memory is | beacon_data | head | tail |
1006 bcn->head = ((u8 *) bcn) + sizeof(*bcn);
1008 /* fill in the head */
1009 mgmt = skb_put_zero(skb, hdr_len);
1010 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1011 IEEE80211_STYPE_BEACON);
1012 eth_broadcast_addr(mgmt->da);
1013 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1014 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
1015 ieee80211_mps_set_frame_flags(sdata, NULL, (void *) mgmt);
1016 mgmt->u.beacon.beacon_int =
1017 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
1018 mgmt->u.beacon.capab_info |= cpu_to_le16(
1019 sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
1021 pos = skb_put(skb, 2);
1022 *pos++ = WLAN_EID_SSID;
1026 csa = rcu_dereference(ifmsh->csa);
1028 enum nl80211_channel_type ct;
1029 struct cfg80211_chan_def *chandef;
1030 int ie_len = 2 + sizeof(struct ieee80211_channel_sw_ie) +
1031 2 + sizeof(struct ieee80211_mesh_chansw_params_ie);
1033 pos = skb_put_zero(skb, ie_len);
1034 *pos++ = WLAN_EID_CHANNEL_SWITCH;
1037 *pos++ = ieee80211_frequency_to_channel(
1038 csa->settings.chandef.chan->center_freq);
1039 bcn->cntdwn_current_counter = csa->settings.count;
1040 bcn->cntdwn_counter_offsets[0] = hdr_len + 6;
1041 *pos++ = csa->settings.count;
1042 *pos++ = WLAN_EID_CHAN_SWITCH_PARAM;
1044 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) {
1045 *pos++ = ifmsh->mshcfg.dot11MeshTTL;
1046 *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
1048 *pos++ = ifmsh->chsw_ttl;
1050 *pos++ |= csa->settings.block_tx ?
1051 WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
1052 put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos);
1054 put_unaligned_le16(ifmsh->pre_value, pos);
1057 switch (csa->settings.chandef.width) {
1058 case NL80211_CHAN_WIDTH_40:
1059 ie_len = 2 + sizeof(struct ieee80211_sec_chan_offs_ie);
1060 pos = skb_put_zero(skb, ie_len);
1062 *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */
1063 *pos++ = 1; /* len */
1064 ct = cfg80211_get_chandef_type(&csa->settings.chandef);
1065 if (ct == NL80211_CHAN_HT40PLUS)
1066 *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1068 *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1070 case NL80211_CHAN_WIDTH_80:
1071 case NL80211_CHAN_WIDTH_80P80:
1072 case NL80211_CHAN_WIDTH_160:
1073 /* Channel Switch Wrapper + Wide Bandwidth CSA IE */
1075 sizeof(struct ieee80211_wide_bw_chansw_ie);
1076 pos = skb_put_zero(skb, ie_len);
1078 *pos++ = WLAN_EID_CHANNEL_SWITCH_WRAPPER; /* EID */
1079 *pos++ = 5; /* len */
1081 chandef = &csa->settings.chandef;
1082 ieee80211_ie_build_wide_bw_cs(pos, chandef);
1090 if (ieee80211_put_srates_elem(skb, sband,
1091 sdata->vif.bss_conf.basic_rates,
1092 0, WLAN_EID_SUPP_RATES) ||
1093 mesh_add_ds_params_ie(sdata, skb))
1096 bcn->head_len = skb->len;
1097 memcpy(bcn->head, skb->data, bcn->head_len);
1101 bcn->tail = bcn->head + bcn->head_len;
1103 if (ieee80211_put_srates_elem(skb, sband,
1104 sdata->vif.bss_conf.basic_rates,
1105 0, WLAN_EID_EXT_SUPP_RATES) ||
1106 mesh_add_rsn_ie(sdata, skb) ||
1107 mesh_add_ht_cap_ie(sdata, skb) ||
1108 mesh_add_ht_oper_ie(sdata, skb) ||
1109 mesh_add_meshid_ie(sdata, skb) ||
1110 mesh_add_meshconf_ie(sdata, skb) ||
1111 mesh_add_awake_window_ie(sdata, skb) ||
1112 mesh_add_vht_cap_ie(sdata, skb) ||
1113 mesh_add_vht_oper_ie(sdata, skb) ||
1114 mesh_add_he_cap_ie(sdata, skb, ie_len_he_cap) ||
1115 mesh_add_he_oper_ie(sdata, skb) ||
1116 mesh_add_he_6ghz_cap_ie(sdata, skb) ||
1117 mesh_add_eht_cap_ie(sdata, skb, ie_len_eht_cap) ||
1118 mesh_add_eht_oper_ie(sdata, skb) ||
1119 mesh_add_vendor_ies(sdata, skb))
1122 bcn->tail_len = skb->len;
1123 memcpy(bcn->tail, skb->data, bcn->tail_len);
1124 ieee80211_mesh_update_bss_params(sdata, bcn->tail, bcn->tail_len);
1125 bcn->meshconf = (struct ieee80211_meshconf_ie *)
1126 (bcn->tail + ifmsh->meshconf_offset);
1129 rcu_assign_pointer(ifmsh->beacon, bcn);
1138 ieee80211_mesh_rebuild_beacon(struct ieee80211_sub_if_data *sdata)
1140 struct beacon_data *old_bcn;
1143 old_bcn = sdata_dereference(sdata->u.mesh.beacon, sdata);
1144 ret = ieee80211_mesh_build_beacon(&sdata->u.mesh);
1146 /* just reuse old beacon */
1150 kfree_rcu(old_bcn, rcu_head);
1154 void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
1157 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1158 unsigned long bits[] = { BITMAP_FROM_U64(changed) };
1164 /* if we race with running work, worst case this work becomes a noop */
1165 for_each_set_bit(bit, bits, sizeof(changed) * BITS_PER_BYTE)
1166 set_bit(bit, ifmsh->mbss_changed);
1167 set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags);
1168 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
1171 int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
1173 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1174 struct ieee80211_local *local = sdata->local;
1175 u64 changed = BSS_CHANGED_BEACON |
1176 BSS_CHANGED_BEACON_ENABLED |
1178 BSS_CHANGED_BASIC_RATES |
1179 BSS_CHANGED_BEACON_INT |
1180 BSS_CHANGED_MCAST_RATE;
1182 local->fif_other_bss++;
1183 /* mesh ifaces must set allmulti to forward mcast traffic */
1184 atomic_inc(&local->iff_allmultis);
1185 ieee80211_configure_filter(local);
1187 ifmsh->mesh_cc_id = 0; /* Disabled */
1188 /* register sync ops from extensible synchronization framework */
1189 ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id);
1190 ifmsh->sync_offset_clockdrift_max = 0;
1191 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
1192 ieee80211_mesh_root_setup(ifmsh);
1193 wiphy_work_queue(local->hw.wiphy, &sdata->work);
1194 sdata->vif.bss_conf.ht_operation_mode =
1195 ifmsh->mshcfg.ht_opmode;
1196 sdata->vif.bss_conf.enable_beacon = true;
1198 changed |= ieee80211_mps_local_status_update(sdata);
1200 if (ieee80211_mesh_build_beacon(ifmsh)) {
1201 ieee80211_stop_mesh(sdata);
1205 ieee80211_recalc_dtim(local, sdata);
1206 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
1208 netif_carrier_on(sdata->dev);
1212 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
1214 struct ieee80211_local *local = sdata->local;
1215 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1216 struct beacon_data *bcn;
1218 netif_carrier_off(sdata->dev);
1220 /* flush STAs and mpaths on this iface */
1221 sta_info_flush(sdata, -1);
1222 ieee80211_free_keys(sdata, true);
1223 mesh_path_flush_by_iface(sdata);
1225 /* stop the beacon */
1226 ifmsh->mesh_id_len = 0;
1227 sdata->vif.bss_conf.enable_beacon = false;
1228 sdata->beacon_rate_set = false;
1229 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1230 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
1231 BSS_CHANGED_BEACON_ENABLED);
1234 bcn = sdata_dereference(ifmsh->beacon, sdata);
1235 RCU_INIT_POINTER(ifmsh->beacon, NULL);
1236 kfree_rcu(bcn, rcu_head);
1238 /* free all potentially still buffered group-addressed frames */
1239 local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf);
1240 skb_queue_purge(&ifmsh->ps.bc_buf);
1242 timer_delete_sync(&sdata->u.mesh.housekeeping_timer);
1243 timer_delete_sync(&sdata->u.mesh.mesh_path_root_timer);
1244 timer_delete_sync(&sdata->u.mesh.mesh_path_timer);
1246 /* clear any mesh work (for next join) we may have accrued */
1247 ifmsh->wrkq_flags = 0;
1248 memset(ifmsh->mbss_changed, 0, sizeof(ifmsh->mbss_changed));
1250 local->fif_other_bss--;
1251 atomic_dec(&local->iff_allmultis);
1252 ieee80211_configure_filter(local);
1255 static void ieee80211_mesh_csa_mark_radar(struct ieee80211_sub_if_data *sdata)
1259 /* if the current channel is a DFS channel, mark the channel as
1262 err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
1263 &sdata->vif.bss_conf.chanreq.oper,
1264 NL80211_IFTYPE_MESH_POINT);
1266 cfg80211_radar_event(sdata->local->hw.wiphy,
1267 &sdata->vif.bss_conf.chanreq.oper,
1272 ieee80211_mesh_process_chnswitch(struct ieee80211_sub_if_data *sdata,
1273 struct ieee802_11_elems *elems, bool beacon)
1275 struct cfg80211_csa_settings params;
1276 struct ieee80211_csa_ie csa_ie;
1277 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1278 struct ieee80211_supported_band *sband;
1280 struct ieee80211_conn_settings conn = ieee80211_conn_settings_unlimited;
1281 u32 vht_cap_info = 0;
1283 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1285 sband = ieee80211_get_sband(sdata);
1289 switch (sdata->vif.bss_conf.chanreq.oper.width) {
1290 case NL80211_CHAN_WIDTH_20_NOHT:
1291 conn.mode = IEEE80211_CONN_MODE_LEGACY;
1292 conn.bw_limit = IEEE80211_CONN_BW_LIMIT_20;
1294 case NL80211_CHAN_WIDTH_20:
1295 conn.mode = IEEE80211_CONN_MODE_HT;
1296 conn.bw_limit = IEEE80211_CONN_BW_LIMIT_20;
1298 case NL80211_CHAN_WIDTH_40:
1299 conn.mode = IEEE80211_CONN_MODE_HT;
1300 conn.bw_limit = IEEE80211_CONN_BW_LIMIT_40;
1306 if (elems->vht_cap_elem)
1308 le32_to_cpu(elems->vht_cap_elem->vht_cap_info);
1310 memset(¶ms, 0, sizeof(params));
1311 err = ieee80211_parse_ch_switch_ie(sdata, elems, sband->band,
1312 vht_cap_info, &conn,
1313 sdata->vif.addr, false,
1320 /* Mark the channel unavailable if the reason for the switch is
1323 if (csa_ie.reason_code == WLAN_REASON_MESH_CHAN_REGULATORY)
1324 ieee80211_mesh_csa_mark_radar(sdata);
1326 params.chandef = csa_ie.chanreq.oper;
1327 params.count = csa_ie.count;
1329 if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, ¶ms.chandef,
1330 IEEE80211_CHAN_DISABLED) ||
1331 !cfg80211_reg_can_beacon(sdata->local->hw.wiphy, ¶ms.chandef,
1332 NL80211_IFTYPE_MESH_POINT)) {
1334 "mesh STA %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n",
1336 params.chandef.chan->center_freq,
1337 params.chandef.width,
1338 params.chandef.center_freq1,
1339 params.chandef.center_freq2);
1343 err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
1345 NL80211_IFTYPE_MESH_POINT);
1348 if (err > 0 && !ifmsh->userspace_handles_dfs) {
1350 "mesh STA %pM switches to channel requiring DFS (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n",
1352 params.chandef.chan->center_freq,
1353 params.chandef.width,
1354 params.chandef.center_freq1,
1355 params.chandef.center_freq2);
1359 params.radar_required = err;
1361 if (cfg80211_chandef_identical(¶ms.chandef,
1362 &sdata->vif.bss_conf.chanreq.oper)) {
1364 "received csa with an identical chandef, ignoring\n");
1369 "received channel switch announcement to go to channel %d MHz\n",
1370 params.chandef.chan->center_freq);
1372 params.block_tx = csa_ie.mode & WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT;
1374 ifmsh->chsw_ttl = csa_ie.ttl - 1;
1375 if (ifmsh->pre_value >= csa_ie.pre_value)
1377 ifmsh->pre_value = csa_ie.pre_value;
1380 if (ifmsh->chsw_ttl >= ifmsh->mshcfg.dot11MeshTTL)
1383 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_REPEATER;
1385 if (ieee80211_channel_switch(sdata->local->hw.wiphy, sdata->dev,
1393 ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata,
1394 struct ieee80211_mgmt *mgmt, size_t len)
1396 struct ieee80211_local *local = sdata->local;
1397 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1398 struct sk_buff *presp;
1399 struct beacon_data *bcn;
1400 struct ieee80211_mgmt *hdr;
1401 struct ieee802_11_elems *elems;
1405 pos = mgmt->u.probe_req.variable;
1406 baselen = (u8 *) pos - (u8 *) mgmt;
1410 elems = ieee802_11_parse_elems(pos, len - baselen, false, NULL);
1414 if (!elems->mesh_id)
1417 /* 802.11-2012 10.1.4.3.2 */
1418 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
1419 !is_broadcast_ether_addr(mgmt->da)) ||
1420 elems->ssid_len != 0)
1423 if (elems->mesh_id_len != 0 &&
1424 (elems->mesh_id_len != ifmsh->mesh_id_len ||
1425 memcmp(elems->mesh_id, ifmsh->mesh_id, ifmsh->mesh_id_len)))
1429 bcn = rcu_dereference(ifmsh->beacon);
1434 presp = dev_alloc_skb(local->tx_headroom +
1435 bcn->head_len + bcn->tail_len);
1439 skb_reserve(presp, local->tx_headroom);
1440 skb_put_data(presp, bcn->head, bcn->head_len);
1441 skb_put_data(presp, bcn->tail, bcn->tail_len);
1442 hdr = (struct ieee80211_mgmt *) presp->data;
1443 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1444 IEEE80211_STYPE_PROBE_RESP);
1445 memcpy(hdr->da, mgmt->sa, ETH_ALEN);
1446 IEEE80211_SKB_CB(presp)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1447 ieee80211_tx_skb(sdata, presp);
1454 static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
1456 struct ieee80211_mgmt *mgmt,
1458 struct ieee80211_rx_status *rx_status)
1460 struct ieee80211_local *local = sdata->local;
1461 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1462 struct ieee802_11_elems *elems;
1463 struct ieee80211_channel *channel;
1466 enum nl80211_band band = rx_status->band;
1468 /* ignore ProbeResp to foreign address */
1469 if (stype == IEEE80211_STYPE_PROBE_RESP &&
1470 !ether_addr_equal(mgmt->da, sdata->vif.addr))
1473 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1477 elems = ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
1483 /* ignore non-mesh or secure / insecure mismatch */
1484 if ((!elems->mesh_id || !elems->mesh_config) ||
1485 (elems->rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
1486 (!elems->rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
1489 if (elems->ds_params)
1490 freq = ieee80211_channel_to_frequency(elems->ds_params[0], band);
1492 freq = rx_status->freq;
1494 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1496 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1499 if (mesh_matches_local(sdata, elems)) {
1500 mpl_dbg(sdata, "rssi_threshold=%d,rx_status->signal=%d\n",
1501 sdata->u.mesh.mshcfg.rssi_threshold, rx_status->signal);
1502 if (!sdata->u.mesh.user_mpm ||
1503 sdata->u.mesh.mshcfg.rssi_threshold == 0 ||
1504 sdata->u.mesh.mshcfg.rssi_threshold < rx_status->signal)
1505 mesh_neighbour_update(sdata, mgmt->sa, elems,
1508 if (ifmsh->csa_role != IEEE80211_MESH_CSA_ROLE_INIT &&
1509 !sdata->vif.bss_conf.csa_active)
1510 ieee80211_mesh_process_chnswitch(sdata, elems, true);
1513 if (ifmsh->sync_ops)
1514 ifmsh->sync_ops->rx_bcn_presp(sdata, stype, mgmt, len,
1515 elems->mesh_config, rx_status);
1520 int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata, u64 *changed)
1522 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1523 struct mesh_csa_settings *tmp_csa_settings;
1526 /* Reset the TTL value and Initiator flag */
1527 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
1528 ifmsh->chsw_ttl = 0;
1530 /* Remove the CSA and MCSP elements from the beacon */
1531 tmp_csa_settings = sdata_dereference(ifmsh->csa, sdata);
1532 RCU_INIT_POINTER(ifmsh->csa, NULL);
1533 if (tmp_csa_settings)
1534 kfree_rcu(tmp_csa_settings, rcu_head);
1535 ret = ieee80211_mesh_rebuild_beacon(sdata);
1539 *changed |= BSS_CHANGED_BEACON;
1541 mcsa_dbg(sdata, "complete switching to center freq %d MHz",
1542 sdata->vif.bss_conf.chanreq.oper.chan->center_freq);
1546 int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
1547 struct cfg80211_csa_settings *csa_settings,
1550 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1551 struct mesh_csa_settings *tmp_csa_settings;
1554 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1556 tmp_csa_settings = kmalloc(sizeof(*tmp_csa_settings),
1558 if (!tmp_csa_settings)
1561 memcpy(&tmp_csa_settings->settings, csa_settings,
1562 sizeof(struct cfg80211_csa_settings));
1564 rcu_assign_pointer(ifmsh->csa, tmp_csa_settings);
1566 ret = ieee80211_mesh_rebuild_beacon(sdata);
1568 tmp_csa_settings = rcu_dereference(ifmsh->csa);
1569 RCU_INIT_POINTER(ifmsh->csa, NULL);
1570 kfree_rcu(tmp_csa_settings, rcu_head);
1574 *changed |= BSS_CHANGED_BEACON;
1578 static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
1579 struct ieee80211_mgmt *mgmt, size_t len,
1580 struct ieee802_11_elems *elems)
1582 struct ieee80211_mgmt *mgmt_fwd;
1583 struct sk_buff *skb;
1584 struct ieee80211_local *local = sdata->local;
1586 skb = dev_alloc_skb(local->tx_headroom + len);
1589 skb_reserve(skb, local->tx_headroom);
1590 mgmt_fwd = skb_put(skb, len);
1592 elems->mesh_chansw_params_ie->mesh_ttl--;
1593 elems->mesh_chansw_params_ie->mesh_flags &=
1594 ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
1596 memcpy(mgmt_fwd, mgmt, len);
1597 eth_broadcast_addr(mgmt_fwd->da);
1598 memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN);
1599 memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN);
1601 ieee80211_tx_skb(sdata, skb);
1605 static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
1606 struct ieee80211_mgmt *mgmt, size_t len)
1608 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1609 struct ieee802_11_elems *elems;
1611 bool fwd_csa = true;
1615 if (mgmt->u.action.u.measurement.action_code !=
1616 WLAN_ACTION_SPCT_CHL_SWITCH)
1619 pos = mgmt->u.action.u.chan_switch.variable;
1620 baselen = offsetof(struct ieee80211_mgmt,
1621 u.action.u.chan_switch.variable);
1622 elems = ieee802_11_parse_elems(pos, len - baselen, true, NULL);
1626 if (!mesh_matches_local(sdata, elems))
1629 ifmsh->chsw_ttl = elems->mesh_chansw_params_ie->mesh_ttl;
1630 if (!--ifmsh->chsw_ttl)
1633 pre_value = le16_to_cpu(elems->mesh_chansw_params_ie->mesh_pre_value);
1634 if (ifmsh->pre_value >= pre_value)
1637 ifmsh->pre_value = pre_value;
1639 if (!sdata->vif.bss_conf.csa_active &&
1640 !ieee80211_mesh_process_chnswitch(sdata, elems, false)) {
1641 mcsa_dbg(sdata, "Failed to process CSA action frame");
1645 /* forward or re-broadcast the CSA frame */
1647 if (mesh_fwd_csa_frame(sdata, mgmt, len, elems) < 0)
1648 mcsa_dbg(sdata, "Failed to forward the CSA frame");
1654 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
1655 struct ieee80211_mgmt *mgmt,
1657 struct ieee80211_rx_status *rx_status)
1659 switch (mgmt->u.action.category) {
1660 case WLAN_CATEGORY_SELF_PROTECTED:
1661 switch (mgmt->u.action.u.self_prot.action_code) {
1662 case WLAN_SP_MESH_PEERING_OPEN:
1663 case WLAN_SP_MESH_PEERING_CLOSE:
1664 case WLAN_SP_MESH_PEERING_CONFIRM:
1665 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
1669 case WLAN_CATEGORY_MESH_ACTION:
1670 if (mesh_action_is_path_sel(mgmt))
1671 mesh_rx_path_sel_frame(sdata, mgmt, len);
1673 case WLAN_CATEGORY_SPECTRUM_MGMT:
1674 mesh_rx_csa_frame(sdata, mgmt, len);
1679 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1680 struct sk_buff *skb)
1682 struct ieee80211_rx_status *rx_status;
1683 struct ieee80211_mgmt *mgmt;
1686 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1688 /* mesh already went down */
1689 if (!sdata->u.mesh.mesh_id_len)
1692 rx_status = IEEE80211_SKB_RXCB(skb);
1693 mgmt = (struct ieee80211_mgmt *) skb->data;
1694 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1697 case IEEE80211_STYPE_PROBE_RESP:
1698 case IEEE80211_STYPE_BEACON:
1699 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
1702 case IEEE80211_STYPE_PROBE_REQ:
1703 ieee80211_mesh_rx_probe_req(sdata, mgmt, skb->len);
1705 case IEEE80211_STYPE_ACTION:
1706 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
1711 static void mesh_bss_info_changed(struct ieee80211_sub_if_data *sdata)
1713 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1717 for_each_set_bit(bit, ifmsh->mbss_changed,
1718 sizeof(changed) * BITS_PER_BYTE) {
1719 clear_bit(bit, ifmsh->mbss_changed);
1720 changed |= BIT(bit);
1723 if (sdata->vif.bss_conf.enable_beacon &&
1724 (changed & (BSS_CHANGED_BEACON |
1726 BSS_CHANGED_BASIC_RATES |
1727 BSS_CHANGED_BEACON_INT)))
1728 if (ieee80211_mesh_rebuild_beacon(sdata))
1731 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
1734 void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
1736 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1738 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1740 /* mesh already went down */
1741 if (!sdata->u.mesh.mesh_id_len)
1744 if (ifmsh->preq_queue_len &&
1746 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
1747 mesh_path_start_discovery(sdata);
1749 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
1750 ieee80211_mesh_housekeeping(sdata);
1752 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
1753 ieee80211_mesh_rootpath(sdata);
1755 if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
1756 mesh_sync_adjust_tsf(sdata);
1758 if (test_and_clear_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags))
1759 mesh_bss_info_changed(sdata);
1763 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
1765 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1766 static u8 zero_addr[ETH_ALEN] = {};
1768 timer_setup(&ifmsh->housekeeping_timer,
1769 ieee80211_mesh_housekeeping_timer, 0);
1771 ifmsh->accepting_plinks = true;
1772 atomic_set(&ifmsh->mpaths, 0);
1773 mesh_rmc_init(sdata);
1774 ifmsh->last_preq = jiffies;
1775 ifmsh->next_perr = jiffies;
1776 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
1777 ifmsh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
1778 /* Allocate all mesh structures when creating the first mesh interface. */
1779 if (!mesh_allocated)
1782 mesh_pathtbl_init(sdata);
1784 timer_setup(&ifmsh->mesh_path_timer, ieee80211_mesh_path_timer, 0);
1785 timer_setup(&ifmsh->mesh_path_root_timer,
1786 ieee80211_mesh_path_root_timer, 0);
1787 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
1788 skb_queue_head_init(&ifmsh->ps.bc_buf);
1789 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
1790 spin_lock_init(&ifmsh->sync_offset_lock);
1791 RCU_INIT_POINTER(ifmsh->beacon, NULL);
1793 sdata->vif.bss_conf.bssid = zero_addr;
1796 void ieee80211_mesh_teardown_sdata(struct ieee80211_sub_if_data *sdata)
1798 mesh_rmc_free(sdata);
1799 mesh_pathtbl_unregister(sdata);