Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Interface handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright 2002-2005, Instant802 Networks, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright 2005-2006, Devicescape Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Copyright 2013-2014  Intel Mobile Communications GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Copyright (c) 2016        Intel Deutschland GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * Copyright (C) 2018-2021 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <net/mac80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <net/ieee80211_radiotap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include "sta_info.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include "debugfs_netdev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include "mesh.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include "led.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include "driver-ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include "wme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include "rate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * DOC: Interface list locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * The interface list in each struct ieee80211_local is protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * three-fold:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * (1) modifications may only be done under the RTNL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * (2) modifications and readers are protected against each other by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *     the iflist_mtx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  * (3) modifications are done in an RCU manner so atomic readers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  *     can traverse the list in RCU-safe blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * As a consequence, reads (traversals) of the list can be protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * by either the RTNL, the iflist_mtx or RCU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) static void ieee80211_iface_work(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	struct ieee80211_chanctx_conf *chanctx_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	int power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	if (!chanctx_conf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	power = ieee80211_chandef_max_power(&chanctx_conf->def);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	if (sdata->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		power = min(power, sdata->user_power_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	if (sdata->ap_power_level != IEEE80211_UNSET_POWER_LEVEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 		power = min(power, sdata->ap_power_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	if (power != sdata->vif.bss_conf.txpower) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 		sdata->vif.bss_conf.txpower = power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		ieee80211_hw_config(sdata->local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 			      bool update_bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	if (__ieee80211_recalc_txpower(sdata) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	    (update_bss && ieee80211_sdata_running(sdata)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_TXPOWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static u32 __ieee80211_idle_off(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	return IEEE80211_CONF_CHANGE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static u32 __ieee80211_idle_on(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	ieee80211_flush_queues(local, NULL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	local->hw.conf.flags |= IEEE80211_CONF_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	return IEEE80211_CONF_CHANGE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static u32 __ieee80211_recalc_idle(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 				   bool force_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	bool working, scanning, active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	unsigned int led_trig_start = 0, led_trig_stop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	active = force_active ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		 !list_empty(&local->chanctx_list) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		 local->monitors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	working = !local->ops->remain_on_channel &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		  !list_empty(&local->roc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		   test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	if (working || scanning)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	if (active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	if (working || scanning || active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		return __ieee80211_idle_off(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	return __ieee80211_idle_on(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) u32 ieee80211_idle_off(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	return __ieee80211_recalc_idle(local, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) void ieee80211_recalc_idle(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	u32 change = __ieee80211_recalc_idle(local, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	if (change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		ieee80211_hw_config(local, change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 				bool check_dup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	struct ieee80211_sub_if_data *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	u64 new, mask, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	u8 *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	m = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	new =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	m = local->hw.wiphy->addr_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	mask =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	if (!check_dup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	list_for_each_entry(iter, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		if (iter == sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		if (iter->vif.type == NL80211_IFTYPE_MONITOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		    !(iter->u.mntr.flags & MONITOR_FLAG_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		m = iter->vif.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		tmp =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		if ((new & ~mask) != (tmp & ~mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) static int ieee80211_change_mac(struct net_device *dev, void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct sockaddr *sa = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	bool check_dup = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	    !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		check_dup = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	ret = ieee80211_verify_mac(sdata, sa->sa_data, check_dup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	ret = eth_mac_addr(dev, sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) static inline int identical_mac_addr_allowed(int type1, int type2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	return type1 == NL80211_IFTYPE_MONITOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		type2 == NL80211_IFTYPE_MONITOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		type1 == NL80211_IFTYPE_P2P_DEVICE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		type2 == NL80211_IFTYPE_P2P_DEVICE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		(type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		(type1 == NL80211_IFTYPE_WDS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			(type2 == NL80211_IFTYPE_WDS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 			 type2 == NL80211_IFTYPE_AP)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		(type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		(type1 == NL80211_IFTYPE_AP_VLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 			(type2 == NL80211_IFTYPE_AP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 			 type2 == NL80211_IFTYPE_AP_VLAN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 					    enum nl80211_iftype iftype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct ieee80211_sub_if_data *nsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	/* we hold the RTNL here so can safely walk the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	list_for_each_entry(nsdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		if (nsdata != sdata && ieee80211_sdata_running(nsdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 			 * Only OCB and monitor mode may coexist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			if ((sdata->vif.type == NL80211_IFTYPE_OCB &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 			     nsdata->vif.type != NL80211_IFTYPE_MONITOR) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 			    (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			     nsdata->vif.type == NL80211_IFTYPE_OCB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 				return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			 * Allow only a single IBSS interface to be up at any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			 * time. This is restricted because beacon distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			 * cannot work properly if both are in the same IBSS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 			 * To remove this restriction we'd have to disallow them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			 * from setting the same SSID on different IBSS interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			 * belonging to the same hardware. Then, however, we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			 * faced with having to adopt two different TSF timers...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			if (iftype == NL80211_IFTYPE_ADHOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 			    nsdata->vif.type == NL80211_IFTYPE_ADHOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 				return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			 * will not add another interface while any channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 			 * switch is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			if (nsdata->vif.csa_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 				return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 			 * The remaining checks are only performed for interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			 * with the same MAC address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			if (!ether_addr_equal(sdata->vif.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 					      nsdata->vif.addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 			 * check whether it may have the same address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			if (!identical_mac_addr_allowed(iftype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 							nsdata->vif.type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 				return -ENOTUNIQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			 * can only add VLANs to enabled APs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			if (iftype == NL80211_IFTYPE_AP_VLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			    nsdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 				sdata->bss = &nsdata->u.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) static int ieee80211_check_queues(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 				  enum nl80211_iftype iftype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	int n_queues = sdata->local->hw.queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	if (iftype == NL80211_IFTYPE_NAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	if (iftype != NL80211_IFTYPE_P2P_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		for (i = 0; i < IEEE80211_NUM_ACS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			if (WARN_ON_ONCE(sdata->vif.hw_queue[i] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 					 IEEE80211_INVAL_HW_QUEUE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			if (WARN_ON_ONCE(sdata->vif.hw_queue[i] >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 					 n_queues))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	if ((iftype != NL80211_IFTYPE_AP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	     iftype != NL80211_IFTYPE_P2P_GO &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	     iftype != NL80211_IFTYPE_MESH_POINT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	    !ieee80211_hw_check(&sdata->local->hw, QUEUE_CONTROL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	if (WARN_ON_ONCE(sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	if (WARN_ON_ONCE(sdata->vif.cab_queue >= n_queues))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) static int ieee80211_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	/* fail early if user set an invalid address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	if (!is_valid_ether_addr(dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	return ieee80211_do_open(&sdata->wdev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			      bool going_down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	struct sk_buff *skb, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	u32 hw_reconf_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	int i, flushed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	struct ps_data *ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	struct cfg80211_chan_def chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	bool cancel_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	struct cfg80211_nan_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	clear_bit(SDATA_STATE_RUNNING, &sdata->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (cancel_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		ieee80211_scan_cancel(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	 * Stop TX on this interface first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (sdata->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		netif_tx_stop_all_queues(sdata->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	ieee80211_roc_purge(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		ieee80211_mgd_stop(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		ieee80211_ibss_stop(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		list_del_rcu(&sdata->u.mntr.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	 * Remove all stations associated with this interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	 * This must be done before calling ops->remove_interface()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	 * because otherwise we can later invoke ops->sta_notify()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	 * whenever the STAs are removed, and that invalidates driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	 * assumptions about always getting a vif pointer that is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	 * (because if we remove a STA after ops->remove_interface()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	 * the driver will have removed the vif info already!)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	 * In WDS mode a station must exist here and be flushed, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	 * AP_VLANs stations may exist since there's nothing else that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	 * would have removed them, but in other modes there shouldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	 * be any stations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	flushed = sta_info_flush(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		     ((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		      (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	/* don't count this interface for allmulti while it is down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		atomic_dec(&local->iff_allmultis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	if (sdata->vif.type == NL80211_IFTYPE_AP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		local->fif_pspoll--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		local->fif_probe_req--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	} else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		local->fif_probe_req--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (sdata->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		netif_addr_lock_bh(sdata->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		spin_lock_bh(&local->filter_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		__hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 				 sdata->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		spin_unlock_bh(&local->filter_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		netif_addr_unlock_bh(sdata->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	del_timer_sync(&local->dynamic_ps_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	cancel_work_sync(&local->dynamic_ps_enable_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	cancel_work_sync(&sdata->recalc_smps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	sdata_lock(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	sdata->vif.csa_active = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	if (sdata->vif.type == NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		sdata->u.mgd.csa_waiting_bcn = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	if (sdata->csa_block_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		ieee80211_wake_vif_queues(local, sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 					  IEEE80211_QUEUE_STOP_REASON_CSA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		sdata->csa_block_tx = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	sdata_unlock(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	cancel_work_sync(&sdata->csa_finalize_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	if (sdata->wdev.cac_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		chandef = sdata->vif.bss_conf.chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		WARN_ON(local->suspended);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		ieee80211_vif_release_channel(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		cfg80211_cac_event(sdata->dev, &chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 				   NL80211_RADAR_CAC_ABORTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	/* APs need special treatment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	if (sdata->vif.type == NL80211_IFTYPE_AP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		struct ieee80211_sub_if_data *vlan, *tmpsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		/* down all dependent devices, that is VLANs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 					 u.vlan.list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			dev_close(vlan->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		WARN_ON(!list_empty(&sdata->u.ap.vlans));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	} else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		/* remove all packets in parent bc_buf pointing to this dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		ps = &sdata->bss->ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		spin_lock_irqsave(&ps->bc_buf.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			if (skb->dev == sdata->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 				__skb_unlink(skb, &ps->bc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				local->total_ps_buffered--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 				ieee80211_free_txskb(&local->hw, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	if (going_down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		local->open_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		list_del(&sdata->u.vlan.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		RCU_INIT_POINTER(sdata->vif.chanctx_conf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		/* see comment in the default case below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		ieee80211_free_keys(sdata, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		/* no need to tell driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			local->cooked_mntrs--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		local->monitors--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		if (local->monitors == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		ieee80211_adjust_monitor_flags(sdata, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		/* clean all the functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		spin_lock_bh(&sdata->u.nan.func_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			idr_remove(&sdata->u.nan.function_inst_ids, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 			cfg80211_free_nan_func(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		idr_destroy(&sdata->u.nan.function_inst_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		spin_unlock_bh(&sdata->u.nan.func_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		/* relies on synchronize_rcu() below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		RCU_INIT_POINTER(local->p2p_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		cancel_work_sync(&sdata->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		 * When we get here, the interface is marked down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		 * Free the remaining keys, if there are any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		 * (which can happen in AP mode if userspace sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		 * keys before the interface is operating, and maybe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		 * also in WDS mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		 * Force the key freeing to always synchronize_net()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		 * to wait for the RX path in case it is using this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		 * interface enqueuing frames at this very time on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		 * another CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		ieee80211_free_keys(sdata, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		skb_queue_purge(&sdata->skb_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		skb_queue_walk_safe(&local->pending[i], skb, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 			struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 			if (info->control.vif == &sdata->vif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 				__skb_unlink(skb, &local->pending[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 				ieee80211_free_txskb(&local->hw, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		ieee80211_txq_remove_vlan(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	sdata->bss = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	if (local->open_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		ieee80211_clear_tx_pending(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	sdata->vif.bss_conf.beacon_int = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	 * If the interface goes down while suspended, presumably because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	 * the device was unplugged and that happens before our resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	 * then the driver is already unconfigured and the remainder of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	 * this function isn't needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	 * XXX: what about WoWLAN? If the device has software state, e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	 *	memory allocated, it might expect teardown commands from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	 *	mac80211 here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (local->suspended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		WARN_ON(local->wowlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		WARN_ON(rtnl_dereference(local->monitor_sdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		if (local->monitors == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 			ieee80211_del_virtual_monitor(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		if (going_down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			drv_remove_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	ieee80211_recalc_ps(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	if (cancel_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		flush_delayed_work(&local->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (local->open_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		ieee80211_stop_device(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		/* no reconfiguring after stop! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	/* do after stop to avoid reconfiguring when we stop anyway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	ieee80211_configure_filter(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	ieee80211_hw_config(local, hw_reconf_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (local->monitors == local->open_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		ieee80211_add_virtual_monitor(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) static int ieee80211_stop(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	ieee80211_do_stop(sdata, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) static void ieee80211_set_multicast_list(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	int allmulti, sdata_allmulti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	allmulti = !!(dev->flags & IFF_ALLMULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (allmulti != sdata_allmulti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		if (dev->flags & IFF_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 			atomic_inc(&local->iff_allmultis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			atomic_dec(&local->iff_allmultis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	spin_lock_bh(&local->filter_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	__hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	spin_unlock_bh(&local->filter_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	ieee80211_queue_work(&local->hw, &local->reconfig_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677)  * Called when the netdev is removed or, by the code below, before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678)  * the interface type changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	/* free extra data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	ieee80211_free_keys(sdata, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	ieee80211_debugfs_remove_netdev(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	ieee80211_destroy_frag_cache(&sdata->frags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	if (ieee80211_vif_is_mesh(&sdata->vif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		ieee80211_mesh_teardown_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) static void ieee80211_uninit(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) static u16 ieee80211_netdev_select_queue(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 					 struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 					 struct net_device *sb_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	dev_fetch_sw_netstats(stats, dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) static const struct net_device_ops ieee80211_dataif_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	.ndo_open		= ieee80211_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	.ndo_stop		= ieee80211_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	.ndo_uninit		= ieee80211_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	.ndo_start_xmit		= ieee80211_subif_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	.ndo_set_rx_mode	= ieee80211_set_multicast_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	.ndo_set_mac_address 	= ieee80211_change_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	.ndo_select_queue	= ieee80211_netdev_select_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	.ndo_get_stats64	= ieee80211_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) static u16 ieee80211_monitor_select_queue(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 					  struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 					  struct net_device *sb_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	struct ieee80211_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	int len_rthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	/* reset flags and info before parsing radiotap header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	memset(info, 0, sizeof(*info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (!ieee80211_parse_tx_radiotap(skb, dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		return 0; /* doesn't matter, frame will be dropped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	len_rthdr = ieee80211_get_radiotap_len(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (skb->len < len_rthdr + 2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	    skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		return 0; /* doesn't matter, frame will be dropped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	return ieee80211_select_queue_80211(sdata, skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) static const struct net_device_ops ieee80211_monitorif_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	.ndo_open		= ieee80211_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	.ndo_stop		= ieee80211_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	.ndo_uninit		= ieee80211_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	.ndo_start_xmit		= ieee80211_monitor_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	.ndo_set_rx_mode	= ieee80211_set_multicast_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	.ndo_set_mac_address 	= ieee80211_change_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	.ndo_select_queue	= ieee80211_monitor_select_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	.ndo_get_stats64	= ieee80211_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static const struct net_device_ops ieee80211_dataif_8023_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	.ndo_open		= ieee80211_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	.ndo_stop		= ieee80211_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	.ndo_uninit		= ieee80211_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	.ndo_start_xmit		= ieee80211_subif_start_xmit_8023,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	.ndo_set_rx_mode	= ieee80211_set_multicast_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	.ndo_set_mac_address	= ieee80211_change_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	.ndo_select_queue	= ieee80211_netdev_select_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	.ndo_get_stats64	= ieee80211_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) static bool ieee80211_iftype_supports_encap_offload(enum nl80211_iftype iftype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	switch (iftype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	/* P2P GO and client are mapped to AP/STATION types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	flags = sdata->vif.offload_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	    ieee80211_iftype_supports_encap_offload(sdata->vif.type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		flags |= IEEE80211_OFFLOAD_ENCAP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		    local->hw.wiphy->frag_threshold != (u32)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		if (local->monitors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	if (sdata->vif.offload_flags == flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	sdata->vif.offload_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	struct ieee80211_sub_if_data *bss = sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	bool enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		if (!sdata->bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	    !ieee80211_iftype_supports_encap_offload(bss->vif.type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	if (sdata->wdev.use_4addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	    !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 					   &ieee80211_dataif_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	struct ieee80211_sub_if_data *vsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (ieee80211_set_sdata_offload_flags(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		drv_update_vif_offload(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		ieee80211_set_vif_encap_ops(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	list_for_each_entry(vsdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		if (vsdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		    vsdata->bss != &sdata->u.ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		ieee80211_set_vif_encap_ops(vsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) void ieee80211_recalc_offload(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		ieee80211_recalc_sdata_offload(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 				    const int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	u32 flags = sdata->u.mntr.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) #define ADJUST(_f, _s)	do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (flags & MONITOR_FLAG_##_f)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		local->fif_##_s += offset;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	ADJUST(FCSFAIL, fcsfail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	ADJUST(PLCPFAIL, plcpfail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	ADJUST(CONTROL, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	ADJUST(CONTROL, pspoll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	ADJUST(OTHER_BSS, other_bss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) #undef ADJUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		else if (local->hw.queues >= IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			sdata->vif.hw_queue[i] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			sdata->vif.hw_queue[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	if (local->monitor_sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	/* set up data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	sdata->local = local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	sdata->vif.type = NL80211_IFTYPE_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	snprintf(sdata->name, IFNAMSIZ, "%s-monitor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		 wiphy_name(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	sdata->wdev.iftype = NL80211_IFTYPE_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	ieee80211_set_default_queues(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	ret = drv_add_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	if (WARN_ON(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		/* ok .. stupid driver, it asked for this! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	set_bit(SDATA_STATE_RUNNING, &sdata->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	rcu_assign_pointer(local->monitor_sdata, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 					IEEE80211_CHANCTX_EXCLUSIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		RCU_INIT_POINTER(local->monitor_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		drv_remove_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	skb_queue_head_init(&sdata->skb_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	INIT_WORK(&sdata->work, ieee80211_iface_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	sdata = rcu_dereference_protected(local->monitor_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 					  lockdep_is_held(&local->iflist_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	if (!sdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	RCU_INIT_POINTER(local->monitor_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	ieee80211_vif_release_channel(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	drv_remove_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)  * NOTE: Be very careful when changing this function, it must NOT return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  * an error on interface type changes that have been pre-checked, so most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  * checks should be in ieee80211_check_concurrent_iface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	struct net_device *dev = wdev->netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	u32 hw_reconf_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 			return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	case NL80211_IFTYPE_AP_VLAN: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		struct ieee80211_sub_if_data *master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		if (!sdata->bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		master = container_of(sdata->bss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 				      struct ieee80211_sub_if_data, u.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		sdata->control_port_protocol =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			master->control_port_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		sdata->control_port_no_encrypt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			master->control_port_no_encrypt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		sdata->control_port_over_nl80211 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			master->control_port_over_nl80211;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		sdata->control_port_no_preauth =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			master->control_port_no_preauth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		sdata->vif.cab_queue = master->vif.cab_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		       sizeof(sdata->vif.hw_queue));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		sdata->vif.bss_conf.chandef = master->vif.bss_conf.chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		mutex_lock(&local->key_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		sdata->crypto_tx_tailroom_needed_cnt +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 			master->crypto_tx_tailroom_needed_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		mutex_unlock(&local->key_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		sdata->bss = &sdata->u.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		/* no special treatment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	case NL80211_IFTYPE_UNSPECIFIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	case NUM_NL80211_IFTYPES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		/* cannot happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (local->open_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		res = drv_start(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			goto err_del_bss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		/* we're brought up, everything changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		hw_reconf_flags = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		ieee80211_led_radio(local, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		ieee80211_mod_tpt_led_trig(local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 					   IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	 * Copy the hopefully now-present MAC address to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	 * this interface, if it has the special null one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	if (dev && is_zero_ether_addr(dev->dev_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		memcpy(dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		       local->hw.wiphy->perm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		       ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		if (!is_valid_ether_addr(dev->dev_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 			res = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		/* no need to tell driver, but set carrier and chanctx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		if (rtnl_dereference(sdata->bss->beacon)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			ieee80211_vif_vlan_copy_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 			netif_carrier_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 			ieee80211_set_vif_encap_ops(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 			netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			local->cooked_mntrs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			res = drv_add_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 				goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		} else if (local->monitors == 0 && local->open_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			res = ieee80211_add_virtual_monitor(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 			if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 				goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		/* must be before the call to ieee80211_configure_filter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		local->monitors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		if (local->monitors == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 			local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 			hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		ieee80211_adjust_monitor_flags(sdata, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		ieee80211_configure_filter(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		ieee80211_recalc_offload(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		netif_carrier_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		if (coming_up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 			ieee80211_del_virtual_monitor(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 			ieee80211_set_sdata_offload_flags(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			res = drv_add_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 				goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			ieee80211_set_vif_encap_ops(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 			res = ieee80211_check_queues(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 				ieee80211_vif_type_p2p(&sdata->vif));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 				goto err_del_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		if (sdata->vif.type == NL80211_IFTYPE_AP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 			local->fif_pspoll++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 			local->fif_probe_req++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 			ieee80211_configure_filter(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		} else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 			local->fif_probe_req++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		if (sdata->vif.probe_req_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			drv_config_iface_filter(local, sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 						FIF_PROBE_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 						FIF_PROBE_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		    sdata->vif.type != NL80211_IFTYPE_NAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 			changed |= ieee80211_reset_erp_info(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		ieee80211_bss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 			netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 			/* not reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		 * Set default queue parameters so drivers don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		 * need to initialise the hardware if the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		 * doesn't start up with sane defaults.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		 * Enable QoS for anything but station interfaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		ieee80211_set_wmm_default(sdata, true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 			sdata->vif.type != NL80211_IFTYPE_STATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	set_bit(SDATA_STATE_RUNNING, &sdata->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		/* Create STA entry for the WDS peer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 				     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 			res = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			goto err_del_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		res = sta_info_insert(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 			/* STA has been freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 			goto err_del_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		rate_control_rate_init(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		netif_carrier_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		rcu_assign_pointer(local->p2p_sdata, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		list_add_tail_rcu(&sdata->u.mntr.list, &local->mon_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	 * set_multicast_list will be invoked by the networking core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	 * which will check whether any increments here were done in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	 * error and sync them down to the hardware as filter flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		atomic_inc(&local->iff_allmultis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	if (coming_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		local->open_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	if (hw_reconf_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		ieee80211_hw_config(local, hw_reconf_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	ieee80211_recalc_ps(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	    local->ops->wake_tx_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		/* XXX: for AP_VLAN, actually track AP queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 			netif_tx_start_all_queues(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	} else if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		int n_acs = IEEE80211_NUM_ACS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		int ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 			n_acs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		if (sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		    (local->queue_stop_reasons[sdata->vif.cab_queue] == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		     skb_queue_empty(&local->pending[sdata->vif.cab_queue]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 			for (ac = 0; ac < n_acs; ac++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 				int ac_queue = sdata->vif.hw_queue[ac];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 				if (local->queue_stop_reasons[ac_queue] == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 				    skb_queue_empty(&local->pending[ac_queue]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 					netif_start_subqueue(dev, ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)  err_del_interface:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	drv_remove_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)  err_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	if (!local->open_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		drv_stop(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)  err_del_bss:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	sdata->bss = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		list_del(&sdata->u.vlan.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	/* might already be clear but that doesn't matter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	clear_bit(SDATA_STATE_RUNNING, &sdata->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) static void ieee80211_if_free(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	free_percpu(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) static void ieee80211_if_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	ether_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	dev->priv_flags &= ~IFF_TX_SKB_SHARING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	dev->netdev_ops = &ieee80211_dataif_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	dev->priv_destructor = ieee80211_if_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) static void ieee80211_if_setup_no_queue(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	ieee80211_if_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	dev->priv_flags |= IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static void ieee80211_iface_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	struct ieee80211_sub_if_data *sdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		container_of(work, struct ieee80211_sub_if_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	if (test_bit(SCAN_SW_SCANNING, &local->scanning))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	if (!ieee80211_can_run_worker(local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	/* first process frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	while ((skb = skb_dequeue(&sdata->skb_queue))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		struct ieee80211_mgmt *mgmt = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		if (ieee80211_is_action(mgmt->frame_control) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		    mgmt->u.action.category == WLAN_CATEGORY_BACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			int len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			mutex_lock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			sta = sta_info_get_bss(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			if (sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 				switch (mgmt->u.action.u.addba_req.action_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 				case WLAN_ACTION_ADDBA_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 					ieee80211_process_addba_request(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 							local, sta, mgmt, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 				case WLAN_ACTION_ADDBA_RESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 					ieee80211_process_addba_resp(local, sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 								     mgmt, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 				case WLAN_ACTION_DELBA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 					ieee80211_process_delba(sdata, sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 								mgmt, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 					WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 			mutex_unlock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		} else if (ieee80211_is_action(mgmt->frame_control) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 			   mgmt->u.action.category == WLAN_CATEGORY_VHT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 			switch (mgmt->u.action.u.vht_group_notif.action_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			case WLAN_VHT_ACTION_OPMODE_NOTIF: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 				struct ieee80211_rx_status *status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 				enum nl80211_band band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 				u8 opmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 				status = IEEE80211_SKB_RXCB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 				band = status->band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 				opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 				mutex_lock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 				sta = sta_info_get_bss(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 				if (sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 					ieee80211_vht_handle_opmode(sdata, sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 								    opmode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 								    band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 				mutex_unlock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			case WLAN_VHT_ACTION_GROUPID_MGMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 				ieee80211_process_mu_groups(sdata, mgmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 				WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		} else if (ieee80211_is_ext(mgmt->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 			if (sdata->vif.type == NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 				ieee80211_sta_rx_queued_ext(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 				WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		} else if (ieee80211_is_data_qos(mgmt->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 			struct ieee80211_hdr *hdr = (void *)mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 			 * So the frame isn't mgmt, but frame_control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 			 * is at the right place anyway, of course, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 			 * the if statement is correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 			 * Warn if we have other data frame types here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 			 * they must not get here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 			WARN_ON(hdr->frame_control &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 					cpu_to_le16(IEEE80211_STYPE_NULLFUNC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			WARN_ON(!(hdr->seq_ctrl &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 					cpu_to_le16(IEEE80211_SCTL_FRAG)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 			 * This was a fragment of a frame, received while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 			 * a block-ack session was active. That cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 			 * right, so terminate the session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 			mutex_lock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 			sta = sta_info_get_bss(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			if (sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 				u16 tid = ieee80211_get_tid(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 				__ieee80211_stop_rx_ba_session(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 					sta, tid, WLAN_BACK_RECIPIENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 					WLAN_REASON_QSTA_REQUIRE_SETUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 					true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			mutex_unlock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		} else switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 			ieee80211_sta_rx_queued_mgmt(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 			ieee80211_ibss_rx_queued_mgmt(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 			if (!ieee80211_vif_is_mesh(&sdata->vif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 			ieee80211_mesh_rx_queued_mgmt(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 			WARN(1, "frame for unexpected interface type");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	/* then other type-dependent work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		ieee80211_sta_work(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		ieee80211_ibss_work(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		if (!ieee80211_vif_is_mesh(&sdata->vif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		ieee80211_mesh_work(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		ieee80211_ocb_work(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) static void ieee80211_recalc_smps_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	struct ieee80211_sub_if_data *sdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		container_of(work, struct ieee80211_sub_if_data, recalc_smps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	ieee80211_recalc_smps(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)  * Helper function to initialise an interface to a specific type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 				  enum nl80211_iftype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	static const u8 bssid_wildcard[ETH_ALEN] = {0xff, 0xff, 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 						    0xff, 0xff, 0xff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	/* clear type-dependent union */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	memset(&sdata->u, 0, sizeof(sdata->u));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	/* and set some type-dependent values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	sdata->vif.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	sdata->vif.p2p = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	sdata->wdev.iftype = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	sdata->control_port_no_encrypt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	sdata->control_port_over_nl80211 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	sdata->control_port_no_preauth = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	sdata->vif.bss_conf.idle = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	sdata->vif.bss_conf.txpower = INT_MIN; /* unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	sdata->noack_map = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	/* only monitor/p2p-device differ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	if (sdata->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		sdata->dev->netdev_ops = &ieee80211_dataif_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		sdata->dev->type = ARPHRD_ETHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	skb_queue_head_init(&sdata->skb_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	INIT_WORK(&sdata->work, ieee80211_iface_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	INIT_WORK(&sdata->recalc_smps, ieee80211_recalc_smps_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	INIT_WORK(&sdata->csa_finalize_work, ieee80211_csa_finalize_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	INIT_LIST_HEAD(&sdata->assigned_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	INIT_LIST_HEAD(&sdata->reserved_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		type = NL80211_IFTYPE_AP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		sdata->vif.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 		sdata->vif.p2p = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		INIT_LIST_HEAD(&sdata->u.ap.vlans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		sdata->vif.bss_conf.bssid = sdata->vif.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		type = NL80211_IFTYPE_STATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 		sdata->vif.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		sdata->vif.p2p = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		ieee80211_sta_setup_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		sdata->vif.bss_conf.bssid = bssid_wildcard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		ieee80211_ocb_setup_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		ieee80211_ibss_setup_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		if (ieee80211_vif_is_mesh(&sdata->vif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 			ieee80211_mesh_init_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 		sdata->u.mntr.flags = MONITOR_FLAG_CONTROL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 				      MONITOR_FLAG_OTHER_BSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		sdata->vif.bss_conf.bssid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 		idr_init(&sdata->u.nan.function_inst_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		spin_lock_init(&sdata->u.nan.func_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		sdata->vif.bss_conf.bssid = sdata->vif.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		sdata->vif.bss_conf.bssid = sdata->vif.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	case NL80211_IFTYPE_UNSPECIFIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	case NUM_NL80211_IFTYPES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	ieee80211_debugfs_add_netdev(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 					   enum nl80211_iftype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	enum nl80211_iftype internal_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	bool p2p = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	if (!local->ops->change_interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		 * Could maybe also all others here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		 * Just not sure how that interacts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		 * with the RX/config path e.g. for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		 * mesh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 		 * Could probably support everything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 		 * but WDS here (WDS do_open can fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 		 * under memory pressure, which this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 		 * code isn't prepared to handle).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 		p2p = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 		internal_type = NL80211_IFTYPE_STATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 		p2p = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		internal_type = NL80211_IFTYPE_AP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	ret = ieee80211_check_concurrent_iface(sdata, internal_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	ieee80211_stop_vif_queues(local, sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 				  IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	ieee80211_do_stop(sdata, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	ieee80211_teardown_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	ieee80211_set_sdata_offload_flags(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	ret = drv_change_interface(local, sdata, internal_type, p2p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		type = ieee80211_vif_type_p2p(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	 * Ignore return value here, there's not much we can do since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	 * the driver changed the interface type internally already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	 * The warnings will hopefully make driver authors fix it :-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	ieee80211_check_queues(sdata, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	ieee80211_setup_sdata(sdata, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	ieee80211_set_vif_encap_ops(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	err = ieee80211_do_open(&sdata->wdev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	WARN(err, "type change: do_open returned %d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	ieee80211_wake_vif_queues(local, sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 				  IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 			     enum nl80211_iftype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	if (type == ieee80211_vif_type_p2p(&sdata->vif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	if (ieee80211_sdata_running(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		ret = ieee80211_runtime_change_iftype(sdata, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		/* Purge and reset type-dependent state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		ieee80211_teardown_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		ieee80211_setup_sdata(sdata, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	/* reset some values that shouldn't be kept across type changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	if (type == NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 		sdata->u.mgd.use_4addr = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 				       u8 *perm_addr, enum nl80211_iftype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	u64 mask, start, addr, val, inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	u8 *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	u8 tmp_addr[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	/* default ... something at least */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	memcpy(perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	if (is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	    local->hw.wiphy->n_addresses <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		/* doesn't matter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 		/* match up with an AP interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 			if (sdata->vif.type != NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		/* keep default if no AP interface present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		if (ieee80211_hw_check(&local->hw, P2P_DEV_ADDR_FOR_INTF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 			list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 				if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 				if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 				memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		/* assign a new address if possible -- try n_addresses first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		for (i = 0; i < local->hw.wiphy->n_addresses; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 			bool used = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 			list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 				if (ether_addr_equal(local->hw.wiphy->addresses[i].addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 						     sdata->vif.addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 					used = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 			if (!used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 				memcpy(perm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 				       local->hw.wiphy->addresses[i].addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 				       ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		/* try mask if available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 		if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		m = local->hw.wiphy->addr_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		mask =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 			/* not a contiguous mask ... not handled now! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 			pr_info("not contiguous\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 		 * Pick address of existing interface in case user changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		 * MAC address manually, default to perm_addr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 		m = local->hw.wiphy->perm_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 			if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 			m = sdata->vif.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		inc = 1ULL<<__ffs64(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 		val = (start & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		addr = (start & ~mask) | (val & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 			bool used = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 			tmp_addr[5] = addr >> 0*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 			tmp_addr[4] = addr >> 1*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 			tmp_addr[3] = addr >> 2*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 			tmp_addr[2] = addr >> 3*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 			tmp_addr[1] = addr >> 4*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 			tmp_addr[0] = addr >> 5*8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 			val += inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 			list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 				if (ether_addr_equal(tmp_addr, sdata->vif.addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 					used = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 			if (!used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 				memcpy(perm_addr, tmp_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 			addr = (start & ~mask) | (val & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		} while (addr != start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)  out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) int ieee80211_if_add(struct ieee80211_local *local, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		     unsigned char name_assign_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 		     struct wireless_dev **new_wdev, enum nl80211_iftype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 		     struct vif_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	struct net_device *ndev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	struct ieee80211_sub_if_data *sdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	struct txq_info *txqi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	void (*if_setup)(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	int txqs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	if (type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 		struct wireless_dev *wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 		sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 		wdev = &sdata->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 		sdata->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		strlcpy(sdata->name, name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		ieee80211_assign_perm_addr(local, wdev->address, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 				 sizeof(void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 		int txq_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		if (local->ops->wake_tx_queue &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 		    type != NL80211_IFTYPE_AP_VLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 		    (type != NL80211_IFTYPE_MONITOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 		     (params->flags & MONITOR_FLAG_ACTIVE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 			txq_size += sizeof(struct txq_info) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 				    local->hw.txq_data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		if (local->ops->wake_tx_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 			if_setup = ieee80211_if_setup_no_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 			if_setup = ieee80211_if_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 			if (local->hw.queues >= IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 				txqs = IEEE80211_NUM_ACS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 		ndev = alloc_netdev_mqs(size + txq_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 					name, name_assign_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 					if_setup, txqs, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		if (!ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 		if (!local->ops->wake_tx_queue && local->hw.wiphy->tx_queue_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 			ndev->tx_queue_len = local->hw.wiphy->tx_queue_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		dev_net_set(ndev, wiphy_net(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		ndev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		if (!ndev->tstats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 			free_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		ndev->needed_headroom = local->tx_headroom +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 					4*6 /* four MAC addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 					+ 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 					+ 6 /* mesh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 					+ 8 /* rfc1042/bridge tunnel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 					- ETH_HLEN /* ethernet hard_header_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 					+ IEEE80211_ENCRYPT_HEADROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 		ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		ret = dev_alloc_name(ndev, ndev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 			ieee80211_if_free(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 			free_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		ieee80211_assign_perm_addr(local, ndev->perm_addr, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		if (is_valid_ether_addr(params->macaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 			memcpy(ndev->dev_addr, params->macaddr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 		SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		/* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 		sdata = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		ndev->ieee80211_ptr = &sdata->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 		memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		memcpy(sdata->name, ndev->name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		if (txq_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 			txqi = netdev_priv(ndev) + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 			ieee80211_txq_init(sdata, NULL, txqi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		sdata->dev = ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	/* initialise type-independent data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	sdata->wdev.wiphy = local->hw.wiphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	sdata->local = local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	ieee80211_init_frag_cache(&sdata->frags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	INIT_LIST_HEAD(&sdata->key_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	INIT_DELAYED_WORK(&sdata->dfs_cac_timer_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 			  ieee80211_dfs_cac_timer_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	INIT_DELAYED_WORK(&sdata->dec_tailroom_needed_wk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 			  ieee80211_delayed_tailroom_dec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	for (i = 0; i < NUM_NL80211_BANDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		sband = local->hw.wiphy->bands[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 		sdata->rc_rateidx_mask[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 			sband ? (1 << sband->n_bitrates) - 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 		if (sband) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 			__le16 cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 			u16 *vht_rate_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 			memcpy(sdata->rc_rateidx_mcs_mask[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 			       sband->ht_cap.mcs.rx_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 			       sizeof(sdata->rc_rateidx_mcs_mask[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 			cap = sband->vht_cap.vht_mcs.rx_mcs_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 			vht_rate_mask = sdata->rc_rateidx_vht_mcs_mask[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 			ieee80211_get_vht_mask_from_cap(cap, vht_rate_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 			memset(sdata->rc_rateidx_mcs_mask[i], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 			       sizeof(sdata->rc_rateidx_mcs_mask[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 			memset(sdata->rc_rateidx_vht_mcs_mask[i], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 			       sizeof(sdata->rc_rateidx_vht_mcs_mask[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 	ieee80211_set_default_queues(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	sdata->user_power_level = local->user_power_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	/* setup type-dependent data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	ieee80211_setup_sdata(sdata, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	if (ndev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 		ndev->ieee80211_ptr->use_4addr = params->use_4addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 		if (type == NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 			sdata->u.mgd.use_4addr = params->use_4addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 		ndev->features |= local->hw.netdev_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 		ndev->hw_features |= ndev->features &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 					MAC80211_SUPPORTED_FEATURES_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 		netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 		/* MTU range is normally 256 - 2304, where the upper limit is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 		 * the maximum MSDU size. Monitor interfaces send and receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		 * MPDU and A-MSDU frames which may be much larger so we do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 		 * not impose an upper limit in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 		ndev->min_mtu = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 		if (type == NL80211_IFTYPE_MONITOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 			ndev->max_mtu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 			ndev->max_mtu = local->hw.max_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 		ret = register_netdevice(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 			free_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	list_add_tail_rcu(&sdata->list, &local->interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	if (new_wdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		*new_wdev = &sdata->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	mutex_lock(&sdata->local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	list_del_rcu(&sdata->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	mutex_unlock(&sdata->local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	if (sdata->vif.txq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 		ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	if (sdata->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		unregister_netdevice(sdata->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		cfg80211_unregister_wdev(&sdata->wdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		ieee80211_teardown_sdata(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 		kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	if (WARN_ON_ONCE(!test_bit(SDATA_STATE_RUNNING, &sdata->state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 	ieee80211_do_stop(sdata, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) void ieee80211_remove_interfaces(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 	struct ieee80211_sub_if_data *sdata, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	LIST_HEAD(unreg_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	LIST_HEAD(wdev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	/* Before destroying the interfaces, make sure they're all stopped so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	 * that the hardware is stopped. Otherwise, the driver might still be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 	 * iterating the interfaces during the shutdown, e.g. from a worker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	 * or from RX processing or similar, and if it does so (using atomic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 	 * iteration) while we're manipulating the list, the iteration will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	 * crash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	 * After this, the hardware should be stopped and the driver should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	 * have stopped all of its activities, so that we can do RCU-unaware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	 * manipulations of the interface list below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	cfg80211_shutdown_all_interfaces(local->hw.wiphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	WARN(local->open_count, "%s: open count remains %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	     wiphy_name(local->hw.wiphy), local->open_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	ieee80211_txq_teardown_flows(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 		list_del(&sdata->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		if (sdata->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 			unregister_netdevice_queue(sdata->dev, &unreg_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 			list_add(&sdata->list, &wdev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	unregister_netdevice_many(&unreg_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	list_for_each_entry_safe(sdata, tmp, &wdev_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		list_del(&sdata->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		cfg80211_unregister_wdev(&sdata->wdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) static int netdev_notify(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 			 unsigned long state, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	if (state != NETDEV_CHANGENAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 	if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	memcpy(sdata->name, dev->name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 	ieee80211_debugfs_rename_netdev(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) static struct notifier_block mac80211_netdev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	.notifier_call = netdev_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) int ieee80211_iface_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 	return register_netdevice_notifier(&mac80211_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) void ieee80211_iface_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	unregister_netdevice_notifier(&mac80211_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	if (sdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 		atomic_inc(&sdata->u.ap.num_mcast_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		atomic_inc(&sdata->u.vlan.num_mcast_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	if (sdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		atomic_dec(&sdata->u.ap.num_mcast_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 		atomic_dec(&sdata->u.vlan.num_mcast_sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }