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)  * Copyright 2002-2005, Instant802 Networks, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright 2005-2006, Devicescape Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright 2013-2014  Intel Mobile Communications GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright (C) 2015-2017	Intel Deutschland GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Copyright (C) 2018-2020 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * utilities for mac80211
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <net/mac80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <net/cfg80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include "driver-ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include "rate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include "mesh.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include "wme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include "led.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include "wep.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) /* privid for wiphys to determine whether they belong to us or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) const void *const mac80211_wiphy_privid = &mac80211_wiphy_privid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	struct ieee80211_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	local = wiphy_priv(wiphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	return &local->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 			enum nl80211_iftype type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	__le16 fc = hdr->frame_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	if (ieee80211_is_data(fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 		if (len < 24) /* drop incorrect hdr len (data) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 		if (ieee80211_has_a4(fc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		if (ieee80211_has_tods(fc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 			return hdr->addr1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		if (ieee80211_has_fromds(fc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 			return hdr->addr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		return hdr->addr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	if (ieee80211_is_s1g_beacon(fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 		struct ieee80211_ext *ext = (void *) hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		return ext->u.s1g_beacon.sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	if (ieee80211_is_mgmt(fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		if (len < 24) /* drop incorrect hdr len (mgmt) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		return hdr->addr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	if (ieee80211_is_ctl(fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 		if (ieee80211_is_pspoll(fc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 			return hdr->addr1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		if (ieee80211_is_back_req(fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 			switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 			case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 				return hdr->addr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 			case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 			case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 				return hdr->addr1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 				break; /* fall through to the return */
^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) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) EXPORT_SYMBOL(ieee80211_get_bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	struct ieee80211_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	skb_queue_walk(&tx->skbs, skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 		hdr = (struct ieee80211_hdr *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) int ieee80211_frame_duration(enum nl80211_band band, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 			     int rate, int erp, int short_preamble,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			     int shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	int dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	/* calculate duration (in microseconds, rounded up to next higher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	 * integer if it includes a fractional microsecond) to send frame of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	 * len bytes (does not include FCS) at the given rate. Duration will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	 * also include SIFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	 * rate is in 100 kbps, so divident is multiplied by 10 in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	 * DIV_ROUND_UP() operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	 * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	 * is assumed to be 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	if (band == NL80211_BAND_5GHZ || erp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		 * OFDM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		 * N_DBPS = DATARATE x 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		 *	(16 = SIGNAL time, 6 = tail bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 		 * T_SYM = 4 usec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		 * 802.11a - 18.5.2: aSIFSTime = 16 usec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 		 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		 *	signal ext = 6 usec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		dur = 16; /* SIFS + signal ext */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		/* IEEE 802.11-2012 18.3.2.4: all values above are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		 *  * times 4 for 5 MHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		 *  * times 2 for 10 MHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		dur *= 1 << shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		/* rates should already consider the channel bandwidth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		 * don't apply divisor again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 					4 * rate); /* T_SYM x N_SYM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		 * 802.11b or 802.11g with 802.11b compatibility:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 		 * aSIFSTime = 10 usec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		 * aPreambleLength = 144 usec or 72 usec with short preamble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		dur = 10; /* aSIFSTime = 10 usec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		dur += short_preamble ? (72 + 24) : (144 + 48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	return dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) /* Exported duration function for driver use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 					struct ieee80211_vif *vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 					enum nl80211_band band,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 					size_t frame_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 					struct ieee80211_rate *rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	u16 dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	int erp, shift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	bool short_preamble = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	erp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	if (vif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		short_preamble = sdata->vif.bss_conf.use_short_preamble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 			erp = rate->flags & IEEE80211_RATE_ERP_G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		shift = ieee80211_vif_get_shift(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 				       short_preamble, shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	return cpu_to_le16(dur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) EXPORT_SYMBOL(ieee80211_generic_frame_duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 			      struct ieee80211_vif *vif, size_t frame_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 			      const struct ieee80211_tx_info *frame_txctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	struct ieee80211_rate *rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	bool short_preamble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	int erp, shift = 0, bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	u16 dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	sband = local->hw.wiphy->bands[frame_txctl->band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	short_preamble = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	erp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	if (vif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		short_preamble = sdata->vif.bss_conf.use_short_preamble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			erp = rate->flags & IEEE80211_RATE_ERP_G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		shift = ieee80211_vif_get_shift(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	/* CTS duration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	dur = ieee80211_frame_duration(sband->band, 10, bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 				       erp, short_preamble, shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	/* Data frame duration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	dur += ieee80211_frame_duration(sband->band, frame_len, bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 					erp, short_preamble, shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	/* ACK duration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	dur += ieee80211_frame_duration(sband->band, 10, bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 					erp, short_preamble, shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	return cpu_to_le16(dur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) EXPORT_SYMBOL(ieee80211_rts_duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 				    struct ieee80211_vif *vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 				    size_t frame_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 				    const struct ieee80211_tx_info *frame_txctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	struct ieee80211_rate *rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	bool short_preamble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	int erp, shift = 0, bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	u16 dur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	sband = local->hw.wiphy->bands[frame_txctl->band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	short_preamble = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	erp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	if (vif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		short_preamble = sdata->vif.bss_conf.use_short_preamble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			erp = rate->flags & IEEE80211_RATE_ERP_G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		shift = ieee80211_vif_get_shift(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	/* Data frame duration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	dur = ieee80211_frame_duration(sband->band, frame_len, bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 				       erp, short_preamble, shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		/* ACK duration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		dur += ieee80211_frame_duration(sband->band, 10, bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 						erp, short_preamble, shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	return cpu_to_le16(dur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) EXPORT_SYMBOL(ieee80211_ctstoself_duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	struct ieee80211_vif *vif = &sdata->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	struct fq *fq = &local->fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	struct ps_data *ps = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	struct txq_info *txqi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	spin_lock(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	if (sdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		ps = &sdata->bss->ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	sdata->vif.txqs_stopped[ac] = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	list_for_each_entry_rcu(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		if (sdata != sta->sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			struct ieee80211_txq *txq = sta->sta.txq[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			if (!txq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			txqi = to_txq_info(txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			if (ac != txq->ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 						&txqi->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			spin_unlock(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			drv_wake_tx_queue(local, txqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			spin_lock(&fq->lock);
^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 (!vif->txq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	txqi = to_txq_info(vif->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	    (ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	spin_unlock(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	drv_wake_tx_queue(local, txqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	spin_unlock(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) __releases(&local->queue_stop_reason_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) __acquires(&local->queue_stop_reason_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) _ieee80211_wake_txqs(struct ieee80211_local *local, unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	int n_acs = IEEE80211_NUM_ACS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		n_acs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	for (i = 0; i < local->hw.queues; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		if (local->queue_stop_reasons[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		spin_unlock_irqrestore(&local->queue_stop_reason_lock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			int ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			for (ac = 0; ac < n_acs; ac++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				int ac_queue = sdata->vif.hw_queue[ac];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 				if (ac_queue == i ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 				    sdata->vif.cab_queue == i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 					__ieee80211_wake_txqs(sdata, ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		spin_lock_irqsave(&local->queue_stop_reason_lock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) void ieee80211_wake_txqs(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	struct ieee80211_local *local = (struct ieee80211_local *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	_ieee80211_wake_txqs(local, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	int n_acs = IEEE80211_NUM_ACS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	if (local->ops->wake_tx_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		n_acs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		int ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		if (!sdata->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		    local->queue_stop_reasons[sdata->vif.cab_queue] != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		for (ac = 0; ac < n_acs; ac++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			int ac_queue = sdata->vif.hw_queue[ac];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			if (ac_queue == queue ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 			    (sdata->vif.cab_queue == queue &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 			     local->queue_stop_reasons[ac_queue] == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			     skb_queue_empty(&local->pending[ac_queue])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 				netif_wake_subqueue(sdata->dev, ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 				   enum queue_stop_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 				   bool refcounted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 				   unsigned long *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	trace_wake_queue(local, queue, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (WARN_ON(queue >= hw->queues))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (!test_bit(reason, &local->queue_stop_reasons[queue]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	if (!refcounted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		local->q_stop_reasons[queue][reason] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		local->q_stop_reasons[queue][reason]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		if (WARN_ON(local->q_stop_reasons[queue][reason] < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 			local->q_stop_reasons[queue][reason] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	if (local->q_stop_reasons[queue][reason] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		__clear_bit(reason, &local->queue_stop_reasons[queue]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	if (local->queue_stop_reasons[queue] != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		/* someone still has this queue stopped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	if (skb_queue_empty(&local->pending[queue])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		ieee80211_propagate_queue_wake(local, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		tasklet_schedule(&local->tx_pending_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	 * Calling _ieee80211_wake_txqs here can be a problem because it may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	 * release queue_stop_reason_lock which has been taken by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	 * __ieee80211_wake_queue's caller. It is certainly not very nice to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	 * release someone's lock, but it is fine because all the callers of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	 * __ieee80211_wake_queue call it right before releasing the lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (local->ops->wake_tx_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		if (reason == IEEE80211_QUEUE_STOP_REASON_DRIVER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			tasklet_schedule(&local->wake_txqs_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			_ieee80211_wake_txqs(local, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 				    enum queue_stop_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 				    bool refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	__ieee80211_wake_queue(hw, queue, reason, refcounted, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	ieee80211_wake_queue_by_reason(hw, queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				       IEEE80211_QUEUE_STOP_REASON_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 				       false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) EXPORT_SYMBOL(ieee80211_wake_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 				   enum queue_stop_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 				   bool refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	int n_acs = IEEE80211_NUM_ACS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	trace_stop_queue(local, queue, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	if (WARN_ON(queue >= hw->queues))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if (!refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		local->q_stop_reasons[queue][reason] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		local->q_stop_reasons[queue][reason]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		n_acs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		int ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		if (!sdata->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		for (ac = 0; ac < n_acs; ac++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			if (sdata->vif.hw_queue[ac] == queue ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			    sdata->vif.cab_queue == queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 				if (!local->ops->wake_tx_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 					netif_stop_subqueue(sdata->dev, ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 				spin_lock(&local->fq.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 				sdata->vif.txqs_stopped[ac] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 				spin_unlock(&local->fq.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 				    enum queue_stop_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 				    bool refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	__ieee80211_stop_queue(hw, queue, reason, refcounted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	ieee80211_stop_queue_by_reason(hw, queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 				       IEEE80211_QUEUE_STOP_REASON_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 				       false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) EXPORT_SYMBOL(ieee80211_stop_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) void ieee80211_add_pending_skb(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 			       struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	struct ieee80211_hw *hw = &local->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	int queue = info->hw_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (WARN_ON(!info->control.vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		ieee80211_free_txskb(&local->hw, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	__ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			       false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	__skb_queue_tail(&local->pending[queue], skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	__ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 			       false, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) void ieee80211_add_pending_skbs(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 				struct sk_buff_head *skbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct ieee80211_hw *hw = &local->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	int queue, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	while ((skb = skb_dequeue(skbs))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		if (WARN_ON(!info->control.vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			ieee80211_free_txskb(&local->hw, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		queue = info->hw_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		__ieee80211_stop_queue(hw, queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 				IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 				false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		__skb_queue_tail(&local->pending[queue], skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	for (i = 0; i < hw->queues; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		__ieee80211_wake_queue(hw, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			false, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 				     unsigned long queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 				     enum queue_stop_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				     bool refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	for_each_set_bit(i, &queues, hw->queues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		__ieee80211_stop_queue(hw, i, reason, refcounted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) void ieee80211_stop_queues(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 					IEEE80211_QUEUE_STOP_REASON_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 					false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) EXPORT_SYMBOL(ieee80211_stop_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	if (WARN_ON(queue >= hw->queues))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		       &local->queue_stop_reasons[queue]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) EXPORT_SYMBOL(ieee80211_queue_stopped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 				     unsigned long queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 				     enum queue_stop_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 				     bool refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	for_each_set_bit(i, &queues, hw->queues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		__ieee80211_wake_queue(hw, i, reason, refcounted, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) void ieee80211_wake_queues(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 					IEEE80211_QUEUE_STOP_REASON_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 					false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) EXPORT_SYMBOL(ieee80211_wake_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) static unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) ieee80211_get_vif_queues(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			 struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	unsigned int queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	if (sdata && ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		int ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		queues = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			queues |= BIT(sdata->vif.hw_queue[ac]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			queues |= BIT(sdata->vif.cab_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		/* all queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		queues = BIT(local->hw.queues) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	return queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) void __ieee80211_flush_queues(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			      struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			      unsigned int queues, bool drop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	if (!local->ops->flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	 * If no queue was set, or if the HW doesn't support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	 * IEEE80211_HW_QUEUE_CONTROL - flush all queues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (!queues || !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		queues = ieee80211_get_vif_queues(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	ieee80211_stop_queues_by_reason(&local->hw, queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 					IEEE80211_QUEUE_STOP_REASON_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 					false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	drv_flush(local, sdata, queues, drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	ieee80211_wake_queues_by_reason(&local->hw, queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 					IEEE80211_QUEUE_STOP_REASON_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 					false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) void ieee80211_flush_queues(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			    struct ieee80211_sub_if_data *sdata, bool drop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	__ieee80211_flush_queues(local, sdata, 0, drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) void ieee80211_stop_vif_queues(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			       struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			       enum queue_stop_reason reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	ieee80211_stop_queues_by_reason(&local->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 					ieee80211_get_vif_queues(local, sdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 					reason, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) void ieee80211_wake_vif_queues(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			       struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			       enum queue_stop_reason reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	ieee80211_wake_queues_by_reason(&local->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 					ieee80211_get_vif_queues(local, sdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 					reason, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) static void __iterate_interfaces(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 				 u32 iter_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 				 void (*iterator)(void *data, u8 *mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 						  struct ieee80211_vif *vif),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 				 void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	bool active_only = iter_flags & IEEE80211_IFACE_ITER_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 			if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		    active_only && !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		if ((iter_flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		    !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		if (ieee80211_sdata_running(sdata) || !active_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			iterator(data, sdata->vif.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 				 &sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	sdata = rcu_dereference_check(local->monitor_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 				      lockdep_is_held(&local->iflist_mtx) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 				      lockdep_rtnl_is_held());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	if (sdata &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	    (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL || !active_only ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	     sdata->flags & IEEE80211_SDATA_IN_DRIVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		iterator(data, sdata->vif.addr, &sdata->vif);
^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) void ieee80211_iterate_interfaces(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	struct ieee80211_hw *hw, u32 iter_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	void (*iterator)(void *data, u8 *mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			 struct ieee80211_vif *vif),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	__iterate_interfaces(local, iter_flags, iterator, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) EXPORT_SYMBOL_GPL(ieee80211_iterate_interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) void ieee80211_iterate_active_interfaces_atomic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	struct ieee80211_hw *hw, u32 iter_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	void (*iterator)(void *data, u8 *mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 			 struct ieee80211_vif *vif),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	__iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			     iterator, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) void ieee80211_iterate_active_interfaces_rtnl(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	struct ieee80211_hw *hw, u32 iter_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	void (*iterator)(void *data, u8 *mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			 struct ieee80211_vif *vif),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	__iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 			     iterator, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) static void __iterate_stations(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 			       void (*iterator)(void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 						struct ieee80211_sta *sta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			       void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	list_for_each_entry_rcu(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		if (!sta->uploaded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		iterator(data, &sta->sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			void (*iterator)(void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 					 struct ieee80211_sta *sta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	__iterate_stations(local, iterator, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_atomic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	if (!ieee80211_sdata_running(sdata) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	    !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	return &sdata->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (!vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	if (!ieee80211_sdata_running(sdata) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	    !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	return &sdata->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) EXPORT_SYMBOL_GPL(ieee80211_vif_to_wdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)  * Nothing should have been stuffed into the workqueue during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)  * the suspend->resume cycle. Since we can't check each caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  * of this function if we are already quiescing / suspended,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)  * check here and don't WARN since this can actually happen when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)  * the rx path (for example) is racing against __ieee80211_suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)  * and suspending / quiescing was set after the rx path checked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)  * them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) static bool ieee80211_can_queue_work(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	if (local->quiescing || (local->suspended && !local->resuming)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		pr_warn("queueing ieee80211 work while going to suspend\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	if (!ieee80211_can_queue_work(local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	queue_work(local->workqueue, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) EXPORT_SYMBOL(ieee80211_queue_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 				  struct delayed_work *dwork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 				  unsigned long delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	if (!ieee80211_can_queue_work(local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	queue_delayed_work(local->workqueue, dwork, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) EXPORT_SYMBOL(ieee80211_queue_delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) static void ieee80211_parse_extension_element(u32 *crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 					      const struct element *elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 					      struct ieee802_11_elems *elems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	const void *data = elem->data + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if (!elem->datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	len = elem->datalen - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	switch (elem->data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	case WLAN_EID_EXT_HE_MU_EDCA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		if (len >= sizeof(*elems->mu_edca_param_set)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			elems->mu_edca_param_set = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 			if (crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 				*crc = crc32_be(*crc, (void *)elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 						elem->datalen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	case WLAN_EID_EXT_HE_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		elems->he_cap = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		elems->he_cap_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	case WLAN_EID_EXT_HE_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		if (len >= sizeof(*elems->he_operation) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		    len >= ieee80211_he_oper_size(data) - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			if (crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 				*crc = crc32_be(*crc, (void *)elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 						elem->datalen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			elems->he_operation = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	case WLAN_EID_EXT_UORA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		if (len >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			elems->uora_element = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	case WLAN_EID_EXT_MAX_CHANNEL_SWITCH_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		if (len == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			elems->max_channel_switch_time = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	case WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		if (len >= sizeof(*elems->mbssid_config_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 			elems->mbssid_config_ie = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	case WLAN_EID_EXT_HE_SPR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		if (len >= sizeof(*elems->he_spr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		    len >= ieee80211_he_spr_size(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			elems->he_spr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	case WLAN_EID_EXT_HE_6GHZ_CAPA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		if (len >= sizeof(*elems->he_6ghz_capa))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			elems->he_6ghz_capa = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) static u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) _ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 			    struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			    u64 filter, u32 crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			    const struct element *check_inherit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	const struct element *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	bool calc_crc = filter != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	DECLARE_BITMAP(seen_elems, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	const u8 *ie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	bitmap_zero(seen_elems, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	for_each_element(elem, start, len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		bool elem_parse_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		u8 id = elem->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		u8 elen = elem->datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		const u8 *pos = elem->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		if (check_inherit &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		    !cfg80211_is_element_inherited(elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 						   check_inherit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		switch (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		case WLAN_EID_SSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		case WLAN_EID_SUPP_RATES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		case WLAN_EID_FH_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		case WLAN_EID_DS_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		case WLAN_EID_CF_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		case WLAN_EID_TIM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		case WLAN_EID_IBSS_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		case WLAN_EID_CHALLENGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		case WLAN_EID_RSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		case WLAN_EID_ERP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		case WLAN_EID_EXT_SUPP_RATES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		case WLAN_EID_HT_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		case WLAN_EID_HT_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		case WLAN_EID_VHT_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		case WLAN_EID_VHT_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		case WLAN_EID_MESH_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		case WLAN_EID_MESH_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		case WLAN_EID_PEER_MGMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		case WLAN_EID_PREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		case WLAN_EID_PREP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		case WLAN_EID_PERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		case WLAN_EID_RANN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		case WLAN_EID_CHANNEL_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		case WLAN_EID_EXT_CHANSWITCH_ANN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		case WLAN_EID_COUNTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		case WLAN_EID_PWR_CONSTRAINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		case WLAN_EID_TIMEOUT_INTERVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		case WLAN_EID_CHAN_SWITCH_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		case WLAN_EID_EXT_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		case WLAN_EID_CHAN_SWITCH_TIMING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		case WLAN_EID_LINK_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		case WLAN_EID_BSS_MAX_IDLE_PERIOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		case WLAN_EID_RSNX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		case WLAN_EID_S1G_BCN_COMPAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		case WLAN_EID_S1G_CAPABILITIES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		case WLAN_EID_S1G_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		case WLAN_EID_AID_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		case WLAN_EID_S1G_SHORT_BCN_INTERVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		 * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		 * that if the content gets bigger it might be needed more than once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			if (test_bit(id, seen_elems)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 				elems->parse_error = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		if (calc_crc && id < 64 && (filter & (1ULL << id)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 			crc = crc32_be(crc, pos - 2, elen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		elem_parse_failed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		switch (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		case WLAN_EID_LINK_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			if (elen + 2 < sizeof(struct ieee80211_tdls_lnkie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 			elems->lnk_id = (void *)(pos - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		case WLAN_EID_CHAN_SWITCH_TIMING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			if (elen < sizeof(struct ieee80211_ch_switch_timing)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 			elems->ch_sw_timing = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		case WLAN_EID_EXT_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			elems->ext_capab = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			elems->ext_capab_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		case WLAN_EID_SSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			elems->ssid = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			elems->ssid_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		case WLAN_EID_SUPP_RATES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 			elems->supp_rates = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			elems->supp_rates_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		case WLAN_EID_DS_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			if (elen >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 				elems->ds_params = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		case WLAN_EID_TIM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 			if (elen >= sizeof(struct ieee80211_tim_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 				elems->tim = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 				elems->tim_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		case WLAN_EID_CHALLENGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 			elems->challenge = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			elems->challenge_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		case WLAN_EID_VENDOR_SPECIFIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			    pos[2] == 0xf2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 				/* Microsoft OUI (00:50:F2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 				if (calc_crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 					crc = crc32_be(crc, pos - 2, elen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 				if (elen >= 5 && pos[3] == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 					/* OUI Type 2 - WMM IE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 					if (pos[4] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 						elems->wmm_info = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 						elems->wmm_info_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 					} else if (pos[4] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 						elems->wmm_param = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 						elems->wmm_param_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		case WLAN_EID_RSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 			elems->rsn = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 			elems->rsn_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		case WLAN_EID_ERP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 			if (elen >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 				elems->erp_info = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		case WLAN_EID_EXT_SUPP_RATES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			elems->ext_supp_rates = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			elems->ext_supp_rates_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		case WLAN_EID_HT_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			if (elen >= sizeof(struct ieee80211_ht_cap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 				elems->ht_cap_elem = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		case WLAN_EID_HT_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 			if (elen >= sizeof(struct ieee80211_ht_operation))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 				elems->ht_operation = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		case WLAN_EID_VHT_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 			if (elen >= sizeof(struct ieee80211_vht_cap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 				elems->vht_cap_elem = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		case WLAN_EID_VHT_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 			if (elen >= sizeof(struct ieee80211_vht_operation)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 				elems->vht_operation = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 				if (calc_crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 					crc = crc32_be(crc, pos - 2, elen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 			elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		case WLAN_EID_OPMODE_NOTIF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 			if (elen > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 				elems->opmode_notif = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 				if (calc_crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 					crc = crc32_be(crc, pos - 2, elen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 			elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		case WLAN_EID_MESH_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 			elems->mesh_id = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			elems->mesh_id_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		case WLAN_EID_MESH_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 			if (elen >= sizeof(struct ieee80211_meshconf_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 				elems->mesh_config = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		case WLAN_EID_PEER_MGMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 			elems->peering = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 			elems->peering_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		case WLAN_EID_MESH_AWAKE_WINDOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 			if (elen >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 				elems->awake_window = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		case WLAN_EID_PREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 			elems->preq = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			elems->preq_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		case WLAN_EID_PREP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 			elems->prep = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			elems->prep_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		case WLAN_EID_PERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 			elems->perr = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 			elems->perr_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		case WLAN_EID_RANN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 			if (elen >= sizeof(struct ieee80211_rann_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 				elems->rann = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		case WLAN_EID_CHANNEL_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 			if (elen != sizeof(struct ieee80211_channel_sw_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 			elems->ch_switch_ie = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		case WLAN_EID_EXT_CHANSWITCH_ANN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 			elems->ext_chansw_ie = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 			if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 			elems->sec_chan_offs = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		case WLAN_EID_CHAN_SWITCH_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 			if (elen <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 			    sizeof(*elems->mesh_chansw_params_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 			elems->mesh_chansw_params_ie = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 			if (!action ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 			    elen < sizeof(*elems->wide_bw_chansw_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 			elems->wide_bw_chansw_ie = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 			if (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 			 * This is a bit tricky, but as we only care about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 			 * the wide bandwidth channel switch element, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 			 * just parse it out manually.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 			ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 					      pos, elen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			if (ie) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 				if (ie[1] >= sizeof(*elems->wide_bw_chansw_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 					elems->wide_bw_chansw_ie =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 						(void *)(ie + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 					elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		case WLAN_EID_COUNTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			elems->country_elem = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			elems->country_elem_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		case WLAN_EID_PWR_CONSTRAINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			if (elen != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 			elems->pwr_constr_elem = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		case WLAN_EID_CISCO_VENDOR_SPECIFIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 			/* Lots of different options exist, but we only care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 			 * about the Dynamic Transmit Power Control element.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 			 * First check for the Cisco OUI, then for the DTPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 			 * tag (0x00).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			if (elen < 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 				break;
^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) 			if (pos[0] != 0x00 || pos[1] != 0x40 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 			    pos[2] != 0x96 || pos[3] != 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			if (elen != 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 			if (calc_crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 				crc = crc32_be(crc, pos - 2, elen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 			elems->cisco_dtpc_elem = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		case WLAN_EID_ADDBA_EXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 			if (elen < sizeof(struct ieee80211_addba_ext_ie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 			elems->addba_ext_ie = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		case WLAN_EID_TIMEOUT_INTERVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 			if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 				elems->timeout_int = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		case WLAN_EID_BSS_MAX_IDLE_PERIOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 			if (elen >= sizeof(*elems->max_idle_period_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 				elems->max_idle_period_ie = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		case WLAN_EID_RSNX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			elems->rsnx = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 			elems->rsnx_len = elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		case WLAN_EID_EXTENSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			ieee80211_parse_extension_element(calc_crc ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 								&crc : NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 							  elem, elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		case WLAN_EID_S1G_CAPABILITIES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 			if (elen >= sizeof(*elems->s1g_capab))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 				elems->s1g_capab = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		case WLAN_EID_S1G_OPERATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			if (elen == sizeof(*elems->s1g_oper))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 				elems->s1g_oper = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		case WLAN_EID_S1G_BCN_COMPAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 			if (elen == sizeof(*elems->s1g_bcn_compat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 				elems->s1g_bcn_compat = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		case WLAN_EID_AID_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 			if (elen == sizeof(struct ieee80211_aid_response_ie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 				elems->aid_resp = (void *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 				elem_parse_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		if (elem_parse_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 			elems->parse_error = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			__set_bit(id, seen_elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	if (!for_each_element_completed(elem, start, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		elems->parse_error = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	return crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) static size_t ieee802_11_find_bssid_profile(const u8 *start, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 					    struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 					    u8 *transmitter_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 					    u8 *bss_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 					    u8 *nontransmitted_profile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	const struct element *elem, *sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	size_t profile_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	if (!bss_bssid || !transmitter_bssid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		return profile_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		if (elem->datalen < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		for_each_element(sub, elem->data + 1, elem->datalen - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 			u8 new_bssid[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 			const u8 *index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			if (sub->id != 0 || sub->datalen < 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 				/* not a valid BSS profile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 			if (sub->data[0] != WLAN_EID_NON_TX_BSSID_CAP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 			    sub->data[1] != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 				/* The first element of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 				 * Nontransmitted BSSID Profile is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 				 * the Nontransmitted BSSID Capability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 				 * element.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 			memset(nontransmitted_profile, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 			profile_len = cfg80211_merge_profile(start, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 							     elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 							     sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 							     nontransmitted_profile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 							     len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			/* found a Nontransmitted BSSID Profile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			index = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 						 nontransmitted_profile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 						 profile_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 			if (!index || index[1] < 1 || index[2] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 				/* Invalid MBSSID Index element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 			cfg80211_gen_new_bssid(transmitter_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 					       elem->data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 					       index[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 					       new_bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 			if (ether_addr_equal(new_bssid, bss_bssid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 				found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 				elems->bssid_index_len = index[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 				elems->bssid_index = (void *)&index[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	return found ? profile_len : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 			       struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 			       u64 filter, u32 crc, u8 *transmitter_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 			       u8 *bss_bssid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	const struct element *non_inherit = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	u8 *nontransmitted_profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	int nontransmitted_profile_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	memset(elems, 0, sizeof(*elems));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	elems->ie_start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	elems->total_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	nontransmitted_profile = kmalloc(len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	if (nontransmitted_profile) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		nontransmitted_profile_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			ieee802_11_find_bssid_profile(start, len, elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 						      transmitter_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 						      bss_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 						      nontransmitted_profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		non_inherit =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 			cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 					       nontransmitted_profile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 					       nontransmitted_profile_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	crc = _ieee802_11_parse_elems_crc(start, len, action, elems, filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 					  crc, non_inherit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	/* Override with nontransmitted profile, if found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	if (nontransmitted_profile_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		_ieee802_11_parse_elems_crc(nontransmitted_profile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 					    nontransmitted_profile_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 					    action, elems, 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	if (elems->tim && !elems->parse_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		const struct ieee80211_tim_ie *tim_ie = elems->tim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		elems->dtim_period = tim_ie->dtim_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		elems->dtim_count = tim_ie->dtim_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	/* Override DTIM period and count if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	if (elems->bssid_index &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	    elems->bssid_index_len >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	    offsetofend(struct ieee80211_bssid_index, dtim_period))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		elems->dtim_period = elems->bssid_index->dtim_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	if (elems->bssid_index &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	    elems->bssid_index_len >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	    offsetofend(struct ieee80211_bssid_index, dtim_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		elems->dtim_count = elems->bssid_index->dtim_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	kfree(nontransmitted_profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	return crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 					   struct ieee80211_tx_queue_params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 					   *qparam, int ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	struct ieee80211_chanctx_conf *chanctx_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	const struct ieee80211_reg_rule *rrule;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	const struct ieee80211_wmm_ac *wmm_ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	u16 center_freq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	if (sdata->vif.type != NL80211_IFTYPE_AP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	    sdata->vif.type != NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	if (chanctx_conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 		center_freq = chanctx_conf->def.chan->center_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	if (!center_freq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	rrule = freq_reg_info(sdata->wdev.wiphy, MHZ_TO_KHZ(center_freq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	if (IS_ERR_OR_NULL(rrule) || !rrule->has_wmm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	if (sdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 		wmm_ac = &rrule->wmm_rule.ap[ac];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		wmm_ac = &rrule->wmm_rule.client[ac];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	qparam->cw_min = max_t(u16, qparam->cw_min, wmm_ac->cw_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	qparam->cw_max = max_t(u16, qparam->cw_max, wmm_ac->cw_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	qparam->aifs = max_t(u8, qparam->aifs, wmm_ac->aifsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	qparam->txop = min_t(u16, qparam->txop, wmm_ac->cot / 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 			       bool bss_notify, bool enable_qos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	struct ieee80211_tx_queue_params qparam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	struct ieee80211_chanctx_conf *chanctx_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	int ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	bool use_11b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	bool is_ocb; /* Use another EDCA parameters if dot11OCBActivated=true */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	int aCWmin, aCWmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	if (!local->ops->conf_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	memset(&qparam, 0, sizeof(qparam));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	use_11b = (chanctx_conf &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		   chanctx_conf->def.chan->band == NL80211_BAND_2GHZ) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	is_ocb = (sdata->vif.type == NL80211_IFTYPE_OCB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	/* Set defaults according to 802.11-2007 Table 7-37 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	aCWmax = 1023;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	if (use_11b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		aCWmin = 31;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 		aCWmin = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	/* Confiure old 802.11b/g medium access rules. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	qparam.cw_max = aCWmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	qparam.cw_min = aCWmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	qparam.txop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	qparam.aifs = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		/* Update if QoS is enabled. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		if (enable_qos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			switch (ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 			case IEEE80211_AC_BK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 				qparam.cw_max = aCWmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 				qparam.cw_min = aCWmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 				qparam.txop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 				if (is_ocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 					qparam.aifs = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 					qparam.aifs = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 			/* never happens but let's not leave undefined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 			case IEEE80211_AC_BE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 				qparam.cw_max = aCWmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 				qparam.cw_min = aCWmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 				qparam.txop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 				if (is_ocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 					qparam.aifs = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 					qparam.aifs = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 			case IEEE80211_AC_VI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 				qparam.cw_max = aCWmin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 				qparam.cw_min = (aCWmin + 1) / 2 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 				if (is_ocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 					qparam.txop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 				else if (use_11b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 					qparam.txop = 6016/32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 					qparam.txop = 3008/32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 				if (is_ocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 					qparam.aifs = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 					qparam.aifs = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 			case IEEE80211_AC_VO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 				qparam.cw_max = (aCWmin + 1) / 2 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 				qparam.cw_min = (aCWmin + 1) / 4 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 				if (is_ocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 					qparam.txop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 				else if (use_11b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 					qparam.txop = 3264/32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 					qparam.txop = 1504/32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 				qparam.aifs = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		ieee80211_regulatory_limit_wmm_params(sdata, &qparam, ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		qparam.uapsd = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		sdata->tx_conf[ac] = qparam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		drv_conf_tx(local, sdata, ac, &qparam);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	if (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	    sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	    sdata->vif.type != NL80211_IFTYPE_NAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 		sdata->vif.bss_conf.qos = enable_qos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		if (bss_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 			ieee80211_bss_info_change_notify(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 							 BSS_CHANGED_QOS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 			 u16 transaction, u16 auth_alg, u16 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 			 const u8 *extra, size_t extra_len, const u8 *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 			 const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 			 u32 tx_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	struct ieee80211_mgmt *mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	/* 24 + 6 = header + auth_algo + auth_transaction + status_code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 			    24 + 6 + extra_len + IEEE80211_WEP_ICV_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	skb_reserve(skb, local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	mgmt = skb_put_zero(skb, 24 + 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 					  IEEE80211_STYPE_AUTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	memcpy(mgmt->da, da, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	memcpy(mgmt->bssid, bssid, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	mgmt->u.auth.status_code = cpu_to_le16(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	if (extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 		skb_put_data(skb, extra, extra_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 		mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 		err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 		WARN_ON(err);
^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) 	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 					tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	ieee80211_tx_skb(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 				    const u8 *da, const u8 *bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 				    u16 stype, u16 reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 				    bool send_frame, u8 *frame_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	struct ieee80211_mgmt *mgmt = (void *)frame_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	/* build frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	mgmt->duration = 0; /* initialize only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	mgmt->seq_ctrl = 0; /* initialize only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	memcpy(mgmt->da, da, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	memcpy(mgmt->bssid, bssid, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	/* u.deauth.reason_code == u.disassoc.reason_code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	mgmt->u.deauth.reason_code = cpu_to_le16(reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	if (send_frame) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		skb = dev_alloc_skb(local->hw.extra_tx_headroom +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 				    IEEE80211_DEAUTH_FRAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		skb_reserve(skb, local->hw.extra_tx_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		/* copy in frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		skb_put_data(skb, mgmt, IEEE80211_DEAUTH_FRAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		if (sdata->vif.type != NL80211_IFTYPE_STATION ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		    !(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 			IEEE80211_SKB_CB(skb)->flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 				IEEE80211_TX_INTFL_DONT_ENCRYPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 		ieee80211_tx_skb(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) static u8 *ieee80211_write_he_6ghz_cap(u8 *pos, __le16 cap, u8 *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	if ((end - pos) < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	*pos++ = WLAN_EID_EXTENSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	*pos++ = 1 + sizeof(cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	*pos++ = WLAN_EID_EXT_HE_6GHZ_CAPA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	memcpy(pos, &cap, sizeof(cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	return pos + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) static int ieee80211_build_preq_ies_band(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 					 u8 *buffer, size_t buffer_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 					 const u8 *ie, size_t ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 					 enum nl80211_band band,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 					 u32 rate_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 					 struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 					 size_t *offset, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	const struct ieee80211_sta_he_cap *he_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	u8 *pos = buffer, *end = buffer + buffer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	size_t noffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	int supp_rates_len, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	u8 rates[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	int num_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	int ext_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	int shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	u32 rate_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	bool have_80mhz = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	*offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	sband = local->hw.wiphy->bands[band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	if (WARN_ON_ONCE(!sband))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	rate_flags = ieee80211_chandef_rate_flags(chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	shift = ieee80211_chandef_get_shift(chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	num_rates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	for (i = 0; i < sband->n_bitrates; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 		if ((BIT(i) & rate_mask) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 			continue; /* skip rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		rates[num_rates++] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 			(u8) DIV_ROUND_UP(sband->bitrates[i].bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 					  (1 << shift) * 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	supp_rates_len = min_t(int, num_rates, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	if (end - pos < 2 + supp_rates_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	*pos++ = WLAN_EID_SUPP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	*pos++ = supp_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	memcpy(pos, rates, supp_rates_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	pos += supp_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	/* insert "request information" if in custom IEs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	if (ie && ie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		static const u8 before_extrates[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 			WLAN_EID_SSID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 			WLAN_EID_SUPP_RATES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 			WLAN_EID_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		noffset = ieee80211_ie_split(ie, ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 					     before_extrates,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 					     ARRAY_SIZE(before_extrates),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 					     *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		if (end - pos < noffset - *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 		memcpy(pos, ie + *offset, noffset - *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		pos += noffset - *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 		*offset = noffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	ext_rates_len = num_rates - supp_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	if (ext_rates_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 		if (end - pos < 2 + ext_rates_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 		*pos++ = WLAN_EID_EXT_SUPP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		*pos++ = ext_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		memcpy(pos, rates + supp_rates_len, ext_rates_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		pos += ext_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	if (chandef->chan && sband->band == NL80211_BAND_2GHZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		if (end - pos < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 		*pos++ = WLAN_EID_DS_PARAMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		*pos++ = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 		*pos++ = ieee80211_frequency_to_channel(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 				chandef->chan->center_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	if (flags & IEEE80211_PROBE_FLAG_MIN_CONTENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	/* insert custom IEs that go before HT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	if (ie && ie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 		static const u8 before_ht[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 			 * no need to list the ones split off already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 			 * (or generated here)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 			WLAN_EID_DS_PARAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 			WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		noffset = ieee80211_ie_split(ie, ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 					     before_ht, ARRAY_SIZE(before_ht),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 					     *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		if (end - pos < noffset - *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 		memcpy(pos, ie + *offset, noffset - *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 		pos += noffset - *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		*offset = noffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	if (sband->ht_cap.ht_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 		if (end - pos < 2 + sizeof(struct ieee80211_ht_cap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 		pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 						sband->ht_cap.cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	/* insert custom IEs that go before VHT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	if (ie && ie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		static const u8 before_vht[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 			 * no need to list the ones split off already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 			 * (or generated here)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 			WLAN_EID_BSS_COEX_2040,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 			WLAN_EID_EXT_CAPABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 			WLAN_EID_SSID_LIST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 			WLAN_EID_CHANNEL_USAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 			WLAN_EID_INTERWORKING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 			WLAN_EID_MESH_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 			/* 60 GHz (Multi-band, DMG, MMS) can't happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		noffset = ieee80211_ie_split(ie, ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 					     before_vht, ARRAY_SIZE(before_vht),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 					     *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 		if (end - pos < noffset - *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 		memcpy(pos, ie + *offset, noffset - *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 		pos += noffset - *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		*offset = noffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	/* Check if any channel in this sband supports at least 80 MHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	for (i = 0; i < sband->n_channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 						IEEE80211_CHAN_NO_80MHZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		have_80mhz = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	if (sband->vht_cap.vht_supported && have_80mhz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 		if (end - pos < 2 + sizeof(struct ieee80211_vht_cap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 						 sband->vht_cap.cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	/* insert custom IEs that go before HE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	if (ie && ie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		static const u8 before_he[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 			 * no need to list the ones split off before VHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 			 * or generated here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 			WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_REQ_PARAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 			WLAN_EID_AP_CSN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 			/* TODO: add 11ah/11aj/11ak elements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		noffset = ieee80211_ie_split(ie, ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 					     before_he, ARRAY_SIZE(before_he),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 					     *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		if (end - pos < noffset - *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		memcpy(pos, ie + *offset, noffset - *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		pos += noffset - *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 		*offset = noffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	he_cap = ieee80211_get_he_sta_cap(sband);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	if (he_cap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 		pos = ieee80211_ie_build_he_cap(pos, he_cap, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		if (!pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		if (sband->band == NL80211_BAND_6GHZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 			enum nl80211_iftype iftype =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 				ieee80211_vif_type_p2p(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 			__le16 cap = ieee80211_get_he_6ghz_capa(sband, iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 			pos = ieee80211_write_he_6ghz_cap(pos, cap, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	 * If adding more here, adjust code in main.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	 * that calculates local->scan_ies_len.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	return pos - buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)  out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	WARN_ONCE(1, "not enough space for preq IEs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)  done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	return pos - buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) int ieee80211_build_preq_ies(struct ieee80211_sub_if_data *sdata, u8 *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 			     size_t buffer_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 			     struct ieee80211_scan_ies *ie_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 			     const u8 *ie, size_t ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 			     u8 bands_used, u32 *rate_masks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 			     struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 			     u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	size_t pos = 0, old_pos = 0, custom_ie_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	memset(ie_desc, 0, sizeof(*ie_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	for (i = 0; i < NUM_NL80211_BANDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 		if (bands_used & BIT(i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 			pos += ieee80211_build_preq_ies_band(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 							     buffer + pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 							     buffer_len - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 							     ie, ie_len, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 							     rate_masks[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 							     chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 							     &custom_ie_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 							     flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 			ie_desc->ies[i] = buffer + old_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 			ie_desc->len[i] = pos - old_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 			old_pos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 	/* add any remaining custom IEs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	if (ie && ie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 		if (WARN_ONCE(buffer_len - pos < ie_len - custom_ie_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 			      "not enough space for preq custom IEs\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 			return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		memcpy(buffer + pos, ie + custom_ie_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 		       ie_len - custom_ie_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		ie_desc->common_ies = buffer + pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		ie_desc->common_ie_len = ie_len - custom_ie_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 		pos += ie_len - custom_ie_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	return pos;
^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) struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 					  const u8 *src, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 					  u32 ratemask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 					  struct ieee80211_channel *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 					  const u8 *ssid, size_t ssid_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 					  const u8 *ie, size_t ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 					  u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	struct cfg80211_chan_def chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	struct ieee80211_mgmt *mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	int ies_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	u32 rate_masks[NUM_NL80211_BANDS] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	struct ieee80211_scan_ies dummy_ie_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	 * Do not send DS Channel parameter for directed probe requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	 * in order to maximize the chance that we get a response.  Some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	 * badly-behaved APs don't respond when this parameter is included.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	chandef.width = sdata->vif.bss_conf.chandef.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	if (flags & IEEE80211_PROBE_FLAG_DIRECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 		chandef.chan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		chandef.chan = chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	skb = ieee80211_probereq_get(&local->hw, src, ssid, ssid_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 				     100 + ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	rate_masks[chan->band] = ratemask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	ies_len = ieee80211_build_preq_ies(sdata, skb_tail_pointer(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 					   skb_tailroom(skb), &dummy_ie_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 					   ie, ie_len, BIT(chan->band),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 					   rate_masks, &chandef, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 	skb_put(skb, ies_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	if (dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		mgmt = (struct ieee80211_mgmt *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 		memcpy(mgmt->da, dst, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		memcpy(mgmt->bssid, dst, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 			    struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 			    enum nl80211_band band, u32 *basic_rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	size_t num_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	u32 supp_rates, rate_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	int i, j, shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	sband = sdata->local->hw.wiphy->bands[band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	if (WARN_ON(!sband))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	shift = ieee80211_vif_get_shift(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	num_rates = sband->n_bitrates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	supp_rates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	for (i = 0; i < elems->supp_rates_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		     elems->ext_supp_rates_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		u8 rate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 		int own_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 		bool is_basic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 		if (i < elems->supp_rates_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 			rate = elems->supp_rates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		else if (elems->ext_supp_rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 			rate = elems->ext_supp_rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 				[i - elems->supp_rates_len];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		own_rate = 5 * (rate & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		is_basic = !!(rate & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		for (j = 0; j < num_rates; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 			int brate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 			if ((rate_flags & sband->bitrates[j].flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 			    != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 			brate = DIV_ROUND_UP(sband->bitrates[j].bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 					     1 << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 			if (brate == own_rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 				supp_rates |= BIT(j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 				if (basic_rates && is_basic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 					*basic_rates |= BIT(j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	return supp_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) void ieee80211_stop_device(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	ieee80211_led_radio(local, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	cancel_work_sync(&local->reconfig_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	flush_workqueue(local->workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	drv_stop(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) static void ieee80211_flush_completed_scan(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 					   bool aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 	/* It's possible that we don't handle the scan completion in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	 * time during suspend, so if it's still marked as completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	 * here, queue the work and flush it to clean things up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	 * Instead of calling the worker function directly here, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	 * really queue it to avoid potential races with other flows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	 * scheduling the same work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	if (test_bit(SCAN_COMPLETED, &local->scanning)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 		/* If coming from reconfiguration failure, abort the scan so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		 * we don't attempt to continue a partial HW scan - which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		 * possible otherwise if (e.g.) the 2.4 GHz portion was the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 		 * completed scan, and a 5 GHz portion is still pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 		if (aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 			set_bit(SCAN_ABORTED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		ieee80211_queue_delayed_work(&local->hw, &local->scan_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		flush_delayed_work(&local->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) static void ieee80211_handle_reconfig_failure(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	 * We get here if during resume the device can't be restarted properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	 * We might also get here if this happens during HW reset, which is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	 * slightly different situation and we need to drop all connections in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	 * the latter case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	 * Ask cfg80211 to turn off all interfaces, this will result in more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	 * warnings but at least we'll then get into a clean stopped state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	local->resuming = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	local->suspended = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	local->in_reconfig = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	ieee80211_flush_completed_scan(local, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	/* scheduled scan clearly can't be running any more, but tell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	 * cfg80211 and clear local state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	ieee80211_sched_scan_end(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	list_for_each_entry(sdata, &local->interfaces, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	/* Mark channel contexts as not being in the driver any more to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	 * removing them from the driver during the shutdown process...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 	mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 	list_for_each_entry(ctx, &local->chanctx_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 		ctx->driver_present = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 	cfg80211_shutdown_all_interfaces(local->hw.wiphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) static void ieee80211_assign_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 				     struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 	struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 	if (!local->use_chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 					 lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	if (conf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 		ctx = container_of(conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 		drv_assign_vif_chanctx(local, sdata, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) static void ieee80211_reconfig_stations(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	/* add STAs back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	mutex_lock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	list_for_each_entry(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		enum ieee80211_sta_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		if (!sta->uploaded || sta->sdata != sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 		for (state = IEEE80211_STA_NOTEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 		     state < sta->sta_state; state++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 			WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 					      state + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	mutex_unlock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) static int ieee80211_reconfig_nan(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	struct cfg80211_nan_func *func, **funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	int res, id, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	res = drv_start_nan(sdata->local, sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 			    &sdata->u.nan.conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	if (WARN_ON(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	funcs = kcalloc(sdata->local->hw.max_nan_de_entries + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 			sizeof(*funcs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	if (!funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	/* Add all the functions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	 * This is a little bit ugly. We need to call a potentially sleeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	 * callback for each NAN function, so we can't hold the spinlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	spin_lock_bh(&sdata->u.nan.func_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		funcs[i++] = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 	spin_unlock_bh(&sdata->u.nan.func_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	for (i = 0; funcs[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		res = drv_add_nan_func(sdata->local, sdata, funcs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		if (WARN_ON(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 			ieee80211_nan_func_terminated(&sdata->vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 						      funcs[i]->instance_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 						      NL80211_NAN_FUNC_TERM_REASON_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 						      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	kfree(funcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) int ieee80211_reconfig(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 	struct ieee80211_hw *hw = &local->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	int res, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	bool reconfig_due_to_wowlan = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	struct ieee80211_sub_if_data *sched_scan_sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	struct cfg80211_sched_scan_request *sched_scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	bool sched_scan_stopped = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	bool suspended = local->suspended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	/* nothing to do if HW shouldn't run */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	if (!local->open_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		goto wake_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	if (suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 		local->resuming = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	if (local->wowlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 		 * In the wowlan case, both mac80211 and the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 		 * are functional when the resume op is called, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 		 * clear local->suspended so the device could operate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		 * normally (e.g. pass rx frames).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 		local->suspended = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 		res = drv_resume(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 		local->wowlan = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 		if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 			local->resuming = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 			return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 		if (res == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 			goto wake_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 		WARN_ON(res > 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 		 * res is 1, which means the driver requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 		 * to go through a regular reset on wakeup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 		 * restore local->suspended in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 		reconfig_due_to_wowlan = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 		local->suspended = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	 * In case of hw_restart during suspend (without wowlan),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	 * cancel restart work, as we are reconfiguring the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	 * anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	 * Note that restart_work is scheduled on a frozen workqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	 * so we can't deadlock in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	if (suspended && local->in_reconfig && !reconfig_due_to_wowlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 		cancel_work_sync(&local->restart_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	local->started = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	 * Upon resume hardware can sometimes be goofy due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	 * various platform / driver / bus issues, so restarting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 	 * the device may at times not work immediately. Propagate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	 * the error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	res = drv_start(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 		if (suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 			WARN(1, "Hardware became unavailable upon resume. This could be a software issue prior to suspend or a hardware issue.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 			WARN(1, "Hardware became unavailable during restart.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 		ieee80211_handle_reconfig_failure(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	/* setup fragmentation threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 	drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	/* setup RTS threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	/* reset coverage class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 	drv_set_coverage_class(local, hw->wiphy->coverage_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	ieee80211_led_radio(local, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	ieee80211_mod_tpt_led_trig(local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 				   IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	/* add interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	sdata = rtnl_dereference(local->monitor_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	if (sdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 		/* in HW restart it exists already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 		WARN_ON(local->resuming);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 		res = drv_add_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 		if (WARN_ON(res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 			RCU_INIT_POINTER(local->monitor_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 			synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 			kfree(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 		    sdata->vif.type != NL80211_IFTYPE_MONITOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 		    ieee80211_sdata_running(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 			res = drv_add_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 			if (WARN_ON(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	/* If adding any of the interfaces failed above, roll back and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	 * report failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 		list_for_each_entry_continue_reverse(sdata, &local->interfaces,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 						     list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 			if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 			    sdata->vif.type != NL80211_IFTYPE_MONITOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 			    ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 				drv_remove_interface(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 		ieee80211_handle_reconfig_failure(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	/* add channel contexts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	if (local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 		mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 		list_for_each_entry(ctx, &local->chanctx_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 			if (ctx->replace_state !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 			    IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 				WARN_ON(drv_add_chanctx(local, ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 		mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 		sdata = rtnl_dereference(local->monitor_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		if (sdata && ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 			ieee80211_assign_chanctx(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	/* reconfigure hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 	ieee80211_hw_config(local, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 	ieee80211_configure_filter(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	/* Finally also reconfigure all the BSS information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 	list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 		u32 changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 		if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 		ieee80211_assign_chanctx(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 		switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 		case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 		case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 		case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 			if (sdata->vif.bss_conf.ibss_joined)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 				WARN_ON(drv_join_ibss(local, sdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 			ieee80211_reconfig_stations(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 		case NL80211_IFTYPE_AP: /* AP stations are handled later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 			for (i = 0; i < IEEE80211_NUM_ACS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 				drv_conf_tx(local, sdata, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 					    &sdata->tx_conf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 		/* common change flags for all interface types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 		changed = BSS_CHANGED_ERP_CTS_PROT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 			  BSS_CHANGED_ERP_PREAMBLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 			  BSS_CHANGED_ERP_SLOT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 			  BSS_CHANGED_HT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 			  BSS_CHANGED_BASIC_RATES |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 			  BSS_CHANGED_BEACON_INT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 			  BSS_CHANGED_BSSID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 			  BSS_CHANGED_CQM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 			  BSS_CHANGED_QOS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 			  BSS_CHANGED_IDLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 			  BSS_CHANGED_TXPOWER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 			  BSS_CHANGED_MCAST_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		if (sdata->vif.mu_mimo_owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 			changed |= BSS_CHANGED_MU_GROUPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 		switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 			changed |= BSS_CHANGED_ASSOC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 				   BSS_CHANGED_ARP_FILTER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 				   BSS_CHANGED_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 			/* Re-send beacon info report to the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 			if (sdata->u.mgd.have_beacon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 				changed |= BSS_CHANGED_BEACON_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 			if (sdata->vif.bss_conf.max_idle_period ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 			    sdata->vif.bss_conf.protected_keep_alive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 				changed |= BSS_CHANGED_KEEP_ALIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 			sdata_lock(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 			ieee80211_bss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 			sdata_unlock(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 			changed |= BSS_CHANGED_OCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 			ieee80211_bss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 		case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 			changed |= BSS_CHANGED_IBSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 			changed |= BSS_CHANGED_SSID | BSS_CHANGED_P2P_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 			if (sdata->vif.bss_conf.ftm_responder == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 			    wiphy_ext_feature_isset(sdata->local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 					NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 				changed |= BSS_CHANGED_FTM_RESPONDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 			if (sdata->vif.type == NL80211_IFTYPE_AP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 				changed |= BSS_CHANGED_AP_PROBE_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 				if (rcu_access_pointer(sdata->u.ap.beacon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 					drv_start_ap(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 		case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 			if (sdata->vif.bss_conf.enable_beacon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 				changed |= BSS_CHANGED_BEACON |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 					   BSS_CHANGED_BEACON_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 				ieee80211_bss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 			res = ieee80211_reconfig_nan(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 			if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 				ieee80211_handle_reconfig_failure(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 				return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 		case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 		case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 		case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 			/* nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 		case NL80211_IFTYPE_UNSPECIFIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 		case NUM_NL80211_IFTYPES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 		case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 		case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 			WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 	ieee80211_recalc_ps(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 	 * The sta might be in psm against the ap (e.g. because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 	 * this was the state before a hw restart), so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	 * explicitly send a null packet in order to make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 	 * it'll sync against the ap (and get out of psm).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 	if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 		list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 			if (sdata->vif.type != NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 			if (!sdata->u.mgd.associated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 			ieee80211_send_nullfunc(local, sdata, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 	/* APs are now beaconing, add back stations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	mutex_lock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 	list_for_each_entry(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		enum ieee80211_sta_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		if (!sta->uploaded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 		if (sta->sdata->vif.type != NL80211_IFTYPE_AP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 		    sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 		for (state = IEEE80211_STA_NOTEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		     state < sta->sta_state; state++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 			WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 					      state + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 	mutex_unlock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 	/* add back keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 	list_for_each_entry(sdata, &local->interfaces, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 		ieee80211_reenable_keys(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 	/* Reconfigure sched scan if it was interrupted by FW restart */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 	sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 						lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	sched_scan_req = rcu_dereference_protected(local->sched_scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 						lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 	if (sched_scan_sdata && sched_scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		 * Sched scan stopped, but we don't want to report it. Instead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		 * we're trying to reschedule. However, if more than one scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 		 * plan was set, we cannot reschedule since we don't know which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 		 * scan plan was currently running (and some scan plans may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 		 * already finished).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		if (sched_scan_req->n_scan_plans > 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 		    __ieee80211_request_sched_scan_start(sched_scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 							 sched_scan_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 			RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 			RCU_INIT_POINTER(local->sched_scan_req, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 			sched_scan_stopped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	if (sched_scan_stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		cfg80211_sched_scan_stopped_rtnl(local->hw.wiphy, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)  wake_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	if (local->monitors == local->open_count && local->monitors > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 		ieee80211_add_virtual_monitor(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 	 * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 	 * sessions can be established after a resume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	 * Also tear down aggregation sessions since reconfiguring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	 * them in a hardware restart scenario is not easily done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 	 * right now, and the hardware will have lost information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 	 * about the sessions, but we and the AP still think they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 	 * are active. This is really a workaround though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		mutex_lock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 		list_for_each_entry(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 			if (!local->resuming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 				ieee80211_sta_tear_down_BA_sessions(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 						sta, AGG_STOP_LOCAL_REQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 			clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		mutex_unlock(&local->sta_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 	if (local->in_reconfig) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 		local->in_reconfig = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 		/* Restart deferred ROCs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 		mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 		ieee80211_start_next_roc(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 		mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 		/* Requeue all works */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 		list_for_each_entry(sdata, &local->interfaces, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 			ieee80211_queue_work(&local->hw, &sdata->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 					IEEE80211_QUEUE_STOP_REASON_SUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 					false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 	 * If this is for hw restart things are still running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	 * We may want to change that later, however.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 	if (local->open_count && (!suspended || reconfig_due_to_wowlan))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 		drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_RESTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	if (!suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 	/* first set suspended false, then resuming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	local->suspended = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	local->resuming = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 	ieee80211_flush_completed_scan(local, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 	if (local->open_count && !reconfig_due_to_wowlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 		drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 	list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 		if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 		if (sdata->vif.type == NL80211_IFTYPE_STATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 			ieee80211_sta_restart(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 	mod_timer(&local->sta_cleanup, jiffies + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	struct ieee80211_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 	struct ieee80211_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 	if (WARN_ON(!vif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 	sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 	local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 	if (WARN_ON(!local->resuming))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 	if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 	sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 	mutex_lock(&local->key_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	list_for_each_entry(key, &sdata->key_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 		key->flags |= KEY_FLAG_TAINTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	mutex_unlock(&local->key_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 	struct ieee80211_chanctx_conf *chanctx_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 	struct ieee80211_chanctx *chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 	mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 	chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 					lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	 * This function can be called from a work, thus it may be possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	 * that the chanctx_conf is removed (due to a disconnection, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	 * example).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 	 * So nothing should be done in such case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 	if (!chanctx_conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 	ieee80211_recalc_smps_chanctx(local, chanctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735)  unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	struct ieee80211_chanctx_conf *chanctx_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	struct ieee80211_chanctx *chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 					lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	if (WARN_ON_ONCE(!chanctx_conf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 	chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	ieee80211_recalc_chanctx_min_def(local, chanctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755)  unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 	size_t pos = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 		pos += 2 + ies[pos + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 					    int rssi_min_thold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 					    int rssi_max_thold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 	trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 	if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 	 * Scale up threshold values before storing it, as the RSSI averaging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 	 * algorithm uses a scaled up value as well. Change this scaling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 	 * factor if the RSSI averaging algorithm changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 	sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 	sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 				    int rssi_min_thold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 				    int rssi_max_thold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 	WARN_ON(rssi_min_thold == rssi_max_thold ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 		rssi_min_thold > rssi_max_thold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	_ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 				       rssi_max_thold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	_ieee80211_enable_rssi_reports(sdata, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 			      u16 cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 	__le16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	*pos++ = WLAN_EID_HT_CAPABILITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	*pos++ = sizeof(struct ieee80211_ht_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	memset(pos, 0, sizeof(struct ieee80211_ht_cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	/* capability flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	tmp = cpu_to_le16(cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 	memcpy(pos, &tmp, sizeof(u16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	pos += sizeof(u16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 	/* AMPDU parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 	*pos++ = ht_cap->ampdu_factor |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 		 (ht_cap->ampdu_density <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 			IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 	/* MCS set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 	memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 	pos += sizeof(ht_cap->mcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 	/* extended capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 	pos += sizeof(__le16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 	/* BF capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 	pos += sizeof(__le32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 	/* antenna selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 	pos += sizeof(u8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 			       u32 cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 	__le32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 	*pos++ = WLAN_EID_VHT_CAPABILITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	*pos++ = sizeof(struct ieee80211_vht_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 	memset(pos, 0, sizeof(struct ieee80211_vht_cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 	/* capability flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 	tmp = cpu_to_le32(cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 	memcpy(pos, &tmp, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	pos += sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	/* VHT MCS set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 	pos += sizeof(vht_cap->vht_mcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) u8 ieee80211_ie_len_he_cap(struct ieee80211_sub_if_data *sdata, u8 iftype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 	const struct ieee80211_sta_he_cap *he_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 	u8 n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 	sband = ieee80211_get_sband(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 	if (!sband)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 	he_cap = ieee80211_get_he_iftype_cap(sband, iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	if (!he_cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 	n = ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 	return 2 + 1 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 	       sizeof(he_cap->he_cap_elem) + n +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 	       ieee80211_he_ppe_size(he_cap->ppe_thres[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 				     he_cap->he_cap_elem.phy_cap_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) u8 *ieee80211_ie_build_he_cap(u8 *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 			      const struct ieee80211_sta_he_cap *he_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 			      u8 *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 	u8 n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 	u8 ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 	u8 *orig_pos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 	/* Make sure we have place for the IE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 	 * TODO: the 1 added is because this temporarily is under the EXTENSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 	 * IE. Get rid of it when it moves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 	if (!he_cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 		return orig_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 	n = ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 	ie_len = 2 + 1 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 		 sizeof(he_cap->he_cap_elem) + n +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 		 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 				       he_cap->he_cap_elem.phy_cap_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 	if ((end - pos) < ie_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 		return orig_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 	*pos++ = WLAN_EID_EXTENSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 	pos++; /* We'll set the size later below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 	*pos++ = WLAN_EID_EXT_HE_CAPABILITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 	/* Fixed data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 	memcpy(pos, &he_cap->he_cap_elem, sizeof(he_cap->he_cap_elem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 	pos += sizeof(he_cap->he_cap_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 	memcpy(pos, &he_cap->he_mcs_nss_supp, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	pos += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	/* Check if PPE Threshold should be present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 	if ((he_cap->he_cap_elem.phy_cap_info[6] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 	     IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	 * Calculate how many PPET16/PPET8 pairs are to come. Algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 	 * (NSS_M1 + 1) x (num of 1 bits in RU_INDEX_BITMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 	n = hweight8(he_cap->ppe_thres[0] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 		     IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 	n *= (1 + ((he_cap->ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 		   IEEE80211_PPE_THRES_NSS_POS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 	 * Each pair is 6 bits, and we need to add the 7 "header" bits to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 	 * total size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 	n = (n * IEEE80211_PPE_THRES_INFO_PPET_SIZE * 2) + 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 	n = DIV_ROUND_UP(n, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 	/* Copy PPE Thresholds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 	memcpy(pos, &he_cap->ppe_thres, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	pos += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 	orig_pos[1] = (pos - orig_pos) - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) void ieee80211_ie_build_he_6ghz_cap(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 				    struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 	const struct ieee80211_sband_iftype_data *iftd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 	enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 	u8 *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 	u16 cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 	sband = ieee80211_get_sband(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 	if (!sband)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 	iftd = ieee80211_get_sband_iftype_data(sband, iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 	if (WARN_ON(!iftd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 	/* Check for device HE 6 GHz capability before adding element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	if (!iftd->he_6ghz_capa.capa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 	cap = le16_to_cpu(iftd->he_6ghz_capa.capa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 	cap &= ~IEEE80211_HE_6GHZ_CAP_SM_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 	switch (sdata->smps_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	case IEEE80211_SMPS_AUTOMATIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 	case IEEE80211_SMPS_NUM_MODES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 	case IEEE80211_SMPS_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 		cap |= u16_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 				       IEEE80211_HE_6GHZ_CAP_SM_PS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 	case IEEE80211_SMPS_STATIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 		cap |= u16_encode_bits(WLAN_HT_CAP_SM_PS_STATIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 				       IEEE80211_HE_6GHZ_CAP_SM_PS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 	case IEEE80211_SMPS_DYNAMIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 		cap |= u16_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 				       IEEE80211_HE_6GHZ_CAP_SM_PS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 	pos = skb_put(skb, 2 + 1 + sizeof(cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 	ieee80211_write_he_6ghz_cap(pos, cpu_to_le16(cap),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 				    pos + 2 + 1 + sizeof(cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 			       const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 			       u16 prot_mode, bool rifs_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 	struct ieee80211_ht_operation *ht_oper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 	/* Build HT Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 	*pos++ = WLAN_EID_HT_OPERATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 	*pos++ = sizeof(struct ieee80211_ht_operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	ht_oper = (struct ieee80211_ht_operation *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	ht_oper->primary_chan = ieee80211_frequency_to_channel(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 					chandef->chan->center_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 	switch (chandef->width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	case NL80211_CHAN_WIDTH_160:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 	case NL80211_CHAN_WIDTH_80P80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 	case NL80211_CHAN_WIDTH_80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 	case NL80211_CHAN_WIDTH_40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 		if (chandef->center_freq1 > chandef->chan->center_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 			ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 			ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 		ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	    chandef->width != NL80211_CHAN_WIDTH_20_NOHT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 	    chandef->width != NL80211_CHAN_WIDTH_20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 		ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 	if (rifs_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 		ht_oper->ht_param |= IEEE80211_HT_PARAM_RIFS_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 	ht_oper->operation_mode = cpu_to_le16(prot_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 	ht_oper->stbc_param = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 	/* It seems that Basic MCS set and Supported MCS set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 	   are identical for the first 10 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	memset(&ht_oper->basic_set, 0, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 	memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 	return pos + sizeof(struct ieee80211_ht_operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) void ieee80211_ie_build_wide_bw_cs(u8 *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 				   const struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 	*pos++ = WLAN_EID_WIDE_BW_CHANNEL_SWITCH;	/* EID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 	*pos++ = 3;					/* IE length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 	/* New channel width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	switch (chandef->width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	case NL80211_CHAN_WIDTH_80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 		*pos++ = IEEE80211_VHT_CHANWIDTH_80MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 	case NL80211_CHAN_WIDTH_160:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 		*pos++ = IEEE80211_VHT_CHANWIDTH_160MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 	case NL80211_CHAN_WIDTH_80P80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 		*pos++ = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 		*pos++ = IEEE80211_VHT_CHANWIDTH_USE_HT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 	/* new center frequency segment 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	*pos++ = ieee80211_frequency_to_channel(chandef->center_freq1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 	/* new center frequency segment 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	if (chandef->center_freq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 		*pos++ = ieee80211_frequency_to_channel(chandef->center_freq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 		*pos++ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 				const struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	struct ieee80211_vht_operation *vht_oper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	*pos++ = WLAN_EID_VHT_OPERATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	*pos++ = sizeof(struct ieee80211_vht_operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 	vht_oper = (struct ieee80211_vht_operation *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	vht_oper->center_freq_seg0_idx = ieee80211_frequency_to_channel(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 							chandef->center_freq1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 	if (chandef->center_freq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 		vht_oper->center_freq_seg1_idx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 			ieee80211_frequency_to_channel(chandef->center_freq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 		vht_oper->center_freq_seg1_idx = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 	switch (chandef->width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	case NL80211_CHAN_WIDTH_160:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 		 * Convert 160 MHz channel width to new style as interop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 		 * workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 		vht_oper->center_freq_seg1_idx = vht_oper->center_freq_seg0_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 		if (chandef->chan->center_freq < chandef->center_freq1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 			vht_oper->center_freq_seg0_idx -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 			vht_oper->center_freq_seg0_idx += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 	case NL80211_CHAN_WIDTH_80P80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 		 * Convert 80+80 MHz channel width to new style as interop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 		 * workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 	case NL80211_CHAN_WIDTH_80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 	/* don't require special VHT peer rates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 	vht_oper->basic_mcs_set = cpu_to_le16(0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 	return pos + sizeof(struct ieee80211_vht_operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) u8 *ieee80211_ie_build_he_oper(u8 *pos, struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 	struct ieee80211_he_operation *he_oper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 	struct ieee80211_he_6ghz_oper *he_6ghz_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 	u32 he_oper_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 	u8 ie_len = 1 + sizeof(struct ieee80211_he_operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 	if (chandef->chan->band == NL80211_BAND_6GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 		ie_len += sizeof(struct ieee80211_he_6ghz_oper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	*pos++ = WLAN_EID_EXTENSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 	*pos++ = ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	*pos++ = WLAN_EID_EXT_HE_OPERATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 	he_oper_params = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 	he_oper_params |= u32_encode_bits(1023, /* disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 				IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	he_oper_params |= u32_encode_bits(1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 				IEEE80211_HE_OPERATION_ER_SU_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 	he_oper_params |= u32_encode_bits(1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 				IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 	if (chandef->chan->band == NL80211_BAND_6GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 		he_oper_params |= u32_encode_bits(1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 				IEEE80211_HE_OPERATION_6GHZ_OP_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 	he_oper = (struct ieee80211_he_operation *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	he_oper->he_oper_params = cpu_to_le32(he_oper_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 	/* don't require special HE peer rates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 	he_oper->he_mcs_nss_set = cpu_to_le16(0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 	pos += sizeof(struct ieee80211_he_operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 	if (chandef->chan->band != NL80211_BAND_6GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 	/* TODO add VHT operational */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 	he_6ghz_op = (struct ieee80211_he_6ghz_oper *)pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 	he_6ghz_op->minrate = 6; /* 6 Mbps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 	he_6ghz_op->primary =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 		ieee80211_frequency_to_channel(chandef->chan->center_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 	he_6ghz_op->ccfs0 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 		ieee80211_frequency_to_channel(chandef->center_freq1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 	if (chandef->center_freq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 		he_6ghz_op->ccfs1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 			ieee80211_frequency_to_channel(chandef->center_freq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 		he_6ghz_op->ccfs1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 	switch (chandef->width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 	case NL80211_CHAN_WIDTH_160:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 		/* Convert 160 MHz channel width to new style as interop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 		 * workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 		he_6ghz_op->control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 		he_6ghz_op->ccfs1 = he_6ghz_op->ccfs0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 		if (chandef->chan->center_freq < chandef->center_freq1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 			he_6ghz_op->ccfs0 -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 			he_6ghz_op->ccfs0 += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 	case NL80211_CHAN_WIDTH_80P80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 		he_6ghz_op->control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 	case NL80211_CHAN_WIDTH_80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 		he_6ghz_op->control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	case NL80211_CHAN_WIDTH_40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 		he_6ghz_op->control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 		he_6ghz_op->control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 	pos += sizeof(struct ieee80211_he_6ghz_oper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) bool ieee80211_chandef_ht_oper(const struct ieee80211_ht_operation *ht_oper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 			       struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 	enum nl80211_channel_type channel_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 	if (!ht_oper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 	switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 	case IEEE80211_HT_PARAM_CHA_SEC_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 		channel_type = NL80211_CHAN_HT20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 	case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 		channel_type = NL80211_CHAN_HT40PLUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 	case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 		channel_type = NL80211_CHAN_HT40MINUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 		channel_type = NL80211_CHAN_NO_HT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 	cfg80211_chandef_create(chandef, chandef->chan, channel_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) bool ieee80211_chandef_vht_oper(struct ieee80211_hw *hw, u32 vht_cap_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 				const struct ieee80211_vht_operation *oper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 				const struct ieee80211_ht_operation *htop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 				struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 	struct cfg80211_chan_def new = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 	int cf0, cf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 	int ccfs0, ccfs1, ccfs2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 	int ccf0, ccf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	u32 vht_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 	bool support_80_80 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 	bool support_160 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 	u8 ext_nss_bw_supp = u32_get_bits(vht_cap_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 					  IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 	u8 supp_chwidth = u32_get_bits(vht_cap_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 				       IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 	if (!oper || !htop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 	vht_cap = hw->wiphy->bands[chandef->chan->band]->vht_cap.cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 	support_160 = (vht_cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 				  IEEE80211_VHT_CAP_EXT_NSS_BW_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	support_80_80 = ((vht_cap &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 			 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 			(vht_cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 			 vht_cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 			((vht_cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 				    IEEE80211_VHT_CAP_EXT_NSS_BW_SHIFT > 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	ccfs0 = oper->center_freq_seg0_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	ccfs1 = oper->center_freq_seg1_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 	ccfs2 = (le16_to_cpu(htop->operation_mode) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 				IEEE80211_HT_OP_MODE_CCFS2_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 			>> IEEE80211_HT_OP_MODE_CCFS2_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 	ccf0 = ccfs0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 	/* if not supported, parse as though we didn't understand it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 	if (!ieee80211_hw_check(hw, SUPPORTS_VHT_EXT_NSS_BW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 		ext_nss_bw_supp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 	 * Cf. IEEE 802.11 Table 9-250
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 	 * We really just consider that because it's inefficient to connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 	 * at a higher bandwidth than we'll actually be able to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 	switch ((supp_chwidth << 4) | ext_nss_bw_supp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 	case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 		ccf1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 		support_160 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 		support_80_80 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 	case 0x01:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 		support_80_80 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 	case 0x02:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 	case 0x03:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 		ccf1 = ccfs2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 	case 0x10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 		ccf1 = ccfs1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 	case 0x11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 	case 0x12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 		if (!ccfs1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 			ccf1 = ccfs2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 			ccf1 = ccfs1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 	case 0x13:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 	case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 	case 0x23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 		ccf1 = ccfs1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 	cf0 = ieee80211_channel_to_frequency(ccf0, chandef->chan->band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 	cf1 = ieee80211_channel_to_frequency(ccf1, chandef->chan->band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 	switch (oper->chan_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 	case IEEE80211_VHT_CHANWIDTH_USE_HT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 		/* just use HT information directly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 	case IEEE80211_VHT_CHANWIDTH_80MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 		new.width = NL80211_CHAN_WIDTH_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 		new.center_freq1 = cf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 		/* If needed, adjust based on the newer interop workaround. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 		if (ccf1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 			unsigned int diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 			diff = abs(ccf1 - ccf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 			if ((diff == 8) && support_160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 				new.width = NL80211_CHAN_WIDTH_160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 				new.center_freq1 = cf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 			} else if ((diff > 8) && support_80_80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 				new.width = NL80211_CHAN_WIDTH_80P80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 				new.center_freq2 = cf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 	case IEEE80211_VHT_CHANWIDTH_160MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 		/* deprecated encoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 		new.width = NL80211_CHAN_WIDTH_160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 		new.center_freq1 = cf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 	case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 		/* deprecated encoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 		new.width = NL80211_CHAN_WIDTH_80P80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 		new.center_freq1 = cf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 		new.center_freq2 = cf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 	if (!cfg80211_chandef_valid(&new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	*chandef = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) bool ieee80211_chandef_he_6ghz_oper(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 				    const struct ieee80211_he_operation *he_oper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 				    struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 	const struct ieee80211_sta_he_cap *he_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 	struct cfg80211_chan_def he_chandef = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 	const struct ieee80211_he_6ghz_oper *he_6ghz_oper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 	bool support_80_80, support_160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	u8 he_phy_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 	u32 freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 	if (chandef->chan->band != NL80211_BAND_6GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 	sband = local->hw.wiphy->bands[NL80211_BAND_6GHZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 	he_cap = ieee80211_get_he_iftype_cap(sband, iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 	if (!he_cap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 		sdata_info(sdata, "Missing iftype sband data/HE cap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 	he_phy_cap = he_cap->he_cap_elem.phy_cap_info[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 	support_160 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 		he_phy_cap &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 		IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 	support_80_80 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 		he_phy_cap &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 		IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 	if (!he_oper) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 		sdata_info(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 			   "HE is not advertised on (on %d MHz), expect issues\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 			   chandef->chan->center_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 	he_6ghz_oper = ieee80211_he_6ghz_oper(he_oper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 	if (!he_6ghz_oper) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 		sdata_info(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 			   "HE 6GHz operation missing (on %d MHz), expect issues\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 			   chandef->chan->center_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 	freq = ieee80211_channel_to_frequency(he_6ghz_oper->primary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 					      NL80211_BAND_6GHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 	he_chandef.chan = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 	switch (u8_get_bits(he_6ghz_oper->control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 			    IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 		he_chandef.width = NL80211_CHAN_WIDTH_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 		he_chandef.width = NL80211_CHAN_WIDTH_40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 		he_chandef.width = NL80211_CHAN_WIDTH_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 		he_chandef.width = NL80211_CHAN_WIDTH_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 		if (!he_6ghz_oper->ccfs1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 		if (abs(he_6ghz_oper->ccfs1 - he_6ghz_oper->ccfs0) == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 			if (support_160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 				he_chandef.width = NL80211_CHAN_WIDTH_160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 			if (support_80_80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 				he_chandef.width = NL80211_CHAN_WIDTH_80P80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 	if (he_chandef.width == NL80211_CHAN_WIDTH_160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 		he_chandef.center_freq1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 			ieee80211_channel_to_frequency(he_6ghz_oper->ccfs1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 						       NL80211_BAND_6GHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 		he_chandef.center_freq1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 			ieee80211_channel_to_frequency(he_6ghz_oper->ccfs0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 						       NL80211_BAND_6GHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 		if (support_80_80 || support_160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 			he_chandef.center_freq2 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 				ieee80211_channel_to_frequency(he_6ghz_oper->ccfs1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 							       NL80211_BAND_6GHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 	if (!cfg80211_chandef_valid(&he_chandef)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) 		sdata_info(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 			   "HE 6GHz operation resulted in invalid chandef: %d MHz/%d/%d MHz/%d MHz\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 			   he_chandef.chan ? he_chandef.chan->center_freq : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 			   he_chandef.width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 			   he_chandef.center_freq1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 			   he_chandef.center_freq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	*chandef = he_chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) bool ieee80211_chandef_s1g_oper(const struct ieee80211_s1g_oper_ie *oper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 				struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 	u32 oper_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 	if (!oper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 	switch (FIELD_GET(S1G_OPER_CH_WIDTH_OPER, oper->ch_width)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 	case IEEE80211_S1G_CHANWIDTH_1MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 		chandef->width = NL80211_CHAN_WIDTH_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 	case IEEE80211_S1G_CHANWIDTH_2MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 		chandef->width = NL80211_CHAN_WIDTH_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 	case IEEE80211_S1G_CHANWIDTH_4MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 		chandef->width = NL80211_CHAN_WIDTH_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 	case IEEE80211_S1G_CHANWIDTH_8MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 		chandef->width = NL80211_CHAN_WIDTH_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 	case IEEE80211_S1G_CHANWIDTH_16MHZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 		chandef->width = NL80211_CHAN_WIDTH_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 	oper_freq = ieee80211_channel_to_freq_khz(oper->oper_ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 						  NL80211_BAND_S1GHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 	chandef->center_freq1 = KHZ_TO_MHZ(oper_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 	chandef->freq1_offset = oper_freq % 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 			     const struct ieee80211_supported_band *sband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 			     const u8 *srates, int srates_len, u32 *rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 	u32 rate_flags = ieee80211_chandef_rate_flags(chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 	int shift = ieee80211_chandef_get_shift(chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 	struct ieee80211_rate *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 	int brate, rate, i, j, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 	*rates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 	for (i = 0; i < srates_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 		rate = srates[i] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 		for (j = 0; j < sband->n_bitrates; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 			br = &sband->bitrates[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 			if ((rate_flags & br->flags) != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 			brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 			if (brate == rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 				*rates |= BIT(j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 				count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 			    struct sk_buff *skb, bool need_basic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 			    enum nl80211_band band)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 	int rate, shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 	u8 i, rates, *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 	u32 basic_rates = sdata->vif.bss_conf.basic_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 	u32 rate_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 	shift = ieee80211_vif_get_shift(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 	rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 	sband = local->hw.wiphy->bands[band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 	rates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 	for (i = 0; i < sband->n_bitrates; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 		if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 		rates++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 	if (rates > 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 		rates = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 	if (skb_tailroom(skb) < rates + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 	pos = skb_put(skb, rates + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 	*pos++ = WLAN_EID_SUPP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 	*pos++ = rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 	for (i = 0; i < rates; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 		u8 basic = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 		if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 		if (need_basic && basic_rates & BIT(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 			basic = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 		rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 				    5 * (1 << shift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 		*pos++ = basic | (u8) rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 				struct sk_buff *skb, bool need_basic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 				enum nl80211_band band)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 	struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 	int rate, shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 	u8 i, exrates, *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 	u32 basic_rates = sdata->vif.bss_conf.basic_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 	u32 rate_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 	rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 	shift = ieee80211_vif_get_shift(&sdata->vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 	sband = local->hw.wiphy->bands[band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 	exrates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 	for (i = 0; i < sband->n_bitrates; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 		if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 		exrates++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 	if (exrates > 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 		exrates -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 		exrates = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 	if (skb_tailroom(skb) < exrates + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 	if (exrates) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 		pos = skb_put(skb, exrates + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 		*pos++ = WLAN_EID_EXT_SUPP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 		*pos++ = exrates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 		for (i = 8; i < sband->n_bitrates; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 			u8 basic = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 			if ((rate_flags & sband->bitrates[i].flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 			    != rate_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 			if (need_basic && basic_rates & BIT(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 				basic = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 			rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 					    5 * (1 << shift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 			*pos++ = basic | (u8) rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) int ieee80211_ave_rssi(struct ieee80211_vif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 	if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 		/* non-managed type inferfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 	return -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 	if (!mcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 	/* TODO: consider rx_highest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 	if (mcs->rx_mask[3])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 		return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 	if (mcs->rx_mask[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 		return 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 	if (mcs->rx_mask[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 		return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)  * ieee80211_calculate_rx_timestamp - calculate timestamp in frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656)  * @local: mac80211 hw info struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)  * @status: RX status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658)  * @mpdu_len: total MPDU length (including FCS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659)  * @mpdu_offset: offset into MPDU to calculate timestamp at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661)  * This function calculates the RX timestamp at the given MPDU offset, taking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662)  * into account what the RX timestamp was. An offset of 0 will just normalize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663)  * the timestamp to TSF at beginning of MPDU reception.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 				     struct ieee80211_rx_status *status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 				     unsigned int mpdu_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 				     unsigned int mpdu_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 	u64 ts = status->mactime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 	struct rate_info ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 	u16 rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 	if (WARN_ON(!ieee80211_have_rx_timestamp(status)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 	memset(&ri, 0, sizeof(ri));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	ri.bw = status->bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 	/* Fill cfg80211 rate info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 	switch (status->encoding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 	case RX_ENC_HT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 		ri.mcs = status->rate_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 		ri.flags |= RATE_INFO_FLAGS_MCS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 		if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 			ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 	case RX_ENC_VHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 		ri.flags |= RATE_INFO_FLAGS_VHT_MCS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 		ri.mcs = status->rate_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 		ri.nss = status->nss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 		if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 			ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 	case RX_ENC_LEGACY: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 		struct ieee80211_supported_band *sband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 		int shift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 		int bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 		switch (status->bw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 		case RATE_INFO_BW_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 			shift = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 		case RATE_INFO_BW_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 			shift = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 		sband = local->hw.wiphy->bands[status->band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 		bitrate = sband->bitrates[status->rate_idx].bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 		ri.legacy = DIV_ROUND_UP(bitrate, (1 << shift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 		if (status->flag & RX_FLAG_MACTIME_PLCP_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 			/* TODO: handle HT/VHT preambles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 			if (status->band == NL80211_BAND_5GHZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 				ts += 20 << shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 				mpdu_offset += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 			} else if (status->enc_flags & RX_ENC_FLAG_SHORTPRE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 				ts += 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 				ts += 192;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 	rate = cfg80211_calculate_bitrate(&ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 	if (WARN_ONCE(!rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 		      "Invalid bitrate: flags=0x%llx, idx=%d, vht_nss=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 		      (unsigned long long)status->flag, status->rate_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 		      status->nss))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 	/* rewind from end of MPDU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 	if (status->flag & RX_FLAG_MACTIME_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 		ts -= mpdu_len * 8 * 10 / rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 	ts += mpdu_offset * 8 * 10 / rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 	return ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) void ieee80211_dfs_cac_cancel(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 	struct cfg80211_chan_def chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 	/* for interface list, to avoid linking iflist_mtx and chanctx_mtx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 	mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 	list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 		/* it might be waiting for the local->mtx, but then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 		 * by the time it gets it, sdata->wdev.cac_started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 		 * will no longer be true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 		cancel_delayed_work(&sdata->dfs_cac_timer_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 		if (sdata->wdev.cac_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 			chandef = sdata->vif.bss_conf.chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 			ieee80211_vif_release_channel(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 			cfg80211_cac_event(sdata->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 					   &chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 					   NL80211_RADAR_CAC_ABORTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 					   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) void ieee80211_dfs_radar_detected_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 	struct ieee80211_local *local =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 		container_of(work, struct ieee80211_local, radar_detected_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 	struct cfg80211_chan_def chandef = local->hw.conf.chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 	struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 	int num_chanctx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 	mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 	list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 		if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 		num_chanctx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 		chandef = ctx->conf.def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 	mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 	ieee80211_dfs_cac_cancel(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 	if (num_chanctx > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 		/* XXX: multi-channel is not supported yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 		cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) void ieee80211_radar_detected(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 	struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 	trace_api_radar_detected(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 	schedule_work(&local->radar_detected_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) EXPORT_SYMBOL(ieee80211_radar_detected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) u32 ieee80211_chandef_downgrade(struct cfg80211_chan_def *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 	u32 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 	int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 	switch (c->width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 	case NL80211_CHAN_WIDTH_20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 		c->width = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 		ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 	case NL80211_CHAN_WIDTH_40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 		c->width = NL80211_CHAN_WIDTH_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 		c->center_freq1 = c->chan->center_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 		ret = IEEE80211_STA_DISABLE_40MHZ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 		      IEEE80211_STA_DISABLE_VHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 	case NL80211_CHAN_WIDTH_80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 		tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 		/* n_P40 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 		tmp /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 		/* freq_P40 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 		c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 		c->width = NL80211_CHAN_WIDTH_40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 		ret = IEEE80211_STA_DISABLE_VHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 	case NL80211_CHAN_WIDTH_80P80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 		c->center_freq2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 		c->width = NL80211_CHAN_WIDTH_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 		ret = IEEE80211_STA_DISABLE_80P80MHZ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 		      IEEE80211_STA_DISABLE_160MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 	case NL80211_CHAN_WIDTH_160:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 		/* n_P20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 		tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 		/* n_P80 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 		tmp /= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 		c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 		c->width = NL80211_CHAN_WIDTH_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 		ret = IEEE80211_STA_DISABLE_80P80MHZ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 		      IEEE80211_STA_DISABLE_160MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 	case NL80211_CHAN_WIDTH_20_NOHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 		WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 		c->width = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 		ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 	case NL80211_CHAN_WIDTH_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 	case NL80211_CHAN_WIDTH_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 	case NL80211_CHAN_WIDTH_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 	case NL80211_CHAN_WIDTH_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 	case NL80211_CHAN_WIDTH_16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 	case NL80211_CHAN_WIDTH_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 	case NL80211_CHAN_WIDTH_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 		WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 		/* keep c->width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 		ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 	WARN_ON_ONCE(!cfg80211_chandef_valid(c));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881)  * Returns true if smps_mode_new is strictly more restrictive than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882)  * smps_mode_old.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) bool ieee80211_smps_is_restrictive(enum ieee80211_smps_mode smps_mode_old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 				   enum ieee80211_smps_mode smps_mode_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 	if (WARN_ON_ONCE(smps_mode_old == IEEE80211_SMPS_AUTOMATIC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 			 smps_mode_new == IEEE80211_SMPS_AUTOMATIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 	switch (smps_mode_old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 	case IEEE80211_SMPS_STATIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 	case IEEE80211_SMPS_DYNAMIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 		return smps_mode_new == IEEE80211_SMPS_STATIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 	case IEEE80211_SMPS_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 		return smps_mode_new != IEEE80211_SMPS_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 			      struct cfg80211_csa_settings *csa_settings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	struct ieee80211_mgmt *mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 	int freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 	int hdr_len = offsetofend(struct ieee80211_mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 				  u.action.u.chan_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 	u8 *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 	if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 	    sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 	skb = dev_alloc_skb(local->tx_headroom + hdr_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 			    5 + /* channel switch announcement element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 			    3 + /* secondary channel offset element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 			    5 + /* wide bandwidth channel switch announcement */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 			    8); /* mesh channel switch parameters element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 	skb_reserve(skb, local->tx_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 	mgmt = skb_put_zero(skb, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 					  IEEE80211_STYPE_ACTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 	eth_broadcast_addr(mgmt->da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 	if (ieee80211_vif_is_mesh(&sdata->vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 		memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 		struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 		memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 	mgmt->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 	mgmt->u.action.u.chan_switch.action_code = WLAN_ACTION_SPCT_CHL_SWITCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 	pos = skb_put(skb, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 	*pos++ = WLAN_EID_CHANNEL_SWITCH;			/* EID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 	*pos++ = 3;						/* IE length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 	*pos++ = csa_settings->block_tx ? 1 : 0;		/* CSA mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 	freq = csa_settings->chandef.chan->center_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 	*pos++ = ieee80211_frequency_to_channel(freq);		/* channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 	*pos++ = csa_settings->count;				/* count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 	if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 		enum nl80211_channel_type ch_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 		skb_put(skb, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 		*pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;	/* EID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 		*pos++ = 1;					/* IE length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 		ch_type = cfg80211_get_chandef_type(&csa_settings->chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 		if (ch_type == NL80211_CHAN_HT40PLUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 			*pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 			*pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 	if (ieee80211_vif_is_mesh(&sdata->vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 		struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 		skb_put(skb, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		*pos++ = WLAN_EID_CHAN_SWITCH_PARAM;		/* EID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 		*pos++ = 6;					/* IE length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 		*pos++ = sdata->u.mesh.mshcfg.dot11MeshTTL;	/* Mesh TTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 		*pos = 0x00;	/* Mesh Flag: Tx Restrict, Initiator, Reason */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 		*pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 		*pos++ |= csa_settings->block_tx ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 			  WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 		put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); /* Reason Cd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 		pos += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 		put_unaligned_le16(ifmsh->pre_value, pos);/* Precedence Value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 		pos += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 	if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_80 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 	    csa_settings->chandef.width == NL80211_CHAN_WIDTH_80P80 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 	    csa_settings->chandef.width == NL80211_CHAN_WIDTH_160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 		skb_put(skb, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 		ieee80211_ie_build_wide_bw_cs(pos, &csa_settings->chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 	ieee80211_tx_skb(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) bool ieee80211_cs_valid(const struct ieee80211_cipher_scheme *cs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 	return !(cs == NULL || cs->cipher == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 		 cs->hdr_len < cs->pn_len + cs->pn_off ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 		 cs->hdr_len <= cs->key_idx_off ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 		 cs->key_idx_shift > 7 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 		 cs->key_idx_mask == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) bool ieee80211_cs_list_valid(const struct ieee80211_cipher_scheme *cs, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 	/* Ensure we have enough iftype bitmap space for all iftype values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 	WARN_ON((NUM_NL80211_IFTYPES / 8 + 1) > sizeof(cs[0].iftype));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 	for (i = 0; i < n; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 		if (!ieee80211_cs_valid(&cs[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) const struct ieee80211_cipher_scheme *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) ieee80211_cs_get(struct ieee80211_local *local, u32 cipher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 		 enum nl80211_iftype iftype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 	const struct ieee80211_cipher_scheme *l = local->hw.cipher_schemes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 	int n = local->hw.n_cipher_schemes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 	const struct ieee80211_cipher_scheme *cs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 	for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 		if (l[i].cipher == cipher) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) 			cs = &l[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 	if (!cs || !(cs->iftype & BIT(iftype)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 	return cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) int ieee80211_cs_headroom(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 			  struct cfg80211_crypto_settings *crypto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 			  enum nl80211_iftype iftype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 	const struct ieee80211_cipher_scheme *cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 	int headroom = IEEE80211_ENCRYPT_HEADROOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 	for (i = 0; i < crypto->n_ciphers_pairwise; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 		cs = ieee80211_cs_get(local, crypto->ciphers_pairwise[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 				      iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 		if (cs && headroom < cs->hdr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 			headroom = cs->hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 	cs = ieee80211_cs_get(local, crypto->cipher_group, iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 	if (cs && headroom < cs->hdr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 		headroom = cs->hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 	return headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) ieee80211_extend_noa_desc(struct ieee80211_noa_data *data, u32 tsf, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) 	s32 end = data->desc[i].start + data->desc[i].duration - (tsf + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 	int skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 	if (end > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 	/* One shot NOA  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 	if (data->count[i] == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 	if (data->desc[i].interval == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 	/* End time is in the past, check for repetitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 	skip = DIV_ROUND_UP(-end, data->desc[i].interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 	if (data->count[i] < 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 		if (data->count[i] <= skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 			data->count[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 		data->count[i] -= skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 	data->desc[i].start += skip * data->desc[i].interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) ieee80211_extend_absent_time(struct ieee80211_noa_data *data, u32 tsf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 			     s32 *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 	bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 	for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 		s32 cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 		if (!data->count[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 		if (ieee80211_extend_noa_desc(data, tsf + *offset, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 			ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 		cur = data->desc[i].start - tsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 		if (cur > *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 		cur = data->desc[i].start + data->desc[i].duration - tsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 		if (cur > *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 			*offset = cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) static u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) ieee80211_get_noa_absent_time(struct ieee80211_noa_data *data, u32 tsf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 	s32 offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 	int tries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 	 * arbitrary limit, used to avoid infinite loops when combined NoA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	 * descriptors cover the full time period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 	int max_tries = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 	ieee80211_extend_absent_time(data, tsf, &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 		if (!ieee80211_extend_absent_time(data, tsf, &offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 		tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 	} while (tries < max_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 	return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 	u32 next_offset = BIT(31) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 	data->absent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 	data->has_next_tsf = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 	for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 		s32 start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 		if (!data->count[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 		ieee80211_extend_noa_desc(data, tsf, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 		start = data->desc[i].start - tsf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 		if (start <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 			data->absent |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 		if (next_offset > start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 			next_offset = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 		data->has_next_tsf = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 	if (data->absent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 		next_offset = ieee80211_get_noa_absent_time(data, tsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 	data->next_tsf = tsf + next_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) EXPORT_SYMBOL(ieee80211_update_p2p_noa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 			    struct ieee80211_noa_data *data, u32 tsf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 	memset(data, 0, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 	for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 		const struct ieee80211_p2p_noa_desc *desc = &attr->desc[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 		if (!desc->count || !desc->duration)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 		data->count[i] = desc->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 		data->desc[i].start = le32_to_cpu(desc->start_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 		data->desc[i].duration = le32_to_cpu(desc->duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 		data->desc[i].interval = le32_to_cpu(desc->interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 		if (data->count[i] > 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 		    data->desc[i].interval < data->desc[i].duration)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 		ieee80211_extend_noa_desc(data, tsf, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 		ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 		ieee80211_update_p2p_noa(data, tsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) EXPORT_SYMBOL(ieee80211_parse_p2p_noa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) void ieee80211_recalc_dtim(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 			   struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 	u64 tsf = drv_get_tsf(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 	u64 dtim_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 	u16 beacon_int = sdata->vif.bss_conf.beacon_int * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 	u8 dtim_period = sdata->vif.bss_conf.dtim_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 	struct ps_data *ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 	u8 bcns_from_dtim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 	if (tsf == -1ULL || !beacon_int || !dtim_period)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 	if (sdata->vif.type == NL80211_IFTYPE_AP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 		if (!sdata->bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 		ps = &sdata->bss->ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 	} else if (ieee80211_vif_is_mesh(&sdata->vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 		ps = &sdata->u.mesh.ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 	 * actually finds last dtim_count, mac80211 will update in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 	 * __beacon_add_tim().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 	 * dtim_count = dtim_period - (tsf / bcn_int) % dtim_period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 	do_div(tsf, beacon_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 	bcns_from_dtim = do_div(tsf, dtim_period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 	/* just had a DTIM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 	if (!bcns_from_dtim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 		dtim_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 		dtim_count = dtim_period - bcns_from_dtim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 	ps->dtim_count = dtim_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) static u8 ieee80211_chanctx_radar_detect(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 					 struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 	u8 radar_detect = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 	lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 	if (WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 	list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 		if (sdata->reserved_radar_required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 			radar_detect |= BIT(sdata->reserved_chandef.width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 	 * An in-place reservation context should not have any assigned vifs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 	 * until it replaces the other context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 	WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 		!list_empty(&ctx->assigned_vifs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 	list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 		if (sdata->radar_required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 			radar_detect |= BIT(sdata->vif.bss_conf.chandef.width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 	return radar_detect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 				 const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 				 enum ieee80211_chanctx_mode chanmode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 				 u8 radar_detect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 	struct ieee80211_sub_if_data *sdata_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 	enum nl80211_iftype iftype = sdata->wdev.iftype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 	struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 	int total = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 	struct iface_combination_params params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 		.radar_detect = radar_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 	lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 	if (WARN_ON(hweight32(radar_detect) > 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 	if (WARN_ON(chandef && chanmode == IEEE80211_CHANCTX_SHARED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 		    !chandef->chan))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 	if (WARN_ON(iftype >= NUM_NL80211_IFTYPES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 	if (sdata->vif.type == NL80211_IFTYPE_AP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 	    sdata->vif.type == NL80211_IFTYPE_MESH_POINT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 		 * always passing this is harmless, since it'll be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 		 * same value that cfg80211 finds if it finds the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 		 * interface ... and that's always allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 		params.new_beacon_int = sdata->vif.bss_conf.beacon_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 	/* Always allow software iftypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) 	if (cfg80211_iftype_allowed(local->hw.wiphy, iftype, 0, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 		if (radar_detect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 	if (chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 		params.num_different_channels = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 	if (iftype != NL80211_IFTYPE_UNSPECIFIED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 		params.iftype_num[iftype] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 	list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 		if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 		params.radar_detect |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 			ieee80211_chanctx_radar_detect(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 		if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 			params.num_different_channels++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 		if (chandef && chanmode == IEEE80211_CHANCTX_SHARED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 		    cfg80211_chandef_compatible(chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 						&ctx->conf.def))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 		params.num_different_channels++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 	list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 		struct wireless_dev *wdev_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 		wdev_iter = &sdata_iter->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 		if (sdata_iter == sdata ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 		    !ieee80211_sdata_running(sdata_iter) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 		    cfg80211_iftype_allowed(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 					    wdev_iter->iftype, 0, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 		params.iftype_num[wdev_iter->iftype]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 		total++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 	if (total == 1 && !params.radar_detect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 	return cfg80211_check_combinations(local->hw.wiphy, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 			 void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 	u32 *max_num_different_channels = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 	*max_num_different_channels = max(*max_num_different_channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 					  c->num_different_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) int ieee80211_max_num_channels(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 	struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 	struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 	u32 max_num_different_channels = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 	struct iface_combination_params params = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 	lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 	list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 		if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 		params.num_different_channels++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 		params.radar_detect |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 			ieee80211_chanctx_radar_detect(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 	list_for_each_entry_rcu(sdata, &local->interfaces, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 		params.iftype_num[sdata->wdev.iftype]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 	err = cfg80211_iter_combinations(local->hw.wiphy, &params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 					 ieee80211_iter_max_chans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 					 &max_num_different_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 	return max_num_different_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) void ieee80211_add_s1g_capab_ie(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 				struct ieee80211_sta_s1g_cap *caps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 				struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 	struct ieee80211_s1g_cap s1g_capab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 	u8 *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 	if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 	if (!caps->s1g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 	memcpy(s1g_capab.capab_info, caps->cap, sizeof(caps->cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 	memcpy(s1g_capab.supp_mcs_nss, caps->nss_mcs, sizeof(caps->nss_mcs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 	/* override the capability info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 	for (i = 0; i < sizeof(ifmgd->s1g_capa.capab_info); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 		u8 mask = ifmgd->s1g_capa_mask.capab_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 		s1g_capab.capab_info[i] &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 		s1g_capab.capab_info[i] |= ifmgd->s1g_capa.capab_info[i] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 	/* then MCS and NSS set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 	for (i = 0; i < sizeof(ifmgd->s1g_capa.supp_mcs_nss); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 		u8 mask = ifmgd->s1g_capa_mask.supp_mcs_nss[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 		s1g_capab.supp_mcs_nss[i] &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 		s1g_capab.supp_mcs_nss[i] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 			ifmgd->s1g_capa.supp_mcs_nss[i] & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 	pos = skb_put(skb, 2 + sizeof(s1g_capab));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 	*pos++ = WLAN_EID_S1G_CAPABILITIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 	*pos++ = sizeof(s1g_capab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 	memcpy(pos, &s1g_capab, sizeof(s1g_capab));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) void ieee80211_add_aid_request_ie(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 				  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 	u8 *pos = skb_put(skb, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 	*pos++ = WLAN_EID_AID_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 	*pos++ = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 	*pos++ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) u8 *ieee80211_add_wmm_info_ie(u8 *buf, u8 qosinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 	*buf++ = WLAN_EID_VENDOR_SPECIFIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 	*buf++ = 7; /* len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 	*buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 	*buf++ = 0x50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 	*buf++ = 0xf2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 	*buf++ = 2; /* WME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 	*buf++ = 0; /* WME info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 	*buf++ = 1; /* WME ver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 	*buf++ = qosinfo; /* U-APSD no in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 	return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) void ieee80211_txq_get_depth(struct ieee80211_txq *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 			     unsigned long *frame_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 			     unsigned long *byte_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 	struct txq_info *txqi = to_txq_info(txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 	u32 frag_cnt = 0, frag_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 	skb_queue_walk(&txqi->frags, skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 		frag_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 		frag_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 	if (frame_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 		*frame_cnt = txqi->tin.backlog_packets + frag_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 	if (byte_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 		*byte_cnt = txqi->tin.backlog_bytes + frag_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) EXPORT_SYMBOL(ieee80211_txq_get_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) const u8 ieee80211_ac_to_qos_mask[IEEE80211_NUM_ACS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 	IEEE80211_WMM_IE_STA_QOSINFO_AC_VO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 	IEEE80211_WMM_IE_STA_QOSINFO_AC_VI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 	IEEE80211_WMM_IE_STA_QOSINFO_AC_BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 	IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) u16 ieee80211_encode_usf(int listen_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 	static const int listen_int_usf[] = { 1, 10, 1000, 10000 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 	u16 ui, usf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 	/* find greatest USF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 	while (usf < IEEE80211_MAX_USF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 		if (listen_interval % listen_int_usf[usf + 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 		usf += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 	ui = listen_interval / listen_int_usf[usf];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 	/* error if there is a remainder. Should've been checked by user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) 	WARN_ON_ONCE(ui > IEEE80211_MAX_UI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 	listen_interval = FIELD_PREP(LISTEN_INT_USF, usf) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 			  FIELD_PREP(LISTEN_INT_UI, ui);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 	return (u16) listen_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) }