1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2002-2005, Instant802 Networks, Inc.
6 * Copyright 2005-2006, Devicescape Software, Inc.
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (c) 2016 Intel Deutschland GmbH
11 * Copyright (C) 2018-2022 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
37 * (2) modifications and readers are protected against each other by
39 * (3) modifications are done in an RCU manner so atomic readers
40 * can traverse the list in RCU-safe blocks.
42 * As a consequence, reads (traversals) of the list can be protected
43 * by either the RTNL, the iflist_mtx or RCU.
46 static void ieee80211_iface_work(struct work_struct *work);
48 bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
50 struct ieee80211_chanctx_conf *chanctx_conf;
54 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
60 power = ieee80211_chandef_max_power(&chanctx_conf->def);
63 if (sdata->deflink.user_power_level != IEEE80211_UNSET_POWER_LEVEL)
64 power = min(power, sdata->deflink.user_power_level);
66 if (sdata->deflink.ap_power_level != IEEE80211_UNSET_POWER_LEVEL)
67 power = min(power, sdata->deflink.ap_power_level);
69 if (power != sdata->vif.bss_conf.txpower) {
70 sdata->vif.bss_conf.txpower = power;
71 ieee80211_hw_config(sdata->local, 0);
78 void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata,
81 if (__ieee80211_recalc_txpower(sdata) ||
82 (update_bss && ieee80211_sdata_running(sdata)))
83 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
87 static u32 __ieee80211_idle_off(struct ieee80211_local *local)
89 if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
92 local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
93 return IEEE80211_CONF_CHANGE_IDLE;
96 static u32 __ieee80211_idle_on(struct ieee80211_local *local)
98 if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
101 ieee80211_flush_queues(local, NULL, false);
103 local->hw.conf.flags |= IEEE80211_CONF_IDLE;
104 return IEEE80211_CONF_CHANGE_IDLE;
107 static u32 __ieee80211_recalc_idle(struct ieee80211_local *local,
110 bool working, scanning, active;
111 unsigned int led_trig_start = 0, led_trig_stop = 0;
113 lockdep_assert_held(&local->mtx);
115 active = force_active ||
116 !list_empty(&local->chanctx_list) ||
119 working = !local->ops->remain_on_channel &&
120 !list_empty(&local->roc_list);
122 scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) ||
123 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
125 if (working || scanning)
126 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
128 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
131 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
133 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
135 ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
137 if (working || scanning || active)
138 return __ieee80211_idle_off(local);
139 return __ieee80211_idle_on(local);
142 u32 ieee80211_idle_off(struct ieee80211_local *local)
144 return __ieee80211_recalc_idle(local, true);
147 void ieee80211_recalc_idle(struct ieee80211_local *local)
149 u32 change = __ieee80211_recalc_idle(local, false);
151 ieee80211_hw_config(local, change);
154 static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 *addr,
157 struct ieee80211_local *local = sdata->local;
158 struct ieee80211_sub_if_data *iter;
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 mutex_lock(&local->iflist_mtx);
180 list_for_each_entry(iter, &local->interfaces, list) {
184 if (iter->vif.type == NL80211_IFTYPE_MONITOR &&
185 !(iter->u.mntr.flags & MONITOR_FLAG_ACTIVE))
189 tmp = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
190 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
191 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
193 if ((new & ~mask) != (tmp & ~mask)) {
198 mutex_unlock(&local->iflist_mtx);
203 static int ieee80211_can_powered_addr_change(struct ieee80211_sub_if_data *sdata)
205 struct ieee80211_roc_work *roc;
206 struct ieee80211_local *local = sdata->local;
207 struct ieee80211_sub_if_data *scan_sdata;
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 mutex_lock(&local->mtx);
219 /* First check no ROC work is happening on this iface */
220 list_for_each_entry(roc, &local->roc_list, list) {
221 if (roc->sdata != sdata)
230 /* And if this iface is scanning */
231 if (local->scanning) {
232 scan_sdata = rcu_dereference_protected(local->scan_sdata,
233 lockdep_is_held(&local->mtx));
234 if (sdata == scan_sdata)
238 switch (sdata->vif.type) {
239 case NL80211_IFTYPE_STATION:
240 case NL80211_IFTYPE_P2P_CLIENT:
241 /* More interface types could be added here but changing the
242 * address while powered makes the most sense in client modes.
250 mutex_unlock(&local->mtx);
254 static int ieee80211_change_mac(struct net_device *dev, void *addr)
256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
257 struct ieee80211_local *local = sdata->local;
258 struct sockaddr *sa = addr;
259 bool check_dup = true;
263 if (ieee80211_sdata_running(sdata)) {
264 ret = ieee80211_can_powered_addr_change(sdata);
271 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
272 !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
275 ret = ieee80211_verify_mac(sdata, sa->sa_data, check_dup);
280 drv_remove_interface(local, sdata);
281 ret = eth_mac_addr(dev, sa);
284 memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
285 ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr);
288 /* Regardless of eth_mac_addr() return we still want to add the
289 * interface back. This should not fail...
292 WARN_ON(drv_add_interface(local, sdata));
297 static inline int identical_mac_addr_allowed(int type1, int type2)
299 return type1 == NL80211_IFTYPE_MONITOR ||
300 type2 == NL80211_IFTYPE_MONITOR ||
301 type1 == NL80211_IFTYPE_P2P_DEVICE ||
302 type2 == NL80211_IFTYPE_P2P_DEVICE ||
303 (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
304 (type1 == NL80211_IFTYPE_AP_VLAN &&
305 (type2 == NL80211_IFTYPE_AP ||
306 type2 == NL80211_IFTYPE_AP_VLAN));
309 static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
310 enum nl80211_iftype iftype)
312 struct ieee80211_local *local = sdata->local;
313 struct ieee80211_sub_if_data *nsdata;
318 /* we hold the RTNL here so can safely walk the list */
319 list_for_each_entry(nsdata, &local->interfaces, list) {
320 if (nsdata != sdata && ieee80211_sdata_running(nsdata)) {
322 * Only OCB and monitor mode may coexist
324 if ((sdata->vif.type == NL80211_IFTYPE_OCB &&
325 nsdata->vif.type != NL80211_IFTYPE_MONITOR) ||
326 (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
327 nsdata->vif.type == NL80211_IFTYPE_OCB))
331 * Allow only a single IBSS interface to be up at any
332 * time. This is restricted because beacon distribution
333 * cannot work properly if both are in the same IBSS.
335 * To remove this restriction we'd have to disallow them
336 * from setting the same SSID on different IBSS interfaces
337 * belonging to the same hardware. Then, however, we're
338 * faced with having to adopt two different TSF timers...
340 if (iftype == NL80211_IFTYPE_ADHOC &&
341 nsdata->vif.type == NL80211_IFTYPE_ADHOC)
344 * will not add another interface while any channel
347 if (nsdata->vif.bss_conf.csa_active)
351 * The remaining checks are only performed for interfaces
352 * with the same MAC address.
354 if (!ether_addr_equal(sdata->vif.addr,
359 * check whether it may have the same address
361 if (!identical_mac_addr_allowed(iftype,
365 /* No support for VLAN with MLO yet */
366 if (iftype == NL80211_IFTYPE_AP_VLAN &&
367 nsdata->wdev.use_4addr)
371 * can only add VLANs to enabled APs
373 if (iftype == NL80211_IFTYPE_AP_VLAN &&
374 nsdata->vif.type == NL80211_IFTYPE_AP)
375 sdata->bss = &nsdata->u.ap;
379 mutex_lock(&local->chanctx_mtx);
380 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
381 mutex_unlock(&local->chanctx_mtx);
385 static int ieee80211_check_queues(struct ieee80211_sub_if_data *sdata,
386 enum nl80211_iftype iftype)
388 int n_queues = sdata->local->hw.queues;
391 if (iftype == NL80211_IFTYPE_NAN)
394 if (iftype != NL80211_IFTYPE_P2P_DEVICE) {
395 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
396 if (WARN_ON_ONCE(sdata->vif.hw_queue[i] ==
397 IEEE80211_INVAL_HW_QUEUE))
399 if (WARN_ON_ONCE(sdata->vif.hw_queue[i] >=
405 if ((iftype != NL80211_IFTYPE_AP &&
406 iftype != NL80211_IFTYPE_P2P_GO &&
407 iftype != NL80211_IFTYPE_MESH_POINT) ||
408 !ieee80211_hw_check(&sdata->local->hw, QUEUE_CONTROL)) {
409 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
413 if (WARN_ON_ONCE(sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE))
416 if (WARN_ON_ONCE(sdata->vif.cab_queue >= n_queues))
422 static int ieee80211_open(struct net_device *dev)
424 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
427 /* fail early if user set an invalid address */
428 if (!is_valid_ether_addr(dev->dev_addr))
429 return -EADDRNOTAVAIL;
431 err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
435 wiphy_lock(sdata->local->hw.wiphy);
436 err = ieee80211_do_open(&sdata->wdev, true);
437 wiphy_unlock(sdata->local->hw.wiphy);
442 static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_down)
444 struct ieee80211_local *local = sdata->local;
446 struct sk_buff *skb, *tmp;
447 u32 hw_reconf_flags = 0;
450 struct cfg80211_chan_def chandef;
452 struct cfg80211_nan_func *func;
454 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
455 synchronize_rcu(); /* flush _ieee80211_wake_txqs() */
457 cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
459 ieee80211_scan_cancel(local);
461 ieee80211_roc_purge(local, sdata);
463 switch (sdata->vif.type) {
464 case NL80211_IFTYPE_STATION:
465 ieee80211_mgd_stop(sdata);
467 case NL80211_IFTYPE_ADHOC:
468 ieee80211_ibss_stop(sdata);
470 case NL80211_IFTYPE_MONITOR:
471 if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
473 list_del_rcu(&sdata->u.mntr.list);
480 * Remove all stations associated with this interface.
482 * This must be done before calling ops->remove_interface()
483 * because otherwise we can later invoke ops->sta_notify()
484 * whenever the STAs are removed, and that invalidates driver
485 * assumptions about always getting a vif pointer that is valid
486 * (because if we remove a STA after ops->remove_interface()
487 * the driver will have removed the vif info already!)
489 * For AP_VLANs stations may exist since there's nothing else that
490 * would have removed them, but in other modes there shouldn't
493 flushed = sta_info_flush(sdata);
494 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN && flushed > 0);
496 /* don't count this interface for allmulti while it is down */
497 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
498 atomic_dec(&local->iff_allmultis);
500 if (sdata->vif.type == NL80211_IFTYPE_AP) {
502 local->fif_probe_req--;
503 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
504 local->fif_probe_req--;
508 netif_addr_lock_bh(sdata->dev);
509 spin_lock_bh(&local->filter_lock);
510 __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
511 sdata->dev->addr_len);
512 spin_unlock_bh(&local->filter_lock);
513 netif_addr_unlock_bh(sdata->dev);
516 del_timer_sync(&local->dynamic_ps_timer);
517 cancel_work_sync(&local->dynamic_ps_enable_work);
519 cancel_work_sync(&sdata->recalc_smps);
522 WARN(sdata->vif.valid_links,
523 "destroying interface with valid links 0x%04x\n",
524 sdata->vif.valid_links);
526 mutex_lock(&local->mtx);
527 sdata->vif.bss_conf.csa_active = false;
528 if (sdata->vif.type == NL80211_IFTYPE_STATION)
529 sdata->deflink.u.mgd.csa_waiting_bcn = false;
530 if (sdata->deflink.csa_block_tx) {
531 ieee80211_wake_vif_queues(local, sdata,
532 IEEE80211_QUEUE_STOP_REASON_CSA);
533 sdata->deflink.csa_block_tx = false;
535 mutex_unlock(&local->mtx);
538 cancel_work_sync(&sdata->deflink.csa_finalize_work);
539 cancel_work_sync(&sdata->deflink.color_change_finalize_work);
541 cancel_delayed_work_sync(&sdata->deflink.dfs_cac_timer_work);
543 if (sdata->wdev.cac_started) {
544 chandef = sdata->vif.bss_conf.chandef;
545 WARN_ON(local->suspended);
546 mutex_lock(&local->mtx);
547 ieee80211_link_release_channel(&sdata->deflink);
548 mutex_unlock(&local->mtx);
549 cfg80211_cac_event(sdata->dev, &chandef,
550 NL80211_RADAR_CAC_ABORTED,
554 if (sdata->vif.type == NL80211_IFTYPE_AP) {
555 WARN_ON(!list_empty(&sdata->u.ap.vlans));
556 } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
557 /* remove all packets in parent bc_buf pointing to this dev */
558 ps = &sdata->bss->ps;
560 spin_lock_irqsave(&ps->bc_buf.lock, flags);
561 skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
562 if (skb->dev == sdata->dev) {
563 __skb_unlink(skb, &ps->bc_buf);
564 local->total_ps_buffered--;
565 ieee80211_free_txskb(&local->hw, skb);
568 spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
574 switch (sdata->vif.type) {
575 case NL80211_IFTYPE_AP_VLAN:
576 mutex_lock(&local->mtx);
577 list_del(&sdata->u.vlan.list);
578 mutex_unlock(&local->mtx);
579 RCU_INIT_POINTER(sdata->vif.bss_conf.chanctx_conf, NULL);
580 /* see comment in the default case below */
581 ieee80211_free_keys(sdata, true);
582 /* no need to tell driver */
584 case NL80211_IFTYPE_MONITOR:
585 if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
586 local->cooked_mntrs--;
591 if (local->monitors == 0) {
592 local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
593 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
596 ieee80211_adjust_monitor_flags(sdata, -1);
598 case NL80211_IFTYPE_NAN:
599 /* clean all the functions */
600 spin_lock_bh(&sdata->u.nan.func_lock);
602 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
603 idr_remove(&sdata->u.nan.function_inst_ids, i);
604 cfg80211_free_nan_func(func);
606 idr_destroy(&sdata->u.nan.function_inst_ids);
608 spin_unlock_bh(&sdata->u.nan.func_lock);
610 case NL80211_IFTYPE_P2P_DEVICE:
611 /* relies on synchronize_rcu() below */
612 RCU_INIT_POINTER(local->p2p_sdata, NULL);
615 cancel_work_sync(&sdata->work);
617 * When we get here, the interface is marked down.
618 * Free the remaining keys, if there are any
619 * (which can happen in AP mode if userspace sets
620 * keys before the interface is operating)
622 * Force the key freeing to always synchronize_net()
623 * to wait for the RX path in case it is using this
624 * interface enqueuing frames at this very time on
627 ieee80211_free_keys(sdata, true);
628 skb_queue_purge(&sdata->skb_queue);
629 skb_queue_purge(&sdata->status_queue);
632 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
633 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
634 skb_queue_walk_safe(&local->pending[i], skb, tmp) {
635 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
636 if (info->control.vif == &sdata->vif) {
637 __skb_unlink(skb, &local->pending[i]);
638 ieee80211_free_txskb(&local->hw, skb);
642 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
644 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
645 ieee80211_txq_remove_vlan(local, sdata);
649 if (local->open_count == 0)
650 ieee80211_clear_tx_pending(local);
652 sdata->vif.bss_conf.beacon_int = 0;
655 * If the interface goes down while suspended, presumably because
656 * the device was unplugged and that happens before our resume,
657 * then the driver is already unconfigured and the remainder of
658 * this function isn't needed.
659 * XXX: what about WoWLAN? If the device has software state, e.g.
660 * memory allocated, it might expect teardown commands from
663 if (local->suspended) {
664 WARN_ON(local->wowlan);
665 WARN_ON(rcu_access_pointer(local->monitor_sdata));
669 switch (sdata->vif.type) {
670 case NL80211_IFTYPE_AP_VLAN:
672 case NL80211_IFTYPE_MONITOR:
673 if (local->monitors == 0)
674 ieee80211_del_virtual_monitor(local);
676 mutex_lock(&local->mtx);
677 ieee80211_recalc_idle(local);
678 mutex_unlock(&local->mtx);
680 if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
686 drv_remove_interface(local, sdata);
689 ieee80211_recalc_ps(local);
692 flush_delayed_work(&local->scan_work);
694 if (local->open_count == 0) {
695 ieee80211_stop_device(local);
697 /* no reconfiguring after stop! */
701 /* do after stop to avoid reconfiguring when we stop anyway */
702 ieee80211_configure_filter(local);
703 ieee80211_hw_config(local, hw_reconf_flags);
705 if (local->monitors == local->open_count)
706 ieee80211_add_virtual_monitor(local);
709 static void ieee80211_stop_mbssid(struct ieee80211_sub_if_data *sdata)
711 struct ieee80211_sub_if_data *tx_sdata, *non_tx_sdata, *tmp_sdata;
712 struct ieee80211_vif *tx_vif = sdata->vif.mbssid_tx_vif;
717 tx_sdata = vif_to_sdata(tx_vif);
718 sdata->vif.mbssid_tx_vif = NULL;
720 list_for_each_entry_safe(non_tx_sdata, tmp_sdata,
721 &tx_sdata->local->interfaces, list) {
722 if (non_tx_sdata != sdata && non_tx_sdata != tx_sdata &&
723 non_tx_sdata->vif.mbssid_tx_vif == tx_vif &&
724 ieee80211_sdata_running(non_tx_sdata)) {
725 non_tx_sdata->vif.mbssid_tx_vif = NULL;
726 dev_close(non_tx_sdata->wdev.netdev);
730 if (sdata != tx_sdata && ieee80211_sdata_running(tx_sdata)) {
731 tx_sdata->vif.mbssid_tx_vif = NULL;
732 dev_close(tx_sdata->wdev.netdev);
736 static int ieee80211_stop(struct net_device *dev)
738 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
740 /* close dependent VLAN and MBSSID interfaces before locking wiphy */
741 if (sdata->vif.type == NL80211_IFTYPE_AP) {
742 struct ieee80211_sub_if_data *vlan, *tmpsdata;
744 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
746 dev_close(vlan->dev);
748 ieee80211_stop_mbssid(sdata);
751 cancel_work_sync(&sdata->activate_links_work);
753 wiphy_lock(sdata->local->hw.wiphy);
754 ieee80211_do_stop(sdata, true);
755 wiphy_unlock(sdata->local->hw.wiphy);
760 static void ieee80211_set_multicast_list(struct net_device *dev)
762 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
763 struct ieee80211_local *local = sdata->local;
764 int allmulti, sdata_allmulti;
766 allmulti = !!(dev->flags & IFF_ALLMULTI);
767 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
769 if (allmulti != sdata_allmulti) {
770 if (dev->flags & IFF_ALLMULTI)
771 atomic_inc(&local->iff_allmultis);
773 atomic_dec(&local->iff_allmultis);
774 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
777 spin_lock_bh(&local->filter_lock);
778 __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
779 spin_unlock_bh(&local->filter_lock);
780 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
784 * Called when the netdev is removed or, by the code below, before
785 * the interface type changes.
787 static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
789 /* free extra data */
790 ieee80211_free_keys(sdata, false);
792 ieee80211_debugfs_remove_netdev(sdata);
794 ieee80211_destroy_frag_cache(&sdata->frags);
796 if (ieee80211_vif_is_mesh(&sdata->vif))
797 ieee80211_mesh_teardown_sdata(sdata);
799 ieee80211_vif_clear_links(sdata);
800 ieee80211_link_stop(&sdata->deflink);
803 static void ieee80211_uninit(struct net_device *dev)
805 ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
809 ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
811 dev_fetch_sw_netstats(stats, dev->tstats);
814 static const struct net_device_ops ieee80211_dataif_ops = {
815 .ndo_open = ieee80211_open,
816 .ndo_stop = ieee80211_stop,
817 .ndo_uninit = ieee80211_uninit,
818 .ndo_start_xmit = ieee80211_subif_start_xmit,
819 .ndo_set_rx_mode = ieee80211_set_multicast_list,
820 .ndo_set_mac_address = ieee80211_change_mac,
821 .ndo_get_stats64 = ieee80211_get_stats64,
824 static u16 ieee80211_monitor_select_queue(struct net_device *dev,
826 struct net_device *sb_dev)
828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
829 struct ieee80211_local *local = sdata->local;
830 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
831 struct ieee80211_hdr *hdr;
834 if (local->hw.queues < IEEE80211_NUM_ACS)
837 /* reset flags and info before parsing radiotap header */
838 memset(info, 0, sizeof(*info));
840 if (!ieee80211_parse_tx_radiotap(skb, dev))
841 return 0; /* doesn't matter, frame will be dropped */
843 len_rthdr = ieee80211_get_radiotap_len(skb->data);
844 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
845 if (skb->len < len_rthdr + 2 ||
846 skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
847 return 0; /* doesn't matter, frame will be dropped */
849 return ieee80211_select_queue_80211(sdata, skb, hdr);
852 static const struct net_device_ops ieee80211_monitorif_ops = {
853 .ndo_open = ieee80211_open,
854 .ndo_stop = ieee80211_stop,
855 .ndo_uninit = ieee80211_uninit,
856 .ndo_start_xmit = ieee80211_monitor_start_xmit,
857 .ndo_set_rx_mode = ieee80211_set_multicast_list,
858 .ndo_set_mac_address = ieee80211_change_mac,
859 .ndo_select_queue = ieee80211_monitor_select_queue,
860 .ndo_get_stats64 = ieee80211_get_stats64,
863 static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx *ctx,
864 struct net_device_path *path)
866 struct ieee80211_sub_if_data *sdata;
867 struct ieee80211_local *local;
868 struct sta_info *sta;
871 sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev);
872 local = sdata->local;
874 if (!local->ops->net_fill_forward_path)
878 switch (sdata->vif.type) {
879 case NL80211_IFTYPE_AP_VLAN:
880 sta = rcu_dereference(sdata->u.vlan.sta);
883 if (sdata->wdev.use_4addr)
885 if (is_multicast_ether_addr(ctx->daddr))
887 sta = sta_info_get_bss(sdata, ctx->daddr);
889 case NL80211_IFTYPE_AP:
890 if (is_multicast_ether_addr(ctx->daddr))
892 sta = sta_info_get(sdata, ctx->daddr);
894 case NL80211_IFTYPE_STATION:
895 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
896 sta = sta_info_get(sdata, ctx->daddr);
897 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
898 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
905 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
914 ret = drv_net_fill_forward_path(local, sdata, &sta->sta, ctx, path);
921 static const struct net_device_ops ieee80211_dataif_8023_ops = {
922 .ndo_open = ieee80211_open,
923 .ndo_stop = ieee80211_stop,
924 .ndo_uninit = ieee80211_uninit,
925 .ndo_start_xmit = ieee80211_subif_start_xmit_8023,
926 .ndo_set_rx_mode = ieee80211_set_multicast_list,
927 .ndo_set_mac_address = ieee80211_change_mac,
928 .ndo_get_stats64 = ieee80211_get_stats64,
929 .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path,
932 static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype)
935 /* P2P GO and client are mapped to AP/STATION types */
936 case NL80211_IFTYPE_AP:
937 case NL80211_IFTYPE_STATION:
944 static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdata)
946 struct ieee80211_local *local = sdata->local;
949 flags = sdata->vif.offload_flags;
951 if (ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) &&
952 ieee80211_iftype_supports_hdr_offload(sdata->vif.type)) {
953 flags |= IEEE80211_OFFLOAD_ENCAP_ENABLED;
955 if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG) &&
956 local->hw.wiphy->frag_threshold != (u32)-1)
957 flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
960 flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
962 flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
965 if (ieee80211_hw_check(&local->hw, SUPPORTS_RX_DECAP_OFFLOAD) &&
966 ieee80211_iftype_supports_hdr_offload(sdata->vif.type)) {
967 flags |= IEEE80211_OFFLOAD_DECAP_ENABLED;
969 if (local->monitors &&
970 !ieee80211_hw_check(&local->hw, SUPPORTS_CONC_MON_RX_DECAP))
971 flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
973 flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
976 if (sdata->vif.offload_flags == flags)
979 sdata->vif.offload_flags = flags;
980 ieee80211_check_fast_rx_iface(sdata);
984 static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
986 struct ieee80211_local *local = sdata->local;
987 struct ieee80211_sub_if_data *bss = sdata;
990 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
994 bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
997 if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
998 !ieee80211_iftype_supports_hdr_offload(bss->vif.type))
1001 enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
1002 if (sdata->wdev.use_4addr &&
1003 !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
1006 sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
1007 &ieee80211_dataif_ops;
1010 static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata)
1012 struct ieee80211_local *local = sdata->local;
1013 struct ieee80211_sub_if_data *vsdata;
1015 if (ieee80211_set_sdata_offload_flags(sdata)) {
1016 drv_update_vif_offload(local, sdata);
1017 ieee80211_set_vif_encap_ops(sdata);
1020 list_for_each_entry(vsdata, &local->interfaces, list) {
1021 if (vsdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
1022 vsdata->bss != &sdata->u.ap)
1025 ieee80211_set_vif_encap_ops(vsdata);
1029 void ieee80211_recalc_offload(struct ieee80211_local *local)
1031 struct ieee80211_sub_if_data *sdata;
1033 if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD))
1036 mutex_lock(&local->iflist_mtx);
1038 list_for_each_entry(sdata, &local->interfaces, list) {
1039 if (!ieee80211_sdata_running(sdata))
1042 ieee80211_recalc_sdata_offload(sdata);
1045 mutex_unlock(&local->iflist_mtx);
1048 void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
1051 struct ieee80211_local *local = sdata->local;
1052 u32 flags = sdata->u.mntr.flags;
1054 #define ADJUST(_f, _s) do { \
1055 if (flags & MONITOR_FLAG_##_f) \
1056 local->fif_##_s += offset; \
1059 ADJUST(FCSFAIL, fcsfail);
1060 ADJUST(PLCPFAIL, plcpfail);
1061 ADJUST(CONTROL, control);
1062 ADJUST(CONTROL, pspoll);
1063 ADJUST(OTHER_BSS, other_bss);
1068 static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata)
1070 struct ieee80211_local *local = sdata->local;
1073 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1074 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1075 sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE;
1076 else if (local->hw.queues >= IEEE80211_NUM_ACS)
1077 sdata->vif.hw_queue[i] = i;
1079 sdata->vif.hw_queue[i] = 0;
1081 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
1084 static void ieee80211_sdata_init(struct ieee80211_local *local,
1085 struct ieee80211_sub_if_data *sdata)
1087 sdata->local = local;
1090 * Initialize the default link, so we can use link_id 0 for non-MLD,
1091 * and that continues to work for non-MLD-aware drivers that use just
1092 * vif.bss_conf instead of vif.link_conf.
1094 * Note that we never change this, so if link ID 0 isn't used in an
1095 * MLD connection, we get a separate allocation for it.
1097 ieee80211_link_init(sdata, -1, &sdata->deflink, &sdata->vif.bss_conf);
1100 int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
1102 struct ieee80211_sub_if_data *sdata;
1105 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
1109 lockdep_assert_wiphy(local->hw.wiphy);
1111 if (local->monitor_sdata)
1114 sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL);
1119 sdata->vif.type = NL80211_IFTYPE_MONITOR;
1120 snprintf(sdata->name, IFNAMSIZ, "%s-monitor",
1121 wiphy_name(local->hw.wiphy));
1122 sdata->wdev.iftype = NL80211_IFTYPE_MONITOR;
1124 ieee80211_sdata_init(local, sdata);
1126 ieee80211_set_default_queues(sdata);
1128 ret = drv_add_interface(local, sdata);
1130 /* ok .. stupid driver, it asked for this! */
1135 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1137 ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR);
1143 mutex_lock(&local->iflist_mtx);
1144 rcu_assign_pointer(local->monitor_sdata, sdata);
1145 mutex_unlock(&local->iflist_mtx);
1147 mutex_lock(&local->mtx);
1148 ret = ieee80211_link_use_channel(&sdata->deflink, &local->monitor_chandef,
1149 IEEE80211_CHANCTX_EXCLUSIVE);
1150 mutex_unlock(&local->mtx);
1152 mutex_lock(&local->iflist_mtx);
1153 RCU_INIT_POINTER(local->monitor_sdata, NULL);
1154 mutex_unlock(&local->iflist_mtx);
1156 drv_remove_interface(local, sdata);
1161 skb_queue_head_init(&sdata->skb_queue);
1162 skb_queue_head_init(&sdata->status_queue);
1163 INIT_WORK(&sdata->work, ieee80211_iface_work);
1168 void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
1170 struct ieee80211_sub_if_data *sdata;
1172 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
1176 lockdep_assert_wiphy(local->hw.wiphy);
1178 mutex_lock(&local->iflist_mtx);
1180 sdata = rcu_dereference_protected(local->monitor_sdata,
1181 lockdep_is_held(&local->iflist_mtx));
1183 mutex_unlock(&local->iflist_mtx);
1187 RCU_INIT_POINTER(local->monitor_sdata, NULL);
1188 mutex_unlock(&local->iflist_mtx);
1192 mutex_lock(&local->mtx);
1193 ieee80211_link_release_channel(&sdata->deflink);
1194 mutex_unlock(&local->mtx);
1196 drv_remove_interface(local, sdata);
1202 * NOTE: Be very careful when changing this function, it must NOT return
1203 * an error on interface type changes that have been pre-checked, so most
1204 * checks should be in ieee80211_check_concurrent_iface.
1206 int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
1208 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
1209 struct net_device *dev = wdev->netdev;
1210 struct ieee80211_local *local = sdata->local;
1213 u32 hw_reconf_flags = 0;
1215 switch (sdata->vif.type) {
1216 case NL80211_IFTYPE_AP_VLAN: {
1217 struct ieee80211_sub_if_data *master;
1222 mutex_lock(&local->mtx);
1223 list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
1224 mutex_unlock(&local->mtx);
1226 master = container_of(sdata->bss,
1227 struct ieee80211_sub_if_data, u.ap);
1228 sdata->control_port_protocol =
1229 master->control_port_protocol;
1230 sdata->control_port_no_encrypt =
1231 master->control_port_no_encrypt;
1232 sdata->control_port_over_nl80211 =
1233 master->control_port_over_nl80211;
1234 sdata->control_port_no_preauth =
1235 master->control_port_no_preauth;
1236 sdata->vif.cab_queue = master->vif.cab_queue;
1237 memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
1238 sizeof(sdata->vif.hw_queue));
1239 sdata->vif.bss_conf.chandef = master->vif.bss_conf.chandef;
1241 mutex_lock(&local->key_mtx);
1242 sdata->crypto_tx_tailroom_needed_cnt +=
1243 master->crypto_tx_tailroom_needed_cnt;
1244 mutex_unlock(&local->key_mtx);
1248 case NL80211_IFTYPE_AP:
1249 sdata->bss = &sdata->u.ap;
1251 case NL80211_IFTYPE_MESH_POINT:
1252 case NL80211_IFTYPE_STATION:
1253 case NL80211_IFTYPE_MONITOR:
1254 case NL80211_IFTYPE_ADHOC:
1255 case NL80211_IFTYPE_P2P_DEVICE:
1256 case NL80211_IFTYPE_OCB:
1257 case NL80211_IFTYPE_NAN:
1258 /* no special treatment */
1260 case NL80211_IFTYPE_UNSPECIFIED:
1261 case NUM_NL80211_IFTYPES:
1262 case NL80211_IFTYPE_P2P_CLIENT:
1263 case NL80211_IFTYPE_P2P_GO:
1264 case NL80211_IFTYPE_WDS:
1270 if (local->open_count == 0) {
1271 res = drv_start(local);
1274 /* we're brought up, everything changes */
1275 hw_reconf_flags = ~0;
1276 ieee80211_led_radio(local, true);
1277 ieee80211_mod_tpt_led_trig(local,
1278 IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
1282 * Copy the hopefully now-present MAC address to
1283 * this interface, if it has the special null one.
1285 if (dev && is_zero_ether_addr(dev->dev_addr)) {
1286 eth_hw_addr_set(dev, local->hw.wiphy->perm_addr);
1287 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
1289 if (!is_valid_ether_addr(dev->dev_addr)) {
1290 res = -EADDRNOTAVAIL;
1295 switch (sdata->vif.type) {
1296 case NL80211_IFTYPE_AP_VLAN:
1297 /* no need to tell driver, but set carrier and chanctx */
1298 if (sdata->bss->active) {
1299 ieee80211_link_vlan_copy_chanctx(&sdata->deflink);
1300 netif_carrier_on(dev);
1301 ieee80211_set_vif_encap_ops(sdata);
1303 netif_carrier_off(dev);
1306 case NL80211_IFTYPE_MONITOR:
1307 if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
1308 local->cooked_mntrs++;
1312 if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
1313 res = drv_add_interface(local, sdata);
1316 } else if (local->monitors == 0 && local->open_count == 0) {
1317 res = ieee80211_add_virtual_monitor(local);
1322 /* must be before the call to ieee80211_configure_filter */
1324 if (local->monitors == 1) {
1325 local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
1326 hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
1329 ieee80211_adjust_monitor_flags(sdata, 1);
1330 ieee80211_configure_filter(local);
1331 ieee80211_recalc_offload(local);
1332 mutex_lock(&local->mtx);
1333 ieee80211_recalc_idle(local);
1334 mutex_unlock(&local->mtx);
1336 netif_carrier_on(dev);
1340 ieee80211_del_virtual_monitor(local);
1341 ieee80211_set_sdata_offload_flags(sdata);
1343 res = drv_add_interface(local, sdata);
1347 ieee80211_set_vif_encap_ops(sdata);
1348 res = ieee80211_check_queues(sdata,
1349 ieee80211_vif_type_p2p(&sdata->vif));
1351 goto err_del_interface;
1354 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1355 local->fif_pspoll++;
1356 local->fif_probe_req++;
1358 ieee80211_configure_filter(local);
1359 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1360 local->fif_probe_req++;
1363 if (sdata->vif.probe_req_reg)
1364 drv_config_iface_filter(local, sdata,
1368 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
1369 sdata->vif.type != NL80211_IFTYPE_NAN)
1370 changed |= ieee80211_reset_erp_info(sdata);
1371 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
1374 switch (sdata->vif.type) {
1375 case NL80211_IFTYPE_STATION:
1376 case NL80211_IFTYPE_ADHOC:
1377 case NL80211_IFTYPE_AP:
1378 case NL80211_IFTYPE_MESH_POINT:
1379 case NL80211_IFTYPE_OCB:
1380 netif_carrier_off(dev);
1382 case NL80211_IFTYPE_P2P_DEVICE:
1383 case NL80211_IFTYPE_NAN:
1391 * Set default queue parameters so drivers don't
1392 * need to initialise the hardware if the hardware
1393 * doesn't start up with sane defaults.
1394 * Enable QoS for anything but station interfaces.
1396 ieee80211_set_wmm_default(&sdata->deflink, true,
1397 sdata->vif.type != NL80211_IFTYPE_STATION);
1400 switch (sdata->vif.type) {
1401 case NL80211_IFTYPE_P2P_DEVICE:
1402 rcu_assign_pointer(local->p2p_sdata, sdata);
1404 case NL80211_IFTYPE_MONITOR:
1405 if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
1407 list_add_tail_rcu(&sdata->u.mntr.list, &local->mon_list);
1414 * set_multicast_list will be invoked by the networking core
1415 * which will check whether any increments here were done in
1416 * error and sync them down to the hardware as filter flags.
1418 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
1419 atomic_inc(&local->iff_allmultis);
1422 local->open_count++;
1424 if (hw_reconf_flags)
1425 ieee80211_hw_config(local, hw_reconf_flags);
1427 ieee80211_recalc_ps(local);
1429 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1433 drv_remove_interface(local, sdata);
1435 if (!local->open_count)
1439 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1440 mutex_lock(&local->mtx);
1441 list_del(&sdata->u.vlan.list);
1442 mutex_unlock(&local->mtx);
1444 /* might already be clear but that doesn't matter */
1445 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
1449 static void ieee80211_if_free(struct net_device *dev)
1451 free_percpu(dev->tstats);
1454 static void ieee80211_if_setup(struct net_device *dev)
1457 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1458 dev->priv_flags |= IFF_NO_QUEUE;
1459 dev->netdev_ops = &ieee80211_dataif_ops;
1460 dev->needs_free_netdev = true;
1461 dev->priv_destructor = ieee80211_if_free;
1464 static void ieee80211_iface_process_skb(struct ieee80211_local *local,
1465 struct ieee80211_sub_if_data *sdata,
1466 struct sk_buff *skb)
1468 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1470 if (ieee80211_is_action(mgmt->frame_control) &&
1471 mgmt->u.action.category == WLAN_CATEGORY_BACK) {
1472 struct sta_info *sta;
1475 mutex_lock(&local->sta_mtx);
1476 sta = sta_info_get_bss(sdata, mgmt->sa);
1478 switch (mgmt->u.action.u.addba_req.action_code) {
1479 case WLAN_ACTION_ADDBA_REQ:
1480 ieee80211_process_addba_request(local, sta,
1483 case WLAN_ACTION_ADDBA_RESP:
1484 ieee80211_process_addba_resp(local, sta,
1487 case WLAN_ACTION_DELBA:
1488 ieee80211_process_delba(sdata, sta,
1496 mutex_unlock(&local->sta_mtx);
1497 } else if (ieee80211_is_action(mgmt->frame_control) &&
1498 mgmt->u.action.category == WLAN_CATEGORY_VHT) {
1499 switch (mgmt->u.action.u.vht_group_notif.action_code) {
1500 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
1501 struct ieee80211_rx_status *status;
1502 enum nl80211_band band;
1503 struct sta_info *sta;
1506 status = IEEE80211_SKB_RXCB(skb);
1507 band = status->band;
1508 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
1510 mutex_lock(&local->sta_mtx);
1511 sta = sta_info_get_bss(sdata, mgmt->sa);
1514 ieee80211_vht_handle_opmode(sdata,
1518 mutex_unlock(&local->sta_mtx);
1521 case WLAN_VHT_ACTION_GROUPID_MGMT:
1522 ieee80211_process_mu_groups(sdata, &sdata->deflink,
1529 } else if (ieee80211_is_action(mgmt->frame_control) &&
1530 mgmt->u.action.category == WLAN_CATEGORY_S1G) {
1531 switch (mgmt->u.action.u.s1g.action_code) {
1532 case WLAN_S1G_TWT_TEARDOWN:
1533 case WLAN_S1G_TWT_SETUP:
1534 ieee80211_s1g_rx_twt_action(sdata, skb);
1539 } else if (ieee80211_is_ext(mgmt->frame_control)) {
1540 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1541 ieee80211_sta_rx_queued_ext(sdata, skb);
1544 } else if (ieee80211_is_data_qos(mgmt->frame_control)) {
1545 struct ieee80211_hdr *hdr = (void *)mgmt;
1546 struct sta_info *sta;
1549 * So the frame isn't mgmt, but frame_control
1550 * is at the right place anyway, of course, so
1551 * the if statement is correct.
1553 * Warn if we have other data frame types here,
1554 * they must not get here.
1556 WARN_ON(hdr->frame_control &
1557 cpu_to_le16(IEEE80211_STYPE_NULLFUNC));
1558 WARN_ON(!(hdr->seq_ctrl &
1559 cpu_to_le16(IEEE80211_SCTL_FRAG)));
1561 * This was a fragment of a frame, received while
1562 * a block-ack session was active. That cannot be
1563 * right, so terminate the session.
1565 mutex_lock(&local->sta_mtx);
1566 sta = sta_info_get_bss(sdata, mgmt->sa);
1568 u16 tid = ieee80211_get_tid(hdr);
1570 __ieee80211_stop_rx_ba_session(
1571 sta, tid, WLAN_BACK_RECIPIENT,
1572 WLAN_REASON_QSTA_REQUIRE_SETUP,
1575 mutex_unlock(&local->sta_mtx);
1576 } else switch (sdata->vif.type) {
1577 case NL80211_IFTYPE_STATION:
1578 ieee80211_sta_rx_queued_mgmt(sdata, skb);
1580 case NL80211_IFTYPE_ADHOC:
1581 ieee80211_ibss_rx_queued_mgmt(sdata, skb);
1583 case NL80211_IFTYPE_MESH_POINT:
1584 if (!ieee80211_vif_is_mesh(&sdata->vif))
1586 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1589 WARN(1, "frame for unexpected interface type");
1594 static void ieee80211_iface_process_status(struct ieee80211_sub_if_data *sdata,
1595 struct sk_buff *skb)
1597 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1599 if (ieee80211_is_action(mgmt->frame_control) &&
1600 mgmt->u.action.category == WLAN_CATEGORY_S1G) {
1601 switch (mgmt->u.action.u.s1g.action_code) {
1602 case WLAN_S1G_TWT_TEARDOWN:
1603 case WLAN_S1G_TWT_SETUP:
1604 ieee80211_s1g_status_twt_action(sdata, skb);
1612 static void ieee80211_iface_work(struct work_struct *work)
1614 struct ieee80211_sub_if_data *sdata =
1615 container_of(work, struct ieee80211_sub_if_data, work);
1616 struct ieee80211_local *local = sdata->local;
1617 struct sk_buff *skb;
1619 if (!ieee80211_sdata_running(sdata))
1622 if (test_bit(SCAN_SW_SCANNING, &local->scanning))
1625 if (!ieee80211_can_run_worker(local))
1628 /* first process frames */
1629 while ((skb = skb_dequeue(&sdata->skb_queue))) {
1630 kcov_remote_start_common(skb_get_kcov_handle(skb));
1632 if (skb->protocol == cpu_to_be16(ETH_P_TDLS))
1633 ieee80211_process_tdls_channel_switch(sdata, skb);
1635 ieee80211_iface_process_skb(local, sdata, skb);
1641 /* process status queue */
1642 while ((skb = skb_dequeue(&sdata->status_queue))) {
1643 kcov_remote_start_common(skb_get_kcov_handle(skb));
1645 ieee80211_iface_process_status(sdata, skb);
1651 /* then other type-dependent work */
1652 switch (sdata->vif.type) {
1653 case NL80211_IFTYPE_STATION:
1654 ieee80211_sta_work(sdata);
1656 case NL80211_IFTYPE_ADHOC:
1657 ieee80211_ibss_work(sdata);
1659 case NL80211_IFTYPE_MESH_POINT:
1660 if (!ieee80211_vif_is_mesh(&sdata->vif))
1662 ieee80211_mesh_work(sdata);
1664 case NL80211_IFTYPE_OCB:
1665 ieee80211_ocb_work(sdata);
1672 static void ieee80211_recalc_smps_work(struct work_struct *work)
1674 struct ieee80211_sub_if_data *sdata =
1675 container_of(work, struct ieee80211_sub_if_data, recalc_smps);
1677 ieee80211_recalc_smps(sdata, &sdata->deflink);
1680 static void ieee80211_activate_links_work(struct work_struct *work)
1682 struct ieee80211_sub_if_data *sdata =
1683 container_of(work, struct ieee80211_sub_if_data,
1684 activate_links_work);
1686 ieee80211_set_active_links(&sdata->vif, sdata->desired_active_links);
1690 * Helper function to initialise an interface to a specific type.
1692 static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1693 enum nl80211_iftype type)
1695 static const u8 bssid_wildcard[ETH_ALEN] = {0xff, 0xff, 0xff,
1698 /* clear type-dependent unions */
1699 memset(&sdata->u, 0, sizeof(sdata->u));
1700 memset(&sdata->deflink.u, 0, sizeof(sdata->deflink.u));
1702 /* and set some type-dependent values */
1703 sdata->vif.type = type;
1704 sdata->vif.p2p = false;
1705 sdata->wdev.iftype = type;
1707 sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
1708 sdata->control_port_no_encrypt = false;
1709 sdata->control_port_over_nl80211 = false;
1710 sdata->control_port_no_preauth = false;
1711 sdata->vif.cfg.idle = true;
1712 sdata->vif.bss_conf.txpower = INT_MIN; /* unset */
1714 sdata->noack_map = 0;
1716 /* only monitor/p2p-device differ */
1718 sdata->dev->netdev_ops = &ieee80211_dataif_ops;
1719 sdata->dev->type = ARPHRD_ETHER;
1722 skb_queue_head_init(&sdata->skb_queue);
1723 skb_queue_head_init(&sdata->status_queue);
1724 INIT_WORK(&sdata->work, ieee80211_iface_work);
1725 INIT_WORK(&sdata->recalc_smps, ieee80211_recalc_smps_work);
1726 INIT_WORK(&sdata->activate_links_work, ieee80211_activate_links_work);
1729 case NL80211_IFTYPE_P2P_GO:
1730 type = NL80211_IFTYPE_AP;
1731 sdata->vif.type = type;
1732 sdata->vif.p2p = true;
1734 case NL80211_IFTYPE_AP:
1735 skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
1736 INIT_LIST_HEAD(&sdata->u.ap.vlans);
1737 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1739 case NL80211_IFTYPE_P2P_CLIENT:
1740 type = NL80211_IFTYPE_STATION;
1741 sdata->vif.type = type;
1742 sdata->vif.p2p = true;
1744 case NL80211_IFTYPE_STATION:
1745 sdata->vif.bss_conf.bssid = sdata->deflink.u.mgd.bssid;
1746 ieee80211_sta_setup_sdata(sdata);
1748 case NL80211_IFTYPE_OCB:
1749 sdata->vif.bss_conf.bssid = bssid_wildcard;
1750 ieee80211_ocb_setup_sdata(sdata);
1752 case NL80211_IFTYPE_ADHOC:
1753 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
1754 ieee80211_ibss_setup_sdata(sdata);
1756 case NL80211_IFTYPE_MESH_POINT:
1757 if (ieee80211_vif_is_mesh(&sdata->vif))
1758 ieee80211_mesh_init_sdata(sdata);
1760 case NL80211_IFTYPE_MONITOR:
1761 sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
1762 sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
1763 sdata->u.mntr.flags = MONITOR_FLAG_CONTROL |
1764 MONITOR_FLAG_OTHER_BSS;
1766 case NL80211_IFTYPE_NAN:
1767 idr_init(&sdata->u.nan.function_inst_ids);
1768 spin_lock_init(&sdata->u.nan.func_lock);
1769 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1771 case NL80211_IFTYPE_AP_VLAN:
1772 case NL80211_IFTYPE_P2P_DEVICE:
1773 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1775 case NL80211_IFTYPE_UNSPECIFIED:
1776 case NL80211_IFTYPE_WDS:
1777 case NUM_NL80211_IFTYPES:
1782 /* need to do this after the switch so vif.type is correct */
1783 ieee80211_link_setup(&sdata->deflink);
1785 ieee80211_debugfs_add_netdev(sdata);
1788 static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
1789 enum nl80211_iftype type)
1791 struct ieee80211_local *local = sdata->local;
1793 enum nl80211_iftype internal_type = type;
1798 if (!local->ops->change_interface)
1801 /* for now, don't support changing while links exist */
1802 if (sdata->vif.valid_links)
1805 switch (sdata->vif.type) {
1806 case NL80211_IFTYPE_AP:
1807 if (!list_empty(&sdata->u.ap.vlans))
1810 case NL80211_IFTYPE_STATION:
1811 case NL80211_IFTYPE_ADHOC:
1812 case NL80211_IFTYPE_OCB:
1814 * Could maybe also all others here?
1815 * Just not sure how that interacts
1816 * with the RX/config path e.g. for
1825 case NL80211_IFTYPE_AP:
1826 case NL80211_IFTYPE_STATION:
1827 case NL80211_IFTYPE_ADHOC:
1828 case NL80211_IFTYPE_OCB:
1830 * Could probably support everything
1834 case NL80211_IFTYPE_P2P_CLIENT:
1836 internal_type = NL80211_IFTYPE_STATION;
1838 case NL80211_IFTYPE_P2P_GO:
1840 internal_type = NL80211_IFTYPE_AP;
1846 ret = ieee80211_check_concurrent_iface(sdata, internal_type);
1850 ieee80211_stop_vif_queues(local, sdata,
1851 IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE);
1852 /* do_stop will synchronize_rcu() first thing */
1853 ieee80211_do_stop(sdata, false);
1855 ieee80211_teardown_sdata(sdata);
1857 ieee80211_set_sdata_offload_flags(sdata);
1858 ret = drv_change_interface(local, sdata, internal_type, p2p);
1860 type = ieee80211_vif_type_p2p(&sdata->vif);
1863 * Ignore return value here, there's not much we can do since
1864 * the driver changed the interface type internally already.
1865 * The warnings will hopefully make driver authors fix it :-)
1867 ieee80211_check_queues(sdata, type);
1869 ieee80211_setup_sdata(sdata, type);
1870 ieee80211_set_vif_encap_ops(sdata);
1872 err = ieee80211_do_open(&sdata->wdev, false);
1873 WARN(err, "type change: do_open returned %d", err);
1875 ieee80211_wake_vif_queues(local, sdata,
1876 IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE);
1880 int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
1881 enum nl80211_iftype type)
1887 if (type == ieee80211_vif_type_p2p(&sdata->vif))
1890 if (ieee80211_sdata_running(sdata)) {
1891 ret = ieee80211_runtime_change_iftype(sdata, type);
1895 /* Purge and reset type-dependent state. */
1896 ieee80211_teardown_sdata(sdata);
1897 ieee80211_setup_sdata(sdata, type);
1900 /* reset some values that shouldn't be kept across type changes */
1901 if (type == NL80211_IFTYPE_STATION)
1902 sdata->u.mgd.use_4addr = false;
1907 static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
1908 u8 *perm_addr, enum nl80211_iftype type)
1910 struct ieee80211_sub_if_data *sdata;
1911 u64 mask, start, addr, val, inc;
1913 u8 tmp_addr[ETH_ALEN];
1916 /* default ... something at least */
1917 memcpy(perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1919 if (is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
1920 local->hw.wiphy->n_addresses <= 1)
1923 mutex_lock(&local->iflist_mtx);
1926 case NL80211_IFTYPE_MONITOR:
1927 /* doesn't matter */
1929 case NL80211_IFTYPE_AP_VLAN:
1930 /* match up with an AP interface */
1931 list_for_each_entry(sdata, &local->interfaces, list) {
1932 if (sdata->vif.type != NL80211_IFTYPE_AP)
1934 memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
1937 /* keep default if no AP interface present */
1939 case NL80211_IFTYPE_P2P_CLIENT:
1940 case NL80211_IFTYPE_P2P_GO:
1941 if (ieee80211_hw_check(&local->hw, P2P_DEV_ADDR_FOR_INTF)) {
1942 list_for_each_entry(sdata, &local->interfaces, list) {
1943 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE)
1945 if (!ieee80211_sdata_running(sdata))
1947 memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
1953 /* assign a new address if possible -- try n_addresses first */
1954 for (i = 0; i < local->hw.wiphy->n_addresses; i++) {
1957 list_for_each_entry(sdata, &local->interfaces, list) {
1958 if (ether_addr_equal(local->hw.wiphy->addresses[i].addr,
1967 local->hw.wiphy->addresses[i].addr,
1973 /* try mask if available */
1974 if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
1977 m = local->hw.wiphy->addr_mask;
1978 mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
1979 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
1980 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
1982 if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
1983 /* not a contiguous mask ... not handled now! */
1984 pr_info("not contiguous\n");
1989 * Pick address of existing interface in case user changed
1990 * MAC address manually, default to perm_addr.
1992 m = local->hw.wiphy->perm_addr;
1993 list_for_each_entry(sdata, &local->interfaces, list) {
1994 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1996 m = sdata->vif.addr;
1999 start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
2000 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
2001 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
2003 inc = 1ULL<<__ffs64(mask);
2004 val = (start & mask);
2005 addr = (start & ~mask) | (val & mask);
2009 tmp_addr[5] = addr >> 0*8;
2010 tmp_addr[4] = addr >> 1*8;
2011 tmp_addr[3] = addr >> 2*8;
2012 tmp_addr[2] = addr >> 3*8;
2013 tmp_addr[1] = addr >> 4*8;
2014 tmp_addr[0] = addr >> 5*8;
2018 list_for_each_entry(sdata, &local->interfaces, list) {
2019 if (ether_addr_equal(tmp_addr, sdata->vif.addr)) {
2026 memcpy(perm_addr, tmp_addr, ETH_ALEN);
2029 addr = (start & ~mask) | (val & mask);
2030 } while (addr != start);
2036 mutex_unlock(&local->iflist_mtx);
2039 int ieee80211_if_add(struct ieee80211_local *local, const char *name,
2040 unsigned char name_assign_type,
2041 struct wireless_dev **new_wdev, enum nl80211_iftype type,
2042 struct vif_params *params)
2044 struct net_device *ndev = NULL;
2045 struct ieee80211_sub_if_data *sdata = NULL;
2046 struct txq_info *txqi;
2051 if (type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN) {
2052 struct wireless_dev *wdev;
2054 sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size,
2058 wdev = &sdata->wdev;
2061 strscpy(sdata->name, name, IFNAMSIZ);
2062 ieee80211_assign_perm_addr(local, wdev->address, type);
2063 memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
2064 ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr);
2066 int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size,
2070 if (type != NL80211_IFTYPE_AP_VLAN &&
2071 (type != NL80211_IFTYPE_MONITOR ||
2072 (params->flags & MONITOR_FLAG_ACTIVE)))
2073 txq_size += sizeof(struct txq_info) +
2074 local->hw.txq_data_size;
2076 ndev = alloc_netdev_mqs(size + txq_size,
2077 name, name_assign_type,
2078 ieee80211_if_setup, 1, 1);
2082 dev_net_set(ndev, wiphy_net(local->hw.wiphy));
2084 ndev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
2085 if (!ndev->tstats) {
2090 ndev->needed_headroom = local->tx_headroom +
2091 4*6 /* four MAC addresses */
2092 + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
2094 + 8 /* rfc1042/bridge tunnel */
2095 - ETH_HLEN /* ethernet hard_header_len */
2096 + IEEE80211_ENCRYPT_HEADROOM;
2097 ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
2099 ret = dev_alloc_name(ndev, ndev->name);
2101 ieee80211_if_free(ndev);
2106 ieee80211_assign_perm_addr(local, ndev->perm_addr, type);
2107 if (is_valid_ether_addr(params->macaddr))
2108 eth_hw_addr_set(ndev, params->macaddr);
2110 eth_hw_addr_set(ndev, ndev->perm_addr);
2111 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
2113 /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */
2114 sdata = netdev_priv(ndev);
2115 ndev->ieee80211_ptr = &sdata->wdev;
2116 memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
2117 ether_addr_copy(sdata->vif.bss_conf.addr, sdata->vif.addr);
2118 memcpy(sdata->name, ndev->name, IFNAMSIZ);
2121 txqi = netdev_priv(ndev) + size;
2122 ieee80211_txq_init(sdata, NULL, txqi, 0);
2128 /* initialise type-independent data */
2129 sdata->wdev.wiphy = local->hw.wiphy;
2131 ieee80211_sdata_init(local, sdata);
2133 ieee80211_init_frag_cache(&sdata->frags);
2135 INIT_LIST_HEAD(&sdata->key_list);
2137 INIT_DELAYED_WORK(&sdata->dec_tailroom_needed_wk,
2138 ieee80211_delayed_tailroom_dec);
2140 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2141 struct ieee80211_supported_band *sband;
2142 sband = local->hw.wiphy->bands[i];
2143 sdata->rc_rateidx_mask[i] =
2144 sband ? (1 << sband->n_bitrates) - 1 : 0;
2149 memcpy(sdata->rc_rateidx_mcs_mask[i],
2150 sband->ht_cap.mcs.rx_mask,
2151 sizeof(sdata->rc_rateidx_mcs_mask[i]));
2153 cap = sband->vht_cap.vht_mcs.rx_mcs_map;
2154 vht_rate_mask = sdata->rc_rateidx_vht_mcs_mask[i];
2155 ieee80211_get_vht_mask_from_cap(cap, vht_rate_mask);
2157 memset(sdata->rc_rateidx_mcs_mask[i], 0,
2158 sizeof(sdata->rc_rateidx_mcs_mask[i]));
2159 memset(sdata->rc_rateidx_vht_mcs_mask[i], 0,
2160 sizeof(sdata->rc_rateidx_vht_mcs_mask[i]));
2164 ieee80211_set_default_queues(sdata);
2166 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2167 sdata->deflink.user_power_level = local->user_power_level;
2169 /* setup type-dependent data */
2170 ieee80211_setup_sdata(sdata, type);
2173 ndev->ieee80211_ptr->use_4addr = params->use_4addr;
2174 if (type == NL80211_IFTYPE_STATION)
2175 sdata->u.mgd.use_4addr = params->use_4addr;
2177 ndev->features |= local->hw.netdev_features;
2178 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
2179 ndev->hw_features |= ndev->features &
2180 MAC80211_SUPPORTED_FEATURES_TX;
2181 sdata->vif.netdev_features = local->hw.netdev_features;
2183 netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops);
2185 /* MTU range is normally 256 - 2304, where the upper limit is
2186 * the maximum MSDU size. Monitor interfaces send and receive
2187 * MPDU and A-MSDU frames which may be much larger so we do
2188 * not impose an upper limit in that case.
2190 ndev->min_mtu = 256;
2191 if (type == NL80211_IFTYPE_MONITOR)
2194 ndev->max_mtu = local->hw.max_mtu;
2196 ret = cfg80211_register_netdevice(ndev);
2198 ieee80211_if_free(ndev);
2204 mutex_lock(&local->iflist_mtx);
2205 list_add_tail_rcu(&sdata->list, &local->interfaces);
2206 mutex_unlock(&local->iflist_mtx);
2209 *new_wdev = &sdata->wdev;
2214 void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
2218 mutex_lock(&sdata->local->iflist_mtx);
2219 list_del_rcu(&sdata->list);
2220 mutex_unlock(&sdata->local->iflist_mtx);
2223 ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq));
2227 cfg80211_unregister_wdev(&sdata->wdev);
2230 ieee80211_teardown_sdata(sdata);
2235 void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata)
2237 if (WARN_ON_ONCE(!test_bit(SDATA_STATE_RUNNING, &sdata->state)))
2239 ieee80211_do_stop(sdata, true);
2242 void ieee80211_remove_interfaces(struct ieee80211_local *local)
2244 struct ieee80211_sub_if_data *sdata, *tmp;
2245 LIST_HEAD(unreg_list);
2246 LIST_HEAD(wdev_list);
2250 /* Before destroying the interfaces, make sure they're all stopped so
2251 * that the hardware is stopped. Otherwise, the driver might still be
2252 * iterating the interfaces during the shutdown, e.g. from a worker
2253 * or from RX processing or similar, and if it does so (using atomic
2254 * iteration) while we're manipulating the list, the iteration will
2257 * After this, the hardware should be stopped and the driver should
2258 * have stopped all of its activities, so that we can do RCU-unaware
2259 * manipulations of the interface list below.
2261 cfg80211_shutdown_all_interfaces(local->hw.wiphy);
2263 WARN(local->open_count, "%s: open count remains %d\n",
2264 wiphy_name(local->hw.wiphy), local->open_count);
2266 ieee80211_txq_teardown_flows(local);
2268 mutex_lock(&local->iflist_mtx);
2269 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
2270 list_del(&sdata->list);
2273 unregister_netdevice_queue(sdata->dev, &unreg_list);
2275 list_add(&sdata->list, &wdev_list);
2277 mutex_unlock(&local->iflist_mtx);
2279 unregister_netdevice_many(&unreg_list);
2281 wiphy_lock(local->hw.wiphy);
2282 list_for_each_entry_safe(sdata, tmp, &wdev_list, list) {
2283 list_del(&sdata->list);
2284 cfg80211_unregister_wdev(&sdata->wdev);
2287 wiphy_unlock(local->hw.wiphy);
2290 static int netdev_notify(struct notifier_block *nb,
2291 unsigned long state, void *ptr)
2293 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
2294 struct ieee80211_sub_if_data *sdata;
2296 if (state != NETDEV_CHANGENAME)
2299 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
2302 if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
2305 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2306 memcpy(sdata->name, dev->name, IFNAMSIZ);
2307 ieee80211_debugfs_rename_netdev(sdata);
2312 static struct notifier_block mac80211_netdev_notifier = {
2313 .notifier_call = netdev_notify,
2316 int ieee80211_iface_init(void)
2318 return register_netdevice_notifier(&mac80211_netdev_notifier);
2321 void ieee80211_iface_exit(void)
2323 unregister_netdevice_notifier(&mac80211_netdev_notifier);
2326 void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata)
2328 if (sdata->vif.type == NL80211_IFTYPE_AP)
2329 atomic_inc(&sdata->u.ap.num_mcast_sta);
2330 else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2331 atomic_inc(&sdata->u.vlan.num_mcast_sta);
2334 void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata)
2336 if (sdata->vif.type == NL80211_IFTYPE_AP)
2337 atomic_dec(&sdata->u.ap.num_mcast_sta);
2338 else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2339 atomic_dec(&sdata->u.vlan.num_mcast_sta);