1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2002-2005, Instant802 Networks, Inc.
6 * Copyright 2005-2006, Devicescape Software, Inc.
7 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (c) 2016 Intel Deutschland GmbH
11 * Copyright (C) 2018-2025 Intel Corporation
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/if_arp.h>
16 #include <linux/netdevice.h>
17 #include <linux/rtnetlink.h>
18 #include <linux/kcov.h>
19 #include <net/mac80211.h>
20 #include <net/ieee80211_radiotap.h>
21 #include "ieee80211_i.h"
23 #include "debugfs_netdev.h"
26 #include "driver-ops.h"
31 * DOC: Interface list locking
33 * The interface list in each struct ieee80211_local is protected
36 * (1) modifications may only be done under the RTNL *and* wiphy mutex
38 * (2) modifications are done in an RCU manner so atomic readers
39 * can traverse the list in RCU-safe blocks.
41 * As a consequence, reads (traversals) of the list can be protected
42 * by either the RTNL, the wiphy mutex, the iflist_mtx or RCU.
45 static void ieee80211_iface_work(struct wiphy *wiphy, struct wiphy_work *work);
47 bool __ieee80211_recalc_txpower(struct ieee80211_link_data *link)
49 struct ieee80211_chanctx_conf *chanctx_conf;
53 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
59 power = ieee80211_chandef_max_power(&chanctx_conf->def);
62 if (link->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
63 power = min(power, link->user_power_level);
65 if (link->ap_power_level != IEEE80211_UNSET_POWER_LEVEL)
66 power = min(power, link->ap_power_level);
68 if (power != link->conf->txpower) {
69 link->conf->txpower = power;
76 void ieee80211_recalc_txpower(struct ieee80211_link_data *link,
79 if (__ieee80211_recalc_txpower(link) ||
80 (update_bss && ieee80211_sdata_running(link->sdata)))
81 ieee80211_link_info_change_notify(link->sdata, link,
85 static u32 __ieee80211_idle_off(struct ieee80211_local *local)
87 if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
90 local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
91 return IEEE80211_CONF_CHANGE_IDLE;
94 static u32 __ieee80211_idle_on(struct ieee80211_local *local)
96 if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
99 ieee80211_flush_queues(local, NULL, false);
101 local->hw.conf.flags |= IEEE80211_CONF_IDLE;
102 return IEEE80211_CONF_CHANGE_IDLE;
105 static u32 __ieee80211_recalc_idle(struct ieee80211_local *local,
108 bool working, scanning, active;
109 unsigned int led_trig_start = 0, led_trig_stop = 0;
111 lockdep_assert_wiphy(local->hw.wiphy);
113 active = force_active ||
114 !list_empty(&local->chanctx_list) ||
117 working = !local->ops->remain_on_channel &&
118 !list_empty(&local->roc_list);
120 scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) ||
121 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
123 if (working || scanning)
124 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
126 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
129 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
131 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
133 ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
135 if (working || scanning || active)
136 return __ieee80211_idle_off(local);
137 return __ieee80211_idle_on(local);
140 u32 ieee80211_idle_off(struct ieee80211_local *local)
142 return __ieee80211_recalc_idle(local, true);
145 void ieee80211_recalc_idle(struct ieee80211_local *local)
147 u32 change = __ieee80211_recalc_idle(local, false);
149 ieee80211_hw_config(local, change);
152 static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 *addr,
155 struct ieee80211_local *local = sdata->local;
156 struct ieee80211_sub_if_data *iter;
161 lockdep_assert_wiphy(local->hw.wiphy);
163 if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
167 new = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
168 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
169 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
171 m = local->hw.wiphy->addr_mask;
172 mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
173 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
174 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
179 list_for_each_entry(iter, &local->interfaces, list) {
183 if (iter->vif.type == NL80211_IFTYPE_MONITOR &&
184 !(iter->u.mntr.flags & MONITOR_FLAG_ACTIVE))
188 tmp = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
189 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
190 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
192 if ((new & ~mask) != (tmp & ~mask)) {
201 static int ieee80211_can_powered_addr_change(struct ieee80211_sub_if_data *sdata)
203 struct ieee80211_roc_work *roc;
204 struct ieee80211_local *local = sdata->local;
205 struct ieee80211_sub_if_data *scan_sdata;
208 lockdep_assert_wiphy(local->hw.wiphy);
210 /* To be the most flexible here we want to only limit changing the
211 * address if the specific interface is doing offchannel work or
214 if (netif_carrier_ok(sdata->dev))
217 /* First check no ROC work is happening on this iface */
218 list_for_each_entry(roc, &local->roc_list, list) {
219 if (roc->sdata != sdata)
228 /* And if this iface is scanning */
229 if (local->scanning) {
230 scan_sdata = rcu_dereference_protected(local->scan_sdata,
231 lockdep_is_held(&local->hw.wiphy->mtx));
232 if (sdata == scan_sdata)
236 switch (sdata->vif.type) {
237 case NL80211_IFTYPE_STATION:
238 case NL80211_IFTYPE_P2P_CLIENT:
239 /* More interface types could be added here but changing the
240 * address while powered makes the most sense in client modes.
251 static int _ieee80211_change_mac(struct ieee80211_sub_if_data *sdata,
254 struct ieee80211_local *local = sdata->local;
255 struct sockaddr *sa = addr;
256 bool check_dup = true;
260 if (ieee80211_sdata_running(sdata)) {
261 ret = ieee80211_can_powered_addr_change(sdata);
268 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
269 !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
272 ret = ieee80211_verify_mac(sdata, sa->sa_data, check_dup);
277 drv_remove_interface(local, sdata);
278 ret = eth_mac_addr(sdata->dev, sa);
281 memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
282 ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr);
285 /* Regardless of eth_mac_addr() return we still want to add the
286 * interface back. This should not fail...
289 WARN_ON(drv_add_interface(local, sdata));
294 static int ieee80211_change_mac(struct net_device *dev, void *addr)
296 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
297 struct ieee80211_local *local = sdata->local;
300 * This happens during unregistration if there's a bond device
301 * active (maybe other cases?) and we must get removed from it.
302 * But we really don't care anymore if it's not registered now.
304 if (!dev->ieee80211_ptr->registered)
307 guard(wiphy)(local->hw.wiphy);
309 return _ieee80211_change_mac(sdata, addr);
312 static inline int identical_mac_addr_allowed(int type1, int type2)
314 return type1 == NL80211_IFTYPE_MONITOR ||
315 type2 == NL80211_IFTYPE_MONITOR ||
316 type1 == NL80211_IFTYPE_P2P_DEVICE ||
317 type2 == NL80211_IFTYPE_P2P_DEVICE ||
318 (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
319 (type1 == NL80211_IFTYPE_AP_VLAN &&
320 (type2 == NL80211_IFTYPE_AP ||
321 type2 == NL80211_IFTYPE_AP_VLAN));
324 static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
325 enum nl80211_iftype iftype)
327 struct ieee80211_local *local = sdata->local;
328 struct ieee80211_sub_if_data *nsdata;
331 lockdep_assert_wiphy(local->hw.wiphy);
333 /* we hold the RTNL here so can safely walk the list */
334 list_for_each_entry(nsdata, &local->interfaces, list) {
335 if (nsdata != sdata && ieee80211_sdata_running(nsdata)) {
337 * Only OCB and monitor mode may coexist
339 if ((sdata->vif.type == NL80211_IFTYPE_OCB &&
340 nsdata->vif.type != NL80211_IFTYPE_MONITOR) ||
341 (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
342 nsdata->vif.type == NL80211_IFTYPE_OCB))
346 * Allow only a single IBSS interface to be up at any
347 * time. This is restricted because beacon distribution
348 * cannot work properly if both are in the same IBSS.
350 * To remove this restriction we'd have to disallow them
351 * from setting the same SSID on different IBSS interfaces
352 * belonging to the same hardware. Then, however, we're
353 * faced with having to adopt two different TSF timers...
355 if (iftype == NL80211_IFTYPE_ADHOC &&
356 nsdata->vif.type == NL80211_IFTYPE_ADHOC)
359 * will not add another interface while any channel
362 if (nsdata->vif.bss_conf.csa_active)
366 * The remaining checks are only performed for interfaces
367 * with the same MAC address.
369 if (!ether_addr_equal(sdata->vif.addr,
374 * check whether it may have the same address
376 if (!identical_mac_addr_allowed(iftype,
380 /* No support for VLAN with MLO yet */
381 if (iftype == NL80211_IFTYPE_AP_VLAN &&
382 sdata->wdev.use_4addr &&
383 nsdata->vif.type == NL80211_IFTYPE_AP &&
384 nsdata->vif.valid_links)
388 * can only add VLANs to enabled APs
390 if (iftype == NL80211_IFTYPE_AP_VLAN &&
391 nsdata->vif.type == NL80211_IFTYPE_AP)
392 sdata->bss = &nsdata->u.ap;
396 return ieee80211_check_combinations(sdata, NULL, 0, 0, -1);
399 static int ieee80211_check_queues(struct ieee80211_sub_if_data *sdata,
400 enum nl80211_iftype iftype)
402 int n_queues = sdata->local->hw.queues;
405 if (iftype == NL80211_IFTYPE_NAN)
408 if (iftype != NL80211_IFTYPE_P2P_DEVICE) {
409 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
410 if (WARN_ON_ONCE(sdata->vif.hw_queue[i] ==
411 IEEE80211_INVAL_HW_QUEUE))
413 if (WARN_ON_ONCE(sdata->vif.hw_queue[i] >=
419 if ((iftype != NL80211_IFTYPE_AP &&
420 iftype != NL80211_IFTYPE_P2P_GO &&
421 iftype != NL80211_IFTYPE_MESH_POINT) ||
422 !ieee80211_hw_check(&sdata->local->hw, QUEUE_CONTROL)) {
423 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
427 if (WARN_ON_ONCE(sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE))
430 if (WARN_ON_ONCE(sdata->vif.cab_queue >= n_queues))
436 static int ieee80211_open(struct net_device *dev)
438 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
441 /* fail early if user set an invalid address */
442 if (!is_valid_ether_addr(dev->dev_addr))
443 return -EADDRNOTAVAIL;
445 guard(wiphy)(sdata->local->hw.wiphy);
447 err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
451 return ieee80211_do_open(&sdata->wdev, true);
454 static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_down)
456 struct ieee80211_local *local = sdata->local;
458 struct sk_buff_head freeq;
459 struct sk_buff *skb, *tmp;
460 u32 hw_reconf_flags = 0;
463 struct cfg80211_chan_def chandef;
465 struct cfg80211_nan_func *func;
467 lockdep_assert_wiphy(local->hw.wiphy);
469 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
470 synchronize_rcu(); /* flush _ieee80211_wake_txqs() */
472 cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
474 ieee80211_scan_cancel(local);
476 ieee80211_roc_purge(local, sdata);
478 switch (sdata->vif.type) {
479 case NL80211_IFTYPE_STATION:
480 ieee80211_mgd_stop(sdata);
482 case NL80211_IFTYPE_ADHOC:
483 ieee80211_ibss_stop(sdata);
485 case NL80211_IFTYPE_MONITOR:
486 list_del_rcu(&sdata->u.mntr.list);
488 case NL80211_IFTYPE_AP_VLAN:
489 ieee80211_apvlan_link_clear(sdata);
496 * Remove all stations associated with this interface.
498 * This must be done before calling ops->remove_interface()
499 * because otherwise we can later invoke ops->sta_notify()
500 * whenever the STAs are removed, and that invalidates driver
501 * assumptions about always getting a vif pointer that is valid
502 * (because if we remove a STA after ops->remove_interface()
503 * the driver will have removed the vif info already!)
505 * For AP_VLANs stations may exist since there's nothing else that
506 * would have removed them, but in other modes there shouldn't
509 flushed = sta_info_flush(sdata, -1);
510 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN && flushed > 0);
512 /* don't count this interface for allmulti while it is down */
513 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
514 atomic_dec(&local->iff_allmultis);
516 if (sdata->vif.type == NL80211_IFTYPE_AP) {
518 local->fif_probe_req--;
519 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
520 local->fif_probe_req--;
524 netif_addr_lock_bh(sdata->dev);
525 spin_lock_bh(&local->filter_lock);
526 __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
527 sdata->dev->addr_len);
528 spin_unlock_bh(&local->filter_lock);
529 netif_addr_unlock_bh(sdata->dev);
532 timer_delete_sync(&local->dynamic_ps_timer);
533 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
535 WARN(ieee80211_vif_is_mld(&sdata->vif),
536 "destroying interface with valid links 0x%04x\n",
537 sdata->vif.valid_links);
539 sdata->vif.bss_conf.csa_active = false;
540 if (sdata->vif.type == NL80211_IFTYPE_STATION)
541 sdata->deflink.u.mgd.csa.waiting_bcn = false;
542 ieee80211_vif_unblock_queues_csa(sdata);
544 wiphy_work_cancel(local->hw.wiphy, &sdata->deflink.csa.finalize_work);
545 wiphy_work_cancel(local->hw.wiphy,
546 &sdata->deflink.color_change_finalize_work);
547 wiphy_delayed_work_cancel(local->hw.wiphy,
548 &sdata->deflink.dfs_cac_timer_work);
550 if (sdata->wdev.links[0].cac_started) {
551 chandef = sdata->vif.bss_conf.chanreq.oper;
552 WARN_ON(local->suspended);
553 ieee80211_link_release_channel(&sdata->deflink);
554 cfg80211_cac_event(sdata->dev, &chandef,
555 NL80211_RADAR_CAC_ABORTED,
559 if (sdata->vif.type == NL80211_IFTYPE_AP) {
560 WARN_ON(!list_empty(&sdata->u.ap.vlans));
561 } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
562 /* remove all packets in parent bc_buf pointing to this dev */
563 ps = &sdata->bss->ps;
565 spin_lock_irqsave(&ps->bc_buf.lock, flags);
566 skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
567 if (skb->dev == sdata->dev) {
568 __skb_unlink(skb, &ps->bc_buf);
569 local->total_ps_buffered--;
570 ieee80211_free_txskb(&local->hw, skb);
573 spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
579 switch (sdata->vif.type) {
580 case NL80211_IFTYPE_AP_VLAN:
581 list_del(&sdata->u.vlan.list);
582 RCU_INIT_POINTER(sdata->vif.bss_conf.chanctx_conf, NULL);
583 /* see comment in the default case below */
584 ieee80211_free_keys(sdata, true);
585 /* no need to tell driver */
587 case NL80211_IFTYPE_MONITOR:
590 if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) &&
591 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
593 local->virt_monitors--;
594 if (local->virt_monitors == 0) {
595 local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
596 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
599 ieee80211_adjust_monitor_flags(sdata, -1);
602 case NL80211_IFTYPE_NAN:
603 /* clean all the functions */
604 spin_lock_bh(&sdata->u.nan.func_lock);
606 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
607 idr_remove(&sdata->u.nan.function_inst_ids, i);
608 cfg80211_free_nan_func(func);
610 idr_destroy(&sdata->u.nan.function_inst_ids);
612 spin_unlock_bh(&sdata->u.nan.func_lock);
614 case NL80211_IFTYPE_P2P_DEVICE:
615 /* relies on synchronize_rcu() below */
616 RCU_INIT_POINTER(local->p2p_sdata, NULL);
619 wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->work);
621 * When we get here, the interface is marked down.
622 * Free the remaining keys, if there are any
623 * (which can happen in AP mode if userspace sets
624 * keys before the interface is operating)
626 * Force the key freeing to always synchronize_net()
627 * to wait for the RX path in case it is using this
628 * interface enqueuing frames at this very time on
631 ieee80211_free_keys(sdata, true);
632 skb_queue_purge(&sdata->skb_queue);
633 skb_queue_purge(&sdata->status_queue);
637 * Since ieee80211_free_txskb() may issue __dev_queue_xmit()
638 * which should be called with interrupts enabled, reclamation
639 * is done in two phases:
641 __skb_queue_head_init(&freeq);
643 /* unlink from local queues... */
644 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
645 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
646 skb_queue_walk_safe(&local->pending[i], skb, tmp) {
647 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
648 if (info->control.vif == &sdata->vif) {
649 __skb_unlink(skb, &local->pending[i]);
650 __skb_queue_tail(&freeq, skb);
654 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
656 /* ... and perform actual reclamation with interrupts enabled. */
657 skb_queue_walk_safe(&freeq, skb, tmp) {
658 __skb_unlink(skb, &freeq);
659 ieee80211_free_txskb(&local->hw, skb);
662 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
663 ieee80211_txq_remove_vlan(local, sdata);
666 ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq));
670 if (local->open_count == 0)
671 ieee80211_clear_tx_pending(local);
673 sdata->vif.bss_conf.beacon_int = 0;
676 * If the interface goes down while suspended, presumably because
677 * the device was unplugged and that happens before our resume,
678 * then the driver is already unconfigured and the remainder of
679 * this function isn't needed.
680 * XXX: what about WoWLAN? If the device has software state, e.g.
681 * memory allocated, it might expect teardown commands from
684 if (local->suspended) {
685 WARN_ON(local->wowlan);
686 WARN_ON(rcu_access_pointer(local->monitor_sdata));
690 switch (sdata->vif.type) {
691 case NL80211_IFTYPE_AP_VLAN:
693 case NL80211_IFTYPE_MONITOR:
694 if (local->virt_monitors == 0)
695 ieee80211_del_virtual_monitor(local);
697 ieee80211_recalc_idle(local);
698 ieee80211_recalc_offload(local);
700 if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) &&
701 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR))
704 ieee80211_link_release_channel(&sdata->deflink);
709 drv_remove_interface(local, sdata);
711 /* Clear private driver data to prevent reuse */
712 memset(sdata->vif.drv_priv, 0, local->hw.vif_data_size);
715 ieee80211_recalc_ps(local);
718 wiphy_delayed_work_flush(local->hw.wiphy, &local->scan_work);
720 if (local->open_count == 0) {
721 ieee80211_stop_device(local, false);
723 /* no reconfiguring after stop! */
727 /* do after stop to avoid reconfiguring when we stop anyway */
728 ieee80211_configure_filter(local);
729 ieee80211_hw_config(local, hw_reconf_flags);
731 if (local->virt_monitors == local->open_count)
732 ieee80211_add_virtual_monitor(local);
735 void ieee80211_stop_mbssid(struct ieee80211_sub_if_data *sdata)
737 struct ieee80211_sub_if_data *tx_sdata;
738 struct ieee80211_bss_conf *link_conf, *tx_bss_conf;
739 struct ieee80211_link_data *tx_link, *link;
740 unsigned int link_id;
742 lockdep_assert_wiphy(sdata->local->hw.wiphy);
744 /* Check if any of the links of current sdata is an MBSSID. */
745 for_each_vif_active_link(&sdata->vif, link_conf, link_id) {
746 tx_bss_conf = sdata_dereference(link_conf->tx_bss_conf, sdata);
750 tx_sdata = vif_to_sdata(tx_bss_conf->vif);
751 RCU_INIT_POINTER(link_conf->tx_bss_conf, NULL);
753 /* If we are not tx sdata reset tx sdata's tx_bss_conf to avoid recusrion
754 * while closing tx sdata at the end of outer loop below.
756 if (sdata != tx_sdata) {
757 tx_link = sdata_dereference(tx_sdata->link[tx_bss_conf->link_id],
762 RCU_INIT_POINTER(tx_link->conf->tx_bss_conf, NULL);
765 /* loop through sdatas to find if any of their links
766 * belong to same MBSSID set as the one getting deleted.
768 for_each_sdata_link(tx_sdata->local, link) {
769 struct ieee80211_sub_if_data *link_sdata = link->sdata;
771 if (link_sdata == sdata || link_sdata == tx_sdata ||
772 rcu_access_pointer(link->conf->tx_bss_conf) != tx_bss_conf)
775 RCU_INIT_POINTER(link->conf->tx_bss_conf, NULL);
777 /* Remove all links of matching MLD until dynamic link
778 * removal can be supported.
780 cfg80211_stop_iface(link_sdata->wdev.wiphy, &link_sdata->wdev,
784 /* If we are not tx sdata, remove links of tx sdata and proceed */
785 if (sdata != tx_sdata && ieee80211_sdata_running(tx_sdata))
786 cfg80211_stop_iface(tx_sdata->wdev.wiphy,
787 &tx_sdata->wdev, GFP_KERNEL);
791 static int ieee80211_stop(struct net_device *dev)
793 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
795 /* close dependent VLAN interfaces before locking wiphy */
796 if (sdata->vif.type == NL80211_IFTYPE_AP) {
797 struct ieee80211_sub_if_data *vlan, *tmpsdata;
799 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
801 dev_close(vlan->dev);
804 guard(wiphy)(sdata->local->hw.wiphy);
806 wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->activate_links_work);
808 /* Close the dependent MBSSID interfaces with wiphy lock as we may be
809 * terminating its partner links too in case of MLD.
811 if (sdata->vif.type == NL80211_IFTYPE_AP)
812 ieee80211_stop_mbssid(sdata);
814 ieee80211_do_stop(sdata, true);
819 static void ieee80211_set_multicast_list(struct net_device *dev)
821 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
822 struct ieee80211_local *local = sdata->local;
823 int allmulti, sdata_allmulti;
825 allmulti = !!(dev->flags & IFF_ALLMULTI);
826 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
828 if (allmulti != sdata_allmulti) {
829 if (dev->flags & IFF_ALLMULTI)
830 atomic_inc(&local->iff_allmultis);
832 atomic_dec(&local->iff_allmultis);
833 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
836 spin_lock_bh(&local->filter_lock);
837 __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
838 spin_unlock_bh(&local->filter_lock);
839 wiphy_work_queue(local->hw.wiphy, &local->reconfig_filter);
843 * Called when the netdev is removed or, by the code below, before
844 * the interface type changes.
846 static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
848 if (WARN_ON(!list_empty(&sdata->work.entry)))
849 wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->work);
851 /* free extra data */
852 ieee80211_free_keys(sdata, false);
854 ieee80211_debugfs_remove_netdev(sdata);
856 ieee80211_destroy_frag_cache(&sdata->frags);
858 if (ieee80211_vif_is_mesh(&sdata->vif))
859 ieee80211_mesh_teardown_sdata(sdata);
861 ieee80211_vif_clear_links(sdata);
862 ieee80211_link_stop(&sdata->deflink);
865 static void ieee80211_uninit(struct net_device *dev)
867 ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
870 static int ieee80211_netdev_setup_tc(struct net_device *dev,
871 enum tc_setup_type type, void *type_data)
873 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
874 struct ieee80211_local *local = sdata->local;
876 return drv_net_setup_tc(local, sdata, dev, type, type_data);
879 static const struct net_device_ops ieee80211_dataif_ops = {
880 .ndo_open = ieee80211_open,
881 .ndo_stop = ieee80211_stop,
882 .ndo_uninit = ieee80211_uninit,
883 .ndo_start_xmit = ieee80211_subif_start_xmit,
884 .ndo_set_rx_mode = ieee80211_set_multicast_list,
885 .ndo_set_mac_address = ieee80211_change_mac,
886 .ndo_setup_tc = ieee80211_netdev_setup_tc,
889 static u16 ieee80211_monitor_select_queue(struct net_device *dev,
891 struct net_device *sb_dev)
893 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
894 struct ieee80211_local *local = sdata->local;
895 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
896 struct ieee80211_hdr *hdr;
899 if (local->hw.queues < IEEE80211_NUM_ACS)
902 /* reset flags and info before parsing radiotap header */
903 memset(info, 0, sizeof(*info));
905 if (!ieee80211_parse_tx_radiotap(skb, dev))
906 return 0; /* doesn't matter, frame will be dropped */
908 len_rthdr = ieee80211_get_radiotap_len(skb->data);
909 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
910 if (skb->len < len_rthdr + 2 ||
911 skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
912 return 0; /* doesn't matter, frame will be dropped */
914 return ieee80211_select_queue_80211(sdata, skb, hdr);
917 static const struct net_device_ops ieee80211_monitorif_ops = {
918 .ndo_open = ieee80211_open,
919 .ndo_stop = ieee80211_stop,
920 .ndo_uninit = ieee80211_uninit,
921 .ndo_start_xmit = ieee80211_monitor_start_xmit,
922 .ndo_set_rx_mode = ieee80211_set_multicast_list,
923 .ndo_set_mac_address = ieee80211_change_mac,
924 .ndo_select_queue = ieee80211_monitor_select_queue,
927 static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx *ctx,
928 struct net_device_path *path)
930 struct ieee80211_sub_if_data *sdata;
931 struct ieee80211_local *local;
932 struct sta_info *sta;
935 sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev);
936 local = sdata->local;
938 if (!local->ops->net_fill_forward_path)
942 switch (sdata->vif.type) {
943 case NL80211_IFTYPE_AP_VLAN:
944 sta = rcu_dereference(sdata->u.vlan.sta);
947 if (sdata->wdev.use_4addr)
949 if (is_multicast_ether_addr(ctx->daddr))
951 sta = sta_info_get_bss(sdata, ctx->daddr);
953 case NL80211_IFTYPE_AP:
954 if (is_multicast_ether_addr(ctx->daddr))
956 sta = sta_info_get(sdata, ctx->daddr);
958 case NL80211_IFTYPE_STATION:
959 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
960 sta = sta_info_get(sdata, ctx->daddr);
961 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
962 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
969 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
978 ret = drv_net_fill_forward_path(local, sdata, &sta->sta, ctx, path);
985 static const struct net_device_ops ieee80211_dataif_8023_ops = {
986 .ndo_open = ieee80211_open,
987 .ndo_stop = ieee80211_stop,
988 .ndo_uninit = ieee80211_uninit,
989 .ndo_start_xmit = ieee80211_subif_start_xmit_8023,
990 .ndo_set_rx_mode = ieee80211_set_multicast_list,
991 .ndo_set_mac_address = ieee80211_change_mac,
992 .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path,
993 .ndo_setup_tc = ieee80211_netdev_setup_tc,
996 static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype)
999 /* P2P GO and client are mapped to AP/STATION types */
1000 case NL80211_IFTYPE_AP:
1001 case NL80211_IFTYPE_STATION:
1008 static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdata)
1010 struct ieee80211_local *local = sdata->local;
1013 flags = sdata->vif.offload_flags;
1015 if (ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) &&
1016 ieee80211_iftype_supports_hdr_offload(sdata->vif.type)) {
1017 flags |= IEEE80211_OFFLOAD_ENCAP_ENABLED;
1019 if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG) &&
1020 local->hw.wiphy->frag_threshold != (u32)-1)
1021 flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
1023 if (local->virt_monitors)
1024 flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
1026 flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
1029 if (ieee80211_hw_check(&local->hw, SUPPORTS_RX_DECAP_OFFLOAD) &&
1030 ieee80211_iftype_supports_hdr_offload(sdata->vif.type)) {
1031 flags |= IEEE80211_OFFLOAD_DECAP_ENABLED;
1033 if (local->virt_monitors &&
1034 !ieee80211_hw_check(&local->hw, SUPPORTS_CONC_MON_RX_DECAP))
1035 flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
1037 flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
1040 if (sdata->vif.offload_flags == flags)
1043 sdata->vif.offload_flags = flags;
1044 ieee80211_check_fast_rx_iface(sdata);
1048 static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
1050 struct ieee80211_local *local = sdata->local;
1051 struct ieee80211_sub_if_data *bss = sdata;
1054 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1058 bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1061 if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
1062 !ieee80211_iftype_supports_hdr_offload(bss->vif.type))
1065 enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
1066 if (sdata->wdev.use_4addr &&
1067 !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
1070 sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
1071 &ieee80211_dataif_ops;
1074 static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata)
1076 struct ieee80211_local *local = sdata->local;
1077 struct ieee80211_sub_if_data *vsdata;
1079 if (ieee80211_set_sdata_offload_flags(sdata)) {
1080 drv_update_vif_offload(local, sdata);
1081 ieee80211_set_vif_encap_ops(sdata);
1084 list_for_each_entry(vsdata, &local->interfaces, list) {
1085 if (vsdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
1086 vsdata->bss != &sdata->u.ap)
1089 ieee80211_set_vif_encap_ops(vsdata);
1093 void ieee80211_recalc_offload(struct ieee80211_local *local)
1095 struct ieee80211_sub_if_data *sdata;
1097 if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD))
1100 lockdep_assert_wiphy(local->hw.wiphy);
1102 list_for_each_entry(sdata, &local->interfaces, list) {
1103 if (!ieee80211_sdata_running(sdata))
1106 ieee80211_recalc_sdata_offload(sdata);
1110 void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
1113 struct ieee80211_local *local = sdata->local;
1114 u32 flags = sdata->u.mntr.flags;
1116 #define ADJUST(_f, _s) do { \
1117 if (flags & MONITOR_FLAG_##_f) \
1118 local->fif_##_s += offset; \
1121 ADJUST(FCSFAIL, fcsfail);
1122 ADJUST(PLCPFAIL, plcpfail);
1123 ADJUST(CONTROL, control);
1124 ADJUST(CONTROL, pspoll);
1125 ADJUST(OTHER_BSS, other_bss);
1126 if (!(flags & MONITOR_FLAG_SKIP_TX))
1127 local->tx_mntrs += offset;
1132 static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata)
1134 struct ieee80211_local *local = sdata->local;
1137 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1138 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1139 sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE;
1140 else if (local->hw.queues >= IEEE80211_NUM_ACS)
1141 sdata->vif.hw_queue[i] = i;
1143 sdata->vif.hw_queue[i] = 0;
1145 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
1148 static void ieee80211_sdata_init(struct ieee80211_local *local,
1149 struct ieee80211_sub_if_data *sdata)
1151 sdata->local = local;
1153 INIT_LIST_HEAD(&sdata->key_list);
1156 * Initialize the default link, so we can use link_id 0 for non-MLD,
1157 * and that continues to work for non-MLD-aware drivers that use just
1158 * vif.bss_conf instead of vif.link_conf.
1160 * Note that we never change this, so if link ID 0 isn't used in an
1161 * MLD connection, we get a separate allocation for it.
1163 ieee80211_link_init(sdata, -1, &sdata->deflink, &sdata->vif.bss_conf);
1166 int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
1168 struct ieee80211_sub_if_data *sdata;
1172 lockdep_assert_wiphy(local->hw.wiphy);
1174 if (local->monitor_sdata ||
1175 ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR))
1178 sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL);
1183 sdata->vif.type = NL80211_IFTYPE_MONITOR;
1184 snprintf(sdata->name, IFNAMSIZ, "%s-monitor",
1185 wiphy_name(local->hw.wiphy));
1186 sdata->wdev.iftype = NL80211_IFTYPE_MONITOR;
1187 sdata->wdev.wiphy = local->hw.wiphy;
1189 ieee80211_sdata_init(local, sdata);
1191 ieee80211_set_default_queues(sdata);
1193 if (ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) {
1194 ret = drv_add_interface(local, sdata);
1196 /* ok .. stupid driver, it asked for this! */
1202 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1204 ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR);
1210 mutex_lock(&local->iflist_mtx);
1211 rcu_assign_pointer(local->monitor_sdata, sdata);
1212 mutex_unlock(&local->iflist_mtx);
1214 ret = ieee80211_link_use_channel(&sdata->deflink, &local->monitor_chanreq,
1215 IEEE80211_CHANCTX_EXCLUSIVE);
1217 mutex_lock(&local->iflist_mtx);
1218 RCU_INIT_POINTER(local->monitor_sdata, NULL);
1219 mutex_unlock(&local->iflist_mtx);
1221 drv_remove_interface(local, sdata);
1226 skb_queue_head_init(&sdata->skb_queue);
1227 skb_queue_head_init(&sdata->status_queue);
1228 wiphy_work_init(&sdata->work, ieee80211_iface_work);
1233 void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
1235 struct ieee80211_sub_if_data *sdata;
1237 if (ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR))
1241 lockdep_assert_wiphy(local->hw.wiphy);
1243 mutex_lock(&local->iflist_mtx);
1245 sdata = rcu_dereference_protected(local->monitor_sdata,
1246 lockdep_is_held(&local->iflist_mtx));
1248 mutex_unlock(&local->iflist_mtx);
1252 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
1253 ieee80211_link_release_channel(&sdata->deflink);
1255 if (ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
1256 drv_remove_interface(local, sdata);
1258 RCU_INIT_POINTER(local->monitor_sdata, NULL);
1259 mutex_unlock(&local->iflist_mtx);
1267 * NOTE: Be very careful when changing this function, it must NOT return
1268 * an error on interface type changes that have been pre-checked, so most
1269 * checks should be in ieee80211_check_concurrent_iface.
1271 int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
1273 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
1274 struct net_device *dev = wdev->netdev;
1275 struct ieee80211_local *local = sdata->local;
1278 u32 hw_reconf_flags = 0;
1280 lockdep_assert_wiphy(local->hw.wiphy);
1282 switch (sdata->vif.type) {
1283 case NL80211_IFTYPE_AP_VLAN: {
1284 struct ieee80211_sub_if_data *master;
1289 list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
1291 master = container_of(sdata->bss,
1292 struct ieee80211_sub_if_data, u.ap);
1293 sdata->control_port_protocol =
1294 master->control_port_protocol;
1295 sdata->control_port_no_encrypt =
1296 master->control_port_no_encrypt;
1297 sdata->control_port_over_nl80211 =
1298 master->control_port_over_nl80211;
1299 sdata->control_port_no_preauth =
1300 master->control_port_no_preauth;
1301 sdata->vif.cab_queue = master->vif.cab_queue;
1302 memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
1303 sizeof(sdata->vif.hw_queue));
1304 sdata->vif.bss_conf.chanreq = master->vif.bss_conf.chanreq;
1306 sdata->crypto_tx_tailroom_needed_cnt +=
1307 master->crypto_tx_tailroom_needed_cnt;
1309 ieee80211_apvlan_link_setup(sdata);
1313 case NL80211_IFTYPE_AP:
1314 sdata->bss = &sdata->u.ap;
1316 case NL80211_IFTYPE_MESH_POINT:
1317 case NL80211_IFTYPE_STATION:
1318 case NL80211_IFTYPE_MONITOR:
1319 case NL80211_IFTYPE_ADHOC:
1320 case NL80211_IFTYPE_P2P_DEVICE:
1321 case NL80211_IFTYPE_OCB:
1322 case NL80211_IFTYPE_NAN:
1323 /* no special treatment */
1325 case NL80211_IFTYPE_UNSPECIFIED:
1326 case NUM_NL80211_IFTYPES:
1327 case NL80211_IFTYPE_P2P_CLIENT:
1328 case NL80211_IFTYPE_P2P_GO:
1329 case NL80211_IFTYPE_WDS:
1335 if (local->open_count == 0) {
1336 /* here we can consider everything in good order (again) */
1337 local->reconfig_failure = false;
1339 res = drv_start(local);
1342 ieee80211_led_radio(local, true);
1343 ieee80211_mod_tpt_led_trig(local,
1344 IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
1348 * Copy the hopefully now-present MAC address to
1349 * this interface, if it has the special null one.
1351 if (dev && is_zero_ether_addr(dev->dev_addr)) {
1352 eth_hw_addr_set(dev, local->hw.wiphy->perm_addr);
1353 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
1355 if (!is_valid_ether_addr(dev->dev_addr)) {
1356 res = -EADDRNOTAVAIL;
1361 sdata->vif.addr_valid = sdata->vif.type != NL80211_IFTYPE_MONITOR ||
1362 (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE);
1363 switch (sdata->vif.type) {
1364 case NL80211_IFTYPE_AP_VLAN:
1365 /* no need to tell driver, but set carrier and chanctx */
1366 if (sdata->bss->active) {
1367 struct ieee80211_link_data *link;
1369 for_each_link_data(sdata, link) {
1370 ieee80211_link_vlan_copy_chanctx(link);
1373 netif_carrier_on(dev);
1374 ieee80211_set_vif_encap_ops(sdata);
1376 netif_carrier_off(dev);
1379 case NL80211_IFTYPE_MONITOR:
1380 if ((sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) ||
1381 ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
1382 res = drv_add_interface(local, sdata);
1386 if (local->virt_monitors == 0 && local->open_count == 0) {
1387 res = ieee80211_add_virtual_monitor(local);
1391 local->virt_monitors++;
1393 /* must be before the call to ieee80211_configure_filter */
1394 if (local->virt_monitors == 1) {
1395 local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
1396 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
1402 ieee80211_adjust_monitor_flags(sdata, 1);
1403 ieee80211_configure_filter(local);
1404 ieee80211_recalc_offload(local);
1405 ieee80211_recalc_idle(local);
1407 netif_carrier_on(dev);
1411 ieee80211_del_virtual_monitor(local);
1412 ieee80211_set_sdata_offload_flags(sdata);
1414 res = drv_add_interface(local, sdata);
1418 ieee80211_set_vif_encap_ops(sdata);
1419 res = ieee80211_check_queues(sdata,
1420 ieee80211_vif_type_p2p(&sdata->vif));
1422 goto err_del_interface;
1425 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1426 local->fif_pspoll++;
1427 local->fif_probe_req++;
1429 ieee80211_configure_filter(local);
1430 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1431 local->fif_probe_req++;
1434 if (sdata->vif.probe_req_reg)
1435 drv_config_iface_filter(local, sdata,
1439 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
1440 sdata->vif.type != NL80211_IFTYPE_NAN)
1441 changed |= ieee80211_reset_erp_info(sdata);
1442 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
1445 switch (sdata->vif.type) {
1446 case NL80211_IFTYPE_STATION:
1447 case NL80211_IFTYPE_ADHOC:
1448 case NL80211_IFTYPE_AP:
1449 case NL80211_IFTYPE_MESH_POINT:
1450 case NL80211_IFTYPE_OCB:
1451 netif_carrier_off(dev);
1453 case NL80211_IFTYPE_P2P_DEVICE:
1454 case NL80211_IFTYPE_NAN:
1462 * Set default queue parameters so drivers don't
1463 * need to initialise the hardware if the hardware
1464 * doesn't start up with sane defaults.
1465 * Enable QoS for anything but station interfaces.
1467 ieee80211_set_wmm_default(&sdata->deflink, true,
1468 sdata->vif.type != NL80211_IFTYPE_STATION);
1471 switch (sdata->vif.type) {
1472 case NL80211_IFTYPE_P2P_DEVICE:
1473 rcu_assign_pointer(local->p2p_sdata, sdata);
1475 case NL80211_IFTYPE_MONITOR:
1476 list_add_tail_rcu(&sdata->u.mntr.list, &local->mon_list);
1483 * set_multicast_list will be invoked by the networking core
1484 * which will check whether any increments here were done in
1485 * error and sync them down to the hardware as filter flags.
1487 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
1488 atomic_inc(&local->iff_allmultis);
1491 local->open_count++;
1493 if (local->open_count == 1)
1494 ieee80211_hw_conf_init(local);
1495 else if (hw_reconf_flags)
1496 ieee80211_hw_config(local, hw_reconf_flags);
1498 ieee80211_recalc_ps(local);
1500 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1504 drv_remove_interface(local, sdata);
1506 if (!local->open_count)
1507 drv_stop(local, false);
1510 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1511 list_del(&sdata->u.vlan.list);
1512 /* might already be clear but that doesn't matter */
1513 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
1517 static void ieee80211_if_setup(struct net_device *dev)
1520 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1521 dev->priv_flags |= IFF_NO_QUEUE;
1522 dev->netdev_ops = &ieee80211_dataif_ops;
1523 dev->needs_free_netdev = true;
1526 static void ieee80211_iface_process_skb(struct ieee80211_local *local,
1527 struct ieee80211_sub_if_data *sdata,
1528 struct sk_buff *skb)
1530 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1532 lockdep_assert_wiphy(local->hw.wiphy);
1534 if (ieee80211_is_action(mgmt->frame_control) &&
1535 mgmt->u.action.category == WLAN_CATEGORY_BACK) {
1536 struct sta_info *sta;
1539 sta = sta_info_get_bss(sdata, mgmt->sa);
1541 switch (mgmt->u.action.u.addba_req.action_code) {
1542 case WLAN_ACTION_ADDBA_REQ:
1543 ieee80211_process_addba_request(local, sta,
1546 case WLAN_ACTION_ADDBA_RESP:
1547 ieee80211_process_addba_resp(local, sta,
1550 case WLAN_ACTION_DELBA:
1551 ieee80211_process_delba(sdata, sta,
1559 } else if (ieee80211_is_action(mgmt->frame_control) &&
1560 mgmt->u.action.category == WLAN_CATEGORY_VHT) {
1561 switch (mgmt->u.action.u.vht_group_notif.action_code) {
1562 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
1563 struct ieee80211_rx_status *status;
1564 enum nl80211_band band;
1565 struct sta_info *sta;
1568 status = IEEE80211_SKB_RXCB(skb);
1569 band = status->band;
1570 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
1572 sta = sta_info_get_bss(sdata, mgmt->sa);
1575 ieee80211_vht_handle_opmode(sdata,
1581 case WLAN_VHT_ACTION_GROUPID_MGMT:
1582 ieee80211_process_mu_groups(sdata, &sdata->deflink,
1589 } else if (ieee80211_is_action(mgmt->frame_control) &&
1590 mgmt->u.action.category == WLAN_CATEGORY_S1G) {
1591 switch (mgmt->u.action.u.s1g.action_code) {
1592 case WLAN_S1G_TWT_TEARDOWN:
1593 case WLAN_S1G_TWT_SETUP:
1594 ieee80211_s1g_rx_twt_action(sdata, skb);
1599 } else if (ieee80211_is_action(mgmt->frame_control) &&
1600 mgmt->u.action.category == WLAN_CATEGORY_PROTECTED_EHT) {
1601 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1602 switch (mgmt->u.action.u.ttlm_req.action_code) {
1603 case WLAN_PROTECTED_EHT_ACTION_TTLM_REQ:
1604 ieee80211_process_neg_ttlm_req(sdata, mgmt,
1607 case WLAN_PROTECTED_EHT_ACTION_TTLM_RES:
1608 ieee80211_process_neg_ttlm_res(sdata, mgmt,
1611 case WLAN_PROTECTED_EHT_ACTION_TTLM_TEARDOWN:
1612 ieee80211_process_ttlm_teardown(sdata);
1614 case WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_RESP:
1615 ieee80211_process_ml_reconf_resp(sdata, mgmt,
1618 case WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_RESP:
1619 ieee80211_process_epcs_ena_resp(sdata, mgmt,
1622 case WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_TEARDOWN:
1623 ieee80211_process_epcs_teardown(sdata, mgmt,
1630 } else if (ieee80211_is_ext(mgmt->frame_control)) {
1631 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1632 ieee80211_sta_rx_queued_ext(sdata, skb);
1635 } else if (ieee80211_is_data_qos(mgmt->frame_control)) {
1636 struct ieee80211_hdr *hdr = (void *)mgmt;
1637 struct sta_info *sta;
1640 * So the frame isn't mgmt, but frame_control
1641 * is at the right place anyway, of course, so
1642 * the if statement is correct.
1644 * Warn if we have other data frame types here,
1645 * they must not get here.
1647 WARN_ON(hdr->frame_control &
1648 cpu_to_le16(IEEE80211_STYPE_NULLFUNC));
1649 WARN_ON(!(hdr->seq_ctrl &
1650 cpu_to_le16(IEEE80211_SCTL_FRAG)));
1652 * This was a fragment of a frame, received while
1653 * a block-ack session was active. That cannot be
1654 * right, so terminate the session.
1656 sta = sta_info_get_bss(sdata, mgmt->sa);
1658 u16 tid = ieee80211_get_tid(hdr);
1660 __ieee80211_stop_rx_ba_session(
1661 sta, tid, WLAN_BACK_RECIPIENT,
1662 WLAN_REASON_QSTA_REQUIRE_SETUP,
1665 } else switch (sdata->vif.type) {
1666 case NL80211_IFTYPE_STATION:
1667 ieee80211_sta_rx_queued_mgmt(sdata, skb);
1669 case NL80211_IFTYPE_ADHOC:
1670 ieee80211_ibss_rx_queued_mgmt(sdata, skb);
1672 case NL80211_IFTYPE_MESH_POINT:
1673 if (!ieee80211_vif_is_mesh(&sdata->vif))
1675 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1678 WARN(1, "frame for unexpected interface type");
1683 static void ieee80211_iface_process_status(struct ieee80211_sub_if_data *sdata,
1684 struct sk_buff *skb)
1686 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1688 if (ieee80211_is_action(mgmt->frame_control) &&
1689 mgmt->u.action.category == WLAN_CATEGORY_S1G) {
1690 switch (mgmt->u.action.u.s1g.action_code) {
1691 case WLAN_S1G_TWT_TEARDOWN:
1692 case WLAN_S1G_TWT_SETUP:
1693 ieee80211_s1g_status_twt_action(sdata, skb);
1701 static void ieee80211_iface_work(struct wiphy *wiphy, struct wiphy_work *work)
1703 struct ieee80211_sub_if_data *sdata =
1704 container_of(work, struct ieee80211_sub_if_data, work);
1705 struct ieee80211_local *local = sdata->local;
1706 struct sk_buff *skb;
1708 if (!ieee80211_sdata_running(sdata))
1711 if (test_bit(SCAN_SW_SCANNING, &local->scanning))
1714 if (!ieee80211_can_run_worker(local))
1717 /* first process frames */
1718 while ((skb = skb_dequeue(&sdata->skb_queue))) {
1719 kcov_remote_start_common(skb_get_kcov_handle(skb));
1721 if (skb->protocol == cpu_to_be16(ETH_P_TDLS))
1722 ieee80211_process_tdls_channel_switch(sdata, skb);
1724 ieee80211_iface_process_skb(local, sdata, skb);
1730 /* process status queue */
1731 while ((skb = skb_dequeue(&sdata->status_queue))) {
1732 kcov_remote_start_common(skb_get_kcov_handle(skb));
1734 ieee80211_iface_process_status(sdata, skb);
1740 /* then other type-dependent work */
1741 switch (sdata->vif.type) {
1742 case NL80211_IFTYPE_STATION:
1743 ieee80211_sta_work(sdata);
1745 case NL80211_IFTYPE_ADHOC:
1746 ieee80211_ibss_work(sdata);
1748 case NL80211_IFTYPE_MESH_POINT:
1749 if (!ieee80211_vif_is_mesh(&sdata->vif))
1751 ieee80211_mesh_work(sdata);
1753 case NL80211_IFTYPE_OCB:
1754 ieee80211_ocb_work(sdata);
1761 static void ieee80211_activate_links_work(struct wiphy *wiphy,
1762 struct wiphy_work *work)
1764 struct ieee80211_sub_if_data *sdata =
1765 container_of(work, struct ieee80211_sub_if_data,
1766 activate_links_work);
1767 struct ieee80211_local *local = wiphy_priv(wiphy);
1769 if (local->in_reconfig)
1772 ieee80211_set_active_links(&sdata->vif, sdata->desired_active_links);
1773 sdata->desired_active_links = 0;
1777 * Helper function to initialise an interface to a specific type.
1779 static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1780 enum nl80211_iftype type)
1782 static const u8 bssid_wildcard[ETH_ALEN] = {0xff, 0xff, 0xff,
1785 /* clear type-dependent unions */
1786 memset(&sdata->u, 0, sizeof(sdata->u));
1787 memset(&sdata->deflink.u, 0, sizeof(sdata->deflink.u));
1789 /* and set some type-dependent values */
1790 sdata->vif.type = type;
1791 sdata->vif.p2p = false;
1792 sdata->wdev.iftype = type;
1794 sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
1795 sdata->control_port_no_encrypt = false;
1796 sdata->control_port_over_nl80211 = false;
1797 sdata->control_port_no_preauth = false;
1798 sdata->vif.cfg.idle = true;
1799 sdata->vif.bss_conf.txpower = INT_MIN; /* unset */
1801 sdata->noack_map = 0;
1803 /* only monitor/p2p-device differ */
1805 sdata->dev->netdev_ops = &ieee80211_dataif_ops;
1806 sdata->dev->type = ARPHRD_ETHER;
1809 skb_queue_head_init(&sdata->skb_queue);
1810 skb_queue_head_init(&sdata->status_queue);
1811 wiphy_work_init(&sdata->work, ieee80211_iface_work);
1812 wiphy_work_init(&sdata->activate_links_work,
1813 ieee80211_activate_links_work);
1816 case NL80211_IFTYPE_P2P_GO:
1817 type = NL80211_IFTYPE_AP;
1818 sdata->vif.type = type;
1819 sdata->vif.p2p = true;
1821 case NL80211_IFTYPE_AP:
1822 skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
1823 INIT_LIST_HEAD(&sdata->u.ap.vlans);
1824 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1826 case NL80211_IFTYPE_P2P_CLIENT:
1827 type = NL80211_IFTYPE_STATION;
1828 sdata->vif.type = type;
1829 sdata->vif.p2p = true;
1831 case NL80211_IFTYPE_STATION:
1832 sdata->vif.bss_conf.bssid = sdata->deflink.u.mgd.bssid;
1833 ieee80211_sta_setup_sdata(sdata);
1835 case NL80211_IFTYPE_OCB:
1836 sdata->vif.bss_conf.bssid = bssid_wildcard;
1837 ieee80211_ocb_setup_sdata(sdata);
1839 case NL80211_IFTYPE_ADHOC:
1840 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
1841 ieee80211_ibss_setup_sdata(sdata);
1843 case NL80211_IFTYPE_MESH_POINT:
1844 if (ieee80211_vif_is_mesh(&sdata->vif))
1845 ieee80211_mesh_init_sdata(sdata);
1847 case NL80211_IFTYPE_MONITOR:
1848 sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
1849 sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
1850 sdata->u.mntr.flags = MONITOR_FLAG_CONTROL |
1851 MONITOR_FLAG_OTHER_BSS;
1853 case NL80211_IFTYPE_NAN:
1854 idr_init(&sdata->u.nan.function_inst_ids);
1855 spin_lock_init(&sdata->u.nan.func_lock);
1856 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1858 case NL80211_IFTYPE_AP_VLAN:
1859 case NL80211_IFTYPE_P2P_DEVICE:
1860 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1862 case NL80211_IFTYPE_UNSPECIFIED:
1863 case NL80211_IFTYPE_WDS:
1864 case NUM_NL80211_IFTYPES:
1869 /* need to do this after the switch so vif.type is correct */
1870 ieee80211_link_setup(&sdata->deflink);
1872 ieee80211_debugfs_recreate_netdev(sdata, false);
1875 static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
1876 enum nl80211_iftype type)
1878 struct ieee80211_local *local = sdata->local;
1880 enum nl80211_iftype internal_type = type;
1885 if (!local->ops->change_interface)
1888 /* for now, don't support changing while links exist */
1889 if (ieee80211_vif_is_mld(&sdata->vif))
1892 switch (sdata->vif.type) {
1893 case NL80211_IFTYPE_AP:
1894 if (!list_empty(&sdata->u.ap.vlans))
1897 case NL80211_IFTYPE_STATION:
1898 case NL80211_IFTYPE_ADHOC:
1899 case NL80211_IFTYPE_OCB:
1901 * Could maybe also all others here?
1902 * Just not sure how that interacts
1903 * with the RX/config path e.g. for
1912 case NL80211_IFTYPE_AP:
1913 case NL80211_IFTYPE_STATION:
1914 case NL80211_IFTYPE_ADHOC:
1915 case NL80211_IFTYPE_OCB:
1917 * Could probably support everything
1921 case NL80211_IFTYPE_P2P_CLIENT:
1923 internal_type = NL80211_IFTYPE_STATION;
1925 case NL80211_IFTYPE_P2P_GO:
1927 internal_type = NL80211_IFTYPE_AP;
1933 ret = ieee80211_check_concurrent_iface(sdata, internal_type);
1937 ieee80211_stop_vif_queues(local, sdata,
1938 IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE);
1939 /* do_stop will synchronize_rcu() first thing */
1940 ieee80211_do_stop(sdata, false);
1942 ieee80211_teardown_sdata(sdata);
1944 ieee80211_set_sdata_offload_flags(sdata);
1945 ret = drv_change_interface(local, sdata, internal_type, p2p);
1947 type = ieee80211_vif_type_p2p(&sdata->vif);
1950 * Ignore return value here, there's not much we can do since
1951 * the driver changed the interface type internally already.
1952 * The warnings will hopefully make driver authors fix it :-)
1954 ieee80211_check_queues(sdata, type);
1956 ieee80211_setup_sdata(sdata, type);
1957 ieee80211_set_vif_encap_ops(sdata);
1959 err = ieee80211_do_open(&sdata->wdev, false);
1960 WARN(err, "type change: do_open returned %d", err);
1962 ieee80211_wake_vif_queues(local, sdata,
1963 IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE);
1967 int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
1968 enum nl80211_iftype type)
1974 if (type == ieee80211_vif_type_p2p(&sdata->vif))
1977 if (ieee80211_sdata_running(sdata)) {
1978 ret = ieee80211_runtime_change_iftype(sdata, type);
1982 /* Purge and reset type-dependent state. */
1983 ieee80211_teardown_sdata(sdata);
1984 ieee80211_setup_sdata(sdata, type);
1987 /* reset some values that shouldn't be kept across type changes */
1988 if (type == NL80211_IFTYPE_STATION)
1989 sdata->u.mgd.use_4addr = false;
1994 static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
1995 u8 *perm_addr, enum nl80211_iftype type)
1997 struct ieee80211_sub_if_data *sdata;
1998 u64 mask, start, addr, val, inc;
2000 u8 tmp_addr[ETH_ALEN];
2003 lockdep_assert_wiphy(local->hw.wiphy);
2005 /* default ... something at least */
2006 memcpy(perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
2008 if (is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
2009 local->hw.wiphy->n_addresses <= 1)
2013 case NL80211_IFTYPE_MONITOR:
2014 /* doesn't matter */
2016 case NL80211_IFTYPE_AP_VLAN:
2017 /* match up with an AP interface */
2018 list_for_each_entry(sdata, &local->interfaces, list) {
2019 if (sdata->vif.type != NL80211_IFTYPE_AP)
2021 memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
2024 /* keep default if no AP interface present */
2026 case NL80211_IFTYPE_P2P_CLIENT:
2027 case NL80211_IFTYPE_P2P_GO:
2028 if (ieee80211_hw_check(&local->hw, P2P_DEV_ADDR_FOR_INTF)) {
2029 list_for_each_entry(sdata, &local->interfaces, list) {
2030 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE)
2032 if (!ieee80211_sdata_running(sdata))
2034 memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
2040 /* assign a new address if possible -- try n_addresses first */
2041 for (i = 0; i < local->hw.wiphy->n_addresses; i++) {
2044 list_for_each_entry(sdata, &local->interfaces, list) {
2045 if (ether_addr_equal(local->hw.wiphy->addresses[i].addr,
2054 local->hw.wiphy->addresses[i].addr,
2060 /* try mask if available */
2061 if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
2064 m = local->hw.wiphy->addr_mask;
2065 mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
2066 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
2067 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
2069 if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
2070 /* not a contiguous mask ... not handled now! */
2071 pr_info("not contiguous\n");
2076 * Pick address of existing interface in case user changed
2077 * MAC address manually, default to perm_addr.
2079 m = local->hw.wiphy->perm_addr;
2080 list_for_each_entry(sdata, &local->interfaces, list) {
2081 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2083 m = sdata->vif.addr;
2086 start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
2087 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
2088 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
2090 inc = 1ULL<<__ffs64(mask);
2091 val = (start & mask);
2092 addr = (start & ~mask) | (val & mask);
2096 tmp_addr[5] = addr >> 0*8;
2097 tmp_addr[4] = addr >> 1*8;
2098 tmp_addr[3] = addr >> 2*8;
2099 tmp_addr[2] = addr >> 3*8;
2100 tmp_addr[1] = addr >> 4*8;
2101 tmp_addr[0] = addr >> 5*8;
2105 list_for_each_entry(sdata, &local->interfaces, list) {
2106 if (ether_addr_equal(tmp_addr, sdata->vif.addr)) {
2113 memcpy(perm_addr, tmp_addr, ETH_ALEN);
2116 addr = (start & ~mask) | (val & mask);
2117 } while (addr != start);
2123 int ieee80211_if_add(struct ieee80211_local *local, const char *name,
2124 unsigned char name_assign_type,
2125 struct wireless_dev **new_wdev, enum nl80211_iftype type,
2126 struct vif_params *params)
2128 struct net_device *ndev = NULL;
2129 struct ieee80211_sub_if_data *sdata = NULL;
2130 struct txq_info *txqi;
2134 lockdep_assert_wiphy(local->hw.wiphy);
2136 if (type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN) {
2137 struct wireless_dev *wdev;
2139 sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size,
2143 wdev = &sdata->wdev;
2146 strscpy(sdata->name, name, IFNAMSIZ);
2147 ieee80211_assign_perm_addr(local, wdev->address, type);
2148 memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
2149 ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr);
2151 int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size,
2155 if (type != NL80211_IFTYPE_AP_VLAN &&
2156 (type != NL80211_IFTYPE_MONITOR ||
2157 (params->flags & MONITOR_FLAG_ACTIVE)))
2158 txq_size += sizeof(struct txq_info) +
2159 local->hw.txq_data_size;
2161 ndev = alloc_netdev_mqs(size + txq_size,
2162 name, name_assign_type,
2163 ieee80211_if_setup, 1, 1);
2167 dev_net_set(ndev, wiphy_net(local->hw.wiphy));
2169 ndev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
2171 ndev->needed_headroom = local->tx_headroom +
2172 4*6 /* four MAC addresses */
2173 + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
2175 + 8 /* rfc1042/bridge tunnel */
2176 - ETH_HLEN /* ethernet hard_header_len */
2177 + IEEE80211_ENCRYPT_HEADROOM;
2178 ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
2180 ret = dev_alloc_name(ndev, ndev->name);
2186 ieee80211_assign_perm_addr(local, ndev->perm_addr, type);
2187 if (is_valid_ether_addr(params->macaddr))
2188 eth_hw_addr_set(ndev, params->macaddr);
2190 eth_hw_addr_set(ndev, ndev->perm_addr);
2191 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
2193 /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */
2194 sdata = netdev_priv(ndev);
2195 ndev->ieee80211_ptr = &sdata->wdev;
2196 memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
2197 ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr);
2198 memcpy(sdata->name, ndev->name, IFNAMSIZ);
2201 txqi = netdev_priv(ndev) + size;
2202 ieee80211_txq_init(sdata, NULL, txqi, 0);
2208 /* initialise type-independent data */
2209 sdata->wdev.wiphy = local->hw.wiphy;
2211 ieee80211_sdata_init(local, sdata);
2213 ieee80211_init_frag_cache(&sdata->frags);
2215 wiphy_delayed_work_init(&sdata->dec_tailroom_needed_wk,
2216 ieee80211_delayed_tailroom_dec);
2218 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2219 struct ieee80211_supported_band *sband;
2220 sband = local->hw.wiphy->bands[i];
2221 sdata->rc_rateidx_mask[i] =
2222 sband ? (1 << sband->n_bitrates) - 1 : 0;
2227 memcpy(sdata->rc_rateidx_mcs_mask[i],
2228 sband->ht_cap.mcs.rx_mask,
2229 sizeof(sdata->rc_rateidx_mcs_mask[i]));
2231 cap = sband->vht_cap.vht_mcs.rx_mcs_map;
2232 vht_rate_mask = sdata->rc_rateidx_vht_mcs_mask[i];
2233 ieee80211_get_vht_mask_from_cap(cap, vht_rate_mask);
2235 memset(sdata->rc_rateidx_mcs_mask[i], 0,
2236 sizeof(sdata->rc_rateidx_mcs_mask[i]));
2237 memset(sdata->rc_rateidx_vht_mcs_mask[i], 0,
2238 sizeof(sdata->rc_rateidx_vht_mcs_mask[i]));
2242 ieee80211_set_default_queues(sdata);
2244 /* setup type-dependent data */
2245 ieee80211_setup_sdata(sdata, type);
2248 ndev->ieee80211_ptr->use_4addr = params->use_4addr;
2249 if (type == NL80211_IFTYPE_STATION)
2250 sdata->u.mgd.use_4addr = params->use_4addr;
2252 ndev->features |= local->hw.netdev_features;
2253 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
2254 ndev->hw_features |= ndev->features &
2255 MAC80211_SUPPORTED_FEATURES_TX;
2256 sdata->vif.netdev_features = local->hw.netdev_features;
2258 netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops);
2260 /* MTU range is normally 256 - 2304, where the upper limit is
2261 * the maximum MSDU size. Monitor interfaces send and receive
2262 * MPDU and A-MSDU frames which may be much larger so we do
2263 * not impose an upper limit in that case.
2265 ndev->min_mtu = 256;
2266 if (type == NL80211_IFTYPE_MONITOR)
2269 ndev->max_mtu = local->hw.max_mtu;
2271 ret = cfg80211_register_netdevice(ndev);
2278 mutex_lock(&local->iflist_mtx);
2279 list_add_tail_rcu(&sdata->list, &local->interfaces);
2280 mutex_unlock(&local->iflist_mtx);
2283 *new_wdev = &sdata->wdev;
2288 void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
2291 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2293 mutex_lock(&sdata->local->iflist_mtx);
2294 list_del_rcu(&sdata->list);
2295 mutex_unlock(&sdata->local->iflist_mtx);
2298 ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq));
2302 cfg80211_unregister_wdev(&sdata->wdev);
2305 ieee80211_teardown_sdata(sdata);
2310 void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata)
2312 if (WARN_ON_ONCE(!test_bit(SDATA_STATE_RUNNING, &sdata->state)))
2314 ieee80211_do_stop(sdata, true);
2317 void ieee80211_remove_interfaces(struct ieee80211_local *local)
2319 struct ieee80211_sub_if_data *sdata, *tmp;
2320 LIST_HEAD(unreg_list);
2324 /* Before destroying the interfaces, make sure they're all stopped so
2325 * that the hardware is stopped. Otherwise, the driver might still be
2326 * iterating the interfaces during the shutdown, e.g. from a worker
2327 * or from RX processing or similar, and if it does so (using atomic
2328 * iteration) while we're manipulating the list, the iteration will
2331 * After this, the hardware should be stopped and the driver should
2332 * have stopped all of its activities, so that we can do RCU-unaware
2333 * manipulations of the interface list below.
2335 cfg80211_shutdown_all_interfaces(local->hw.wiphy);
2337 guard(wiphy)(local->hw.wiphy);
2339 WARN(local->open_count, "%s: open count remains %d\n",
2340 wiphy_name(local->hw.wiphy), local->open_count);
2342 mutex_lock(&local->iflist_mtx);
2343 list_splice_init(&local->interfaces, &unreg_list);
2344 mutex_unlock(&local->iflist_mtx);
2346 list_for_each_entry_safe(sdata, tmp, &unreg_list, list) {
2347 bool netdev = sdata->dev;
2350 * Remove IP addresses explicitly, since the notifier will
2351 * skip the callbacks if wdev->registered is false, since
2352 * we can't acquire the wiphy_lock() again there if already
2353 * inside this locked section.
2355 sdata->vif.cfg.arp_addr_cnt = 0;
2356 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2357 sdata->u.mgd.associated)
2358 ieee80211_vif_cfg_change_notify(sdata,
2359 BSS_CHANGED_ARP_FILTER);
2361 list_del(&sdata->list);
2362 cfg80211_unregister_wdev(&sdata->wdev);
2369 static int netdev_notify(struct notifier_block *nb,
2370 unsigned long state, void *ptr)
2372 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
2373 struct ieee80211_sub_if_data *sdata;
2375 if (state != NETDEV_CHANGENAME)
2378 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
2381 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
2384 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2385 memcpy(sdata->name, dev->name, IFNAMSIZ);
2386 ieee80211_debugfs_rename_netdev(sdata);
2391 static struct notifier_block mac80211_netdev_notifier = {
2392 .notifier_call = netdev_notify,
2395 int ieee80211_iface_init(void)
2397 return register_netdevice_notifier(&mac80211_netdev_notifier);
2400 void ieee80211_iface_exit(void)
2402 unregister_netdevice_notifier(&mac80211_netdev_notifier);
2405 void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata)
2407 if (sdata->vif.type == NL80211_IFTYPE_AP)
2408 atomic_inc(&sdata->u.ap.num_mcast_sta);
2409 else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2410 atomic_inc(&sdata->u.vlan.num_mcast_sta);
2413 void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata)
2415 if (sdata->vif.type == NL80211_IFTYPE_AP)
2416 atomic_dec(&sdata->u.ap.num_mcast_sta);
2417 else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2418 atomic_dec(&sdata->u.vlan.num_mcast_sta);
2421 void ieee80211_vif_block_queues_csa(struct ieee80211_sub_if_data *sdata)
2423 struct ieee80211_local *local = sdata->local;
2425 if (ieee80211_hw_check(&local->hw, HANDLES_QUIET_CSA))
2428 ieee80211_stop_vif_queues_norefcount(local, sdata,
2429 IEEE80211_QUEUE_STOP_REASON_CSA);
2432 void ieee80211_vif_unblock_queues_csa(struct ieee80211_sub_if_data *sdata)
2434 struct ieee80211_local *local = sdata->local;
2436 ieee80211_wake_vif_queues_norefcount(local, sdata,
2437 IEEE80211_QUEUE_STOP_REASON_CSA);