• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2002-2005, Instant802 Networks, Inc.
4  * Copyright 2005, Devicescape Software, Inc.
5  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
6  * Copyright 2007-2010	Johannes Berg <johannes@sipsolutions.net>
7  * Copyright 2013-2015  Intel Mobile Communications GmbH
8  * Copyright (C) 2018-2020 Intel Corporation
9  */
10 
11 #ifndef IEEE80211_I_H
12 #define IEEE80211_I_H
13 
14 #include <linux/kernel.h>
15 #include <linux/device.h>
16 #include <linux/if_ether.h>
17 #include <linux/interrupt.h>
18 #include <linux/list.h>
19 #include <linux/netdevice.h>
20 #include <linux/skbuff.h>
21 #include <linux/workqueue.h>
22 #include <linux/types.h>
23 #include <linux/spinlock.h>
24 #include <linux/etherdevice.h>
25 #include <linux/leds.h>
26 #include <linux/idr.h>
27 #include <linux/rhashtable.h>
28 #include <net/ieee80211_radiotap.h>
29 #include <net/cfg80211.h>
30 #include <net/mac80211.h>
31 #include <net/fq.h>
32 #include "key.h"
33 #include "sta_info.h"
34 #include "debug.h"
35 
36 extern const struct cfg80211_ops mac80211_config_ops;
37 
38 struct ieee80211_local;
39 
40 /* Maximum number of broadcast/multicast frames to buffer when some of the
41  * associated stations are using power saving. */
42 #define AP_MAX_BC_BUFFER 128
43 
44 /* Maximum number of frames buffered to all STAs, including multicast frames.
45  * Note: increasing this limit increases the potential memory requirement. Each
46  * frame can be up to about 2 kB long. */
47 #define TOTAL_MAX_TX_BUFFER 512
48 
49 /* Required encryption head and tailroom */
50 #define IEEE80211_ENCRYPT_HEADROOM 8
51 #define IEEE80211_ENCRYPT_TAILROOM 18
52 
53 /* power level hasn't been configured (or set to automatic) */
54 #define IEEE80211_UNSET_POWER_LEVEL	INT_MIN
55 
56 /*
57  * Some APs experience problems when working with U-APSD. Decreasing the
58  * probability of that happening by using legacy mode for all ACs but VO isn't
59  * enough.
60  *
61  * Cisco 4410N originally forced us to enable VO by default only because it
62  * treated non-VO ACs as legacy.
63  *
64  * However some APs (notably Netgear R7000) silently reclassify packets to
65  * different ACs. Since u-APSD ACs require trigger frames for frame retrieval
66  * clients would never see some frames (e.g. ARP responses) or would fetch them
67  * accidentally after a long time.
68  *
69  * It makes little sense to enable u-APSD queues by default because it needs
70  * userspace applications to be aware of it to actually take advantage of the
71  * possible additional powersavings. Implicitly depending on driver autotrigger
72  * frame support doesn't make much sense.
73  */
74 #define IEEE80211_DEFAULT_UAPSD_QUEUES 0
75 
76 #define IEEE80211_DEFAULT_MAX_SP_LEN		\
77 	IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL
78 
79 extern const u8 ieee80211_ac_to_qos_mask[IEEE80211_NUM_ACS];
80 
81 #define IEEE80211_DEAUTH_FRAME_LEN	(24 /* hdr */ + 2 /* reason */)
82 
83 #define IEEE80211_MAX_NAN_INSTANCE_ID 255
84 
85 struct ieee80211_bss {
86 	u32 device_ts_beacon, device_ts_presp;
87 
88 	bool wmm_used;
89 	bool uapsd_supported;
90 
91 #define IEEE80211_MAX_SUPP_RATES 32
92 	u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
93 	size_t supp_rates_len;
94 	struct ieee80211_rate *beacon_rate;
95 
96 	u32 vht_cap_info;
97 
98 	/*
99 	 * During association, we save an ERP value from a probe response so
100 	 * that we can feed ERP info to the driver when handling the
101 	 * association completes. these fields probably won't be up-to-date
102 	 * otherwise, you probably don't want to use them.
103 	 */
104 	bool has_erp_value;
105 	u8 erp_value;
106 
107 	/* Keep track of the corruption of the last beacon/probe response. */
108 	u8 corrupt_data;
109 
110 	/* Keep track of what bits of information we have valid info for. */
111 	u8 valid_data;
112 };
113 
114 /**
115  * enum ieee80211_corrupt_data_flags - BSS data corruption flags
116  * @IEEE80211_BSS_CORRUPT_BEACON: last beacon frame received was corrupted
117  * @IEEE80211_BSS_CORRUPT_PROBE_RESP: last probe response received was corrupted
118  *
119  * These are bss flags that are attached to a bss in the
120  * @corrupt_data field of &struct ieee80211_bss.
121  */
122 enum ieee80211_bss_corrupt_data_flags {
123 	IEEE80211_BSS_CORRUPT_BEACON		= BIT(0),
124 	IEEE80211_BSS_CORRUPT_PROBE_RESP	= BIT(1)
125 };
126 
127 /**
128  * enum ieee80211_valid_data_flags - BSS valid data flags
129  * @IEEE80211_BSS_VALID_WMM: WMM/UAPSD data was gathered from non-corrupt IE
130  * @IEEE80211_BSS_VALID_RATES: Supported rates were gathered from non-corrupt IE
131  * @IEEE80211_BSS_VALID_ERP: ERP flag was gathered from non-corrupt IE
132  *
133  * These are bss flags that are attached to a bss in the
134  * @valid_data field of &struct ieee80211_bss.  They show which parts
135  * of the data structure were received as a result of an un-corrupted
136  * beacon/probe response.
137  */
138 enum ieee80211_bss_valid_data_flags {
139 	IEEE80211_BSS_VALID_WMM			= BIT(1),
140 	IEEE80211_BSS_VALID_RATES		= BIT(2),
141 	IEEE80211_BSS_VALID_ERP			= BIT(3)
142 };
143 
144 typedef unsigned __bitwise ieee80211_tx_result;
145 #define TX_CONTINUE	((__force ieee80211_tx_result) 0u)
146 #define TX_DROP		((__force ieee80211_tx_result) 1u)
147 #define TX_QUEUED	((__force ieee80211_tx_result) 2u)
148 
149 #define IEEE80211_TX_UNICAST		BIT(1)
150 #define IEEE80211_TX_PS_BUFFERED	BIT(2)
151 
152 struct ieee80211_tx_data {
153 	struct sk_buff *skb;
154 	struct sk_buff_head skbs;
155 	struct ieee80211_local *local;
156 	struct ieee80211_sub_if_data *sdata;
157 	struct sta_info *sta;
158 	struct ieee80211_key *key;
159 	struct ieee80211_tx_rate rate;
160 
161 	unsigned int flags;
162 };
163 
164 
165 typedef unsigned __bitwise ieee80211_rx_result;
166 #define RX_CONTINUE		((__force ieee80211_rx_result) 0u)
167 #define RX_DROP_UNUSABLE	((__force ieee80211_rx_result) 1u)
168 #define RX_DROP_MONITOR		((__force ieee80211_rx_result) 2u)
169 #define RX_QUEUED		((__force ieee80211_rx_result) 3u)
170 
171 /**
172  * enum ieee80211_packet_rx_flags - packet RX flags
173  * @IEEE80211_RX_AMSDU: a-MSDU packet
174  * @IEEE80211_RX_MALFORMED_ACTION_FRM: action frame is malformed
175  * @IEEE80211_RX_DEFERRED_RELEASE: frame was subjected to receive reordering
176  *
177  * These are per-frame flags that are attached to a frame in the
178  * @rx_flags field of &struct ieee80211_rx_status.
179  */
180 enum ieee80211_packet_rx_flags {
181 	IEEE80211_RX_AMSDU			= BIT(3),
182 	IEEE80211_RX_MALFORMED_ACTION_FRM	= BIT(4),
183 	IEEE80211_RX_DEFERRED_RELEASE		= BIT(5),
184 };
185 
186 /**
187  * enum ieee80211_rx_flags - RX data flags
188  *
189  * @IEEE80211_RX_CMNTR: received on cooked monitor already
190  * @IEEE80211_RX_BEACON_REPORTED: This frame was already reported
191  *	to cfg80211_report_obss_beacon().
192  *
193  * These flags are used across handling multiple interfaces
194  * for a single frame.
195  */
196 enum ieee80211_rx_flags {
197 	IEEE80211_RX_CMNTR		= BIT(0),
198 	IEEE80211_RX_BEACON_REPORTED	= BIT(1),
199 };
200 
201 struct ieee80211_rx_data {
202 	struct list_head *list;
203 	struct sk_buff *skb;
204 	struct ieee80211_local *local;
205 	struct ieee80211_sub_if_data *sdata;
206 	struct sta_info *sta;
207 	struct ieee80211_key *key;
208 
209 	unsigned int flags;
210 
211 	/*
212 	 * Index into sequence numbers array, 0..16
213 	 * since the last (16) is used for non-QoS,
214 	 * will be 16 on non-QoS frames.
215 	 */
216 	int seqno_idx;
217 
218 	/*
219 	 * Index into the security IV/PN arrays, 0..16
220 	 * since the last (16) is used for CCMP-encrypted
221 	 * management frames, will be set to 16 on mgmt
222 	 * frames and 0 on non-QoS frames.
223 	 */
224 	int security_idx;
225 
226 	union {
227 		struct {
228 			u32 iv32;
229 			u16 iv16;
230 		} tkip;
231 		struct {
232 			u8 pn[IEEE80211_CCMP_PN_LEN];
233 		} ccm_gcm;
234 	};
235 };
236 
237 struct ieee80211_csa_settings {
238 	const u16 *counter_offsets_beacon;
239 	const u16 *counter_offsets_presp;
240 
241 	int n_counter_offsets_beacon;
242 	int n_counter_offsets_presp;
243 
244 	u8 count;
245 };
246 
247 struct beacon_data {
248 	u8 *head, *tail;
249 	int head_len, tail_len;
250 	struct ieee80211_meshconf_ie *meshconf;
251 	u16 cntdwn_counter_offsets[IEEE80211_MAX_CNTDWN_COUNTERS_NUM];
252 	u8 cntdwn_current_counter;
253 	struct rcu_head rcu_head;
254 };
255 
256 struct probe_resp {
257 	struct rcu_head rcu_head;
258 	int len;
259 	u16 cntdwn_counter_offsets[IEEE80211_MAX_CNTDWN_COUNTERS_NUM];
260 	u8 data[];
261 };
262 
263 struct fils_discovery_data {
264 	struct rcu_head rcu_head;
265 	int len;
266 	u8 data[];
267 };
268 
269 struct unsol_bcast_probe_resp_data {
270 	struct rcu_head rcu_head;
271 	int len;
272 	u8 data[];
273 };
274 
275 struct ps_data {
276 	/* yes, this looks ugly, but guarantees that we can later use
277 	 * bitmap_empty :)
278 	 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
279 	u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)]
280 			__aligned(__alignof__(unsigned long));
281 	struct sk_buff_head bc_buf;
282 	atomic_t num_sta_ps; /* number of stations in PS mode */
283 	int dtim_count;
284 	bool dtim_bc_mc;
285 };
286 
287 struct ieee80211_if_ap {
288 	struct beacon_data __rcu *beacon;
289 	struct probe_resp __rcu *probe_resp;
290 	struct fils_discovery_data __rcu *fils_discovery;
291 	struct unsol_bcast_probe_resp_data __rcu *unsol_bcast_probe_resp;
292 
293 	/* to be used after channel switch. */
294 	struct cfg80211_beacon_data *next_beacon;
295 	struct list_head vlans; /* write-protected with RTNL and local->mtx */
296 
297 	struct ps_data ps;
298 	atomic_t num_mcast_sta; /* number of stations receiving multicast */
299 
300 	bool multicast_to_unicast;
301 };
302 
303 struct ieee80211_if_wds {
304 	struct sta_info *sta;
305 	u8 remote_addr[ETH_ALEN];
306 };
307 
308 struct ieee80211_if_vlan {
309 	struct list_head list; /* write-protected with RTNL and local->mtx */
310 
311 	/* used for all tx if the VLAN is configured to 4-addr mode */
312 	struct sta_info __rcu *sta;
313 	atomic_t num_mcast_sta; /* number of stations receiving multicast */
314 };
315 
316 struct mesh_stats {
317 	__u32 fwded_mcast;		/* Mesh forwarded multicast frames */
318 	__u32 fwded_unicast;		/* Mesh forwarded unicast frames */
319 	__u32 fwded_frames;		/* Mesh total forwarded frames */
320 	__u32 dropped_frames_ttl;	/* Not transmitted since mesh_ttl == 0*/
321 	__u32 dropped_frames_no_route;	/* Not transmitted, no route found */
322 	__u32 dropped_frames_congestion;/* Not forwarded due to congestion */
323 };
324 
325 #define PREQ_Q_F_START		0x1
326 #define PREQ_Q_F_REFRESH	0x2
327 struct mesh_preq_queue {
328 	struct list_head list;
329 	u8 dst[ETH_ALEN];
330 	u8 flags;
331 };
332 
333 struct ieee80211_roc_work {
334 	struct list_head list;
335 
336 	struct ieee80211_sub_if_data *sdata;
337 
338 	struct ieee80211_channel *chan;
339 
340 	bool started, abort, hw_begun, notified;
341 	bool on_channel;
342 
343 	unsigned long start_time;
344 
345 	u32 duration, req_duration;
346 	struct sk_buff *frame;
347 	u64 cookie, mgmt_tx_cookie;
348 	enum ieee80211_roc_type type;
349 };
350 
351 /* flags used in struct ieee80211_if_managed.flags */
352 enum ieee80211_sta_flags {
353 	IEEE80211_STA_CONNECTION_POLL	= BIT(1),
354 	IEEE80211_STA_CONTROL_PORT	= BIT(2),
355 	IEEE80211_STA_DISABLE_HT	= BIT(4),
356 	IEEE80211_STA_MFP_ENABLED	= BIT(6),
357 	IEEE80211_STA_UAPSD_ENABLED	= BIT(7),
358 	IEEE80211_STA_NULLFUNC_ACKED	= BIT(8),
359 	IEEE80211_STA_RESET_SIGNAL_AVE	= BIT(9),
360 	IEEE80211_STA_DISABLE_40MHZ	= BIT(10),
361 	IEEE80211_STA_DISABLE_VHT	= BIT(11),
362 	IEEE80211_STA_DISABLE_80P80MHZ	= BIT(12),
363 	IEEE80211_STA_DISABLE_160MHZ	= BIT(13),
364 	IEEE80211_STA_DISABLE_WMM	= BIT(14),
365 	IEEE80211_STA_ENABLE_RRM	= BIT(15),
366 	IEEE80211_STA_DISABLE_HE	= BIT(16),
367 };
368 
369 struct ieee80211_mgd_auth_data {
370 	struct cfg80211_bss *bss;
371 	unsigned long timeout;
372 	int tries;
373 	u16 algorithm, expected_transaction;
374 
375 	u8 key[WLAN_KEY_LEN_WEP104];
376 	u8 key_len, key_idx;
377 	bool done, waiting;
378 	bool peer_confirmed;
379 	bool timeout_started;
380 
381 	u16 sae_trans, sae_status;
382 	size_t data_len;
383 	u8 data[];
384 };
385 
386 struct ieee80211_mgd_assoc_data {
387 	struct cfg80211_bss *bss;
388 	const u8 *supp_rates;
389 
390 	unsigned long timeout;
391 	int tries;
392 
393 	u16 capability;
394 	u8 prev_bssid[ETH_ALEN];
395 	u8 ssid[IEEE80211_MAX_SSID_LEN];
396 	u8 ssid_len;
397 	u8 supp_rates_len;
398 	bool wmm, uapsd;
399 	bool need_beacon;
400 	bool synced;
401 	bool timeout_started;
402 
403 	u8 ap_ht_param;
404 
405 	struct ieee80211_vht_cap ap_vht_cap;
406 
407 	u8 fils_nonces[2 * FILS_NONCE_LEN];
408 	u8 fils_kek[FILS_MAX_KEK_LEN];
409 	size_t fils_kek_len;
410 
411 	size_t ie_len;
412 	u8 ie[];
413 };
414 
415 struct ieee80211_sta_tx_tspec {
416 	/* timestamp of the first packet in the time slice */
417 	unsigned long time_slice_start;
418 
419 	u32 admitted_time; /* in usecs, unlike over the air */
420 	u8 tsid;
421 	s8 up; /* signed to be able to invalidate with -1 during teardown */
422 
423 	/* consumed TX time in microseconds in the time slice */
424 	u32 consumed_tx_time;
425 	enum {
426 		TX_TSPEC_ACTION_NONE = 0,
427 		TX_TSPEC_ACTION_DOWNGRADE,
428 		TX_TSPEC_ACTION_STOP_DOWNGRADE,
429 	} action;
430 	bool downgraded;
431 };
432 
433 DECLARE_EWMA(beacon_signal, 4, 4)
434 
435 struct ieee80211_if_managed {
436 	struct timer_list timer;
437 	struct timer_list conn_mon_timer;
438 	struct timer_list bcn_mon_timer;
439 	struct timer_list chswitch_timer;
440 	struct work_struct monitor_work;
441 	struct work_struct chswitch_work;
442 	struct work_struct beacon_connection_loss_work;
443 	struct work_struct csa_connection_drop_work;
444 
445 	unsigned long beacon_timeout;
446 	unsigned long probe_timeout;
447 	int probe_send_count;
448 	bool nullfunc_failed;
449 	bool connection_loss;
450 
451 	struct cfg80211_bss *associated;
452 	struct ieee80211_mgd_auth_data *auth_data;
453 	struct ieee80211_mgd_assoc_data *assoc_data;
454 
455 	u8 bssid[ETH_ALEN] __aligned(2);
456 
457 	bool powersave; /* powersave requested for this iface */
458 	bool broken_ap; /* AP is broken -- turn off powersave */
459 	bool have_beacon;
460 	u8 dtim_period;
461 	enum ieee80211_smps_mode req_smps, /* requested smps mode */
462 				 driver_smps_mode; /* smps mode request */
463 
464 	struct work_struct request_smps_work;
465 
466 	unsigned int flags;
467 
468 	bool csa_waiting_bcn;
469 	bool csa_ignored_same_chan;
470 
471 	bool beacon_crc_valid;
472 	u32 beacon_crc;
473 
474 	bool status_acked;
475 	bool status_received;
476 	__le16 status_fc;
477 
478 	enum {
479 		IEEE80211_MFP_DISABLED,
480 		IEEE80211_MFP_OPTIONAL,
481 		IEEE80211_MFP_REQUIRED
482 	} mfp; /* management frame protection */
483 
484 	/*
485 	 * Bitmask of enabled u-apsd queues,
486 	 * IEEE80211_WMM_IE_STA_QOSINFO_AC_BE & co. Needs a new association
487 	 * to take effect.
488 	 */
489 	unsigned int uapsd_queues;
490 
491 	/*
492 	 * Maximum number of buffered frames AP can deliver during a
493 	 * service period, IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL or similar.
494 	 * Needs a new association to take effect.
495 	 */
496 	unsigned int uapsd_max_sp_len;
497 
498 	int wmm_last_param_set;
499 	int mu_edca_last_param_set;
500 
501 	u8 use_4addr;
502 
503 	s16 p2p_noa_index;
504 
505 	struct ewma_beacon_signal ave_beacon_signal;
506 
507 	/*
508 	 * Number of Beacon frames used in ave_beacon_signal. This can be used
509 	 * to avoid generating less reliable cqm events that would be based
510 	 * only on couple of received frames.
511 	 */
512 	unsigned int count_beacon_signal;
513 
514 	/* Number of times beacon loss was invoked. */
515 	unsigned int beacon_loss_count;
516 
517 	/*
518 	 * Last Beacon frame signal strength average (ave_beacon_signal / 16)
519 	 * that triggered a cqm event. 0 indicates that no event has been
520 	 * generated for the current association.
521 	 */
522 	int last_cqm_event_signal;
523 
524 	/*
525 	 * State variables for keeping track of RSSI of the AP currently
526 	 * connected to and informing driver when RSSI has gone
527 	 * below/above a certain threshold.
528 	 */
529 	int rssi_min_thold, rssi_max_thold;
530 	int last_ave_beacon_signal;
531 
532 	struct ieee80211_ht_cap ht_capa; /* configured ht-cap over-rides */
533 	struct ieee80211_ht_cap ht_capa_mask; /* Valid parts of ht_capa */
534 	struct ieee80211_vht_cap vht_capa; /* configured VHT overrides */
535 	struct ieee80211_vht_cap vht_capa_mask; /* Valid parts of vht_capa */
536 	struct ieee80211_s1g_cap s1g_capa; /* configured S1G overrides */
537 	struct ieee80211_s1g_cap s1g_capa_mask; /* valid s1g_capa bits */
538 
539 	/* TDLS support */
540 	u8 tdls_peer[ETH_ALEN] __aligned(2);
541 	struct delayed_work tdls_peer_del_work;
542 	struct sk_buff *orig_teardown_skb; /* The original teardown skb */
543 	struct sk_buff *teardown_skb; /* A copy to send through the AP */
544 	spinlock_t teardown_lock; /* To lock changing teardown_skb */
545 	bool tdls_chan_switch_prohibited;
546 	bool tdls_wider_bw_prohibited;
547 
548 	/* WMM-AC TSPEC support */
549 	struct ieee80211_sta_tx_tspec tx_tspec[IEEE80211_NUM_ACS];
550 	/* Use a separate work struct so that we can do something here
551 	 * while the sdata->work is flushing the queues, for example.
552 	 * otherwise, in scenarios where we hardly get any traffic out
553 	 * on the BE queue, but there's a lot of VO traffic, we might
554 	 * get stuck in a downgraded situation and flush takes forever.
555 	 */
556 	struct delayed_work tx_tspec_wk;
557 
558 	/* Information elements from the last transmitted (Re)Association
559 	 * Request frame.
560 	 */
561 	u8 *assoc_req_ies;
562 	size_t assoc_req_ies_len;
563 };
564 
565 struct ieee80211_if_ibss {
566 	struct timer_list timer;
567 	struct work_struct csa_connection_drop_work;
568 
569 	unsigned long last_scan_completed;
570 
571 	u32 basic_rates;
572 
573 	bool fixed_bssid;
574 	bool fixed_channel;
575 	bool privacy;
576 
577 	bool control_port;
578 	bool userspace_handles_dfs;
579 
580 	u8 bssid[ETH_ALEN] __aligned(2);
581 	u8 ssid[IEEE80211_MAX_SSID_LEN];
582 	u8 ssid_len, ie_len;
583 	u8 *ie;
584 	struct cfg80211_chan_def chandef;
585 
586 	unsigned long ibss_join_req;
587 	/* probe response/beacon for IBSS */
588 	struct beacon_data __rcu *presp;
589 
590 	struct ieee80211_ht_cap ht_capa; /* configured ht-cap over-rides */
591 	struct ieee80211_ht_cap ht_capa_mask; /* Valid parts of ht_capa */
592 
593 	spinlock_t incomplete_lock;
594 	struct list_head incomplete_stations;
595 
596 	enum {
597 		IEEE80211_IBSS_MLME_SEARCH,
598 		IEEE80211_IBSS_MLME_JOINED,
599 	} state;
600 };
601 
602 /**
603  * struct ieee80211_if_ocb - OCB mode state
604  *
605  * @housekeeping_timer: timer for periodic invocation of a housekeeping task
606  * @wrkq_flags: OCB deferred task action
607  * @incomplete_lock: delayed STA insertion lock
608  * @incomplete_stations: list of STAs waiting for delayed insertion
609  * @joined: indication if the interface is connected to an OCB network
610  */
611 struct ieee80211_if_ocb {
612 	struct timer_list housekeeping_timer;
613 	unsigned long wrkq_flags;
614 
615 	spinlock_t incomplete_lock;
616 	struct list_head incomplete_stations;
617 
618 	bool joined;
619 };
620 
621 /**
622  * struct ieee80211_mesh_sync_ops - Extensible synchronization framework interface
623  *
624  * these declarations define the interface, which enables
625  * vendor-specific mesh synchronization
626  *
627  */
628 struct ieee802_11_elems;
629 struct ieee80211_mesh_sync_ops {
630 	void (*rx_bcn_presp)(struct ieee80211_sub_if_data *sdata,
631 			     u16 stype,
632 			     struct ieee80211_mgmt *mgmt,
633 			     struct ieee802_11_elems *elems,
634 			     struct ieee80211_rx_status *rx_status);
635 
636 	/* should be called with beacon_data under RCU read lock */
637 	void (*adjust_tsf)(struct ieee80211_sub_if_data *sdata,
638 			   struct beacon_data *beacon);
639 	/* add other framework functions here */
640 };
641 
642 struct mesh_csa_settings {
643 	struct rcu_head rcu_head;
644 	struct cfg80211_csa_settings settings;
645 };
646 
647 struct ieee80211_if_mesh {
648 	struct timer_list housekeeping_timer;
649 	struct timer_list mesh_path_timer;
650 	struct timer_list mesh_path_root_timer;
651 
652 	unsigned long wrkq_flags;
653 	unsigned long mbss_changed;
654 
655 	bool userspace_handles_dfs;
656 
657 	u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
658 	size_t mesh_id_len;
659 	/* Active Path Selection Protocol Identifier */
660 	u8 mesh_pp_id;
661 	/* Active Path Selection Metric Identifier */
662 	u8 mesh_pm_id;
663 	/* Congestion Control Mode Identifier */
664 	u8 mesh_cc_id;
665 	/* Synchronization Protocol Identifier */
666 	u8 mesh_sp_id;
667 	/* Authentication Protocol Identifier */
668 	u8 mesh_auth_id;
669 	/* Local mesh Sequence Number */
670 	u32 sn;
671 	/* Last used PREQ ID */
672 	u32 preq_id;
673 	atomic_t mpaths;
674 	/* Timestamp of last SN update */
675 	unsigned long last_sn_update;
676 	/* Time when it's ok to send next PERR */
677 	unsigned long next_perr;
678 	/* Timestamp of last PREQ sent */
679 	unsigned long last_preq;
680 	struct mesh_rmc *rmc;
681 	spinlock_t mesh_preq_queue_lock;
682 	struct mesh_preq_queue preq_queue;
683 	int preq_queue_len;
684 	struct mesh_stats mshstats;
685 	struct mesh_config mshcfg;
686 	atomic_t estab_plinks;
687 	u32 mesh_seqnum;
688 	bool accepting_plinks;
689 	int num_gates;
690 	struct beacon_data __rcu *beacon;
691 	const u8 *ie;
692 	u8 ie_len;
693 	enum {
694 		IEEE80211_MESH_SEC_NONE = 0x0,
695 		IEEE80211_MESH_SEC_AUTHED = 0x1,
696 		IEEE80211_MESH_SEC_SECURED = 0x2,
697 	} security;
698 	bool user_mpm;
699 	/* Extensible Synchronization Framework */
700 	const struct ieee80211_mesh_sync_ops *sync_ops;
701 	s64 sync_offset_clockdrift_max;
702 	spinlock_t sync_offset_lock;
703 	/* mesh power save */
704 	enum nl80211_mesh_power_mode nonpeer_pm;
705 	int ps_peers_light_sleep;
706 	int ps_peers_deep_sleep;
707 	struct ps_data ps;
708 	/* Channel Switching Support */
709 	struct mesh_csa_settings __rcu *csa;
710 	enum {
711 		IEEE80211_MESH_CSA_ROLE_NONE,
712 		IEEE80211_MESH_CSA_ROLE_INIT,
713 		IEEE80211_MESH_CSA_ROLE_REPEATER,
714 	} csa_role;
715 	u8 chsw_ttl;
716 	u16 pre_value;
717 
718 	/* offset from skb->data while building IE */
719 	int meshconf_offset;
720 
721 	struct mesh_table *mesh_paths;
722 	struct mesh_table *mpp_paths; /* Store paths for MPP&MAP */
723 	int mesh_paths_generation;
724 	int mpp_paths_generation;
725 };
726 
727 #ifdef CONFIG_MAC80211_MESH
728 #define IEEE80211_IFSTA_MESH_CTR_INC(msh, name)	\
729 	do { (msh)->mshstats.name++; } while (0)
730 #else
731 #define IEEE80211_IFSTA_MESH_CTR_INC(msh, name) \
732 	do { } while (0)
733 #endif
734 
735 /**
736  * enum ieee80211_sub_if_data_flags - virtual interface flags
737  *
738  * @IEEE80211_SDATA_ALLMULTI: interface wants all multicast packets
739  * @IEEE80211_SDATA_OPERATING_GMODE: operating in G-only mode
740  * @IEEE80211_SDATA_DONT_BRIDGE_PACKETS: bridge packets between
741  *	associated stations and deliver multicast frames both
742  *	back to wireless media and to the local net stack.
743  * @IEEE80211_SDATA_DISCONNECT_RESUME: Disconnect after resume.
744  * @IEEE80211_SDATA_IN_DRIVER: indicates interface was added to driver
745  */
746 enum ieee80211_sub_if_data_flags {
747 	IEEE80211_SDATA_ALLMULTI		= BIT(0),
748 	IEEE80211_SDATA_OPERATING_GMODE		= BIT(2),
749 	IEEE80211_SDATA_DONT_BRIDGE_PACKETS	= BIT(3),
750 	IEEE80211_SDATA_DISCONNECT_RESUME	= BIT(4),
751 	IEEE80211_SDATA_IN_DRIVER		= BIT(5),
752 };
753 
754 /**
755  * enum ieee80211_sdata_state_bits - virtual interface state bits
756  * @SDATA_STATE_RUNNING: virtual interface is up & running; this
757  *	mirrors netif_running() but is separate for interface type
758  *	change handling while the interface is up
759  * @SDATA_STATE_OFFCHANNEL: This interface is currently in offchannel
760  *	mode, so queues are stopped
761  * @SDATA_STATE_OFFCHANNEL_BEACON_STOPPED: Beaconing was stopped due
762  *	to offchannel, reset when offchannel returns
763  */
764 enum ieee80211_sdata_state_bits {
765 	SDATA_STATE_RUNNING,
766 	SDATA_STATE_OFFCHANNEL,
767 	SDATA_STATE_OFFCHANNEL_BEACON_STOPPED,
768 };
769 
770 /**
771  * enum ieee80211_chanctx_mode - channel context configuration mode
772  *
773  * @IEEE80211_CHANCTX_SHARED: channel context may be used by
774  *	multiple interfaces
775  * @IEEE80211_CHANCTX_EXCLUSIVE: channel context can be used
776  *	only by a single interface. This can be used for example for
777  *	non-fixed channel IBSS.
778  */
779 enum ieee80211_chanctx_mode {
780 	IEEE80211_CHANCTX_SHARED,
781 	IEEE80211_CHANCTX_EXCLUSIVE
782 };
783 
784 /**
785  * enum ieee80211_chanctx_replace_state - channel context replacement state
786  *
787  * This is used for channel context in-place reservations that require channel
788  * context switch/swap.
789  *
790  * @IEEE80211_CHANCTX_REPLACE_NONE: no replacement is taking place
791  * @IEEE80211_CHANCTX_WILL_BE_REPLACED: this channel context will be replaced
792  *	by a (not yet registered) channel context pointed by %replace_ctx.
793  * @IEEE80211_CHANCTX_REPLACES_OTHER: this (not yet registered) channel context
794  *	replaces an existing channel context pointed to by %replace_ctx.
795  */
796 enum ieee80211_chanctx_replace_state {
797 	IEEE80211_CHANCTX_REPLACE_NONE,
798 	IEEE80211_CHANCTX_WILL_BE_REPLACED,
799 	IEEE80211_CHANCTX_REPLACES_OTHER,
800 };
801 
802 struct ieee80211_chanctx {
803 	struct list_head list;
804 	struct rcu_head rcu_head;
805 
806 	struct list_head assigned_vifs;
807 	struct list_head reserved_vifs;
808 
809 	enum ieee80211_chanctx_replace_state replace_state;
810 	struct ieee80211_chanctx *replace_ctx;
811 
812 	enum ieee80211_chanctx_mode mode;
813 	bool driver_present;
814 
815 	struct ieee80211_chanctx_conf conf;
816 };
817 
818 struct mac80211_qos_map {
819 	struct cfg80211_qos_map qos_map;
820 	struct rcu_head rcu_head;
821 };
822 
823 enum txq_info_flags {
824 	IEEE80211_TXQ_STOP,
825 	IEEE80211_TXQ_AMPDU,
826 	IEEE80211_TXQ_NO_AMSDU,
827 	IEEE80211_TXQ_STOP_NETIF_TX,
828 };
829 
830 /**
831  * struct txq_info - per tid queue
832  *
833  * @tin: contains packets split into multiple flows
834  * @def_flow: used as a fallback flow when a packet destined to @tin hashes to
835  *	a fq_flow which is already owned by a different tin
836  * @def_cvars: codel vars for @def_flow
837  * @frags: used to keep fragments created after dequeue
838  * @schedule_order: used with ieee80211_local->active_txqs
839  * @schedule_round: counter to prevent infinite loops on TXQ scheduling
840  */
841 struct txq_info {
842 	struct fq_tin tin;
843 	struct fq_flow def_flow;
844 	struct codel_vars def_cvars;
845 	struct codel_stats cstats;
846 	struct sk_buff_head frags;
847 	struct list_head schedule_order;
848 	u16 schedule_round;
849 	unsigned long flags;
850 
851 	/* keep last! */
852 	struct ieee80211_txq txq;
853 };
854 
855 struct ieee80211_if_mntr {
856 	u32 flags;
857 	u8 mu_follow_addr[ETH_ALEN] __aligned(2);
858 
859 	struct list_head list;
860 };
861 
862 /**
863  * struct ieee80211_if_nan - NAN state
864  *
865  * @conf: current NAN configuration
866  * @func_ids: a bitmap of available instance_id's
867  */
868 struct ieee80211_if_nan {
869 	struct cfg80211_nan_conf conf;
870 
871 	/* protects function_inst_ids */
872 	spinlock_t func_lock;
873 	struct idr function_inst_ids;
874 };
875 
876 struct ieee80211_sub_if_data {
877 	struct list_head list;
878 
879 	struct wireless_dev wdev;
880 
881 	/* keys */
882 	struct list_head key_list;
883 
884 	/* count for keys needing tailroom space allocation */
885 	int crypto_tx_tailroom_needed_cnt;
886 	int crypto_tx_tailroom_pending_dec;
887 	struct delayed_work dec_tailroom_needed_wk;
888 
889 	struct net_device *dev;
890 	struct ieee80211_local *local;
891 
892 	unsigned int flags;
893 
894 	unsigned long state;
895 
896 	char name[IFNAMSIZ];
897 
898 	struct ieee80211_fragment_cache frags;
899 
900 	/* TID bitmap for NoAck policy */
901 	u16 noack_map;
902 
903 	/* bit field of ACM bits (BIT(802.1D tag)) */
904 	u8 wmm_acm;
905 
906 	struct ieee80211_key __rcu *keys[NUM_DEFAULT_KEYS +
907 					 NUM_DEFAULT_MGMT_KEYS +
908 					 NUM_DEFAULT_BEACON_KEYS];
909 	struct ieee80211_key __rcu *default_unicast_key;
910 	struct ieee80211_key __rcu *default_multicast_key;
911 	struct ieee80211_key __rcu *default_mgmt_key;
912 	struct ieee80211_key __rcu *default_beacon_key;
913 
914 	u16 sequence_number;
915 	__be16 control_port_protocol;
916 	bool control_port_no_encrypt;
917 	bool control_port_no_preauth;
918 	bool control_port_over_nl80211;
919 	int encrypt_headroom;
920 
921 	atomic_t num_tx_queued;
922 	struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
923 	struct mac80211_qos_map __rcu *qos_map;
924 
925 	struct work_struct csa_finalize_work;
926 	bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */
927 	struct cfg80211_chan_def csa_chandef;
928 
929 	struct list_head assigned_chanctx_list; /* protected by chanctx_mtx */
930 	struct list_head reserved_chanctx_list; /* protected by chanctx_mtx */
931 
932 	/* context reservation -- protected with chanctx_mtx */
933 	struct ieee80211_chanctx *reserved_chanctx;
934 	struct cfg80211_chan_def reserved_chandef;
935 	bool reserved_radar_required;
936 	bool reserved_ready;
937 
938 	/* used to reconfigure hardware SM PS */
939 	struct work_struct recalc_smps;
940 
941 	struct work_struct work;
942 	struct sk_buff_head skb_queue;
943 
944 	u8 needed_rx_chains;
945 	enum ieee80211_smps_mode smps_mode;
946 
947 	int user_power_level; /* in dBm */
948 	int ap_power_level; /* in dBm */
949 
950 	bool radar_required;
951 	struct delayed_work dfs_cac_timer_work;
952 
953 	/*
954 	 * AP this belongs to: self in AP mode and
955 	 * corresponding AP in VLAN mode, NULL for
956 	 * all others (might be needed later in IBSS)
957 	 */
958 	struct ieee80211_if_ap *bss;
959 
960 	/* bitmap of allowed (non-MCS) rate indexes for rate control */
961 	u32 rc_rateidx_mask[NUM_NL80211_BANDS];
962 
963 	bool rc_has_mcs_mask[NUM_NL80211_BANDS];
964 	u8  rc_rateidx_mcs_mask[NUM_NL80211_BANDS][IEEE80211_HT_MCS_MASK_LEN];
965 
966 	bool rc_has_vht_mcs_mask[NUM_NL80211_BANDS];
967 	u16 rc_rateidx_vht_mcs_mask[NUM_NL80211_BANDS][NL80211_VHT_NSS_MAX];
968 
969 	/* Beacon frame (non-MCS) rate (as a bitmap) */
970 	u32 beacon_rateidx_mask[NUM_NL80211_BANDS];
971 	bool beacon_rate_set;
972 
973 	union {
974 		struct ieee80211_if_ap ap;
975 		struct ieee80211_if_wds wds;
976 		struct ieee80211_if_vlan vlan;
977 		struct ieee80211_if_managed mgd;
978 		struct ieee80211_if_ibss ibss;
979 		struct ieee80211_if_mesh mesh;
980 		struct ieee80211_if_ocb ocb;
981 		struct ieee80211_if_mntr mntr;
982 		struct ieee80211_if_nan nan;
983 	} u;
984 
985 #ifdef CONFIG_MAC80211_DEBUGFS
986 	struct {
987 		struct dentry *subdir_stations;
988 		struct dentry *default_unicast_key;
989 		struct dentry *default_multicast_key;
990 		struct dentry *default_mgmt_key;
991 		struct dentry *default_beacon_key;
992 	} debugfs;
993 #endif
994 
995 	/* must be last, dynamically sized area in this! */
996 	struct ieee80211_vif vif;
997 };
998 
999 static inline
vif_to_sdata(struct ieee80211_vif * p)1000 struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
1001 {
1002 	return container_of(p, struct ieee80211_sub_if_data, vif);
1003 }
1004 
sdata_lock(struct ieee80211_sub_if_data * sdata)1005 static inline void sdata_lock(struct ieee80211_sub_if_data *sdata)
1006 	__acquires(&sdata->wdev.mtx)
1007 {
1008 	mutex_lock(&sdata->wdev.mtx);
1009 	__acquire(&sdata->wdev.mtx);
1010 }
1011 
sdata_unlock(struct ieee80211_sub_if_data * sdata)1012 static inline void sdata_unlock(struct ieee80211_sub_if_data *sdata)
1013 	__releases(&sdata->wdev.mtx)
1014 {
1015 	mutex_unlock(&sdata->wdev.mtx);
1016 	__release(&sdata->wdev.mtx);
1017 }
1018 
1019 #define sdata_dereference(p, sdata) \
1020 	rcu_dereference_protected(p, lockdep_is_held(&sdata->wdev.mtx))
1021 
1022 static inline void
sdata_assert_lock(struct ieee80211_sub_if_data * sdata)1023 sdata_assert_lock(struct ieee80211_sub_if_data *sdata)
1024 {
1025 	lockdep_assert_held(&sdata->wdev.mtx);
1026 }
1027 
1028 static inline int
ieee80211_chandef_get_shift(struct cfg80211_chan_def * chandef)1029 ieee80211_chandef_get_shift(struct cfg80211_chan_def *chandef)
1030 {
1031 	switch (chandef->width) {
1032 	case NL80211_CHAN_WIDTH_5:
1033 		return 2;
1034 	case NL80211_CHAN_WIDTH_10:
1035 		return 1;
1036 	default:
1037 		return 0;
1038 	}
1039 }
1040 
1041 static inline int
ieee80211_vif_get_shift(struct ieee80211_vif * vif)1042 ieee80211_vif_get_shift(struct ieee80211_vif *vif)
1043 {
1044 	struct ieee80211_chanctx_conf *chanctx_conf;
1045 	int shift = 0;
1046 
1047 	rcu_read_lock();
1048 	chanctx_conf = rcu_dereference(vif->chanctx_conf);
1049 	if (chanctx_conf)
1050 		shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
1051 	rcu_read_unlock();
1052 
1053 	return shift;
1054 }
1055 
1056 enum {
1057 	IEEE80211_RX_MSG	= 1,
1058 	IEEE80211_TX_STATUS_MSG	= 2,
1059 };
1060 
1061 enum queue_stop_reason {
1062 	IEEE80211_QUEUE_STOP_REASON_DRIVER,
1063 	IEEE80211_QUEUE_STOP_REASON_PS,
1064 	IEEE80211_QUEUE_STOP_REASON_CSA,
1065 	IEEE80211_QUEUE_STOP_REASON_AGGREGATION,
1066 	IEEE80211_QUEUE_STOP_REASON_SUSPEND,
1067 	IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
1068 	IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL,
1069 	IEEE80211_QUEUE_STOP_REASON_FLUSH,
1070 	IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN,
1071 	IEEE80211_QUEUE_STOP_REASON_RESERVE_TID,
1072 	IEEE80211_QUEUE_STOP_REASON_IFTYPE_CHANGE,
1073 
1074 	IEEE80211_QUEUE_STOP_REASONS,
1075 };
1076 
1077 #ifdef CONFIG_MAC80211_LEDS
1078 struct tpt_led_trigger {
1079 	char name[32];
1080 	const struct ieee80211_tpt_blink *blink_table;
1081 	unsigned int blink_table_len;
1082 	struct timer_list timer;
1083 	struct ieee80211_local *local;
1084 	unsigned long prev_traffic;
1085 	unsigned long tx_bytes, rx_bytes;
1086 	unsigned int active, want;
1087 	bool running;
1088 };
1089 #endif
1090 
1091 /**
1092  * mac80211 scan flags - currently active scan mode
1093  *
1094  * @SCAN_SW_SCANNING: We're currently in the process of scanning but may as
1095  *	well be on the operating channel
1096  * @SCAN_HW_SCANNING: The hardware is scanning for us, we have no way to
1097  *	determine if we are on the operating channel or not
1098  * @SCAN_ONCHANNEL_SCANNING:  Do a software scan on only the current operating
1099  *	channel. This should not interrupt normal traffic.
1100  * @SCAN_COMPLETED: Set for our scan work function when the driver reported
1101  *	that the scan completed.
1102  * @SCAN_ABORTED: Set for our scan work function when the driver reported
1103  *	a scan complete for an aborted scan.
1104  * @SCAN_HW_CANCELLED: Set for our scan work function when the scan is being
1105  *	cancelled.
1106  * @SCAN_BEACON_WAIT: Set whenever we're passive scanning because of radar/no-IR
1107  *	and could send a probe request after receiving a beacon.
1108  * @SCAN_BEACON_DONE: Beacon received, we can now send a probe request
1109  */
1110 enum {
1111 	SCAN_SW_SCANNING,
1112 	SCAN_HW_SCANNING,
1113 	SCAN_ONCHANNEL_SCANNING,
1114 	SCAN_COMPLETED,
1115 	SCAN_ABORTED,
1116 	SCAN_HW_CANCELLED,
1117 	SCAN_BEACON_WAIT,
1118 	SCAN_BEACON_DONE,
1119 };
1120 
1121 /**
1122  * enum mac80211_scan_state - scan state machine states
1123  *
1124  * @SCAN_DECISION: Main entry point to the scan state machine, this state
1125  *	determines if we should keep on scanning or switch back to the
1126  *	operating channel
1127  * @SCAN_SET_CHANNEL: Set the next channel to be scanned
1128  * @SCAN_SEND_PROBE: Send probe requests and wait for probe responses
1129  * @SCAN_SUSPEND: Suspend the scan and go back to operating channel to
1130  *	send out data
1131  * @SCAN_RESUME: Resume the scan and scan the next channel
1132  * @SCAN_ABORT: Abort the scan and go back to operating channel
1133  */
1134 enum mac80211_scan_state {
1135 	SCAN_DECISION,
1136 	SCAN_SET_CHANNEL,
1137 	SCAN_SEND_PROBE,
1138 	SCAN_SUSPEND,
1139 	SCAN_RESUME,
1140 	SCAN_ABORT,
1141 };
1142 
1143 struct ieee80211_local {
1144 	/* embed the driver visible part.
1145 	 * don't cast (use the static inlines below), but we keep
1146 	 * it first anyway so they become a no-op */
1147 	struct ieee80211_hw hw;
1148 
1149 	struct fq fq;
1150 	struct codel_vars *cvars;
1151 	struct codel_params cparams;
1152 
1153 	/* protects active_txqs and txqi->schedule_order */
1154 	spinlock_t active_txq_lock[IEEE80211_NUM_ACS];
1155 	struct list_head active_txqs[IEEE80211_NUM_ACS];
1156 	u16 schedule_round[IEEE80211_NUM_ACS];
1157 
1158 	u16 airtime_flags;
1159 	u32 aql_txq_limit_low[IEEE80211_NUM_ACS];
1160 	u32 aql_txq_limit_high[IEEE80211_NUM_ACS];
1161 	u32 aql_threshold;
1162 	atomic_t aql_total_pending_airtime;
1163 
1164 	const struct ieee80211_ops *ops;
1165 
1166 	/*
1167 	 * private workqueue to mac80211. mac80211 makes this accessible
1168 	 * via ieee80211_queue_work()
1169 	 */
1170 	struct workqueue_struct *workqueue;
1171 
1172 	unsigned long queue_stop_reasons[IEEE80211_MAX_QUEUES];
1173 	int q_stop_reasons[IEEE80211_MAX_QUEUES][IEEE80211_QUEUE_STOP_REASONS];
1174 	/* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
1175 	spinlock_t queue_stop_reason_lock;
1176 
1177 	int open_count;
1178 	int monitors, cooked_mntrs;
1179 	/* number of interfaces with corresponding FIF_ flags */
1180 	int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
1181 	    fif_probe_req;
1182 	bool probe_req_reg;
1183 	bool rx_mcast_action_reg;
1184 	unsigned int filter_flags; /* FIF_* */
1185 
1186 	bool wiphy_ciphers_allocated;
1187 
1188 	bool use_chanctx;
1189 
1190 	/* protects the aggregated multicast list and filter calls */
1191 	spinlock_t filter_lock;
1192 
1193 	/* used for uploading changed mc list */
1194 	struct work_struct reconfig_filter;
1195 
1196 	/* aggregated multicast list */
1197 	struct netdev_hw_addr_list mc_list;
1198 
1199 	bool tim_in_locked_section; /* see ieee80211_beacon_get() */
1200 
1201 	/*
1202 	 * suspended is true if we finished all the suspend _and_ we have
1203 	 * not yet come up from resume. This is to be used by mac80211
1204 	 * to ensure driver sanity during suspend and mac80211's own
1205 	 * sanity. It can eventually be used for WoW as well.
1206 	 */
1207 	bool suspended;
1208 
1209 	/*
1210 	 * Resuming is true while suspended, but when we're reprogramming the
1211 	 * hardware -- at that time it's allowed to use ieee80211_queue_work()
1212 	 * again even though some other parts of the stack are still suspended
1213 	 * and we still drop received frames to avoid waking the stack.
1214 	 */
1215 	bool resuming;
1216 
1217 	/*
1218 	 * quiescing is true during the suspend process _only_ to
1219 	 * ease timer cancelling etc.
1220 	 */
1221 	bool quiescing;
1222 
1223 	/* device is started */
1224 	bool started;
1225 
1226 	/* device is during a HW reconfig */
1227 	bool in_reconfig;
1228 
1229 	/* wowlan is enabled -- don't reconfig on resume */
1230 	bool wowlan;
1231 
1232 	struct work_struct radar_detected_work;
1233 
1234 	/* number of RX chains the hardware has */
1235 	u8 rx_chains;
1236 
1237 	/* bitmap of which sbands were copied */
1238 	u8 sband_allocated;
1239 
1240 	int tx_headroom; /* required headroom for hardware/radiotap */
1241 
1242 	/* Tasklet and skb queue to process calls from IRQ mode. All frames
1243 	 * added to skb_queue will be processed, but frames in
1244 	 * skb_queue_unreliable may be dropped if the total length of these
1245 	 * queues increases over the limit. */
1246 #define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
1247 	struct tasklet_struct tasklet;
1248 	struct sk_buff_head skb_queue;
1249 	struct sk_buff_head skb_queue_unreliable;
1250 
1251 	spinlock_t rx_path_lock;
1252 
1253 	/* Station data */
1254 	/*
1255 	 * The mutex only protects the list, hash table and
1256 	 * counter, reads are done with RCU.
1257 	 */
1258 	struct mutex sta_mtx;
1259 	spinlock_t tim_lock;
1260 	unsigned long num_sta;
1261 	struct list_head sta_list;
1262 	struct rhltable sta_hash;
1263 	struct timer_list sta_cleanup;
1264 	int sta_generation;
1265 
1266 	struct sk_buff_head pending[IEEE80211_MAX_QUEUES];
1267 	struct tasklet_struct tx_pending_tasklet;
1268 	struct tasklet_struct wake_txqs_tasklet;
1269 
1270 	atomic_t agg_queue_stop[IEEE80211_MAX_QUEUES];
1271 
1272 	/* number of interfaces with allmulti RX */
1273 	atomic_t iff_allmultis;
1274 
1275 	struct rate_control_ref *rate_ctrl;
1276 
1277 	struct arc4_ctx wep_tx_ctx;
1278 	struct arc4_ctx wep_rx_ctx;
1279 	u32 wep_iv;
1280 
1281 	/* see iface.c */
1282 	struct list_head interfaces;
1283 	struct list_head mon_list; /* only that are IFF_UP && !cooked */
1284 	struct mutex iflist_mtx;
1285 
1286 	/*
1287 	 * Key mutex, protects sdata's key_list and sta_info's
1288 	 * key pointers and ptk_idx (write access, they're RCU.)
1289 	 */
1290 	struct mutex key_mtx;
1291 
1292 	/* mutex for scan and work locking */
1293 	struct mutex mtx;
1294 
1295 	/* Scanning and BSS list */
1296 	unsigned long scanning;
1297 	struct cfg80211_ssid scan_ssid;
1298 	struct cfg80211_scan_request *int_scan_req;
1299 	struct cfg80211_scan_request __rcu *scan_req;
1300 	struct ieee80211_scan_request *hw_scan_req;
1301 	struct cfg80211_chan_def scan_chandef;
1302 	enum nl80211_band hw_scan_band;
1303 	int scan_channel_idx;
1304 	int scan_ies_len;
1305 	int hw_scan_ies_bufsize;
1306 	struct cfg80211_scan_info scan_info;
1307 
1308 	struct work_struct sched_scan_stopped_work;
1309 	struct ieee80211_sub_if_data __rcu *sched_scan_sdata;
1310 	struct cfg80211_sched_scan_request __rcu *sched_scan_req;
1311 	u8 scan_addr[ETH_ALEN];
1312 
1313 	unsigned long leave_oper_channel_time;
1314 	enum mac80211_scan_state next_scan_state;
1315 	struct delayed_work scan_work;
1316 	struct ieee80211_sub_if_data __rcu *scan_sdata;
1317 	/* For backward compatibility only -- do not use */
1318 	struct cfg80211_chan_def _oper_chandef;
1319 
1320 	/* Temporary remain-on-channel for off-channel operations */
1321 	struct ieee80211_channel *tmp_channel;
1322 
1323 	/* channel contexts */
1324 	struct list_head chanctx_list;
1325 	struct mutex chanctx_mtx;
1326 
1327 #ifdef CONFIG_MAC80211_LEDS
1328 	struct led_trigger tx_led, rx_led, assoc_led, radio_led;
1329 	struct led_trigger tpt_led;
1330 	atomic_t tx_led_active, rx_led_active, assoc_led_active;
1331 	atomic_t radio_led_active, tpt_led_active;
1332 	struct tpt_led_trigger *tpt_led_trigger;
1333 #endif
1334 
1335 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
1336 	/* SNMP counters */
1337 	/* dot11CountersTable */
1338 	u32 dot11TransmittedFragmentCount;
1339 	u32 dot11MulticastTransmittedFrameCount;
1340 	u32 dot11FailedCount;
1341 	u32 dot11RetryCount;
1342 	u32 dot11MultipleRetryCount;
1343 	u32 dot11FrameDuplicateCount;
1344 	u32 dot11ReceivedFragmentCount;
1345 	u32 dot11MulticastReceivedFrameCount;
1346 	u32 dot11TransmittedFrameCount;
1347 
1348 	/* TX/RX handler statistics */
1349 	unsigned int tx_handlers_drop;
1350 	unsigned int tx_handlers_queued;
1351 	unsigned int tx_handlers_drop_wep;
1352 	unsigned int tx_handlers_drop_not_assoc;
1353 	unsigned int tx_handlers_drop_unauth_port;
1354 	unsigned int rx_handlers_drop;
1355 	unsigned int rx_handlers_queued;
1356 	unsigned int rx_handlers_drop_nullfunc;
1357 	unsigned int rx_handlers_drop_defrag;
1358 	unsigned int tx_expand_skb_head;
1359 	unsigned int tx_expand_skb_head_cloned;
1360 	unsigned int rx_expand_skb_head_defrag;
1361 	unsigned int rx_handlers_fragments;
1362 	unsigned int tx_status_drop;
1363 #define I802_DEBUG_INC(c) (c)++
1364 #else /* CONFIG_MAC80211_DEBUG_COUNTERS */
1365 #define I802_DEBUG_INC(c) do { } while (0)
1366 #endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
1367 
1368 
1369 	int total_ps_buffered; /* total number of all buffered unicast and
1370 				* multicast packets for power saving stations
1371 				*/
1372 
1373 	bool pspolling;
1374 	/*
1375 	 * PS can only be enabled when we have exactly one managed
1376 	 * interface (and monitors) in PS, this then points there.
1377 	 */
1378 	struct ieee80211_sub_if_data *ps_sdata;
1379 	struct work_struct dynamic_ps_enable_work;
1380 	struct work_struct dynamic_ps_disable_work;
1381 	struct timer_list dynamic_ps_timer;
1382 	struct notifier_block ifa_notifier;
1383 	struct notifier_block ifa6_notifier;
1384 
1385 	/*
1386 	 * The dynamic ps timeout configured from user space via WEXT -
1387 	 * this will override whatever chosen by mac80211 internally.
1388 	 */
1389 	int dynamic_ps_forced_timeout;
1390 
1391 	int user_power_level; /* in dBm, for all interfaces */
1392 
1393 	enum ieee80211_smps_mode smps_mode;
1394 
1395 	struct work_struct restart_work;
1396 
1397 #ifdef CONFIG_MAC80211_DEBUGFS
1398 	struct local_debugfsdentries {
1399 		struct dentry *rcdir;
1400 		struct dentry *keys;
1401 	} debugfs;
1402 	bool force_tx_status;
1403 #endif
1404 
1405 	/*
1406 	 * Remain-on-channel support
1407 	 */
1408 	struct delayed_work roc_work;
1409 	struct list_head roc_list;
1410 	struct work_struct hw_roc_start, hw_roc_done;
1411 	unsigned long hw_roc_start_time;
1412 	u64 roc_cookie_counter;
1413 
1414 	struct idr ack_status_frames;
1415 	spinlock_t ack_status_lock;
1416 
1417 	struct ieee80211_sub_if_data __rcu *p2p_sdata;
1418 
1419 	/* virtual monitor interface */
1420 	struct ieee80211_sub_if_data __rcu *monitor_sdata;
1421 	struct cfg80211_chan_def monitor_chandef;
1422 
1423 	/* extended capabilities provided by mac80211 */
1424 	u8 ext_capa[8];
1425 
1426 	/* TDLS channel switch */
1427 	struct work_struct tdls_chsw_work;
1428 	struct sk_buff_head skb_queue_tdls_chsw;
1429 };
1430 
1431 static inline struct ieee80211_sub_if_data *
IEEE80211_DEV_TO_SUB_IF(struct net_device * dev)1432 IEEE80211_DEV_TO_SUB_IF(struct net_device *dev)
1433 {
1434 	return netdev_priv(dev);
1435 }
1436 
1437 static inline struct ieee80211_sub_if_data *
IEEE80211_WDEV_TO_SUB_IF(struct wireless_dev * wdev)1438 IEEE80211_WDEV_TO_SUB_IF(struct wireless_dev *wdev)
1439 {
1440 	return container_of(wdev, struct ieee80211_sub_if_data, wdev);
1441 }
1442 
1443 static inline struct ieee80211_supported_band *
ieee80211_get_sband(struct ieee80211_sub_if_data * sdata)1444 ieee80211_get_sband(struct ieee80211_sub_if_data *sdata)
1445 {
1446 	struct ieee80211_local *local = sdata->local;
1447 	struct ieee80211_chanctx_conf *chanctx_conf;
1448 	enum nl80211_band band;
1449 
1450 	rcu_read_lock();
1451 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1452 
1453 	if (!chanctx_conf) {
1454 		rcu_read_unlock();
1455 		return NULL;
1456 	}
1457 
1458 	band = chanctx_conf->def.chan->band;
1459 	rcu_read_unlock();
1460 
1461 	return local->hw.wiphy->bands[band];
1462 }
1463 
1464 /* this struct holds the value parsing from channel switch IE  */
1465 struct ieee80211_csa_ie {
1466 	struct cfg80211_chan_def chandef;
1467 	u8 mode;
1468 	u8 count;
1469 	u8 ttl;
1470 	u16 pre_value;
1471 	u16 reason_code;
1472 	u32 max_switch_time;
1473 };
1474 
1475 /* Parsed Information Elements */
1476 struct ieee802_11_elems {
1477 	const u8 *ie_start;
1478 	size_t total_len;
1479 
1480 	/* pointers to IEs */
1481 	const struct ieee80211_tdls_lnkie *lnk_id;
1482 	const struct ieee80211_ch_switch_timing *ch_sw_timing;
1483 	const u8 *ext_capab;
1484 	const u8 *ssid;
1485 	const u8 *supp_rates;
1486 	const u8 *ds_params;
1487 	const struct ieee80211_tim_ie *tim;
1488 	const u8 *rsn;
1489 	const u8 *rsnx;
1490 	const u8 *erp_info;
1491 	const u8 *ext_supp_rates;
1492 	const u8 *wmm_info;
1493 	const u8 *wmm_param;
1494 	const struct ieee80211_ht_cap *ht_cap_elem;
1495 	const struct ieee80211_ht_operation *ht_operation;
1496 	const struct ieee80211_vht_cap *vht_cap_elem;
1497 	const struct ieee80211_vht_operation *vht_operation;
1498 	const struct ieee80211_meshconf_ie *mesh_config;
1499 	const u8 *he_cap;
1500 	const struct ieee80211_he_operation *he_operation;
1501 	const struct ieee80211_he_spr *he_spr;
1502 	const struct ieee80211_mu_edca_param_set *mu_edca_param_set;
1503 	const struct ieee80211_he_6ghz_capa *he_6ghz_capa;
1504 	const u8 *uora_element;
1505 	const u8 *mesh_id;
1506 	const u8 *peering;
1507 	const __le16 *awake_window;
1508 	const u8 *preq;
1509 	const u8 *prep;
1510 	const u8 *perr;
1511 	const struct ieee80211_rann_ie *rann;
1512 	const struct ieee80211_channel_sw_ie *ch_switch_ie;
1513 	const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
1514 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1515 	const u8 *max_channel_switch_time;
1516 	const u8 *country_elem;
1517 	const u8 *pwr_constr_elem;
1518 	const u8 *cisco_dtpc_elem;
1519 	const struct ieee80211_timeout_interval_ie *timeout_int;
1520 	const u8 *opmode_notif;
1521 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1522 	struct ieee80211_mesh_chansw_params_ie *mesh_chansw_params_ie;
1523 	const struct ieee80211_bss_max_idle_period_ie *max_idle_period_ie;
1524 	const struct ieee80211_multiple_bssid_configuration *mbssid_config_ie;
1525 	const struct ieee80211_bssid_index *bssid_index;
1526 	u8 max_bssid_indicator;
1527 	u8 dtim_count;
1528 	u8 dtim_period;
1529 	const struct ieee80211_addba_ext_ie *addba_ext_ie;
1530 	const struct ieee80211_s1g_cap *s1g_capab;
1531 	const struct ieee80211_s1g_oper_ie *s1g_oper;
1532 	const struct ieee80211_s1g_bcn_compat_ie *s1g_bcn_compat;
1533 	const struct ieee80211_aid_response_ie *aid_resp;
1534 
1535 	/* length of them, respectively */
1536 	u8 ext_capab_len;
1537 	u8 ssid_len;
1538 	u8 supp_rates_len;
1539 	u8 tim_len;
1540 	u8 rsn_len;
1541 	u8 rsnx_len;
1542 	u8 ext_supp_rates_len;
1543 	u8 wmm_info_len;
1544 	u8 wmm_param_len;
1545 	u8 he_cap_len;
1546 	u8 mesh_id_len;
1547 	u8 peering_len;
1548 	u8 preq_len;
1549 	u8 prep_len;
1550 	u8 perr_len;
1551 	u8 country_elem_len;
1552 	u8 bssid_index_len;
1553 
1554 	void *nontx_profile;
1555 
1556 	/* whether a parse error occurred while retrieving these elements */
1557 	bool parse_error;
1558 };
1559 
hw_to_local(struct ieee80211_hw * hw)1560 static inline struct ieee80211_local *hw_to_local(
1561 	struct ieee80211_hw *hw)
1562 {
1563 	return container_of(hw, struct ieee80211_local, hw);
1564 }
1565 
to_txq_info(struct ieee80211_txq * txq)1566 static inline struct txq_info *to_txq_info(struct ieee80211_txq *txq)
1567 {
1568 	return container_of(txq, struct txq_info, txq);
1569 }
1570 
txq_has_queue(struct ieee80211_txq * txq)1571 static inline bool txq_has_queue(struct ieee80211_txq *txq)
1572 {
1573 	struct txq_info *txqi = to_txq_info(txq);
1574 
1575 	return !(skb_queue_empty(&txqi->frags) && !txqi->tin.backlog_packets);
1576 }
1577 
ieee80211_bssid_match(const u8 * raddr,const u8 * addr)1578 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
1579 {
1580 	return ether_addr_equal(raddr, addr) ||
1581 	       is_broadcast_ether_addr(raddr);
1582 }
1583 
1584 static inline bool
ieee80211_have_rx_timestamp(struct ieee80211_rx_status * status)1585 ieee80211_have_rx_timestamp(struct ieee80211_rx_status *status)
1586 {
1587 	WARN_ON_ONCE(status->flag & RX_FLAG_MACTIME_START &&
1588 		     status->flag & RX_FLAG_MACTIME_END);
1589 	if (status->flag & (RX_FLAG_MACTIME_START | RX_FLAG_MACTIME_END))
1590 		return true;
1591 	/* can't handle non-legacy preamble yet */
1592 	if (status->flag & RX_FLAG_MACTIME_PLCP_START &&
1593 	    status->encoding == RX_ENC_LEGACY)
1594 		return true;
1595 	return false;
1596 }
1597 
1598 void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata);
1599 void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata);
1600 
1601 /* This function returns the number of multicast stations connected to this
1602  * interface. It returns -1 if that number is not tracked, that is for netdevs
1603  * not in AP or AP_VLAN mode or when using 4addr.
1604  */
1605 static inline int
ieee80211_vif_get_num_mcast_if(struct ieee80211_sub_if_data * sdata)1606 ieee80211_vif_get_num_mcast_if(struct ieee80211_sub_if_data *sdata)
1607 {
1608 	if (sdata->vif.type == NL80211_IFTYPE_AP)
1609 		return atomic_read(&sdata->u.ap.num_mcast_sta);
1610 	if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1611 		return atomic_read(&sdata->u.vlan.num_mcast_sta);
1612 	return -1;
1613 }
1614 
1615 u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
1616 				     struct ieee80211_rx_status *status,
1617 				     unsigned int mpdu_len,
1618 				     unsigned int mpdu_offset);
1619 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed);
1620 void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
1621 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
1622 				      u32 changed);
1623 void ieee80211_configure_filter(struct ieee80211_local *local);
1624 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata);
1625 
1626 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local);
1627 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
1628 			     u64 *cookie, gfp_t gfp);
1629 
1630 void ieee80211_check_fast_rx(struct sta_info *sta);
1631 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata);
1632 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata);
1633 void ieee80211_clear_fast_rx(struct sta_info *sta);
1634 
1635 /* STA code */
1636 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata);
1637 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
1638 		       struct cfg80211_auth_request *req);
1639 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
1640 			struct cfg80211_assoc_request *req);
1641 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
1642 			 struct cfg80211_deauth_request *req);
1643 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
1644 			   struct cfg80211_disassoc_request *req);
1645 void ieee80211_send_pspoll(struct ieee80211_local *local,
1646 			   struct ieee80211_sub_if_data *sdata);
1647 void ieee80211_recalc_ps(struct ieee80211_local *local);
1648 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata);
1649 int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata);
1650 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata);
1651 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1652 				  struct sk_buff *skb);
1653 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
1654 				 struct sk_buff *skb);
1655 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata);
1656 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata);
1657 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata);
1658 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
1659 				  __le16 fc, bool acked);
1660 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata);
1661 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata);
1662 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata);
1663 
1664 /* IBSS code */
1665 void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
1666 void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
1667 void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
1668 			      const u8 *bssid, const u8 *addr, u32 supp_rates);
1669 int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1670 			struct cfg80211_ibss_params *params);
1671 int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
1672 void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata);
1673 void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1674 				   struct sk_buff *skb);
1675 int ieee80211_ibss_csa_beacon(struct ieee80211_sub_if_data *sdata,
1676 			      struct cfg80211_csa_settings *csa_settings);
1677 int ieee80211_ibss_finish_csa(struct ieee80211_sub_if_data *sdata);
1678 void ieee80211_ibss_stop(struct ieee80211_sub_if_data *sdata);
1679 
1680 /* OCB code */
1681 void ieee80211_ocb_work(struct ieee80211_sub_if_data *sdata);
1682 void ieee80211_ocb_rx_no_sta(struct ieee80211_sub_if_data *sdata,
1683 			     const u8 *bssid, const u8 *addr, u32 supp_rates);
1684 void ieee80211_ocb_setup_sdata(struct ieee80211_sub_if_data *sdata);
1685 int ieee80211_ocb_join(struct ieee80211_sub_if_data *sdata,
1686 		       struct ocb_setup *setup);
1687 int ieee80211_ocb_leave(struct ieee80211_sub_if_data *sdata);
1688 
1689 /* mesh code */
1690 void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata);
1691 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1692 				   struct sk_buff *skb);
1693 int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
1694 			      struct cfg80211_csa_settings *csa_settings);
1695 int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata);
1696 
1697 /* scan/BSS handling */
1698 void ieee80211_scan_work(struct work_struct *work);
1699 int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
1700 				const u8 *ssid, u8 ssid_len,
1701 				struct ieee80211_channel **channels,
1702 				unsigned int n_channels,
1703 				enum nl80211_bss_scan_width scan_width);
1704 int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
1705 			   struct cfg80211_scan_request *req);
1706 void ieee80211_scan_cancel(struct ieee80211_local *local);
1707 void ieee80211_run_deferred_scan(struct ieee80211_local *local);
1708 void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb);
1709 
1710 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
1711 struct ieee80211_bss *
1712 ieee80211_bss_info_update(struct ieee80211_local *local,
1713 			  struct ieee80211_rx_status *rx_status,
1714 			  struct ieee80211_mgmt *mgmt,
1715 			  size_t len,
1716 			  struct ieee80211_channel *channel);
1717 void ieee80211_rx_bss_put(struct ieee80211_local *local,
1718 			  struct ieee80211_bss *bss);
1719 
1720 /* scheduled scan handling */
1721 int
1722 __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
1723 				     struct cfg80211_sched_scan_request *req);
1724 int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
1725 				       struct cfg80211_sched_scan_request *req);
1726 int ieee80211_request_sched_scan_stop(struct ieee80211_local *local);
1727 void ieee80211_sched_scan_end(struct ieee80211_local *local);
1728 void ieee80211_sched_scan_stopped_work(struct work_struct *work);
1729 
1730 /* off-channel/mgmt-tx */
1731 void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local);
1732 void ieee80211_offchannel_return(struct ieee80211_local *local);
1733 void ieee80211_roc_setup(struct ieee80211_local *local);
1734 void ieee80211_start_next_roc(struct ieee80211_local *local);
1735 void ieee80211_roc_purge(struct ieee80211_local *local,
1736 			 struct ieee80211_sub_if_data *sdata);
1737 int ieee80211_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
1738 				struct ieee80211_channel *chan,
1739 				unsigned int duration, u64 *cookie);
1740 int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1741 				       struct wireless_dev *wdev, u64 cookie);
1742 int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
1743 		      struct cfg80211_mgmt_tx_params *params, u64 *cookie);
1744 int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
1745 				  struct wireless_dev *wdev, u64 cookie);
1746 
1747 /* channel switch handling */
1748 void ieee80211_csa_finalize_work(struct work_struct *work);
1749 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
1750 			     struct cfg80211_csa_settings *params);
1751 
1752 /* interface handling */
1753 #define MAC80211_SUPPORTED_FEATURES_TX	(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | \
1754 					 NETIF_F_HW_CSUM | NETIF_F_SG | \
1755 					 NETIF_F_HIGHDMA | NETIF_F_GSO_SOFTWARE)
1756 #define MAC80211_SUPPORTED_FEATURES_RX	(NETIF_F_RXCSUM)
1757 #define MAC80211_SUPPORTED_FEATURES	(MAC80211_SUPPORTED_FEATURES_TX | \
1758 					 MAC80211_SUPPORTED_FEATURES_RX)
1759 
1760 int ieee80211_iface_init(void);
1761 void ieee80211_iface_exit(void);
1762 int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1763 		     unsigned char name_assign_type,
1764 		     struct wireless_dev **new_wdev, enum nl80211_iftype type,
1765 		     struct vif_params *params);
1766 int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
1767 			     enum nl80211_iftype type);
1768 void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata);
1769 void ieee80211_remove_interfaces(struct ieee80211_local *local);
1770 u32 ieee80211_idle_off(struct ieee80211_local *local);
1771 void ieee80211_recalc_idle(struct ieee80211_local *local);
1772 void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
1773 				    const int offset);
1774 int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up);
1775 void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata);
1776 int ieee80211_add_virtual_monitor(struct ieee80211_local *local);
1777 void ieee80211_del_virtual_monitor(struct ieee80211_local *local);
1778 
1779 bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
1780 void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata,
1781 			      bool update_bss);
1782 void ieee80211_recalc_offload(struct ieee80211_local *local);
1783 
ieee80211_sdata_running(struct ieee80211_sub_if_data * sdata)1784 static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata)
1785 {
1786 	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
1787 }
1788 
1789 /* tx handling */
1790 void ieee80211_clear_tx_pending(struct ieee80211_local *local);
1791 void ieee80211_tx_pending(unsigned long data);
1792 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1793 					 struct net_device *dev);
1794 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1795 				       struct net_device *dev);
1796 netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
1797 					    struct net_device *dev);
1798 void __ieee80211_subif_start_xmit(struct sk_buff *skb,
1799 				  struct net_device *dev,
1800 				  u32 info_flags,
1801 				  u32 ctrl_flags,
1802 				  u64 *cookie);
1803 void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
1804 			      struct sk_buff_head *skbs);
1805 struct sk_buff *
1806 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
1807 			      struct sk_buff *skb, u32 info_flags);
1808 void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
1809 			  struct ieee80211_supported_band *sband,
1810 			  int retry_count, int shift, bool send_to_cooked,
1811 			  struct ieee80211_tx_status *status);
1812 
1813 void ieee80211_check_fast_xmit(struct sta_info *sta);
1814 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local);
1815 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata);
1816 void ieee80211_clear_fast_xmit(struct sta_info *sta);
1817 int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
1818 			      const u8 *buf, size_t len,
1819 			      const u8 *dest, __be16 proto, bool unencrypted,
1820 			      u64 *cookie);
1821 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
1822 			      const u8 *buf, size_t len);
1823 
1824 /* HT */
1825 void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
1826 				     struct ieee80211_sta_ht_cap *ht_cap);
1827 bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
1828 				       struct ieee80211_supported_band *sband,
1829 				       const struct ieee80211_ht_cap *ht_cap_ie,
1830 				       struct sta_info *sta);
1831 void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
1832 			  const u8 *da, u16 tid,
1833 			  u16 initiator, u16 reason_code);
1834 int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
1835 			       enum ieee80211_smps_mode smps, const u8 *da,
1836 			       const u8 *bssid);
1837 void ieee80211_request_smps_ap_work(struct work_struct *work);
1838 void ieee80211_request_smps_mgd_work(struct work_struct *work);
1839 bool ieee80211_smps_is_restrictive(enum ieee80211_smps_mode smps_mode_old,
1840 				   enum ieee80211_smps_mode smps_mode_new);
1841 
1842 void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
1843 				     u16 initiator, u16 reason, bool stop);
1844 void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
1845 				    u16 initiator, u16 reason, bool stop);
1846 void ___ieee80211_start_rx_ba_session(struct sta_info *sta,
1847 				      u8 dialog_token, u16 timeout,
1848 				      u16 start_seq_num, u16 ba_policy, u16 tid,
1849 				      u16 buf_size, bool tx, bool auto_seq,
1850 				      const struct ieee80211_addba_ext_ie *addbaext);
1851 void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
1852 					 enum ieee80211_agg_stop_reason reason);
1853 void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
1854 			     struct sta_info *sta,
1855 			     struct ieee80211_mgmt *mgmt, size_t len);
1856 void ieee80211_process_addba_resp(struct ieee80211_local *local,
1857 				  struct sta_info *sta,
1858 				  struct ieee80211_mgmt *mgmt,
1859 				  size_t len);
1860 void ieee80211_process_addba_request(struct ieee80211_local *local,
1861 				     struct sta_info *sta,
1862 				     struct ieee80211_mgmt *mgmt,
1863 				     size_t len);
1864 
1865 int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
1866 				   enum ieee80211_agg_stop_reason reason);
1867 int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
1868 				    enum ieee80211_agg_stop_reason reason);
1869 void ieee80211_start_tx_ba_cb(struct sta_info *sta, int tid,
1870 			      struct tid_ampdu_tx *tid_tx);
1871 void ieee80211_stop_tx_ba_cb(struct sta_info *sta, int tid,
1872 			     struct tid_ampdu_tx *tid_tx);
1873 void ieee80211_ba_session_work(struct work_struct *work);
1874 void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid);
1875 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid);
1876 
1877 u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs);
1878 enum nl80211_smps_mode
1879 ieee80211_smps_mode_to_smps_mode(enum ieee80211_smps_mode smps);
1880 
1881 /* VHT */
1882 void
1883 ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
1884 				    struct ieee80211_supported_band *sband,
1885 				    const struct ieee80211_vht_cap *vht_cap_ie,
1886 				    struct sta_info *sta);
1887 enum ieee80211_sta_rx_bandwidth ieee80211_sta_cap_rx_bw(struct sta_info *sta);
1888 enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta);
1889 void ieee80211_sta_set_rx_nss(struct sta_info *sta);
1890 enum ieee80211_sta_rx_bandwidth
1891 ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width);
1892 enum nl80211_chan_width ieee80211_sta_cap_chan_bw(struct sta_info *sta);
1893 void ieee80211_sta_set_rx_nss(struct sta_info *sta);
1894 void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
1895 				 struct ieee80211_mgmt *mgmt);
1896 u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
1897                                   struct sta_info *sta, u8 opmode,
1898 				  enum nl80211_band band);
1899 void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
1900 				 struct sta_info *sta, u8 opmode,
1901 				 enum nl80211_band band);
1902 void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
1903 				      struct ieee80211_sta_vht_cap *vht_cap);
1904 void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
1905 				     u16 vht_mask[NL80211_VHT_NSS_MAX]);
1906 enum nl80211_chan_width
1907 ieee80211_sta_rx_bw_to_chan_width(struct sta_info *sta);
1908 
1909 /* HE */
1910 void
1911 ieee80211_he_cap_ie_to_sta_he_cap(struct ieee80211_sub_if_data *sdata,
1912 				  struct ieee80211_supported_band *sband,
1913 				  const u8 *he_cap_ie, u8 he_cap_len,
1914 				  const struct ieee80211_he_6ghz_capa *he_6ghz_capa,
1915 				  struct sta_info *sta);
1916 void
1917 ieee80211_he_spr_ie_to_bss_conf(struct ieee80211_vif *vif,
1918 				const struct ieee80211_he_spr *he_spr_ie_elem);
1919 
1920 void
1921 ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif,
1922 			const struct ieee80211_he_operation *he_op_ie_elem);
1923 
1924 /* S1G */
1925 void ieee80211_s1g_sta_rate_init(struct sta_info *sta);
1926 
1927 /* Spectrum management */
1928 void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
1929 				       struct ieee80211_mgmt *mgmt,
1930 				       size_t len);
1931 /**
1932  * ieee80211_parse_ch_switch_ie - parses channel switch IEs
1933  * @sdata: the sdata of the interface which has received the frame
1934  * @elems: parsed 802.11 elements received with the frame
1935  * @current_band: indicates the current band
1936  * @vht_cap_info: VHT capabilities of the transmitter
1937  * @sta_flags: contains information about own capabilities and restrictions
1938  *	to decide which channel switch announcements can be accepted. Only the
1939  *	following subset of &enum ieee80211_sta_flags are evaluated:
1940  *	%IEEE80211_STA_DISABLE_HT, %IEEE80211_STA_DISABLE_VHT,
1941  *	%IEEE80211_STA_DISABLE_40MHZ, %IEEE80211_STA_DISABLE_80P80MHZ,
1942  *	%IEEE80211_STA_DISABLE_160MHZ.
1943  * @bssid: the currently connected bssid (for reporting)
1944  * @csa_ie: parsed 802.11 csa elements on count, mode, chandef and mesh ttl.
1945 	All of them will be filled with if success only.
1946  * Return: 0 on success, <0 on error and >0 if there is nothing to parse.
1947  */
1948 int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
1949 				 struct ieee802_11_elems *elems,
1950 				 enum nl80211_band current_band,
1951 				 u32 vht_cap_info,
1952 				 u32 sta_flags, u8 *bssid,
1953 				 struct ieee80211_csa_ie *csa_ie);
1954 
1955 /* Suspend/resume and hw reconfiguration */
1956 int ieee80211_reconfig(struct ieee80211_local *local);
1957 void ieee80211_stop_device(struct ieee80211_local *local);
1958 
1959 int __ieee80211_suspend(struct ieee80211_hw *hw,
1960 			struct cfg80211_wowlan *wowlan);
1961 
__ieee80211_resume(struct ieee80211_hw * hw)1962 static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1963 {
1964 	struct ieee80211_local *local = hw_to_local(hw);
1965 
1966 	WARN(test_bit(SCAN_HW_SCANNING, &local->scanning) &&
1967 	     !test_bit(SCAN_COMPLETED, &local->scanning),
1968 		"%s: resume with hardware scan still in progress\n",
1969 		wiphy_name(hw->wiphy));
1970 
1971 	return ieee80211_reconfig(hw_to_local(hw));
1972 }
1973 
1974 /* utility functions/constants */
1975 extern const void *const mac80211_wiphy_privid; /* for wiphy privid */
1976 int ieee80211_frame_duration(enum nl80211_band band, size_t len,
1977 			     int rate, int erp, int short_preamble,
1978 			     int shift);
1979 void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
1980 					   struct ieee80211_tx_queue_params *qparam,
1981 					   int ac);
1982 void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
1983 			       bool bss_notify, bool enable_qos);
1984 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1985 		    struct sta_info *sta, struct sk_buff *skb);
1986 
1987 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
1988 				 struct sk_buff *skb, int tid,
1989 				 enum nl80211_band band);
1990 
1991 /* sta_out needs to be checked for ERR_PTR() before using */
1992 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
1993 			    struct sk_buff *skb,
1994 			    struct sta_info **sta_out);
1995 
1996 static inline void
ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,int tid,enum nl80211_band band)1997 ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
1998 			  struct sk_buff *skb, int tid,
1999 			  enum nl80211_band band)
2000 {
2001 	rcu_read_lock();
2002 	__ieee80211_tx_skb_tid_band(sdata, skb, tid, band);
2003 	rcu_read_unlock();
2004 }
2005 
ieee80211_tx_skb_tid(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,int tid)2006 static inline void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
2007 					struct sk_buff *skb, int tid)
2008 {
2009 	struct ieee80211_chanctx_conf *chanctx_conf;
2010 
2011 	rcu_read_lock();
2012 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2013 	if (WARN_ON(!chanctx_conf)) {
2014 		rcu_read_unlock();
2015 		kfree_skb(skb);
2016 		return;
2017 	}
2018 
2019 	__ieee80211_tx_skb_tid_band(sdata, skb, tid,
2020 				    chanctx_conf->def.chan->band);
2021 	rcu_read_unlock();
2022 }
2023 
ieee80211_tx_skb(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb)2024 static inline void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata,
2025 				    struct sk_buff *skb)
2026 {
2027 	/* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
2028 	ieee80211_tx_skb_tid(sdata, skb, 7);
2029 }
2030 
2031 u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
2032 			       struct ieee802_11_elems *elems,
2033 			       u64 filter, u32 crc, u8 *transmitter_bssid,
2034 			       u8 *bss_bssid);
ieee802_11_parse_elems(const u8 * start,size_t len,bool action,struct ieee802_11_elems * elems,u8 * transmitter_bssid,u8 * bss_bssid)2035 static inline void ieee802_11_parse_elems(const u8 *start, size_t len,
2036 					  bool action,
2037 					  struct ieee802_11_elems *elems,
2038 					  u8 *transmitter_bssid,
2039 					  u8 *bss_bssid)
2040 {
2041 	ieee802_11_parse_elems_crc(start, len, action, elems, 0, 0,
2042 				   transmitter_bssid, bss_bssid);
2043 }
2044 
2045 
2046 extern const int ieee802_1d_to_ac[8];
2047 
ieee80211_ac_from_tid(int tid)2048 static inline int ieee80211_ac_from_tid(int tid)
2049 {
2050 	return ieee802_1d_to_ac[tid & 7];
2051 }
2052 
2053 void ieee80211_dynamic_ps_enable_work(struct work_struct *work);
2054 void ieee80211_dynamic_ps_disable_work(struct work_struct *work);
2055 void ieee80211_dynamic_ps_timer(struct timer_list *t);
2056 void ieee80211_send_nullfunc(struct ieee80211_local *local,
2057 			     struct ieee80211_sub_if_data *sdata,
2058 			     bool powersave);
2059 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
2060 				   struct ieee80211_sub_if_data *sdata);
2061 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2062 			     struct ieee80211_hdr *hdr, bool ack, u16 tx_time);
2063 
2064 void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
2065 				     unsigned long queues,
2066 				     enum queue_stop_reason reason,
2067 				     bool refcounted);
2068 void ieee80211_stop_vif_queues(struct ieee80211_local *local,
2069 			       struct ieee80211_sub_if_data *sdata,
2070 			       enum queue_stop_reason reason);
2071 void ieee80211_wake_vif_queues(struct ieee80211_local *local,
2072 			       struct ieee80211_sub_if_data *sdata,
2073 			       enum queue_stop_reason reason);
2074 void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
2075 				     unsigned long queues,
2076 				     enum queue_stop_reason reason,
2077 				     bool refcounted);
2078 void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
2079 				    enum queue_stop_reason reason,
2080 				    bool refcounted);
2081 void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
2082 				    enum queue_stop_reason reason,
2083 				    bool refcounted);
2084 void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue);
2085 void ieee80211_add_pending_skb(struct ieee80211_local *local,
2086 			       struct sk_buff *skb);
2087 void ieee80211_add_pending_skbs(struct ieee80211_local *local,
2088 				struct sk_buff_head *skbs);
2089 void ieee80211_flush_queues(struct ieee80211_local *local,
2090 			    struct ieee80211_sub_if_data *sdata, bool drop);
2091 void __ieee80211_flush_queues(struct ieee80211_local *local,
2092 			      struct ieee80211_sub_if_data *sdata,
2093 			      unsigned int queues, bool drop);
2094 
ieee80211_can_run_worker(struct ieee80211_local * local)2095 static inline bool ieee80211_can_run_worker(struct ieee80211_local *local)
2096 {
2097 	/*
2098 	 * It's unsafe to try to do any work during reconfigure flow.
2099 	 * When the flow ends the work will be requeued.
2100 	 */
2101 	if (local->in_reconfig)
2102 		return false;
2103 
2104 	/*
2105 	 * If quiescing is set, we are racing with __ieee80211_suspend.
2106 	 * __ieee80211_suspend flushes the workers after setting quiescing,
2107 	 * and we check quiescing / suspended before enqueing new workers.
2108 	 * We should abort the worker to avoid the races below.
2109 	 */
2110 	if (local->quiescing)
2111 		return false;
2112 
2113 	/*
2114 	 * We might already be suspended if the following scenario occurs:
2115 	 * __ieee80211_suspend		Control path
2116 	 *
2117 	 *				if (local->quiescing)
2118 	 *					return;
2119 	 * local->quiescing = true;
2120 	 * flush_workqueue();
2121 	 *				queue_work(...);
2122 	 * local->suspended = true;
2123 	 * local->quiescing = false;
2124 	 *				worker starts running...
2125 	 */
2126 	if (local->suspended)
2127 		return false;
2128 
2129 	return true;
2130 }
2131 
2132 int ieee80211_txq_setup_flows(struct ieee80211_local *local);
2133 void ieee80211_txq_set_params(struct ieee80211_local *local);
2134 void ieee80211_txq_teardown_flows(struct ieee80211_local *local);
2135 void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
2136 			struct sta_info *sta,
2137 			struct txq_info *txq, int tid);
2138 void ieee80211_txq_purge(struct ieee80211_local *local,
2139 			 struct txq_info *txqi);
2140 void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
2141 			       struct ieee80211_sub_if_data *sdata);
2142 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
2143 			      struct txq_info *txqi);
2144 void ieee80211_wake_txqs(unsigned long data);
2145 void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
2146 			 u16 transaction, u16 auth_alg, u16 status,
2147 			 const u8 *extra, size_t extra_len, const u8 *bssid,
2148 			 const u8 *da, const u8 *key, u8 key_len, u8 key_idx,
2149 			 u32 tx_flags);
2150 void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
2151 				    const u8 *da, const u8 *bssid,
2152 				    u16 stype, u16 reason,
2153 				    bool send_frame, u8 *frame_buf);
2154 
2155 enum {
2156 	IEEE80211_PROBE_FLAG_DIRECTED		= BIT(0),
2157 	IEEE80211_PROBE_FLAG_MIN_CONTENT	= BIT(1),
2158 	IEEE80211_PROBE_FLAG_RANDOM_SN		= BIT(2),
2159 };
2160 
2161 int ieee80211_build_preq_ies(struct ieee80211_sub_if_data *sdata, u8 *buffer,
2162 			     size_t buffer_len,
2163 			     struct ieee80211_scan_ies *ie_desc,
2164 			     const u8 *ie, size_t ie_len,
2165 			     u8 bands_used, u32 *rate_masks,
2166 			     struct cfg80211_chan_def *chandef,
2167 			     u32 flags);
2168 struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
2169 					  const u8 *src, const u8 *dst,
2170 					  u32 ratemask,
2171 					  struct ieee80211_channel *chan,
2172 					  const u8 *ssid, size_t ssid_len,
2173 					  const u8 *ie, size_t ie_len,
2174 					  u32 flags);
2175 u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
2176 			    struct ieee802_11_elems *elems,
2177 			    enum nl80211_band band, u32 *basic_rates);
2178 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2179 				 enum ieee80211_smps_mode smps_mode);
2180 void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata);
2181 void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata);
2182 
2183 size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset);
2184 u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
2185 			      u16 cap);
2186 u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
2187 			       const struct cfg80211_chan_def *chandef,
2188 			       u16 prot_mode, bool rifs_mode);
2189 void ieee80211_ie_build_wide_bw_cs(u8 *pos,
2190 				   const struct cfg80211_chan_def *chandef);
2191 u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
2192 			       u32 cap);
2193 u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
2194 				const struct cfg80211_chan_def *chandef);
2195 u8 ieee80211_ie_len_he_cap(struct ieee80211_sub_if_data *sdata, u8 iftype);
2196 u8 *ieee80211_ie_build_he_cap(u8 *pos,
2197 			      const struct ieee80211_sta_he_cap *he_cap,
2198 			      u8 *end);
2199 void ieee80211_ie_build_he_6ghz_cap(struct ieee80211_sub_if_data *sdata,
2200 				    struct sk_buff *skb);
2201 u8 *ieee80211_ie_build_he_oper(u8 *pos, struct cfg80211_chan_def *chandef);
2202 int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
2203 			     const struct ieee80211_supported_band *sband,
2204 			     const u8 *srates, int srates_len, u32 *rates);
2205 int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
2206 			    struct sk_buff *skb, bool need_basic,
2207 			    enum nl80211_band band);
2208 int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
2209 				struct sk_buff *skb, bool need_basic,
2210 				enum nl80211_band band);
2211 u8 *ieee80211_add_wmm_info_ie(u8 *buf, u8 qosinfo);
2212 void ieee80211_add_s1g_capab_ie(struct ieee80211_sub_if_data *sdata,
2213 				struct ieee80211_sta_s1g_cap *caps,
2214 				struct sk_buff *skb);
2215 void ieee80211_add_aid_request_ie(struct ieee80211_sub_if_data *sdata,
2216 				  struct sk_buff *skb);
2217 
2218 /* channel management */
2219 bool ieee80211_chandef_ht_oper(const struct ieee80211_ht_operation *ht_oper,
2220 			       struct cfg80211_chan_def *chandef);
2221 bool ieee80211_chandef_vht_oper(struct ieee80211_hw *hw, u32 vht_cap_info,
2222 				const struct ieee80211_vht_operation *oper,
2223 				const struct ieee80211_ht_operation *htop,
2224 				struct cfg80211_chan_def *chandef);
2225 bool ieee80211_chandef_he_6ghz_oper(struct ieee80211_sub_if_data *sdata,
2226 				    const struct ieee80211_he_operation *he_oper,
2227 				    struct cfg80211_chan_def *chandef);
2228 bool ieee80211_chandef_s1g_oper(const struct ieee80211_s1g_oper_ie *oper,
2229 				struct cfg80211_chan_def *chandef);
2230 u32 ieee80211_chandef_downgrade(struct cfg80211_chan_def *c);
2231 
2232 int __must_check
2233 ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
2234 			  const struct cfg80211_chan_def *chandef,
2235 			  enum ieee80211_chanctx_mode mode);
2236 int __must_check
2237 ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata,
2238 			      const struct cfg80211_chan_def *chandef,
2239 			      enum ieee80211_chanctx_mode mode,
2240 			      bool radar_required);
2241 int __must_check
2242 ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata);
2243 int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata);
2244 
2245 int __must_check
2246 ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
2247 			       const struct cfg80211_chan_def *chandef,
2248 			       u32 *changed);
2249 void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
2250 void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);
2251 void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
2252 					 bool clear);
2253 int ieee80211_chanctx_refcount(struct ieee80211_local *local,
2254 			       struct ieee80211_chanctx *ctx);
2255 
2256 void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
2257 				   struct ieee80211_chanctx *chanctx);
2258 void ieee80211_recalc_chanctx_min_def(struct ieee80211_local *local,
2259 				      struct ieee80211_chanctx *ctx);
2260 bool ieee80211_is_radar_required(struct ieee80211_local *local);
2261 
2262 void ieee80211_dfs_cac_timer(unsigned long data);
2263 void ieee80211_dfs_cac_timer_work(struct work_struct *work);
2264 void ieee80211_dfs_cac_cancel(struct ieee80211_local *local);
2265 void ieee80211_dfs_radar_detected_work(struct work_struct *work);
2266 int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata,
2267 			      struct cfg80211_csa_settings *csa_settings);
2268 
2269 bool ieee80211_cs_valid(const struct ieee80211_cipher_scheme *cs);
2270 bool ieee80211_cs_list_valid(const struct ieee80211_cipher_scheme *cs, int n);
2271 const struct ieee80211_cipher_scheme *
2272 ieee80211_cs_get(struct ieee80211_local *local, u32 cipher,
2273 		 enum nl80211_iftype iftype);
2274 int ieee80211_cs_headroom(struct ieee80211_local *local,
2275 			  struct cfg80211_crypto_settings *crypto,
2276 			  enum nl80211_iftype iftype);
2277 void ieee80211_recalc_dtim(struct ieee80211_local *local,
2278 			   struct ieee80211_sub_if_data *sdata);
2279 int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
2280 				 const struct cfg80211_chan_def *chandef,
2281 				 enum ieee80211_chanctx_mode chanmode,
2282 				 u8 radar_detect);
2283 int ieee80211_max_num_channels(struct ieee80211_local *local);
2284 enum nl80211_chan_width ieee80211_get_sta_bw(struct ieee80211_sta *sta);
2285 void ieee80211_recalc_chanctx_chantype(struct ieee80211_local *local,
2286 				       struct ieee80211_chanctx *ctx);
2287 
2288 /* TDLS */
2289 int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2290 			const u8 *peer, u8 action_code, u8 dialog_token,
2291 			u16 status_code, u32 peer_capability,
2292 			bool initiator, const u8 *extra_ies,
2293 			size_t extra_ies_len);
2294 int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2295 			const u8 *peer, enum nl80211_tdls_operation oper);
2296 void ieee80211_tdls_peer_del_work(struct work_struct *wk);
2297 int ieee80211_tdls_channel_switch(struct wiphy *wiphy, struct net_device *dev,
2298 				  const u8 *addr, u8 oper_class,
2299 				  struct cfg80211_chan_def *chandef);
2300 void ieee80211_tdls_cancel_channel_switch(struct wiphy *wiphy,
2301 					  struct net_device *dev,
2302 					  const u8 *addr);
2303 void ieee80211_teardown_tdls_peers(struct ieee80211_sub_if_data *sdata);
2304 void ieee80211_tdls_chsw_work(struct work_struct *wk);
2305 void ieee80211_tdls_handle_disconnect(struct ieee80211_sub_if_data *sdata,
2306 				      const u8 *peer, u16 reason);
2307 const char *ieee80211_get_reason_code_string(u16 reason_code);
2308 u16 ieee80211_encode_usf(int val);
2309 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
2310 			enum nl80211_iftype type);
2311 
2312 extern const struct ethtool_ops ieee80211_ethtool_ops;
2313 
2314 u32 ieee80211_calc_expected_tx_airtime(struct ieee80211_hw *hw,
2315 				       struct ieee80211_vif *vif,
2316 				       struct ieee80211_sta *pubsta,
2317 				       int len, bool ampdu);
2318 #ifdef CONFIG_MAC80211_NOINLINE
2319 #define debug_noinline noinline
2320 #else
2321 #define debug_noinline
2322 #endif
2323 
2324 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache);
2325 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache);
2326 
2327 #endif /* IEEE80211_I_H */
2328