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-2024 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
;
301 * This happens during unregistration if there's a bond device
302 * active (maybe other cases?) and we must get removed from it.
303 * But we really don't care anymore if it's not registered now.
305 if (!dev
->ieee80211_ptr
->registered
)
308 wiphy_lock(local
->hw
.wiphy
);
309 ret
= _ieee80211_change_mac(sdata
, addr
);
310 wiphy_unlock(local
->hw
.wiphy
);
315 static inline int identical_mac_addr_allowed(int type1
, int type2
)
317 return type1
== NL80211_IFTYPE_MONITOR
||
318 type2
== NL80211_IFTYPE_MONITOR
||
319 type1
== NL80211_IFTYPE_P2P_DEVICE
||
320 type2
== NL80211_IFTYPE_P2P_DEVICE
||
321 (type1
== NL80211_IFTYPE_AP
&& type2
== NL80211_IFTYPE_AP_VLAN
) ||
322 (type1
== NL80211_IFTYPE_AP_VLAN
&&
323 (type2
== NL80211_IFTYPE_AP
||
324 type2
== NL80211_IFTYPE_AP_VLAN
));
327 static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data
*sdata
,
328 enum nl80211_iftype iftype
)
330 struct ieee80211_local
*local
= sdata
->local
;
331 struct ieee80211_sub_if_data
*nsdata
;
334 lockdep_assert_wiphy(local
->hw
.wiphy
);
336 /* we hold the RTNL here so can safely walk the list */
337 list_for_each_entry(nsdata
, &local
->interfaces
, list
) {
338 if (nsdata
!= sdata
&& ieee80211_sdata_running(nsdata
)) {
340 * Only OCB and monitor mode may coexist
342 if ((sdata
->vif
.type
== NL80211_IFTYPE_OCB
&&
343 nsdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
) ||
344 (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
&&
345 nsdata
->vif
.type
== NL80211_IFTYPE_OCB
))
349 * Allow only a single IBSS interface to be up at any
350 * time. This is restricted because beacon distribution
351 * cannot work properly if both are in the same IBSS.
353 * To remove this restriction we'd have to disallow them
354 * from setting the same SSID on different IBSS interfaces
355 * belonging to the same hardware. Then, however, we're
356 * faced with having to adopt two different TSF timers...
358 if (iftype
== NL80211_IFTYPE_ADHOC
&&
359 nsdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
362 * will not add another interface while any channel
365 if (nsdata
->vif
.bss_conf
.csa_active
)
369 * The remaining checks are only performed for interfaces
370 * with the same MAC address.
372 if (!ether_addr_equal(sdata
->vif
.addr
,
377 * check whether it may have the same address
379 if (!identical_mac_addr_allowed(iftype
,
383 /* No support for VLAN with MLO yet */
384 if (iftype
== NL80211_IFTYPE_AP_VLAN
&&
385 sdata
->wdev
.use_4addr
&&
386 nsdata
->vif
.type
== NL80211_IFTYPE_AP
&&
387 nsdata
->vif
.valid_links
)
391 * can only add VLANs to enabled APs
393 if (iftype
== NL80211_IFTYPE_AP_VLAN
&&
394 nsdata
->vif
.type
== NL80211_IFTYPE_AP
)
395 sdata
->bss
= &nsdata
->u
.ap
;
399 return ieee80211_check_combinations(sdata
, NULL
, 0, 0, -1);
402 static int ieee80211_check_queues(struct ieee80211_sub_if_data
*sdata
,
403 enum nl80211_iftype iftype
)
405 int n_queues
= sdata
->local
->hw
.queues
;
408 if (iftype
== NL80211_IFTYPE_NAN
)
411 if (iftype
!= NL80211_IFTYPE_P2P_DEVICE
) {
412 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
413 if (WARN_ON_ONCE(sdata
->vif
.hw_queue
[i
] ==
414 IEEE80211_INVAL_HW_QUEUE
))
416 if (WARN_ON_ONCE(sdata
->vif
.hw_queue
[i
] >=
422 if ((iftype
!= NL80211_IFTYPE_AP
&&
423 iftype
!= NL80211_IFTYPE_P2P_GO
&&
424 iftype
!= NL80211_IFTYPE_MESH_POINT
) ||
425 !ieee80211_hw_check(&sdata
->local
->hw
, QUEUE_CONTROL
)) {
426 sdata
->vif
.cab_queue
= IEEE80211_INVAL_HW_QUEUE
;
430 if (WARN_ON_ONCE(sdata
->vif
.cab_queue
== IEEE80211_INVAL_HW_QUEUE
))
433 if (WARN_ON_ONCE(sdata
->vif
.cab_queue
>= n_queues
))
439 static int ieee80211_open(struct net_device
*dev
)
441 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
444 /* fail early if user set an invalid address */
445 if (!is_valid_ether_addr(dev
->dev_addr
))
446 return -EADDRNOTAVAIL
;
448 wiphy_lock(sdata
->local
->hw
.wiphy
);
449 err
= ieee80211_check_concurrent_iface(sdata
, sdata
->vif
.type
);
453 err
= ieee80211_do_open(&sdata
->wdev
, true);
455 wiphy_unlock(sdata
->local
->hw
.wiphy
);
460 static void ieee80211_do_stop(struct ieee80211_sub_if_data
*sdata
, bool going_down
)
462 struct ieee80211_local
*local
= sdata
->local
;
464 struct sk_buff_head freeq
;
465 struct sk_buff
*skb
, *tmp
;
466 u32 hw_reconf_flags
= 0;
469 struct cfg80211_chan_def chandef
;
471 struct cfg80211_nan_func
*func
;
473 lockdep_assert_wiphy(local
->hw
.wiphy
);
475 clear_bit(SDATA_STATE_RUNNING
, &sdata
->state
);
476 synchronize_rcu(); /* flush _ieee80211_wake_txqs() */
478 cancel_scan
= rcu_access_pointer(local
->scan_sdata
) == sdata
;
480 ieee80211_scan_cancel(local
);
482 ieee80211_roc_purge(local
, sdata
);
484 switch (sdata
->vif
.type
) {
485 case NL80211_IFTYPE_STATION
:
486 ieee80211_mgd_stop(sdata
);
488 case NL80211_IFTYPE_ADHOC
:
489 ieee80211_ibss_stop(sdata
);
491 case NL80211_IFTYPE_MONITOR
:
492 if (sdata
->u
.mntr
.flags
& MONITOR_FLAG_COOK_FRAMES
)
494 list_del_rcu(&sdata
->u
.mntr
.list
);
501 * Remove all stations associated with this interface.
503 * This must be done before calling ops->remove_interface()
504 * because otherwise we can later invoke ops->sta_notify()
505 * whenever the STAs are removed, and that invalidates driver
506 * assumptions about always getting a vif pointer that is valid
507 * (because if we remove a STA after ops->remove_interface()
508 * the driver will have removed the vif info already!)
510 * For AP_VLANs stations may exist since there's nothing else that
511 * would have removed them, but in other modes there shouldn't
514 flushed
= sta_info_flush(sdata
, -1);
515 WARN_ON_ONCE(sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&& flushed
> 0);
517 /* don't count this interface for allmulti while it is down */
518 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
519 atomic_dec(&local
->iff_allmultis
);
521 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
523 local
->fif_probe_req
--;
524 } else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
525 local
->fif_probe_req
--;
529 netif_addr_lock_bh(sdata
->dev
);
530 spin_lock_bh(&local
->filter_lock
);
531 __hw_addr_unsync(&local
->mc_list
, &sdata
->dev
->mc
,
532 sdata
->dev
->addr_len
);
533 spin_unlock_bh(&local
->filter_lock
);
534 netif_addr_unlock_bh(sdata
->dev
);
537 del_timer_sync(&local
->dynamic_ps_timer
);
538 wiphy_work_cancel(local
->hw
.wiphy
, &local
->dynamic_ps_enable_work
);
540 WARN(ieee80211_vif_is_mld(&sdata
->vif
),
541 "destroying interface with valid links 0x%04x\n",
542 sdata
->vif
.valid_links
);
544 sdata
->vif
.bss_conf
.csa_active
= false;
545 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
546 sdata
->deflink
.u
.mgd
.csa
.waiting_bcn
= false;
547 ieee80211_vif_unblock_queues_csa(sdata
);
549 wiphy_work_cancel(local
->hw
.wiphy
, &sdata
->deflink
.csa
.finalize_work
);
550 wiphy_work_cancel(local
->hw
.wiphy
,
551 &sdata
->deflink
.color_change_finalize_work
);
552 wiphy_delayed_work_cancel(local
->hw
.wiphy
,
553 &sdata
->deflink
.dfs_cac_timer_work
);
555 if (sdata
->wdev
.links
[0].cac_started
) {
556 chandef
= sdata
->vif
.bss_conf
.chanreq
.oper
;
557 WARN_ON(local
->suspended
);
558 ieee80211_link_release_channel(&sdata
->deflink
);
559 cfg80211_cac_event(sdata
->dev
, &chandef
,
560 NL80211_RADAR_CAC_ABORTED
,
564 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
565 WARN_ON(!list_empty(&sdata
->u
.ap
.vlans
));
566 } else if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) {
567 /* remove all packets in parent bc_buf pointing to this dev */
568 ps
= &sdata
->bss
->ps
;
570 spin_lock_irqsave(&ps
->bc_buf
.lock
, flags
);
571 skb_queue_walk_safe(&ps
->bc_buf
, skb
, tmp
) {
572 if (skb
->dev
== sdata
->dev
) {
573 __skb_unlink(skb
, &ps
->bc_buf
);
574 local
->total_ps_buffered
--;
575 ieee80211_free_txskb(&local
->hw
, skb
);
578 spin_unlock_irqrestore(&ps
->bc_buf
.lock
, flags
);
584 switch (sdata
->vif
.type
) {
585 case NL80211_IFTYPE_AP_VLAN
:
586 list_del(&sdata
->u
.vlan
.list
);
587 RCU_INIT_POINTER(sdata
->vif
.bss_conf
.chanctx_conf
, NULL
);
588 /* see comment in the default case below */
589 ieee80211_free_keys(sdata
, true);
590 /* no need to tell driver */
592 case NL80211_IFTYPE_MONITOR
:
593 if (sdata
->u
.mntr
.flags
& MONITOR_FLAG_COOK_FRAMES
) {
594 local
->cooked_mntrs
--;
599 if (local
->monitors
== 0) {
600 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_MONITOR
;
601 hw_reconf_flags
|= IEEE80211_CONF_CHANGE_MONITOR
;
604 ieee80211_adjust_monitor_flags(sdata
, -1);
606 case NL80211_IFTYPE_NAN
:
607 /* clean all the functions */
608 spin_lock_bh(&sdata
->u
.nan
.func_lock
);
610 idr_for_each_entry(&sdata
->u
.nan
.function_inst_ids
, func
, i
) {
611 idr_remove(&sdata
->u
.nan
.function_inst_ids
, i
);
612 cfg80211_free_nan_func(func
);
614 idr_destroy(&sdata
->u
.nan
.function_inst_ids
);
616 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
618 case NL80211_IFTYPE_P2P_DEVICE
:
619 /* relies on synchronize_rcu() below */
620 RCU_INIT_POINTER(local
->p2p_sdata
, NULL
);
623 wiphy_work_cancel(sdata
->local
->hw
.wiphy
, &sdata
->work
);
625 * When we get here, the interface is marked down.
626 * Free the remaining keys, if there are any
627 * (which can happen in AP mode if userspace sets
628 * keys before the interface is operating)
630 * Force the key freeing to always synchronize_net()
631 * to wait for the RX path in case it is using this
632 * interface enqueuing frames at this very time on
635 ieee80211_free_keys(sdata
, true);
636 skb_queue_purge(&sdata
->skb_queue
);
637 skb_queue_purge(&sdata
->status_queue
);
641 * Since ieee80211_free_txskb() may issue __dev_queue_xmit()
642 * which should be called with interrupts enabled, reclamation
643 * is done in two phases:
645 __skb_queue_head_init(&freeq
);
647 /* unlink from local queues... */
648 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
649 for (i
= 0; i
< IEEE80211_MAX_QUEUES
; i
++) {
650 skb_queue_walk_safe(&local
->pending
[i
], skb
, tmp
) {
651 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
652 if (info
->control
.vif
== &sdata
->vif
) {
653 __skb_unlink(skb
, &local
->pending
[i
]);
654 __skb_queue_tail(&freeq
, skb
);
658 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
660 /* ... and perform actual reclamation with interrupts enabled. */
661 skb_queue_walk_safe(&freeq
, skb
, tmp
) {
662 __skb_unlink(skb
, &freeq
);
663 ieee80211_free_txskb(&local
->hw
, skb
);
666 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
667 ieee80211_txq_remove_vlan(local
, sdata
);
671 if (local
->open_count
== 0)
672 ieee80211_clear_tx_pending(local
);
674 sdata
->vif
.bss_conf
.beacon_int
= 0;
677 * If the interface goes down while suspended, presumably because
678 * the device was unplugged and that happens before our resume,
679 * then the driver is already unconfigured and the remainder of
680 * this function isn't needed.
681 * XXX: what about WoWLAN? If the device has software state, e.g.
682 * memory allocated, it might expect teardown commands from
685 if (local
->suspended
) {
686 WARN_ON(local
->wowlan
);
687 WARN_ON(rcu_access_pointer(local
->monitor_sdata
));
691 switch (sdata
->vif
.type
) {
692 case NL80211_IFTYPE_AP_VLAN
:
694 case NL80211_IFTYPE_MONITOR
:
695 if (local
->monitors
== 0)
696 ieee80211_del_virtual_monitor(local
);
698 ieee80211_recalc_idle(local
);
699 ieee80211_recalc_offload(local
);
701 if (!(sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
) &&
702 !ieee80211_hw_check(&local
->hw
, NO_VIRTUAL_MONITOR
))
705 ieee80211_link_release_channel(&sdata
->deflink
);
710 drv_remove_interface(local
, sdata
);
712 /* Clear private driver data to prevent reuse */
713 memset(sdata
->vif
.drv_priv
, 0, local
->hw
.vif_data_size
);
716 ieee80211_recalc_ps(local
);
719 wiphy_delayed_work_flush(local
->hw
.wiphy
, &local
->scan_work
);
721 if (local
->open_count
== 0) {
722 ieee80211_stop_device(local
, false);
724 /* no reconfiguring after stop! */
728 /* do after stop to avoid reconfiguring when we stop anyway */
729 ieee80211_configure_filter(local
);
730 ieee80211_hw_config(local
, hw_reconf_flags
);
732 if (local
->monitors
== local
->open_count
)
733 ieee80211_add_virtual_monitor(local
);
736 static void ieee80211_stop_mbssid(struct ieee80211_sub_if_data
*sdata
)
738 struct ieee80211_sub_if_data
*tx_sdata
, *non_tx_sdata
, *tmp_sdata
;
739 struct ieee80211_vif
*tx_vif
= sdata
->vif
.mbssid_tx_vif
;
744 tx_sdata
= vif_to_sdata(tx_vif
);
745 sdata
->vif
.mbssid_tx_vif
= NULL
;
747 list_for_each_entry_safe(non_tx_sdata
, tmp_sdata
,
748 &tx_sdata
->local
->interfaces
, list
) {
749 if (non_tx_sdata
!= sdata
&& non_tx_sdata
!= tx_sdata
&&
750 non_tx_sdata
->vif
.mbssid_tx_vif
== tx_vif
&&
751 ieee80211_sdata_running(non_tx_sdata
)) {
752 non_tx_sdata
->vif
.mbssid_tx_vif
= NULL
;
753 dev_close(non_tx_sdata
->wdev
.netdev
);
757 if (sdata
!= tx_sdata
&& ieee80211_sdata_running(tx_sdata
)) {
758 tx_sdata
->vif
.mbssid_tx_vif
= NULL
;
759 dev_close(tx_sdata
->wdev
.netdev
);
763 static int ieee80211_stop(struct net_device
*dev
)
765 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
767 /* close dependent VLAN and MBSSID interfaces before locking wiphy */
768 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
769 struct ieee80211_sub_if_data
*vlan
, *tmpsdata
;
771 list_for_each_entry_safe(vlan
, tmpsdata
, &sdata
->u
.ap
.vlans
,
773 dev_close(vlan
->dev
);
775 ieee80211_stop_mbssid(sdata
);
778 wiphy_lock(sdata
->local
->hw
.wiphy
);
779 wiphy_work_cancel(sdata
->local
->hw
.wiphy
, &sdata
->activate_links_work
);
781 ieee80211_do_stop(sdata
, true);
782 wiphy_unlock(sdata
->local
->hw
.wiphy
);
787 static void ieee80211_set_multicast_list(struct net_device
*dev
)
789 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
790 struct ieee80211_local
*local
= sdata
->local
;
791 int allmulti
, sdata_allmulti
;
793 allmulti
= !!(dev
->flags
& IFF_ALLMULTI
);
794 sdata_allmulti
= !!(sdata
->flags
& IEEE80211_SDATA_ALLMULTI
);
796 if (allmulti
!= sdata_allmulti
) {
797 if (dev
->flags
& IFF_ALLMULTI
)
798 atomic_inc(&local
->iff_allmultis
);
800 atomic_dec(&local
->iff_allmultis
);
801 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
804 spin_lock_bh(&local
->filter_lock
);
805 __hw_addr_sync(&local
->mc_list
, &dev
->mc
, dev
->addr_len
);
806 spin_unlock_bh(&local
->filter_lock
);
807 wiphy_work_queue(local
->hw
.wiphy
, &local
->reconfig_filter
);
811 * Called when the netdev is removed or, by the code below, before
812 * the interface type changes.
814 static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data
*sdata
)
816 /* free extra data */
817 ieee80211_free_keys(sdata
, false);
819 ieee80211_debugfs_remove_netdev(sdata
);
821 ieee80211_destroy_frag_cache(&sdata
->frags
);
823 if (ieee80211_vif_is_mesh(&sdata
->vif
))
824 ieee80211_mesh_teardown_sdata(sdata
);
826 ieee80211_vif_clear_links(sdata
);
827 ieee80211_link_stop(&sdata
->deflink
);
830 static void ieee80211_uninit(struct net_device
*dev
)
832 ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev
));
835 static int ieee80211_netdev_setup_tc(struct net_device
*dev
,
836 enum tc_setup_type type
, void *type_data
)
838 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
839 struct ieee80211_local
*local
= sdata
->local
;
841 return drv_net_setup_tc(local
, sdata
, dev
, type
, type_data
);
844 static const struct net_device_ops ieee80211_dataif_ops
= {
845 .ndo_open
= ieee80211_open
,
846 .ndo_stop
= ieee80211_stop
,
847 .ndo_uninit
= ieee80211_uninit
,
848 .ndo_start_xmit
= ieee80211_subif_start_xmit
,
849 .ndo_set_rx_mode
= ieee80211_set_multicast_list
,
850 .ndo_set_mac_address
= ieee80211_change_mac
,
851 .ndo_setup_tc
= ieee80211_netdev_setup_tc
,
854 static u16
ieee80211_monitor_select_queue(struct net_device
*dev
,
856 struct net_device
*sb_dev
)
858 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
859 struct ieee80211_local
*local
= sdata
->local
;
860 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
861 struct ieee80211_hdr
*hdr
;
864 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
867 /* reset flags and info before parsing radiotap header */
868 memset(info
, 0, sizeof(*info
));
870 if (!ieee80211_parse_tx_radiotap(skb
, dev
))
871 return 0; /* doesn't matter, frame will be dropped */
873 len_rthdr
= ieee80211_get_radiotap_len(skb
->data
);
874 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ len_rthdr
);
875 if (skb
->len
< len_rthdr
+ 2 ||
876 skb
->len
< len_rthdr
+ ieee80211_hdrlen(hdr
->frame_control
))
877 return 0; /* doesn't matter, frame will be dropped */
879 return ieee80211_select_queue_80211(sdata
, skb
, hdr
);
882 static const struct net_device_ops ieee80211_monitorif_ops
= {
883 .ndo_open
= ieee80211_open
,
884 .ndo_stop
= ieee80211_stop
,
885 .ndo_uninit
= ieee80211_uninit
,
886 .ndo_start_xmit
= ieee80211_monitor_start_xmit
,
887 .ndo_set_rx_mode
= ieee80211_set_multicast_list
,
888 .ndo_set_mac_address
= ieee80211_change_mac
,
889 .ndo_select_queue
= ieee80211_monitor_select_queue
,
892 static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx
*ctx
,
893 struct net_device_path
*path
)
895 struct ieee80211_sub_if_data
*sdata
;
896 struct ieee80211_local
*local
;
897 struct sta_info
*sta
;
900 sdata
= IEEE80211_DEV_TO_SUB_IF(ctx
->dev
);
901 local
= sdata
->local
;
903 if (!local
->ops
->net_fill_forward_path
)
907 switch (sdata
->vif
.type
) {
908 case NL80211_IFTYPE_AP_VLAN
:
909 sta
= rcu_dereference(sdata
->u
.vlan
.sta
);
912 if (sdata
->wdev
.use_4addr
)
914 if (is_multicast_ether_addr(ctx
->daddr
))
916 sta
= sta_info_get_bss(sdata
, ctx
->daddr
);
918 case NL80211_IFTYPE_AP
:
919 if (is_multicast_ether_addr(ctx
->daddr
))
921 sta
= sta_info_get(sdata
, ctx
->daddr
);
923 case NL80211_IFTYPE_STATION
:
924 if (sdata
->wdev
.wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
925 sta
= sta_info_get(sdata
, ctx
->daddr
);
926 if (sta
&& test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
927 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
))
934 sta
= sta_info_get(sdata
, sdata
->deflink
.u
.mgd
.bssid
);
943 ret
= drv_net_fill_forward_path(local
, sdata
, &sta
->sta
, ctx
, path
);
950 static const struct net_device_ops ieee80211_dataif_8023_ops
= {
951 .ndo_open
= ieee80211_open
,
952 .ndo_stop
= ieee80211_stop
,
953 .ndo_uninit
= ieee80211_uninit
,
954 .ndo_start_xmit
= ieee80211_subif_start_xmit_8023
,
955 .ndo_set_rx_mode
= ieee80211_set_multicast_list
,
956 .ndo_set_mac_address
= ieee80211_change_mac
,
957 .ndo_fill_forward_path
= ieee80211_netdev_fill_forward_path
,
958 .ndo_setup_tc
= ieee80211_netdev_setup_tc
,
961 static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype
)
964 /* P2P GO and client are mapped to AP/STATION types */
965 case NL80211_IFTYPE_AP
:
966 case NL80211_IFTYPE_STATION
:
973 static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data
*sdata
)
975 struct ieee80211_local
*local
= sdata
->local
;
978 flags
= sdata
->vif
.offload_flags
;
980 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_TX_ENCAP_OFFLOAD
) &&
981 ieee80211_iftype_supports_hdr_offload(sdata
->vif
.type
)) {
982 flags
|= IEEE80211_OFFLOAD_ENCAP_ENABLED
;
984 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_TX_FRAG
) &&
985 local
->hw
.wiphy
->frag_threshold
!= (u32
)-1)
986 flags
&= ~IEEE80211_OFFLOAD_ENCAP_ENABLED
;
989 flags
&= ~IEEE80211_OFFLOAD_ENCAP_ENABLED
;
991 flags
&= ~IEEE80211_OFFLOAD_ENCAP_ENABLED
;
994 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_RX_DECAP_OFFLOAD
) &&
995 ieee80211_iftype_supports_hdr_offload(sdata
->vif
.type
)) {
996 flags
|= IEEE80211_OFFLOAD_DECAP_ENABLED
;
998 if (local
->monitors
&&
999 !ieee80211_hw_check(&local
->hw
, SUPPORTS_CONC_MON_RX_DECAP
))
1000 flags
&= ~IEEE80211_OFFLOAD_DECAP_ENABLED
;
1002 flags
&= ~IEEE80211_OFFLOAD_DECAP_ENABLED
;
1005 if (sdata
->vif
.offload_flags
== flags
)
1008 sdata
->vif
.offload_flags
= flags
;
1009 ieee80211_check_fast_rx_iface(sdata
);
1013 static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data
*sdata
)
1015 struct ieee80211_local
*local
= sdata
->local
;
1016 struct ieee80211_sub_if_data
*bss
= sdata
;
1019 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) {
1023 bss
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
, u
.ap
);
1026 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_TX_ENCAP_OFFLOAD
) ||
1027 !ieee80211_iftype_supports_hdr_offload(bss
->vif
.type
))
1030 enabled
= bss
->vif
.offload_flags
& IEEE80211_OFFLOAD_ENCAP_ENABLED
;
1031 if (sdata
->wdev
.use_4addr
&&
1032 !(bss
->vif
.offload_flags
& IEEE80211_OFFLOAD_ENCAP_4ADDR
))
1035 sdata
->dev
->netdev_ops
= enabled
? &ieee80211_dataif_8023_ops
:
1036 &ieee80211_dataif_ops
;
1039 static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data
*sdata
)
1041 struct ieee80211_local
*local
= sdata
->local
;
1042 struct ieee80211_sub_if_data
*vsdata
;
1044 if (ieee80211_set_sdata_offload_flags(sdata
)) {
1045 drv_update_vif_offload(local
, sdata
);
1046 ieee80211_set_vif_encap_ops(sdata
);
1049 list_for_each_entry(vsdata
, &local
->interfaces
, list
) {
1050 if (vsdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
||
1051 vsdata
->bss
!= &sdata
->u
.ap
)
1054 ieee80211_set_vif_encap_ops(vsdata
);
1058 void ieee80211_recalc_offload(struct ieee80211_local
*local
)
1060 struct ieee80211_sub_if_data
*sdata
;
1062 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_TX_ENCAP_OFFLOAD
))
1065 lockdep_assert_wiphy(local
->hw
.wiphy
);
1067 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1068 if (!ieee80211_sdata_running(sdata
))
1071 ieee80211_recalc_sdata_offload(sdata
);
1075 void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data
*sdata
,
1078 struct ieee80211_local
*local
= sdata
->local
;
1079 u32 flags
= sdata
->u
.mntr
.flags
;
1081 #define ADJUST(_f, _s) do { \
1082 if (flags & MONITOR_FLAG_##_f) \
1083 local->fif_##_s += offset; \
1086 ADJUST(FCSFAIL
, fcsfail
);
1087 ADJUST(PLCPFAIL
, plcpfail
);
1088 ADJUST(CONTROL
, control
);
1089 ADJUST(CONTROL
, pspoll
);
1090 ADJUST(OTHER_BSS
, other_bss
);
1091 if (!(flags
& MONITOR_FLAG_SKIP_TX
))
1092 local
->tx_mntrs
+= offset
;
1097 static void ieee80211_set_default_queues(struct ieee80211_sub_if_data
*sdata
)
1099 struct ieee80211_local
*local
= sdata
->local
;
1102 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
1103 if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
))
1104 sdata
->vif
.hw_queue
[i
] = IEEE80211_INVAL_HW_QUEUE
;
1105 else if (local
->hw
.queues
>= IEEE80211_NUM_ACS
)
1106 sdata
->vif
.hw_queue
[i
] = i
;
1108 sdata
->vif
.hw_queue
[i
] = 0;
1110 sdata
->vif
.cab_queue
= IEEE80211_INVAL_HW_QUEUE
;
1113 static void ieee80211_sdata_init(struct ieee80211_local
*local
,
1114 struct ieee80211_sub_if_data
*sdata
)
1116 sdata
->local
= local
;
1119 * Initialize the default link, so we can use link_id 0 for non-MLD,
1120 * and that continues to work for non-MLD-aware drivers that use just
1121 * vif.bss_conf instead of vif.link_conf.
1123 * Note that we never change this, so if link ID 0 isn't used in an
1124 * MLD connection, we get a separate allocation for it.
1126 ieee80211_link_init(sdata
, -1, &sdata
->deflink
, &sdata
->vif
.bss_conf
);
1129 int ieee80211_add_virtual_monitor(struct ieee80211_local
*local
)
1131 struct ieee80211_sub_if_data
*sdata
;
1135 lockdep_assert_wiphy(local
->hw
.wiphy
);
1137 if (local
->monitor_sdata
||
1138 ieee80211_hw_check(&local
->hw
, NO_VIRTUAL_MONITOR
))
1141 sdata
= kzalloc(sizeof(*sdata
) + local
->hw
.vif_data_size
, GFP_KERNEL
);
1146 sdata
->vif
.type
= NL80211_IFTYPE_MONITOR
;
1147 snprintf(sdata
->name
, IFNAMSIZ
, "%s-monitor",
1148 wiphy_name(local
->hw
.wiphy
));
1149 sdata
->wdev
.iftype
= NL80211_IFTYPE_MONITOR
;
1150 sdata
->wdev
.wiphy
= local
->hw
.wiphy
;
1152 ieee80211_sdata_init(local
, sdata
);
1154 ieee80211_set_default_queues(sdata
);
1156 if (ieee80211_hw_check(&local
->hw
, WANT_MONITOR_VIF
)) {
1157 ret
= drv_add_interface(local
, sdata
);
1159 /* ok .. stupid driver, it asked for this! */
1165 set_bit(SDATA_STATE_RUNNING
, &sdata
->state
);
1167 ret
= ieee80211_check_queues(sdata
, NL80211_IFTYPE_MONITOR
);
1173 mutex_lock(&local
->iflist_mtx
);
1174 rcu_assign_pointer(local
->monitor_sdata
, sdata
);
1175 mutex_unlock(&local
->iflist_mtx
);
1177 ret
= ieee80211_link_use_channel(&sdata
->deflink
, &local
->monitor_chanreq
,
1178 IEEE80211_CHANCTX_EXCLUSIVE
);
1180 mutex_lock(&local
->iflist_mtx
);
1181 RCU_INIT_POINTER(local
->monitor_sdata
, NULL
);
1182 mutex_unlock(&local
->iflist_mtx
);
1184 drv_remove_interface(local
, sdata
);
1189 skb_queue_head_init(&sdata
->skb_queue
);
1190 skb_queue_head_init(&sdata
->status_queue
);
1191 wiphy_work_init(&sdata
->work
, ieee80211_iface_work
);
1196 void ieee80211_del_virtual_monitor(struct ieee80211_local
*local
)
1198 struct ieee80211_sub_if_data
*sdata
;
1200 if (ieee80211_hw_check(&local
->hw
, NO_VIRTUAL_MONITOR
))
1204 lockdep_assert_wiphy(local
->hw
.wiphy
);
1206 mutex_lock(&local
->iflist_mtx
);
1208 sdata
= rcu_dereference_protected(local
->monitor_sdata
,
1209 lockdep_is_held(&local
->iflist_mtx
));
1211 mutex_unlock(&local
->iflist_mtx
);
1215 RCU_INIT_POINTER(local
->monitor_sdata
, NULL
);
1216 mutex_unlock(&local
->iflist_mtx
);
1220 ieee80211_link_release_channel(&sdata
->deflink
);
1222 if (ieee80211_hw_check(&local
->hw
, WANT_MONITOR_VIF
))
1223 drv_remove_interface(local
, sdata
);
1229 * NOTE: Be very careful when changing this function, it must NOT return
1230 * an error on interface type changes that have been pre-checked, so most
1231 * checks should be in ieee80211_check_concurrent_iface.
1233 int ieee80211_do_open(struct wireless_dev
*wdev
, bool coming_up
)
1235 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
1236 struct net_device
*dev
= wdev
->netdev
;
1237 struct ieee80211_local
*local
= sdata
->local
;
1240 u32 hw_reconf_flags
= 0;
1242 lockdep_assert_wiphy(local
->hw
.wiphy
);
1244 switch (sdata
->vif
.type
) {
1245 case NL80211_IFTYPE_AP_VLAN
: {
1246 struct ieee80211_sub_if_data
*master
;
1251 list_add(&sdata
->u
.vlan
.list
, &sdata
->bss
->vlans
);
1253 master
= container_of(sdata
->bss
,
1254 struct ieee80211_sub_if_data
, u
.ap
);
1255 sdata
->control_port_protocol
=
1256 master
->control_port_protocol
;
1257 sdata
->control_port_no_encrypt
=
1258 master
->control_port_no_encrypt
;
1259 sdata
->control_port_over_nl80211
=
1260 master
->control_port_over_nl80211
;
1261 sdata
->control_port_no_preauth
=
1262 master
->control_port_no_preauth
;
1263 sdata
->vif
.cab_queue
= master
->vif
.cab_queue
;
1264 memcpy(sdata
->vif
.hw_queue
, master
->vif
.hw_queue
,
1265 sizeof(sdata
->vif
.hw_queue
));
1266 sdata
->vif
.bss_conf
.chanreq
= master
->vif
.bss_conf
.chanreq
;
1268 sdata
->crypto_tx_tailroom_needed_cnt
+=
1269 master
->crypto_tx_tailroom_needed_cnt
;
1273 case NL80211_IFTYPE_AP
:
1274 sdata
->bss
= &sdata
->u
.ap
;
1276 case NL80211_IFTYPE_MESH_POINT
:
1277 case NL80211_IFTYPE_STATION
:
1278 case NL80211_IFTYPE_MONITOR
:
1279 case NL80211_IFTYPE_ADHOC
:
1280 case NL80211_IFTYPE_P2P_DEVICE
:
1281 case NL80211_IFTYPE_OCB
:
1282 case NL80211_IFTYPE_NAN
:
1283 /* no special treatment */
1285 case NL80211_IFTYPE_UNSPECIFIED
:
1286 case NUM_NL80211_IFTYPES
:
1287 case NL80211_IFTYPE_P2P_CLIENT
:
1288 case NL80211_IFTYPE_P2P_GO
:
1289 case NL80211_IFTYPE_WDS
:
1295 if (local
->open_count
== 0) {
1296 /* here we can consider everything in good order (again) */
1297 local
->reconfig_failure
= false;
1299 res
= drv_start(local
);
1302 ieee80211_led_radio(local
, true);
1303 ieee80211_mod_tpt_led_trig(local
,
1304 IEEE80211_TPT_LEDTRIG_FL_RADIO
, 0);
1308 * Copy the hopefully now-present MAC address to
1309 * this interface, if it has the special null one.
1311 if (dev
&& is_zero_ether_addr(dev
->dev_addr
)) {
1312 eth_hw_addr_set(dev
, local
->hw
.wiphy
->perm_addr
);
1313 memcpy(dev
->perm_addr
, dev
->dev_addr
, ETH_ALEN
);
1315 if (!is_valid_ether_addr(dev
->dev_addr
)) {
1316 res
= -EADDRNOTAVAIL
;
1321 sdata
->vif
.addr_valid
= sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
||
1322 (sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
);
1323 switch (sdata
->vif
.type
) {
1324 case NL80211_IFTYPE_AP_VLAN
:
1325 /* no need to tell driver, but set carrier and chanctx */
1326 if (sdata
->bss
->active
) {
1327 ieee80211_link_vlan_copy_chanctx(&sdata
->deflink
);
1328 netif_carrier_on(dev
);
1329 ieee80211_set_vif_encap_ops(sdata
);
1331 netif_carrier_off(dev
);
1334 case NL80211_IFTYPE_MONITOR
:
1335 if (sdata
->u
.mntr
.flags
& MONITOR_FLAG_COOK_FRAMES
) {
1336 local
->cooked_mntrs
++;
1340 if ((sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
) ||
1341 ieee80211_hw_check(&local
->hw
, NO_VIRTUAL_MONITOR
)) {
1342 res
= drv_add_interface(local
, sdata
);
1345 } else if (local
->monitors
== 0 && local
->open_count
== 0) {
1346 res
= ieee80211_add_virtual_monitor(local
);
1351 /* must be before the call to ieee80211_configure_filter */
1353 if (local
->monitors
== 1) {
1354 local
->hw
.conf
.flags
|= IEEE80211_CONF_MONITOR
;
1355 hw_reconf_flags
|= IEEE80211_CONF_CHANGE_MONITOR
;
1358 ieee80211_adjust_monitor_flags(sdata
, 1);
1359 ieee80211_configure_filter(local
);
1360 ieee80211_recalc_offload(local
);
1361 ieee80211_recalc_idle(local
);
1363 netif_carrier_on(dev
);
1367 ieee80211_del_virtual_monitor(local
);
1368 ieee80211_set_sdata_offload_flags(sdata
);
1370 res
= drv_add_interface(local
, sdata
);
1374 ieee80211_set_vif_encap_ops(sdata
);
1375 res
= ieee80211_check_queues(sdata
,
1376 ieee80211_vif_type_p2p(&sdata
->vif
));
1378 goto err_del_interface
;
1381 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
1382 local
->fif_pspoll
++;
1383 local
->fif_probe_req
++;
1385 ieee80211_configure_filter(local
);
1386 } else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
1387 local
->fif_probe_req
++;
1390 if (sdata
->vif
.probe_req_reg
)
1391 drv_config_iface_filter(local
, sdata
,
1395 if (sdata
->vif
.type
!= NL80211_IFTYPE_P2P_DEVICE
&&
1396 sdata
->vif
.type
!= NL80211_IFTYPE_NAN
)
1397 changed
|= ieee80211_reset_erp_info(sdata
);
1398 ieee80211_link_info_change_notify(sdata
, &sdata
->deflink
,
1401 switch (sdata
->vif
.type
) {
1402 case NL80211_IFTYPE_STATION
:
1403 case NL80211_IFTYPE_ADHOC
:
1404 case NL80211_IFTYPE_AP
:
1405 case NL80211_IFTYPE_MESH_POINT
:
1406 case NL80211_IFTYPE_OCB
:
1407 netif_carrier_off(dev
);
1409 case NL80211_IFTYPE_P2P_DEVICE
:
1410 case NL80211_IFTYPE_NAN
:
1418 * Set default queue parameters so drivers don't
1419 * need to initialise the hardware if the hardware
1420 * doesn't start up with sane defaults.
1421 * Enable QoS for anything but station interfaces.
1423 ieee80211_set_wmm_default(&sdata
->deflink
, true,
1424 sdata
->vif
.type
!= NL80211_IFTYPE_STATION
);
1427 switch (sdata
->vif
.type
) {
1428 case NL80211_IFTYPE_P2P_DEVICE
:
1429 rcu_assign_pointer(local
->p2p_sdata
, sdata
);
1431 case NL80211_IFTYPE_MONITOR
:
1432 if (sdata
->u
.mntr
.flags
& MONITOR_FLAG_COOK_FRAMES
)
1434 list_add_tail_rcu(&sdata
->u
.mntr
.list
, &local
->mon_list
);
1441 * set_multicast_list will be invoked by the networking core
1442 * which will check whether any increments here were done in
1443 * error and sync them down to the hardware as filter flags.
1445 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
1446 atomic_inc(&local
->iff_allmultis
);
1449 local
->open_count
++;
1451 if (local
->open_count
== 1)
1452 ieee80211_hw_conf_init(local
);
1453 else if (hw_reconf_flags
)
1454 ieee80211_hw_config(local
, hw_reconf_flags
);
1456 ieee80211_recalc_ps(local
);
1458 set_bit(SDATA_STATE_RUNNING
, &sdata
->state
);
1462 drv_remove_interface(local
, sdata
);
1464 if (!local
->open_count
)
1465 drv_stop(local
, false);
1468 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
1469 list_del(&sdata
->u
.vlan
.list
);
1470 /* might already be clear but that doesn't matter */
1471 clear_bit(SDATA_STATE_RUNNING
, &sdata
->state
);
1475 static void ieee80211_if_setup(struct net_device
*dev
)
1478 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
1479 dev
->priv_flags
|= IFF_NO_QUEUE
;
1480 dev
->netdev_ops
= &ieee80211_dataif_ops
;
1481 dev
->needs_free_netdev
= true;
1484 static void ieee80211_iface_process_skb(struct ieee80211_local
*local
,
1485 struct ieee80211_sub_if_data
*sdata
,
1486 struct sk_buff
*skb
)
1488 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1490 lockdep_assert_wiphy(local
->hw
.wiphy
);
1492 if (ieee80211_is_action(mgmt
->frame_control
) &&
1493 mgmt
->u
.action
.category
== WLAN_CATEGORY_BACK
) {
1494 struct sta_info
*sta
;
1497 sta
= sta_info_get_bss(sdata
, mgmt
->sa
);
1499 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
1500 case WLAN_ACTION_ADDBA_REQ
:
1501 ieee80211_process_addba_request(local
, sta
,
1504 case WLAN_ACTION_ADDBA_RESP
:
1505 ieee80211_process_addba_resp(local
, sta
,
1508 case WLAN_ACTION_DELBA
:
1509 ieee80211_process_delba(sdata
, sta
,
1517 } else if (ieee80211_is_action(mgmt
->frame_control
) &&
1518 mgmt
->u
.action
.category
== WLAN_CATEGORY_VHT
) {
1519 switch (mgmt
->u
.action
.u
.vht_group_notif
.action_code
) {
1520 case WLAN_VHT_ACTION_OPMODE_NOTIF
: {
1521 struct ieee80211_rx_status
*status
;
1522 enum nl80211_band band
;
1523 struct sta_info
*sta
;
1526 status
= IEEE80211_SKB_RXCB(skb
);
1527 band
= status
->band
;
1528 opmode
= mgmt
->u
.action
.u
.vht_opmode_notif
.operating_mode
;
1530 sta
= sta_info_get_bss(sdata
, mgmt
->sa
);
1533 ieee80211_vht_handle_opmode(sdata
,
1539 case WLAN_VHT_ACTION_GROUPID_MGMT
:
1540 ieee80211_process_mu_groups(sdata
, &sdata
->deflink
,
1547 } else if (ieee80211_is_action(mgmt
->frame_control
) &&
1548 mgmt
->u
.action
.category
== WLAN_CATEGORY_S1G
) {
1549 switch (mgmt
->u
.action
.u
.s1g
.action_code
) {
1550 case WLAN_S1G_TWT_TEARDOWN
:
1551 case WLAN_S1G_TWT_SETUP
:
1552 ieee80211_s1g_rx_twt_action(sdata
, skb
);
1557 } else if (ieee80211_is_action(mgmt
->frame_control
) &&
1558 mgmt
->u
.action
.category
== WLAN_CATEGORY_PROTECTED_EHT
) {
1559 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
1560 switch (mgmt
->u
.action
.u
.ttlm_req
.action_code
) {
1561 case WLAN_PROTECTED_EHT_ACTION_TTLM_REQ
:
1562 ieee80211_process_neg_ttlm_req(sdata
, mgmt
,
1565 case WLAN_PROTECTED_EHT_ACTION_TTLM_RES
:
1566 ieee80211_process_neg_ttlm_res(sdata
, mgmt
,
1573 } else if (ieee80211_is_ext(mgmt
->frame_control
)) {
1574 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
1575 ieee80211_sta_rx_queued_ext(sdata
, skb
);
1578 } else if (ieee80211_is_data_qos(mgmt
->frame_control
)) {
1579 struct ieee80211_hdr
*hdr
= (void *)mgmt
;
1580 struct sta_info
*sta
;
1583 * So the frame isn't mgmt, but frame_control
1584 * is at the right place anyway, of course, so
1585 * the if statement is correct.
1587 * Warn if we have other data frame types here,
1588 * they must not get here.
1590 WARN_ON(hdr
->frame_control
&
1591 cpu_to_le16(IEEE80211_STYPE_NULLFUNC
));
1592 WARN_ON(!(hdr
->seq_ctrl
&
1593 cpu_to_le16(IEEE80211_SCTL_FRAG
)));
1595 * This was a fragment of a frame, received while
1596 * a block-ack session was active. That cannot be
1597 * right, so terminate the session.
1599 sta
= sta_info_get_bss(sdata
, mgmt
->sa
);
1601 u16 tid
= ieee80211_get_tid(hdr
);
1603 __ieee80211_stop_rx_ba_session(
1604 sta
, tid
, WLAN_BACK_RECIPIENT
,
1605 WLAN_REASON_QSTA_REQUIRE_SETUP
,
1608 } else switch (sdata
->vif
.type
) {
1609 case NL80211_IFTYPE_STATION
:
1610 ieee80211_sta_rx_queued_mgmt(sdata
, skb
);
1612 case NL80211_IFTYPE_ADHOC
:
1613 ieee80211_ibss_rx_queued_mgmt(sdata
, skb
);
1615 case NL80211_IFTYPE_MESH_POINT
:
1616 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
1618 ieee80211_mesh_rx_queued_mgmt(sdata
, skb
);
1621 WARN(1, "frame for unexpected interface type");
1626 static void ieee80211_iface_process_status(struct ieee80211_sub_if_data
*sdata
,
1627 struct sk_buff
*skb
)
1629 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1631 if (ieee80211_is_action(mgmt
->frame_control
) &&
1632 mgmt
->u
.action
.category
== WLAN_CATEGORY_S1G
) {
1633 switch (mgmt
->u
.action
.u
.s1g
.action_code
) {
1634 case WLAN_S1G_TWT_TEARDOWN
:
1635 case WLAN_S1G_TWT_SETUP
:
1636 ieee80211_s1g_status_twt_action(sdata
, skb
);
1644 static void ieee80211_iface_work(struct wiphy
*wiphy
, struct wiphy_work
*work
)
1646 struct ieee80211_sub_if_data
*sdata
=
1647 container_of(work
, struct ieee80211_sub_if_data
, work
);
1648 struct ieee80211_local
*local
= sdata
->local
;
1649 struct sk_buff
*skb
;
1651 if (!ieee80211_sdata_running(sdata
))
1654 if (test_bit(SCAN_SW_SCANNING
, &local
->scanning
))
1657 if (!ieee80211_can_run_worker(local
))
1660 /* first process frames */
1661 while ((skb
= skb_dequeue(&sdata
->skb_queue
))) {
1662 kcov_remote_start_common(skb_get_kcov_handle(skb
));
1664 if (skb
->protocol
== cpu_to_be16(ETH_P_TDLS
))
1665 ieee80211_process_tdls_channel_switch(sdata
, skb
);
1667 ieee80211_iface_process_skb(local
, sdata
, skb
);
1673 /* process status queue */
1674 while ((skb
= skb_dequeue(&sdata
->status_queue
))) {
1675 kcov_remote_start_common(skb_get_kcov_handle(skb
));
1677 ieee80211_iface_process_status(sdata
, skb
);
1683 /* then other type-dependent work */
1684 switch (sdata
->vif
.type
) {
1685 case NL80211_IFTYPE_STATION
:
1686 ieee80211_sta_work(sdata
);
1688 case NL80211_IFTYPE_ADHOC
:
1689 ieee80211_ibss_work(sdata
);
1691 case NL80211_IFTYPE_MESH_POINT
:
1692 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
1694 ieee80211_mesh_work(sdata
);
1696 case NL80211_IFTYPE_OCB
:
1697 ieee80211_ocb_work(sdata
);
1704 static void ieee80211_activate_links_work(struct wiphy
*wiphy
,
1705 struct wiphy_work
*work
)
1707 struct ieee80211_sub_if_data
*sdata
=
1708 container_of(work
, struct ieee80211_sub_if_data
,
1709 activate_links_work
);
1710 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1712 if (local
->in_reconfig
)
1715 ieee80211_set_active_links(&sdata
->vif
, sdata
->desired_active_links
);
1716 sdata
->desired_active_links
= 0;
1720 * Helper function to initialise an interface to a specific type.
1722 static void ieee80211_setup_sdata(struct ieee80211_sub_if_data
*sdata
,
1723 enum nl80211_iftype type
)
1725 static const u8 bssid_wildcard
[ETH_ALEN
] = {0xff, 0xff, 0xff,
1728 /* clear type-dependent unions */
1729 memset(&sdata
->u
, 0, sizeof(sdata
->u
));
1730 memset(&sdata
->deflink
.u
, 0, sizeof(sdata
->deflink
.u
));
1732 /* and set some type-dependent values */
1733 sdata
->vif
.type
= type
;
1734 sdata
->vif
.p2p
= false;
1735 sdata
->wdev
.iftype
= type
;
1737 sdata
->control_port_protocol
= cpu_to_be16(ETH_P_PAE
);
1738 sdata
->control_port_no_encrypt
= false;
1739 sdata
->control_port_over_nl80211
= false;
1740 sdata
->control_port_no_preauth
= false;
1741 sdata
->vif
.cfg
.idle
= true;
1742 sdata
->vif
.bss_conf
.txpower
= INT_MIN
; /* unset */
1744 sdata
->noack_map
= 0;
1746 /* only monitor/p2p-device differ */
1748 sdata
->dev
->netdev_ops
= &ieee80211_dataif_ops
;
1749 sdata
->dev
->type
= ARPHRD_ETHER
;
1752 skb_queue_head_init(&sdata
->skb_queue
);
1753 skb_queue_head_init(&sdata
->status_queue
);
1754 wiphy_work_init(&sdata
->work
, ieee80211_iface_work
);
1755 wiphy_work_init(&sdata
->activate_links_work
,
1756 ieee80211_activate_links_work
);
1759 case NL80211_IFTYPE_P2P_GO
:
1760 type
= NL80211_IFTYPE_AP
;
1761 sdata
->vif
.type
= type
;
1762 sdata
->vif
.p2p
= true;
1764 case NL80211_IFTYPE_AP
:
1765 skb_queue_head_init(&sdata
->u
.ap
.ps
.bc_buf
);
1766 INIT_LIST_HEAD(&sdata
->u
.ap
.vlans
);
1767 sdata
->vif
.bss_conf
.bssid
= sdata
->vif
.addr
;
1769 case NL80211_IFTYPE_P2P_CLIENT
:
1770 type
= NL80211_IFTYPE_STATION
;
1771 sdata
->vif
.type
= type
;
1772 sdata
->vif
.p2p
= true;
1774 case NL80211_IFTYPE_STATION
:
1775 sdata
->vif
.bss_conf
.bssid
= sdata
->deflink
.u
.mgd
.bssid
;
1776 ieee80211_sta_setup_sdata(sdata
);
1778 case NL80211_IFTYPE_OCB
:
1779 sdata
->vif
.bss_conf
.bssid
= bssid_wildcard
;
1780 ieee80211_ocb_setup_sdata(sdata
);
1782 case NL80211_IFTYPE_ADHOC
:
1783 sdata
->vif
.bss_conf
.bssid
= sdata
->u
.ibss
.bssid
;
1784 ieee80211_ibss_setup_sdata(sdata
);
1786 case NL80211_IFTYPE_MESH_POINT
:
1787 if (ieee80211_vif_is_mesh(&sdata
->vif
))
1788 ieee80211_mesh_init_sdata(sdata
);
1790 case NL80211_IFTYPE_MONITOR
:
1791 sdata
->dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
1792 sdata
->dev
->netdev_ops
= &ieee80211_monitorif_ops
;
1793 sdata
->u
.mntr
.flags
= MONITOR_FLAG_CONTROL
|
1794 MONITOR_FLAG_OTHER_BSS
;
1796 case NL80211_IFTYPE_NAN
:
1797 idr_init(&sdata
->u
.nan
.function_inst_ids
);
1798 spin_lock_init(&sdata
->u
.nan
.func_lock
);
1799 sdata
->vif
.bss_conf
.bssid
= sdata
->vif
.addr
;
1801 case NL80211_IFTYPE_AP_VLAN
:
1802 case NL80211_IFTYPE_P2P_DEVICE
:
1803 sdata
->vif
.bss_conf
.bssid
= sdata
->vif
.addr
;
1805 case NL80211_IFTYPE_UNSPECIFIED
:
1806 case NL80211_IFTYPE_WDS
:
1807 case NUM_NL80211_IFTYPES
:
1812 /* need to do this after the switch so vif.type is correct */
1813 ieee80211_link_setup(&sdata
->deflink
);
1815 ieee80211_debugfs_recreate_netdev(sdata
, false);
1818 static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data
*sdata
,
1819 enum nl80211_iftype type
)
1821 struct ieee80211_local
*local
= sdata
->local
;
1823 enum nl80211_iftype internal_type
= type
;
1828 if (!local
->ops
->change_interface
)
1831 /* for now, don't support changing while links exist */
1832 if (ieee80211_vif_is_mld(&sdata
->vif
))
1835 switch (sdata
->vif
.type
) {
1836 case NL80211_IFTYPE_AP
:
1837 if (!list_empty(&sdata
->u
.ap
.vlans
))
1840 case NL80211_IFTYPE_STATION
:
1841 case NL80211_IFTYPE_ADHOC
:
1842 case NL80211_IFTYPE_OCB
:
1844 * Could maybe also all others here?
1845 * Just not sure how that interacts
1846 * with the RX/config path e.g. for
1855 case NL80211_IFTYPE_AP
:
1856 case NL80211_IFTYPE_STATION
:
1857 case NL80211_IFTYPE_ADHOC
:
1858 case NL80211_IFTYPE_OCB
:
1860 * Could probably support everything
1864 case NL80211_IFTYPE_P2P_CLIENT
:
1866 internal_type
= NL80211_IFTYPE_STATION
;
1868 case NL80211_IFTYPE_P2P_GO
:
1870 internal_type
= NL80211_IFTYPE_AP
;
1876 ret
= ieee80211_check_concurrent_iface(sdata
, internal_type
);
1880 ieee80211_stop_vif_queues(local
, sdata
,
1881 IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE
);
1882 /* do_stop will synchronize_rcu() first thing */
1883 ieee80211_do_stop(sdata
, false);
1885 ieee80211_teardown_sdata(sdata
);
1887 ieee80211_set_sdata_offload_flags(sdata
);
1888 ret
= drv_change_interface(local
, sdata
, internal_type
, p2p
);
1890 type
= ieee80211_vif_type_p2p(&sdata
->vif
);
1893 * Ignore return value here, there's not much we can do since
1894 * the driver changed the interface type internally already.
1895 * The warnings will hopefully make driver authors fix it :-)
1897 ieee80211_check_queues(sdata
, type
);
1899 ieee80211_setup_sdata(sdata
, type
);
1900 ieee80211_set_vif_encap_ops(sdata
);
1902 err
= ieee80211_do_open(&sdata
->wdev
, false);
1903 WARN(err
, "type change: do_open returned %d", err
);
1905 ieee80211_wake_vif_queues(local
, sdata
,
1906 IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE
);
1910 int ieee80211_if_change_type(struct ieee80211_sub_if_data
*sdata
,
1911 enum nl80211_iftype type
)
1917 if (type
== ieee80211_vif_type_p2p(&sdata
->vif
))
1920 if (ieee80211_sdata_running(sdata
)) {
1921 ret
= ieee80211_runtime_change_iftype(sdata
, type
);
1925 /* Purge and reset type-dependent state. */
1926 ieee80211_teardown_sdata(sdata
);
1927 ieee80211_setup_sdata(sdata
, type
);
1930 /* reset some values that shouldn't be kept across type changes */
1931 if (type
== NL80211_IFTYPE_STATION
)
1932 sdata
->u
.mgd
.use_4addr
= false;
1937 static void ieee80211_assign_perm_addr(struct ieee80211_local
*local
,
1938 u8
*perm_addr
, enum nl80211_iftype type
)
1940 struct ieee80211_sub_if_data
*sdata
;
1941 u64 mask
, start
, addr
, val
, inc
;
1943 u8 tmp_addr
[ETH_ALEN
];
1946 lockdep_assert_wiphy(local
->hw
.wiphy
);
1948 /* default ... something at least */
1949 memcpy(perm_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1951 if (is_zero_ether_addr(local
->hw
.wiphy
->addr_mask
) &&
1952 local
->hw
.wiphy
->n_addresses
<= 1)
1956 case NL80211_IFTYPE_MONITOR
:
1957 /* doesn't matter */
1959 case NL80211_IFTYPE_AP_VLAN
:
1960 /* match up with an AP interface */
1961 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1962 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1964 memcpy(perm_addr
, sdata
->vif
.addr
, ETH_ALEN
);
1967 /* keep default if no AP interface present */
1969 case NL80211_IFTYPE_P2P_CLIENT
:
1970 case NL80211_IFTYPE_P2P_GO
:
1971 if (ieee80211_hw_check(&local
->hw
, P2P_DEV_ADDR_FOR_INTF
)) {
1972 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1973 if (sdata
->vif
.type
!= NL80211_IFTYPE_P2P_DEVICE
)
1975 if (!ieee80211_sdata_running(sdata
))
1977 memcpy(perm_addr
, sdata
->vif
.addr
, ETH_ALEN
);
1983 /* assign a new address if possible -- try n_addresses first */
1984 for (i
= 0; i
< local
->hw
.wiphy
->n_addresses
; i
++) {
1987 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1988 if (ether_addr_equal(local
->hw
.wiphy
->addresses
[i
].addr
,
1997 local
->hw
.wiphy
->addresses
[i
].addr
,
2003 /* try mask if available */
2004 if (is_zero_ether_addr(local
->hw
.wiphy
->addr_mask
))
2007 m
= local
->hw
.wiphy
->addr_mask
;
2008 mask
= ((u64
)m
[0] << 5*8) | ((u64
)m
[1] << 4*8) |
2009 ((u64
)m
[2] << 3*8) | ((u64
)m
[3] << 2*8) |
2010 ((u64
)m
[4] << 1*8) | ((u64
)m
[5] << 0*8);
2012 if (__ffs64(mask
) + hweight64(mask
) != fls64(mask
)) {
2013 /* not a contiguous mask ... not handled now! */
2014 pr_info("not contiguous\n");
2019 * Pick address of existing interface in case user changed
2020 * MAC address manually, default to perm_addr.
2022 m
= local
->hw
.wiphy
->perm_addr
;
2023 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
2024 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
)
2026 m
= sdata
->vif
.addr
;
2029 start
= ((u64
)m
[0] << 5*8) | ((u64
)m
[1] << 4*8) |
2030 ((u64
)m
[2] << 3*8) | ((u64
)m
[3] << 2*8) |
2031 ((u64
)m
[4] << 1*8) | ((u64
)m
[5] << 0*8);
2033 inc
= 1ULL<<__ffs64(mask
);
2034 val
= (start
& mask
);
2035 addr
= (start
& ~mask
) | (val
& mask
);
2039 tmp_addr
[5] = addr
>> 0*8;
2040 tmp_addr
[4] = addr
>> 1*8;
2041 tmp_addr
[3] = addr
>> 2*8;
2042 tmp_addr
[2] = addr
>> 3*8;
2043 tmp_addr
[1] = addr
>> 4*8;
2044 tmp_addr
[0] = addr
>> 5*8;
2048 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
2049 if (ether_addr_equal(tmp_addr
, sdata
->vif
.addr
)) {
2056 memcpy(perm_addr
, tmp_addr
, ETH_ALEN
);
2059 addr
= (start
& ~mask
) | (val
& mask
);
2060 } while (addr
!= start
);
2066 int ieee80211_if_add(struct ieee80211_local
*local
, const char *name
,
2067 unsigned char name_assign_type
,
2068 struct wireless_dev
**new_wdev
, enum nl80211_iftype type
,
2069 struct vif_params
*params
)
2071 struct net_device
*ndev
= NULL
;
2072 struct ieee80211_sub_if_data
*sdata
= NULL
;
2073 struct txq_info
*txqi
;
2077 lockdep_assert_wiphy(local
->hw
.wiphy
);
2079 if (type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
) {
2080 struct wireless_dev
*wdev
;
2082 sdata
= kzalloc(sizeof(*sdata
) + local
->hw
.vif_data_size
,
2086 wdev
= &sdata
->wdev
;
2089 strscpy(sdata
->name
, name
, IFNAMSIZ
);
2090 ieee80211_assign_perm_addr(local
, wdev
->address
, type
);
2091 memcpy(sdata
->vif
.addr
, wdev
->address
, ETH_ALEN
);
2092 ether_addr_copy(sdata
->vif
.bss_conf
.addr
, sdata
->vif
.addr
);
2094 int size
= ALIGN(sizeof(*sdata
) + local
->hw
.vif_data_size
,
2098 if (type
!= NL80211_IFTYPE_AP_VLAN
&&
2099 (type
!= NL80211_IFTYPE_MONITOR
||
2100 (params
->flags
& MONITOR_FLAG_ACTIVE
)))
2101 txq_size
+= sizeof(struct txq_info
) +
2102 local
->hw
.txq_data_size
;
2104 ndev
= alloc_netdev_mqs(size
+ txq_size
,
2105 name
, name_assign_type
,
2106 ieee80211_if_setup
, 1, 1);
2110 dev_net_set(ndev
, wiphy_net(local
->hw
.wiphy
));
2112 ndev
->pcpu_stat_type
= NETDEV_PCPU_STAT_TSTATS
;
2114 ndev
->needed_headroom
= local
->tx_headroom
+
2115 4*6 /* four MAC addresses */
2116 + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
2118 + 8 /* rfc1042/bridge tunnel */
2119 - ETH_HLEN
/* ethernet hard_header_len */
2120 + IEEE80211_ENCRYPT_HEADROOM
;
2121 ndev
->needed_tailroom
= IEEE80211_ENCRYPT_TAILROOM
;
2123 ret
= dev_alloc_name(ndev
, ndev
->name
);
2129 ieee80211_assign_perm_addr(local
, ndev
->perm_addr
, type
);
2130 if (is_valid_ether_addr(params
->macaddr
))
2131 eth_hw_addr_set(ndev
, params
->macaddr
);
2133 eth_hw_addr_set(ndev
, ndev
->perm_addr
);
2134 SET_NETDEV_DEV(ndev
, wiphy_dev(local
->hw
.wiphy
));
2136 /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */
2137 sdata
= netdev_priv(ndev
);
2138 ndev
->ieee80211_ptr
= &sdata
->wdev
;
2139 memcpy(sdata
->vif
.addr
, ndev
->dev_addr
, ETH_ALEN
);
2140 ether_addr_copy(sdata
->vif
.bss_conf
.addr
, sdata
->vif
.addr
);
2141 memcpy(sdata
->name
, ndev
->name
, IFNAMSIZ
);
2144 txqi
= netdev_priv(ndev
) + size
;
2145 ieee80211_txq_init(sdata
, NULL
, txqi
, 0);
2151 /* initialise type-independent data */
2152 sdata
->wdev
.wiphy
= local
->hw
.wiphy
;
2154 ieee80211_sdata_init(local
, sdata
);
2156 ieee80211_init_frag_cache(&sdata
->frags
);
2158 INIT_LIST_HEAD(&sdata
->key_list
);
2160 wiphy_delayed_work_init(&sdata
->dec_tailroom_needed_wk
,
2161 ieee80211_delayed_tailroom_dec
);
2163 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
2164 struct ieee80211_supported_band
*sband
;
2165 sband
= local
->hw
.wiphy
->bands
[i
];
2166 sdata
->rc_rateidx_mask
[i
] =
2167 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
2172 memcpy(sdata
->rc_rateidx_mcs_mask
[i
],
2173 sband
->ht_cap
.mcs
.rx_mask
,
2174 sizeof(sdata
->rc_rateidx_mcs_mask
[i
]));
2176 cap
= sband
->vht_cap
.vht_mcs
.rx_mcs_map
;
2177 vht_rate_mask
= sdata
->rc_rateidx_vht_mcs_mask
[i
];
2178 ieee80211_get_vht_mask_from_cap(cap
, vht_rate_mask
);
2180 memset(sdata
->rc_rateidx_mcs_mask
[i
], 0,
2181 sizeof(sdata
->rc_rateidx_mcs_mask
[i
]));
2182 memset(sdata
->rc_rateidx_vht_mcs_mask
[i
], 0,
2183 sizeof(sdata
->rc_rateidx_vht_mcs_mask
[i
]));
2187 ieee80211_set_default_queues(sdata
);
2189 /* setup type-dependent data */
2190 ieee80211_setup_sdata(sdata
, type
);
2193 ndev
->ieee80211_ptr
->use_4addr
= params
->use_4addr
;
2194 if (type
== NL80211_IFTYPE_STATION
)
2195 sdata
->u
.mgd
.use_4addr
= params
->use_4addr
;
2197 ndev
->features
|= local
->hw
.netdev_features
;
2198 ndev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
2199 ndev
->hw_features
|= ndev
->features
&
2200 MAC80211_SUPPORTED_FEATURES_TX
;
2201 sdata
->vif
.netdev_features
= local
->hw
.netdev_features
;
2203 netdev_set_default_ethtool_ops(ndev
, &ieee80211_ethtool_ops
);
2205 /* MTU range is normally 256 - 2304, where the upper limit is
2206 * the maximum MSDU size. Monitor interfaces send and receive
2207 * MPDU and A-MSDU frames which may be much larger so we do
2208 * not impose an upper limit in that case.
2210 ndev
->min_mtu
= 256;
2211 if (type
== NL80211_IFTYPE_MONITOR
)
2214 ndev
->max_mtu
= local
->hw
.max_mtu
;
2216 ret
= cfg80211_register_netdevice(ndev
);
2223 mutex_lock(&local
->iflist_mtx
);
2224 list_add_tail_rcu(&sdata
->list
, &local
->interfaces
);
2225 mutex_unlock(&local
->iflist_mtx
);
2228 *new_wdev
= &sdata
->wdev
;
2233 void ieee80211_if_remove(struct ieee80211_sub_if_data
*sdata
)
2236 lockdep_assert_wiphy(sdata
->local
->hw
.wiphy
);
2238 mutex_lock(&sdata
->local
->iflist_mtx
);
2239 list_del_rcu(&sdata
->list
);
2240 mutex_unlock(&sdata
->local
->iflist_mtx
);
2243 ieee80211_txq_purge(sdata
->local
, to_txq_info(sdata
->vif
.txq
));
2247 cfg80211_unregister_wdev(&sdata
->wdev
);
2250 ieee80211_teardown_sdata(sdata
);
2255 void ieee80211_sdata_stop(struct ieee80211_sub_if_data
*sdata
)
2257 if (WARN_ON_ONCE(!test_bit(SDATA_STATE_RUNNING
, &sdata
->state
)))
2259 ieee80211_do_stop(sdata
, true);
2262 void ieee80211_remove_interfaces(struct ieee80211_local
*local
)
2264 struct ieee80211_sub_if_data
*sdata
, *tmp
;
2265 LIST_HEAD(unreg_list
);
2269 /* Before destroying the interfaces, make sure they're all stopped so
2270 * that the hardware is stopped. Otherwise, the driver might still be
2271 * iterating the interfaces during the shutdown, e.g. from a worker
2272 * or from RX processing or similar, and if it does so (using atomic
2273 * iteration) while we're manipulating the list, the iteration will
2276 * After this, the hardware should be stopped and the driver should
2277 * have stopped all of its activities, so that we can do RCU-unaware
2278 * manipulations of the interface list below.
2280 cfg80211_shutdown_all_interfaces(local
->hw
.wiphy
);
2282 wiphy_lock(local
->hw
.wiphy
);
2284 WARN(local
->open_count
, "%s: open count remains %d\n",
2285 wiphy_name(local
->hw
.wiphy
), local
->open_count
);
2287 mutex_lock(&local
->iflist_mtx
);
2288 list_splice_init(&local
->interfaces
, &unreg_list
);
2289 mutex_unlock(&local
->iflist_mtx
);
2291 list_for_each_entry_safe(sdata
, tmp
, &unreg_list
, list
) {
2292 bool netdev
= sdata
->dev
;
2295 * Remove IP addresses explicitly, since the notifier will
2296 * skip the callbacks if wdev->registered is false, since
2297 * we can't acquire the wiphy_lock() again there if already
2298 * inside this locked section.
2300 sdata
->vif
.cfg
.arp_addr_cnt
= 0;
2301 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
2302 sdata
->u
.mgd
.associated
)
2303 ieee80211_vif_cfg_change_notify(sdata
,
2304 BSS_CHANGED_ARP_FILTER
);
2306 list_del(&sdata
->list
);
2307 cfg80211_unregister_wdev(&sdata
->wdev
);
2312 wiphy_unlock(local
->hw
.wiphy
);
2315 static int netdev_notify(struct notifier_block
*nb
,
2316 unsigned long state
, void *ptr
)
2318 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
2319 struct ieee80211_sub_if_data
*sdata
;
2321 if (state
!= NETDEV_CHANGENAME
)
2324 if (!dev
->ieee80211_ptr
|| !dev
->ieee80211_ptr
->wiphy
)
2327 if (dev
->ieee80211_ptr
->wiphy
->privid
!= mac80211_wiphy_privid
)
2330 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2331 memcpy(sdata
->name
, dev
->name
, IFNAMSIZ
);
2332 ieee80211_debugfs_rename_netdev(sdata
);
2337 static struct notifier_block mac80211_netdev_notifier
= {
2338 .notifier_call
= netdev_notify
,
2341 int ieee80211_iface_init(void)
2343 return register_netdevice_notifier(&mac80211_netdev_notifier
);
2346 void ieee80211_iface_exit(void)
2348 unregister_netdevice_notifier(&mac80211_netdev_notifier
);
2351 void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data
*sdata
)
2353 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
2354 atomic_inc(&sdata
->u
.ap
.num_mcast_sta
);
2355 else if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
2356 atomic_inc(&sdata
->u
.vlan
.num_mcast_sta
);
2359 void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data
*sdata
)
2361 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
2362 atomic_dec(&sdata
->u
.ap
.num_mcast_sta
);
2363 else if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
2364 atomic_dec(&sdata
->u
.vlan
.num_mcast_sta
);
2367 void ieee80211_vif_block_queues_csa(struct ieee80211_sub_if_data
*sdata
)
2369 struct ieee80211_local
*local
= sdata
->local
;
2371 if (ieee80211_hw_check(&local
->hw
, HANDLES_QUIET_CSA
))
2374 ieee80211_stop_vif_queues_norefcount(local
, sdata
,
2375 IEEE80211_QUEUE_STOP_REASON_CSA
);
2378 void ieee80211_vif_unblock_queues_csa(struct ieee80211_sub_if_data
*sdata
)
2380 struct ieee80211_local
*local
= sdata
->local
;
2382 ieee80211_wake_vif_queues_norefcount(local
, sdata
,
2383 IEEE80211_QUEUE_STOP_REASON_CSA
);