1 /******************************************************************************
2  *
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11  * Copyright(c) 2018 - 2019 Intel Corporation
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of version 2 of the GNU General Public License as
15  * published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License for more details.
21  *
22  * The full GNU General Public License is included in this distribution
23  * in the file called COPYING.
24  *
25  * Contact Information:
26  *  Intel Linux Wireless <linuxwifi@intel.com>
27  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28  *
29  * BSD LICENSE
30  *
31  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34  * Copyright(c) 2018 - 2019 Intel Corporation
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  *
41  *  * Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  *  * Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in
45  *    the documentation and/or other materials provided with the
46  *    distribution.
47  *  * Neither the name Intel Corporation nor the names of its
48  *    contributors may be used to endorse or promote products derived
49  *    from this software without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  *
63  *****************************************************************************/
64 
65 #ifndef __iwl_fw_api_scan_h__
66 #define __iwl_fw_api_scan_h__
67 
68 /* Scan Commands, Responses, Notifications */
69 
70 /* Max number of IEs for direct SSID scans in a command */
71 #define PROBE_OPTION_MAX		20
72 
73 /**
74  * struct iwl_ssid_ie - directed scan network information element
75  *
76  * Up to 20 of these may appear in REPLY_SCAN_CMD,
77  * selected by "type" bit field in struct iwl_scan_channel;
78  * each channel may select different ssids from among the 20 entries.
79  * SSID IEs get transmitted in reverse order of entry.
80  *
81  * @id: element ID
82  * @len: element length
83  * @ssid: element (SSID) data
84  */
85 struct iwl_ssid_ie {
86 	u8 id;
87 	u8 len;
88 	u8 ssid[IEEE80211_MAX_SSID_LEN];
89 } __packed; /* SCAN_DIRECT_SSID_IE_API_S_VER_1 */
90 
91 /* scan offload */
92 #define IWL_SCAN_MAX_BLACKLIST_LEN	64
93 #define IWL_SCAN_SHORT_BLACKLIST_LEN	16
94 #define IWL_SCAN_MAX_PROFILES		11
95 #define SCAN_OFFLOAD_PROBE_REQ_SIZE	512
96 
97 /* Default watchdog (in MS) for scheduled scan iteration */
98 #define IWL_SCHED_SCAN_WATCHDOG cpu_to_le16(15000)
99 
100 #define IWL_GOOD_CRC_TH_DEFAULT cpu_to_le16(1)
101 #define CAN_ABORT_STATUS 1
102 
103 #define IWL_FULL_SCAN_MULTIPLIER 5
104 #define IWL_FAST_SCHED_SCAN_ITERATIONS 3
105 #define IWL_MAX_SCHED_SCAN_PLANS 2
106 
107 enum scan_framework_client {
108 	SCAN_CLIENT_SCHED_SCAN		= BIT(0),
109 	SCAN_CLIENT_NETDETECT		= BIT(1),
110 	SCAN_CLIENT_ASSET_TRACKING	= BIT(2),
111 };
112 
113 /**
114  * struct iwl_scan_offload_blacklist - SCAN_OFFLOAD_BLACKLIST_S
115  * @ssid:		MAC address to filter out
116  * @reported_rssi:	AP rssi reported to the host
117  * @client_bitmap: clients ignore this entry  - enum scan_framework_client
118  */
119 struct iwl_scan_offload_blacklist {
120 	u8 ssid[ETH_ALEN];
121 	u8 reported_rssi;
122 	u8 client_bitmap;
123 } __packed;
124 
125 enum iwl_scan_offload_network_type {
126 	IWL_NETWORK_TYPE_BSS	= 1,
127 	IWL_NETWORK_TYPE_IBSS	= 2,
128 	IWL_NETWORK_TYPE_ANY	= 3,
129 };
130 
131 enum iwl_scan_offload_band_selection {
132 	IWL_SCAN_OFFLOAD_SELECT_2_4	= 0x4,
133 	IWL_SCAN_OFFLOAD_SELECT_5_2	= 0x8,
134 	IWL_SCAN_OFFLOAD_SELECT_ANY	= 0xc,
135 };
136 
137 /**
138  * struct iwl_scan_offload_profile - SCAN_OFFLOAD_PROFILE_S
139  * @ssid_index:		index to ssid list in fixed part
140  * @unicast_cipher:	encryption algorithm to match - bitmap
141  * @auth_alg:		authentication algorithm to match - bitmap
142  * @network_type:	enum iwl_scan_offload_network_type
143  * @band_selection:	enum iwl_scan_offload_band_selection
144  * @client_bitmap:	clients waiting for match - enum scan_framework_client
145  * @reserved:		reserved
146  */
147 struct iwl_scan_offload_profile {
148 	u8 ssid_index;
149 	u8 unicast_cipher;
150 	u8 auth_alg;
151 	u8 network_type;
152 	u8 band_selection;
153 	u8 client_bitmap;
154 	u8 reserved[2];
155 } __packed;
156 
157 /**
158  * struct iwl_scan_offload_profile_cfg - SCAN_OFFLOAD_PROFILES_CFG_API_S_VER_1
159  * @profiles:		profiles to search for match
160  * @blacklist_len:	length of blacklist
161  * @num_profiles:	num of profiles in the list
162  * @match_notify:	clients waiting for match found notification
163  * @pass_match:		clients waiting for the results
164  * @active_clients:	active clients bitmap - enum scan_framework_client
165  * @any_beacon_notify:	clients waiting for match notification without match
166  * @reserved:		reserved
167  */
168 struct iwl_scan_offload_profile_cfg {
169 	struct iwl_scan_offload_profile profiles[IWL_SCAN_MAX_PROFILES];
170 	u8 blacklist_len;
171 	u8 num_profiles;
172 	u8 match_notify;
173 	u8 pass_match;
174 	u8 active_clients;
175 	u8 any_beacon_notify;
176 	u8 reserved[2];
177 } __packed;
178 
179 /**
180  * struct iwl_scan_schedule_lmac - schedule of scan offload
181  * @delay:		delay between iterations, in seconds.
182  * @iterations:		num of scan iterations
183  * @full_scan_mul:	number of partial scans before each full scan
184  */
185 struct iwl_scan_schedule_lmac {
186 	__le16 delay;
187 	u8 iterations;
188 	u8 full_scan_mul;
189 } __packed; /* SCAN_SCHEDULE_API_S */
190 
191 enum iwl_scan_offload_complete_status {
192 	IWL_SCAN_OFFLOAD_COMPLETED	= 1,
193 	IWL_SCAN_OFFLOAD_ABORTED	= 2,
194 };
195 
196 enum iwl_scan_ebs_status {
197 	IWL_SCAN_EBS_SUCCESS,
198 	IWL_SCAN_EBS_FAILED,
199 	IWL_SCAN_EBS_CHAN_NOT_FOUND,
200 	IWL_SCAN_EBS_INACTIVE,
201 };
202 
203 /**
204  * struct iwl_scan_req_tx_cmd - SCAN_REQ_TX_CMD_API_S
205  * @tx_flags: combination of TX_CMD_FLG_*
206  * @rate_n_flags: rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is
207  *	cleared. Combination of RATE_MCS_*
208  * @sta_id: index of destination station in FW station table
209  * @reserved: for alignment and future use
210  */
211 struct iwl_scan_req_tx_cmd {
212 	__le32 tx_flags;
213 	__le32 rate_n_flags;
214 	u8 sta_id;
215 	u8 reserved[3];
216 } __packed;
217 
218 enum iwl_scan_channel_flags_lmac {
219 	IWL_UNIFIED_SCAN_CHANNEL_FULL		= BIT(27),
220 	IWL_UNIFIED_SCAN_CHANNEL_PARTIAL	= BIT(28),
221 };
222 
223 /**
224  * struct iwl_scan_channel_cfg_lmac - SCAN_CHANNEL_CFG_S_VER2
225  * @flags:		bits 1-20: directed scan to i'th ssid
226  *			other bits &enum iwl_scan_channel_flags_lmac
227  * @channel_num:	channel number 1-13 etc
228  * @iter_count:		scan iteration on this channel
229  * @iter_interval:	interval in seconds between iterations on one channel
230  */
231 struct iwl_scan_channel_cfg_lmac {
232 	__le32 flags;
233 	__le16 channel_num;
234 	__le16 iter_count;
235 	__le32 iter_interval;
236 } __packed;
237 
238 /*
239  * struct iwl_scan_probe_segment - PROBE_SEGMENT_API_S_VER_1
240  * @offset: offset in the data block
241  * @len: length of the segment
242  */
243 struct iwl_scan_probe_segment {
244 	__le16 offset;
245 	__le16 len;
246 } __packed;
247 
248 /* iwl_scan_probe_req - PROBE_REQUEST_FRAME_API_S_VER_2
249  * @mac_header: first (and common) part of the probe
250  * @band_data: band specific data
251  * @common_data: last (and common) part of the probe
252  * @buf: raw data block
253  */
254 struct iwl_scan_probe_req {
255 	struct iwl_scan_probe_segment mac_header;
256 	struct iwl_scan_probe_segment band_data[2];
257 	struct iwl_scan_probe_segment common_data;
258 	u8 buf[SCAN_OFFLOAD_PROBE_REQ_SIZE];
259 } __packed;
260 
261 enum iwl_scan_channel_flags {
262 	IWL_SCAN_CHANNEL_FLAG_EBS		= BIT(0),
263 	IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE	= BIT(1),
264 	IWL_SCAN_CHANNEL_FLAG_CACHE_ADD		= BIT(2),
265 	IWL_SCAN_CHANNEL_FLAG_EBS_FRAG		= BIT(3),
266 };
267 
268 /* struct iwl_scan_channel_opt - CHANNEL_OPTIMIZATION_API_S
269  * @flags: enum iwl_scan_channel_flags
270  * @non_ebs_ratio: defines the ratio of number of scan iterations where EBS is
271  *	involved.
272  *	1 - EBS is disabled.
273  *	2 - every second scan will be full scan(and so on).
274  */
275 struct iwl_scan_channel_opt {
276 	__le16 flags;
277 	__le16 non_ebs_ratio;
278 } __packed;
279 
280 /**
281  * enum iwl_mvm_lmac_scan_flags - LMAC scan flags
282  * @IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL: pass all beacons and probe responses
283  *	without filtering.
284  * @IWL_MVM_LMAC_SCAN_FLAG_PASSIVE: force passive scan on all channels
285  * @IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION: single channel scan
286  * @IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE: send iteration complete notification
287  * @IWL_MVM_LMAC_SCAN_FLAG_MULTIPLE_SSIDS: multiple SSID matching
288  * @IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED: all passive scans will be fragmented
289  * @IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED: insert WFA vendor-specific TPC report
290  *	and DS parameter set IEs into probe requests.
291  * @IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL: use extended dwell time on channels
292  *	1, 6 and 11.
293  * @IWL_MVM_LMAC_SCAN_FLAG_MATCH: Send match found notification on matches
294  */
295 enum iwl_mvm_lmac_scan_flags {
296 	IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL		= BIT(0),
297 	IWL_MVM_LMAC_SCAN_FLAG_PASSIVE		= BIT(1),
298 	IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION	= BIT(2),
299 	IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE	= BIT(3),
300 	IWL_MVM_LMAC_SCAN_FLAG_MULTIPLE_SSIDS	= BIT(4),
301 	IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED	= BIT(5),
302 	IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED	= BIT(6),
303 	IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL	= BIT(7),
304 	IWL_MVM_LMAC_SCAN_FLAG_MATCH		= BIT(9),
305 };
306 
307 enum iwl_scan_priority {
308 	IWL_SCAN_PRIORITY_LOW,
309 	IWL_SCAN_PRIORITY_MEDIUM,
310 	IWL_SCAN_PRIORITY_HIGH,
311 };
312 
313 enum iwl_scan_priority_ext {
314 	IWL_SCAN_PRIORITY_EXT_0_LOWEST,
315 	IWL_SCAN_PRIORITY_EXT_1,
316 	IWL_SCAN_PRIORITY_EXT_2,
317 	IWL_SCAN_PRIORITY_EXT_3,
318 	IWL_SCAN_PRIORITY_EXT_4,
319 	IWL_SCAN_PRIORITY_EXT_5,
320 	IWL_SCAN_PRIORITY_EXT_6,
321 	IWL_SCAN_PRIORITY_EXT_7_HIGHEST,
322 };
323 
324 /**
325  * struct iwl_scan_req_lmac - SCAN_REQUEST_CMD_API_S_VER_1
326  * @reserved1: for alignment and future use
327  * @n_channels: num of channels to scan
328  * @active_dwell: dwell time for active channels
329  * @passive_dwell: dwell time for passive channels
330  * @fragmented_dwell: dwell time for fragmented passive scan
331  * @extended_dwell: dwell time for channels 1, 6 and 11 (in certain cases)
332  * @reserved2: for alignment and future use
333  * @rx_chain_select: PHY_RX_CHAIN_* flags
334  * @scan_flags: &enum iwl_mvm_lmac_scan_flags
335  * @max_out_time: max time (in TU) to be out of associated channel
336  * @suspend_time: pause scan this long (TUs) when returning to service channel
337  * @flags: RXON flags
338  * @filter_flags: RXON filter
339  * @tx_cmd: tx command for active scan; for 2GHz and for 5GHz
340  * @direct_scan: list of SSIDs for directed active scan
341  * @scan_prio: enum iwl_scan_priority
342  * @iter_num: number of scan iterations
343  * @delay: delay in seconds before first iteration
344  * @schedule: two scheduling plans. The first one is finite, the second one can
345  *	be infinite.
346  * @channel_opt: channel optimization options, for full and partial scan
347  * @data: channel configuration and probe request packet.
348  */
349 struct iwl_scan_req_lmac {
350 	/* SCAN_REQUEST_FIXED_PART_API_S_VER_7 */
351 	__le32 reserved1;
352 	u8 n_channels;
353 	u8 active_dwell;
354 	u8 passive_dwell;
355 	u8 fragmented_dwell;
356 	u8 extended_dwell;
357 	u8 reserved2;
358 	__le16 rx_chain_select;
359 	__le32 scan_flags;
360 	__le32 max_out_time;
361 	__le32 suspend_time;
362 	/* RX_ON_FLAGS_API_S_VER_1 */
363 	__le32 flags;
364 	__le32 filter_flags;
365 	struct iwl_scan_req_tx_cmd tx_cmd[2];
366 	struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
367 	__le32 scan_prio;
368 	/* SCAN_REQ_PERIODIC_PARAMS_API_S */
369 	__le32 iter_num;
370 	__le32 delay;
371 	struct iwl_scan_schedule_lmac schedule[IWL_MAX_SCHED_SCAN_PLANS];
372 	struct iwl_scan_channel_opt channel_opt[2];
373 	u8 data[];
374 } __packed;
375 
376 /**
377  * struct iwl_scan_results_notif - scan results for one channel -
378  *	SCAN_RESULT_NTF_API_S_VER_3
379  * @channel: which channel the results are from
380  * @band: 0 for 5.2 GHz, 1 for 2.4 GHz
381  * @probe_status: SCAN_PROBE_STATUS_*, indicates success of probe request
382  * @num_probe_not_sent: # of request that weren't sent due to not enough time
383  * @duration: duration spent in channel, in usecs
384  */
385 struct iwl_scan_results_notif {
386 	u8 channel;
387 	u8 band;
388 	u8 probe_status;
389 	u8 num_probe_not_sent;
390 	__le32 duration;
391 } __packed;
392 
393 /**
394  * struct iwl_lmac_scan_complete_notif - notifies end of scanning (all channels)
395  *	SCAN_COMPLETE_NTF_API_S_VER_3
396  * @scanned_channels: number of channels scanned (and number of valid results)
397  * @status: one of SCAN_COMP_STATUS_*
398  * @bt_status: BT on/off status
399  * @last_channel: last channel that was scanned
400  * @tsf_low: TSF timer (lower half) in usecs
401  * @tsf_high: TSF timer (higher half) in usecs
402  * @results: an array of scan results, only "scanned_channels" of them are valid
403  */
404 struct iwl_lmac_scan_complete_notif {
405 	u8 scanned_channels;
406 	u8 status;
407 	u8 bt_status;
408 	u8 last_channel;
409 	__le32 tsf_low;
410 	__le32 tsf_high;
411 	struct iwl_scan_results_notif results[];
412 } __packed;
413 
414 /**
415  * struct iwl_scan_offload_complete - PERIODIC_SCAN_COMPLETE_NTF_API_S_VER_2
416  * @last_schedule_line: last schedule line executed (fast or regular)
417  * @last_schedule_iteration: last scan iteration executed before scan abort
418  * @status: &enum iwl_scan_offload_complete_status
419  * @ebs_status: EBS success status &enum iwl_scan_ebs_status
420  * @time_after_last_iter: time in seconds elapsed after last iteration
421  * @reserved: reserved
422  */
423 struct iwl_periodic_scan_complete {
424 	u8 last_schedule_line;
425 	u8 last_schedule_iteration;
426 	u8 status;
427 	u8 ebs_status;
428 	__le32 time_after_last_iter;
429 	__le32 reserved;
430 } __packed;
431 
432 /* UMAC Scan API */
433 
434 /* The maximum of either of these cannot exceed 8, because we use an
435  * 8-bit mask (see IWL_MVM_SCAN_MASK in mvm.h).
436  */
437 #define IWL_MVM_MAX_UMAC_SCANS 4
438 #define IWL_MVM_MAX_LMAC_SCANS 1
439 
440 enum scan_config_flags {
441 	SCAN_CONFIG_FLAG_ACTIVATE			= BIT(0),
442 	SCAN_CONFIG_FLAG_DEACTIVATE			= BIT(1),
443 	SCAN_CONFIG_FLAG_FORBID_CHUB_REQS		= BIT(2),
444 	SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS		= BIT(3),
445 	SCAN_CONFIG_FLAG_SET_TX_CHAINS			= BIT(8),
446 	SCAN_CONFIG_FLAG_SET_RX_CHAINS			= BIT(9),
447 	SCAN_CONFIG_FLAG_SET_AUX_STA_ID			= BIT(10),
448 	SCAN_CONFIG_FLAG_SET_ALL_TIMES			= BIT(11),
449 	SCAN_CONFIG_FLAG_SET_EFFECTIVE_TIMES		= BIT(12),
450 	SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS		= BIT(13),
451 	SCAN_CONFIG_FLAG_SET_LEGACY_RATES		= BIT(14),
452 	SCAN_CONFIG_FLAG_SET_MAC_ADDR			= BIT(15),
453 	SCAN_CONFIG_FLAG_SET_FRAGMENTED			= BIT(16),
454 	SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED		= BIT(17),
455 	SCAN_CONFIG_FLAG_SET_CAM_MODE			= BIT(18),
456 	SCAN_CONFIG_FLAG_CLEAR_CAM_MODE			= BIT(19),
457 	SCAN_CONFIG_FLAG_SET_PROMISC_MODE		= BIT(20),
458 	SCAN_CONFIG_FLAG_CLEAR_PROMISC_MODE		= BIT(21),
459 	SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED		= BIT(22),
460 	SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED		= BIT(23),
461 
462 	/* Bits 26-31 are for num of channels in channel_array */
463 #define SCAN_CONFIG_N_CHANNELS(n) ((n) << 26)
464 };
465 
466 enum scan_config_rates {
467 	/* OFDM basic rates */
468 	SCAN_CONFIG_RATE_6M	= BIT(0),
469 	SCAN_CONFIG_RATE_9M	= BIT(1),
470 	SCAN_CONFIG_RATE_12M	= BIT(2),
471 	SCAN_CONFIG_RATE_18M	= BIT(3),
472 	SCAN_CONFIG_RATE_24M	= BIT(4),
473 	SCAN_CONFIG_RATE_36M	= BIT(5),
474 	SCAN_CONFIG_RATE_48M	= BIT(6),
475 	SCAN_CONFIG_RATE_54M	= BIT(7),
476 	/* CCK basic rates */
477 	SCAN_CONFIG_RATE_1M	= BIT(8),
478 	SCAN_CONFIG_RATE_2M	= BIT(9),
479 	SCAN_CONFIG_RATE_5M	= BIT(10),
480 	SCAN_CONFIG_RATE_11M	= BIT(11),
481 
482 	/* Bits 16-27 are for supported rates */
483 #define SCAN_CONFIG_SUPPORTED_RATE(rate)	((rate) << 16)
484 };
485 
486 enum iwl_channel_flags {
487 	IWL_CHANNEL_FLAG_EBS				= BIT(0),
488 	IWL_CHANNEL_FLAG_ACCURATE_EBS			= BIT(1),
489 	IWL_CHANNEL_FLAG_EBS_ADD			= BIT(2),
490 	IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE	= BIT(3),
491 };
492 
493 /**
494  * struct iwl_scan_dwell
495  * @active:		default dwell time for active scan
496  * @passive:		default dwell time for passive scan
497  * @fragmented:		default dwell time for fragmented scan
498  * @extended:		default dwell time for channels 1, 6 and 11
499  */
500 struct iwl_scan_dwell {
501 	u8 active;
502 	u8 passive;
503 	u8 fragmented;
504 	u8 extended;
505 } __packed;
506 
507 /**
508  * struct iwl_scan_config
509  * @flags:			enum scan_config_flags
510  * @tx_chains:			valid_tx antenna - ANT_* definitions
511  * @rx_chains:			valid_rx antenna - ANT_* definitions
512  * @legacy_rates:		default legacy rates - enum scan_config_rates
513  * @out_of_channel_time:	default max out of serving channel time
514  * @suspend_time:		default max suspend time
515  * @dwell:			dwells for the scan
516  * @mac_addr:			default mac address to be used in probes
517  * @bcast_sta_id:		the index of the station in the fw
518  * @channel_flags:		default channel flags - enum iwl_channel_flags
519  *				scan_config_channel_flag
520  * @channel_array:		default supported channels
521  */
522 struct iwl_scan_config_v1 {
523 	__le32 flags;
524 	__le32 tx_chains;
525 	__le32 rx_chains;
526 	__le32 legacy_rates;
527 	__le32 out_of_channel_time;
528 	__le32 suspend_time;
529 	struct iwl_scan_dwell dwell;
530 	u8 mac_addr[ETH_ALEN];
531 	u8 bcast_sta_id;
532 	u8 channel_flags;
533 	u8 channel_array[];
534 } __packed; /* SCAN_CONFIG_DB_CMD_API_S */
535 
536 #define SCAN_TWO_LMACS 2
537 #define SCAN_LB_LMAC_IDX 0
538 #define SCAN_HB_LMAC_IDX 1
539 
540 struct iwl_scan_config {
541 	__le32 flags;
542 	__le32 tx_chains;
543 	__le32 rx_chains;
544 	__le32 legacy_rates;
545 	__le32 out_of_channel_time[SCAN_TWO_LMACS];
546 	__le32 suspend_time[SCAN_TWO_LMACS];
547 	struct iwl_scan_dwell dwell;
548 	u8 mac_addr[ETH_ALEN];
549 	u8 bcast_sta_id;
550 	u8 channel_flags;
551 	u8 channel_array[];
552 } __packed; /* SCAN_CONFIG_DB_CMD_API_S_3 */
553 
554 /**
555  * enum iwl_umac_scan_flags - UMAC scan flags
556  * @IWL_UMAC_SCAN_FLAG_PREEMPTIVE: scan process triggered by this scan request
557  *	can be preempted by other scan requests with higher priority.
558  *	The low priority scan will be resumed when the higher proirity scan is
559  *	completed.
560  * @IWL_UMAC_SCAN_FLAG_START_NOTIF: notification will be sent to the driver
561  *	when scan starts.
562  */
563 enum iwl_umac_scan_flags {
564 	IWL_UMAC_SCAN_FLAG_PREEMPTIVE		= BIT(0),
565 	IWL_UMAC_SCAN_FLAG_START_NOTIF		= BIT(1),
566 };
567 
568 enum iwl_umac_scan_uid_offsets {
569 	IWL_UMAC_SCAN_UID_TYPE_OFFSET		= 0,
570 	IWL_UMAC_SCAN_UID_SEQ_OFFSET		= 8,
571 };
572 
573 enum iwl_umac_scan_general_flags {
574 	IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC		= BIT(0),
575 	IWL_UMAC_SCAN_GEN_FLAGS_OVER_BT			= BIT(1),
576 	IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL		= BIT(2),
577 	IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE			= BIT(3),
578 	IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT		= BIT(4),
579 	IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE		= BIT(5),
580 	IWL_UMAC_SCAN_GEN_FLAGS_MULTIPLE_SSID		= BIT(6),
581 	IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED		= BIT(7),
582 	IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED		= BIT(8),
583 	IWL_UMAC_SCAN_GEN_FLAGS_MATCH			= BIT(9),
584 	IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL		= BIT(10),
585 	/* Extended dwell is obselete when adaptive dwell is used, making this
586 	 * bit reusable. Hence, probe request defer is used only when adaptive
587 	 * dwell is supported. */
588 	IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP	= BIT(10),
589 	IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED	= BIT(11),
590 	IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL		= BIT(13),
591 	IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME		= BIT(14),
592 	IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE	= BIT(15),
593 };
594 
595 /**
596  * enum iwl_umac_scan_general_flags2 - UMAC scan general flags #2
597  * @IWL_UMAC_SCAN_GEN_FLAGS2_NOTIF_PER_CHNL: Whether to send a complete
598  *	notification per channel or not.
599  * @IWL_UMAC_SCAN_GEN_FLAGS2_ALLOW_CHNL_REORDER: Whether to allow channel
600  *	reorder optimization or not.
601  */
602 enum iwl_umac_scan_general_flags2 {
603 	IWL_UMAC_SCAN_GEN_FLAGS2_NOTIF_PER_CHNL		= BIT(0),
604 	IWL_UMAC_SCAN_GEN_FLAGS2_ALLOW_CHNL_REORDER	= BIT(1),
605 };
606 
607 /**
608  * struct iwl_scan_channel_cfg_umac
609  * @flags:		bitmap - 0-19:	directed scan to i'th ssid.
610  * @channel_num:	channel number 1-13 etc.
611  * @iter_count:		repetition count for the channel.
612  * @iter_interval:	interval between two scan iterations on one channel.
613  */
614 struct iwl_scan_channel_cfg_umac {
615 	__le32 flags;
616 	u8 channel_num;
617 	u8 iter_count;
618 	__le16 iter_interval;
619 } __packed; /* SCAN_CHANNEL_CFG_S_VER2 */
620 
621 /**
622  * struct iwl_scan_umac_schedule
623  * @interval: interval in seconds between scan iterations
624  * @iter_count: num of scan iterations for schedule plan, 0xff for infinite loop
625  * @reserved: for alignment and future use
626  */
627 struct iwl_scan_umac_schedule {
628 	__le16 interval;
629 	u8 iter_count;
630 	u8 reserved;
631 } __packed; /* SCAN_SCHED_PARAM_API_S_VER_1 */
632 
633 /**
634  * struct iwl_scan_req_umac_tail - the rest of the UMAC scan request command
635  *      parameters following channels configuration array.
636  * @schedule: two scheduling plans.
637  * @delay: delay in TUs before starting the first scan iteration
638  * @reserved: for future use and alignment
639  * @preq: probe request with IEs blocks
640  * @direct_scan: list of SSIDs for directed active scan
641  */
642 struct iwl_scan_req_umac_tail {
643 	/* SCAN_PERIODIC_PARAMS_API_S_VER_1 */
644 	struct iwl_scan_umac_schedule schedule[IWL_MAX_SCHED_SCAN_PLANS];
645 	__le16 delay;
646 	__le16 reserved;
647 	/* SCAN_PROBE_PARAMS_API_S_VER_1 */
648 	struct iwl_scan_probe_req preq;
649 	struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
650 } __packed;
651 
652 /**
653  * struct iwl_scan_umac_chan_param
654  * @flags: channel flags &enum iwl_scan_channel_flags
655  * @count: num of channels in scan request
656  * @reserved: for future use and alignment
657  */
658 struct iwl_scan_umac_chan_param {
659 	u8 flags;
660 	u8 count;
661 	__le16 reserved;
662 } __packed; /*SCAN_CHANNEL_PARAMS_API_S_VER_1 */
663 
664 /**
665  * struct iwl_scan_req_umac
666  * @flags: &enum iwl_umac_scan_flags
667  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
668  * @ooc_priority: out of channel priority - &enum iwl_scan_priority
669  * @general_flags: &enum iwl_umac_scan_general_flags
670  * @scan_start_mac_id: report the scan start TSF time according to this mac TSF
671  * @extended_dwell: dwell time for channels 1, 6 and 11
672  * @active_dwell: dwell time for active scan per LMAC
673  * @passive_dwell: dwell time for passive scan per LMAC
674  * @fragmented_dwell: dwell time for fragmented passive scan
675  * @adwell_default_n_aps: for adaptive dwell the default number of APs
676  *	per channel
677  * @adwell_default_n_aps_social: for adaptive dwell the default
678  *	number of APs per social (1,6,11) channel
679  * @general_flags2: &enum iwl_umac_scan_general_flags2
680  * @adwell_max_budget: for adaptive dwell the maximal budget of TU to be added
681  *	to total scan time
682  * @max_out_time: max out of serving channel time, per LMAC - for CDB there
683  *	are 2 LMACs
684  * @suspend_time: max suspend time, per LMAC - for CDB there are 2 LMACs
685  * @scan_priority: scan internal prioritization &enum iwl_scan_priority
686  * @num_of_fragments: Number of fragments needed for full coverage per band.
687  *	Relevant only for fragmented scan.
688  * @channel: &struct iwl_scan_umac_chan_param
689  * @reserved: for future use and alignment
690  * @reserved3: for future use and alignment
691  * @data: &struct iwl_scan_channel_cfg_umac and
692  *	&struct iwl_scan_req_umac_tail
693  */
694 struct iwl_scan_req_umac {
695 	__le32 flags;
696 	__le32 uid;
697 	__le32 ooc_priority;
698 	__le16 general_flags;
699 	u8 reserved;
700 	u8 scan_start_mac_id;
701 	union {
702 		struct {
703 			u8 extended_dwell;
704 			u8 active_dwell;
705 			u8 passive_dwell;
706 			u8 fragmented_dwell;
707 			__le32 max_out_time;
708 			__le32 suspend_time;
709 			__le32 scan_priority;
710 			struct iwl_scan_umac_chan_param channel;
711 			u8 data[];
712 		} v1; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_1 */
713 		struct {
714 			u8 extended_dwell;
715 			u8 active_dwell;
716 			u8 passive_dwell;
717 			u8 fragmented_dwell;
718 			__le32 max_out_time[SCAN_TWO_LMACS];
719 			__le32 suspend_time[SCAN_TWO_LMACS];
720 			__le32 scan_priority;
721 			struct iwl_scan_umac_chan_param channel;
722 			u8 data[];
723 		} v6; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_6 */
724 		struct {
725 			u8 active_dwell;
726 			u8 passive_dwell;
727 			u8 fragmented_dwell;
728 			u8 adwell_default_n_aps;
729 			u8 adwell_default_n_aps_social;
730 			u8 reserved3;
731 			__le16 adwell_max_budget;
732 			__le32 max_out_time[SCAN_TWO_LMACS];
733 			__le32 suspend_time[SCAN_TWO_LMACS];
734 			__le32 scan_priority;
735 			struct iwl_scan_umac_chan_param channel;
736 			u8 data[];
737 		} v7; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_7 */
738 		struct {
739 			u8 active_dwell[SCAN_TWO_LMACS];
740 			u8 reserved2;
741 			u8 adwell_default_n_aps;
742 			u8 adwell_default_n_aps_social;
743 			u8 general_flags2;
744 			__le16 adwell_max_budget;
745 			__le32 max_out_time[SCAN_TWO_LMACS];
746 			__le32 suspend_time[SCAN_TWO_LMACS];
747 			__le32 scan_priority;
748 			u8 passive_dwell[SCAN_TWO_LMACS];
749 			u8 num_of_fragments[SCAN_TWO_LMACS];
750 			struct iwl_scan_umac_chan_param channel;
751 			u8 data[];
752 		} v8; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_8 */
753 		struct {
754 			u8 active_dwell[SCAN_TWO_LMACS];
755 			u8 adwell_default_hb_n_aps;
756 			u8 adwell_default_lb_n_aps;
757 			u8 adwell_default_n_aps_social;
758 			u8 general_flags2;
759 			__le16 adwell_max_budget;
760 			__le32 max_out_time[SCAN_TWO_LMACS];
761 			__le32 suspend_time[SCAN_TWO_LMACS];
762 			__le32 scan_priority;
763 			u8 passive_dwell[SCAN_TWO_LMACS];
764 			u8 num_of_fragments[SCAN_TWO_LMACS];
765 			struct iwl_scan_umac_chan_param channel;
766 			u8 data[];
767 		} v9; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_9 */
768 	};
769 } __packed;
770 
771 #define IWL_SCAN_REQ_UMAC_SIZE_V8 sizeof(struct iwl_scan_req_umac)
772 #define IWL_SCAN_REQ_UMAC_SIZE_V7 48
773 #define IWL_SCAN_REQ_UMAC_SIZE_V6 44
774 #define IWL_SCAN_REQ_UMAC_SIZE_V1 36
775 
776 /**
777  * struct iwl_umac_scan_abort
778  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
779  * @flags: reserved
780  */
781 struct iwl_umac_scan_abort {
782 	__le32 uid;
783 	__le32 flags;
784 } __packed; /* SCAN_ABORT_CMD_UMAC_API_S_VER_1 */
785 
786 /**
787  * struct iwl_umac_scan_complete
788  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
789  * @last_schedule: last scheduling line
790  * @last_iter: last scan iteration number
791  * @status: &enum iwl_scan_offload_complete_status
792  * @ebs_status: &enum iwl_scan_ebs_status
793  * @time_from_last_iter: time elapsed from last iteration
794  * @reserved: for future use
795  */
796 struct iwl_umac_scan_complete {
797 	__le32 uid;
798 	u8 last_schedule;
799 	u8 last_iter;
800 	u8 status;
801 	u8 ebs_status;
802 	__le32 time_from_last_iter;
803 	__le32 reserved;
804 } __packed; /* SCAN_COMPLETE_NTF_UMAC_API_S_VER_1 */
805 
806 #define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 5
807 #define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN    7
808 
809 /**
810  * struct iwl_scan_offload_profile_match_v1 - match information
811  * @bssid: matched bssid
812  * @reserved: reserved
813  * @channel: channel where the match occurred
814  * @energy: energy
815  * @matching_feature: feature matches
816  * @matching_channels: bitmap of channels that matched, referencing
817  *	the channels passed in the scan offload request.
818  */
819 struct iwl_scan_offload_profile_match_v1 {
820 	u8 bssid[ETH_ALEN];
821 	__le16 reserved;
822 	u8 channel;
823 	u8 energy;
824 	u8 matching_feature;
825 	u8 matching_channels[SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1];
826 } __packed; /* SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_1 */
827 
828 /**
829  * struct iwl_scan_offload_profiles_query_v1 - match results query response
830  * @matched_profiles: bitmap of matched profiles, referencing the
831  *	matches passed in the scan offload request
832  * @last_scan_age: age of the last offloaded scan
833  * @n_scans_done: number of offloaded scans done
834  * @gp2_d0u: GP2 when D0U occurred
835  * @gp2_invoked: GP2 when scan offload was invoked
836  * @resume_while_scanning: not used
837  * @self_recovery: obsolete
838  * @reserved: reserved
839  * @matches: array of match information, one for each match
840  */
841 struct iwl_scan_offload_profiles_query_v1 {
842 	__le32 matched_profiles;
843 	__le32 last_scan_age;
844 	__le32 n_scans_done;
845 	__le32 gp2_d0u;
846 	__le32 gp2_invoked;
847 	u8 resume_while_scanning;
848 	u8 self_recovery;
849 	__le16 reserved;
850 	struct iwl_scan_offload_profile_match_v1 matches[IWL_SCAN_MAX_PROFILES];
851 } __packed; /* SCAN_OFFLOAD_PROFILES_QUERY_RSP_S_VER_2 */
852 
853 /**
854  * struct iwl_scan_offload_profile_match - match information
855  * @bssid: matched bssid
856  * @reserved: reserved
857  * @channel: channel where the match occurred
858  * @energy: energy
859  * @matching_feature: feature matches
860  * @matching_channels: bitmap of channels that matched, referencing
861  *	the channels passed in the scan offload request.
862  */
863 struct iwl_scan_offload_profile_match {
864 	u8 bssid[ETH_ALEN];
865 	__le16 reserved;
866 	u8 channel;
867 	u8 energy;
868 	u8 matching_feature;
869 	u8 matching_channels[SCAN_OFFLOAD_MATCHING_CHANNELS_LEN];
870 } __packed; /* SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_2 */
871 
872 /**
873  * struct iwl_scan_offload_profiles_query - match results query response
874  * @matched_profiles: bitmap of matched profiles, referencing the
875  *	matches passed in the scan offload request
876  * @last_scan_age: age of the last offloaded scan
877  * @n_scans_done: number of offloaded scans done
878  * @gp2_d0u: GP2 when D0U occurred
879  * @gp2_invoked: GP2 when scan offload was invoked
880  * @resume_while_scanning: not used
881  * @self_recovery: obsolete
882  * @reserved: reserved
883  * @matches: array of match information, one for each match
884  */
885 struct iwl_scan_offload_profiles_query {
886 	__le32 matched_profiles;
887 	__le32 last_scan_age;
888 	__le32 n_scans_done;
889 	__le32 gp2_d0u;
890 	__le32 gp2_invoked;
891 	u8 resume_while_scanning;
892 	u8 self_recovery;
893 	__le16 reserved;
894 	struct iwl_scan_offload_profile_match matches[IWL_SCAN_MAX_PROFILES];
895 } __packed; /* SCAN_OFFLOAD_PROFILES_QUERY_RSP_S_VER_3 */
896 
897 /**
898  * struct iwl_umac_scan_iter_complete_notif - notifies end of scanning iteration
899  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
900  * @scanned_channels: number of channels scanned and number of valid elements in
901  *	results array
902  * @status: one of SCAN_COMP_STATUS_*
903  * @bt_status: BT on/off status
904  * @last_channel: last channel that was scanned
905  * @start_tsf: TSF timer in usecs of the scan start time for the mac specified
906  *	in &struct iwl_scan_req_umac.
907  * @results: array of scan results, length in @scanned_channels
908  */
909 struct iwl_umac_scan_iter_complete_notif {
910 	__le32 uid;
911 	u8 scanned_channels;
912 	u8 status;
913 	u8 bt_status;
914 	u8 last_channel;
915 	__le64 start_tsf;
916 	struct iwl_scan_results_notif results[];
917 } __packed; /* SCAN_ITER_COMPLETE_NTF_UMAC_API_S_VER_2 */
918 
919 #endif /* __iwl_fw_api_scan_h__ */
920