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