xref: /wlan-dirver/qca-wifi-host-cmn/os_if/linux/scan/inc/wlan_cfg80211_scan.h (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931) !
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: declares driver functions interfacing with linux kernel
22  */
23 
24 
25 #ifndef _WLAN_CFG80211_SCAN_H_
26 #define _WLAN_CFG80211_SCAN_H_
27 
28 #include <linux/version.h>
29 #include <linux/netdevice.h>
30 #include <net/cfg80211.h>
31 #include <qca_vendor.h>
32 #include <wlan_scan_public_structs.h>
33 #include <qdf_list.h>
34 #include <qdf_types.h>
35 #include <wlan_scan_ucfg_api.h>
36 #include <wlan_mgmt_txrx_utils_api.h>
37 
38 /* Max number of scans allowed from userspace */
39 #define WLAN_MAX_SCAN_COUNT 8
40 
41 extern const struct nla_policy cfg80211_scan_policy[
42 			QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1];
43 
44 #define FEATURE_ABORT_SCAN_VENDOR_COMMANDS \
45 	{ \
46 		.info.vendor_id = QCA_NL80211_VENDOR_ID, \
47 		.info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ABORT_SCAN, \
48 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | \
49 			WIPHY_VENDOR_CMD_NEED_NETDEV | \
50 			WIPHY_VENDOR_CMD_NEED_RUNNING, \
51 		.doit = wlan_hdd_vendor_abort_scan, \
52 		vendor_command_policy(cfg80211_scan_policy, \
53 				      QCA_WLAN_VENDOR_ATTR_SCAN_MAX) \
54 	},
55 
56 /* GPS application requirement */
57 #define QCOM_VENDOR_IE_ID 221
58 #define QCOM_OUI1         0x00
59 #define QCOM_OUI2         0xA0
60 #define QCOM_OUI3         0xC6
61 #define QCOM_VENDOR_IE_AGE_TYPE  0x100
62 #define QCOM_VENDOR_IE_AGE_LEN   (sizeof(qcom_ie_age) - 2)
63 #define SCAN_DONE_EVENT_BUF_SIZE 4096
64 #define SCAN_WAKE_LOCK_CONNECT_DURATION (1 * 1000) /* in msec */
65 #define SCAN_WAKE_LOCK_SCAN_DURATION (5 * 1000) /* in msec */
66 
67 /**
68  * typedef qcom_ie_age - age ie
69  * @element_id: Element id
70  * @len: Length
71  * @oui_1: OUI 1
72  * @oui_2: OUI 2
73  * @oui_3: OUI 3
74  * @type: Type
75  * @age: Age
76  * @tsf_delta: tsf delta from FW
77  * @beacon_tsf: original beacon TSF
78  * @seq_ctrl: sequence control field
79  */
80 typedef struct {
81 	u8 element_id;
82 	u8 len;
83 	u8 oui_1;
84 	u8 oui_2;
85 	u8 oui_3;
86 	u32 type;
87 	u32 age;
88 	u32 tsf_delta;
89 	u64 beacon_tsf;
90 	u16 seq_ctrl;
91 } __attribute__ ((packed)) qcom_ie_age;
92 
93 /**
94  * struct osif_scan_pdev - OS scan private structure
95  * @scan_req_q: Scan request queue
96  * @scan_req_q_lock: Protect scan request queue
97  * @req_id: Scan request Id
98  * @runtime_pm_lock: Runtime suspend lock
99  * @scan_wake_lock: Scan wake lock
100  */
101 struct osif_scan_pdev{
102 	qdf_list_t scan_req_q;
103 	qdf_mutex_t scan_req_q_lock;
104 	wlan_scan_requester req_id;
105 	qdf_runtime_lock_t runtime_pm_lock;
106 	qdf_wake_lock_t scan_wake_lock;
107 };
108 
109 /*
110  * enum scan_source - scan request source
111  * @NL_SCAN: Scan initiated from NL
112  * @VENDOR_SCAN: Scan intiated from vendor command
113  */
114 enum scan_source {
115 	NL_SCAN,
116 	VENDOR_SCAN,
117 };
118 
119 /**
120  * struct scan_req - Scan Request entry
121  * @node : List entry element
122  * @scan_request: scan request holder
123  * @scan_id: scan identifier used across host layers which is generated at WMI
124  * @source: scan request originator (NL/Vendor scan)
125  * @dev: net device (same as what is in scan_request)
126  * @scan_start_timestamp: scan start time
127  *
128  * Scan request linked list element
129  */
130 struct scan_req {
131 	qdf_list_node_t node;
132 	struct cfg80211_scan_request *scan_request;
133 	uint32_t scan_id;
134 	uint8_t source;
135 	struct net_device *dev;
136 	qdf_time_t scan_start_timestamp;
137 };
138 
139 /**
140  * struct scan_params - Scan params
141  * @source: scan request source
142  * @default_ie: default scan ie
143  * @vendor_ie: vendor ie
144  * @priority: scan priority
145  * @half_rate: Half rate flag
146  * @quarter_rate: Quarter rate flag
147  * @strict_pscan: strict passive scan flag
148  * @dwell_time_active: Active dwell time. Ignored if zero or inapplicable.
149  * @dwell_time_active_2g: 2.4 GHz specific active dwell time. Ignored if zero or
150  * inapplicable.
151  * @dwell_time_passive: Passive dwell time. Ignored if zero or inapplicable.
152  * @dwell_time_active_6g: 6 GHz specific active dwell time. Ignored if zero or
153  * inapplicable.
154  * @dwell_time_passive_6g: 6 GHz specific passive dwell time. Ignored if zero or
155  * inapplicable.
156  * @scan_probe_unicast_ra: Use BSSID in probe request frame RA.
157  * @scan_f_2ghz: Scan only 2GHz channels
158  * @scan_f_5ghz: Scan only 5+6GHz channels
159  */
160 struct scan_params {
161 	uint8_t source;
162 	struct element_info default_ie;
163 	struct element_info vendor_ie;
164 	enum scan_priority priority;
165 	bool half_rate;
166 	bool quarter_rate;
167 	bool strict_pscan;
168 	uint32_t dwell_time_active;
169 	uint32_t dwell_time_active_2g;
170 	uint32_t dwell_time_passive;
171 	uint32_t dwell_time_active_6g;
172 	uint32_t dwell_time_passive_6g;
173 	bool scan_probe_unicast_ra;
174 	bool scan_f_2ghz;
175 	bool scan_f_5ghz;
176 };
177 
178 /**
179  * struct wlan_cfg80211_inform_bss - BSS inform data
180  * @chan: channel the frame was received on
181  * @mgmt: beacon/probe resp frame
182  * @frame_len: frame length
183  * @rssi: signal strength in mBm (100*dBm)
184  * @boottime_ns: timestamp (CLOCK_BOOTTIME) when the information was received.
185  * @per_chain_rssi: per chain rssi received
186  */
187 struct wlan_cfg80211_inform_bss {
188 	struct ieee80211_channel *chan;
189 	struct ieee80211_mgmt *mgmt;
190 	size_t frame_len;
191 	int rssi;
192 	uint64_t boottime_ns;
193 	uint8_t per_chain_rssi[WLAN_MGMT_TXRX_HOST_MAX_ANTENNA];
194 };
195 
196 
197 #ifdef FEATURE_WLAN_SCAN_PNO
198 /**
199  * wlan_cfg80211_sched_scan_start() - cfg80211 scheduled scan(pno) start
200  * @vdev: vdev pointer
201  * @request: Pointer to cfg80211 scheduled scan start request
202  * @scan_backoff_multiplier: multiply scan period by this after max cycles
203  *
204  * Return: 0 for success, non zero for failure
205  */
206 int wlan_cfg80211_sched_scan_start(struct wlan_objmgr_vdev *vdev,
207 				   struct cfg80211_sched_scan_request *request,
208 				   uint8_t scan_backoff_multiplier);
209 
210 /**
211  * wlan_cfg80211_sched_scan_stop() - cfg80211 scheduled scan(pno) stop
212  * @vdev: vdev pointer
213  *
214  * Return: 0 for success, non zero for failure
215  */
216 int wlan_cfg80211_sched_scan_stop(struct wlan_objmgr_vdev *vdev);
217 #endif
218 
219 /**
220  * wlan_scan_runtime_pm_init() - API to initialize runtime pm context for scan
221  * @pdev: Pointer to pdev
222  *
223  * This will help to initialize scan runtime pm context separately.
224  *
225  * Return: QDF_STATUS
226  */
227 QDF_STATUS wlan_scan_runtime_pm_init(struct wlan_objmgr_pdev *pdev);
228 
229 /**
230  * wlan_scan_runtime_pm_deinit() - API to deinitialize runtime pm
231  * for scan.
232  * @pdev: Pointer to pdev
233  *
234  * This will help to deinitialize scan runtime pm before deinitialize
235  * HIF
236  *
237  * Return: void
238  */
239 void wlan_scan_runtime_pm_deinit(struct wlan_objmgr_pdev *pdev);
240 
241 /**
242  * wlan_cfg80211_scan_priv_init() - API to initialize cfg80211 scan
243  * @pdev: Pointer to net device
244  *
245  * API to initialize cfg80211 scan module.
246  *
247  * Return: QDF_STATUS
248  */
249 QDF_STATUS wlan_cfg80211_scan_priv_init(struct wlan_objmgr_pdev *pdev);
250 
251 /**
252  * wlan_cfg80211_scan_priv_deinit() - API to deinitialize cfg80211 scan
253  * @pdev: Pointer to net device
254  *
255  * API to deinitialize cfg80211 scan module.
256  *
257  * Return: QDF_STATUS
258  */
259 QDF_STATUS wlan_cfg80211_scan_priv_deinit(
260 		struct wlan_objmgr_pdev *pdev);
261 
262 /**
263  * wlan_cfg80211_scan() - API to process cfg80211 scan request
264  * @vdev: Pointer to vdev
265  * @request: Pointer to scan request
266  * @params: scan params
267  *
268  * API to trigger scan and update cfg80211 scan database.
269  * scan dump command can be used to fetch scan results
270  * on receipt of scan complete event.
271  *
272  * Return: 0 for success, non zero for failure
273  */
274 int wlan_cfg80211_scan(struct wlan_objmgr_vdev *vdev,
275 		       struct cfg80211_scan_request *request,
276 		       struct scan_params *params);
277 
278 /**
279  * wlan_cfg80211_inform_bss_frame_data() - API to inform beacon to cfg80211
280  * @wiphy: wiphy
281  * @bss: bss data
282  *
283  * API to inform beacon to cfg80211
284  *
285  * Return: pointer to bss entry
286  */
287 struct cfg80211_bss *
288 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
289 		struct wlan_cfg80211_inform_bss *bss);
290 
291 /**
292  * wlan_cfg80211_inform_bss_frame() - API to inform beacon to cfg80211
293  * @pdev: Pointer to pdev
294  * @scan_params: scan entry
295  *
296  * API to inform beacon to cfg80211
297  *
298  * Return: void
299  */
300 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev,
301 	struct scan_cache_entry *scan_params);
302 
303 /**
304  * __wlan_cfg80211_unlink_bss_list() - flush bss from the kernel cache
305  * @wiphy: wiphy
306  * @pdev: pdev object
307  * @bssid: bssid of the BSS to find
308  * @ssid: ssid of the BSS to find
309  * @ssid_len: ssid len of of the BSS to find
310  *
311  * Return: QDF_STATUS
312  */
313 QDF_STATUS __wlan_cfg80211_unlink_bss_list(struct wiphy *wiphy,
314 					   struct wlan_objmgr_pdev *pdev,
315 					   uint8_t *bssid, uint8_t *ssid,
316 					   uint8_t ssid_len);
317 
318 /**
319  * wlan_cfg80211_get_bss() - Get the bss entry matching the chan, bssid and ssid
320  * @wiphy: wiphy
321  * @channel: channel of the BSS to find
322  * @bssid: bssid of the BSS to find
323  * @ssid: ssid of the BSS to find
324  * @ssid_len: ssid len of of the BSS to find
325  *
326  * The API is a wrapper to get bss from kernel matching the chan,
327  * bssid and ssid
328  *
329  * Return: bss structure if found else NULL
330  */
331 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy,
332 					   struct ieee80211_channel *channel,
333 					   const u8 *bssid,
334 					   const u8 *ssid, size_t ssid_len);
335 
336 /*
337  * wlan_cfg80211_unlink_bss_list : flush bss from the kernel cache
338  * @pdev: Pointer to pdev
339  * @scan_entry: scan entry
340  *
341  * Return: bss which is unlinked from kernel cache
342  */
343 void wlan_cfg80211_unlink_bss_list(struct wlan_objmgr_pdev *pdev,
344 				   struct scan_cache_entry *scan_entry);
345 
346 /**
347  * wlan_vendor_abort_scan() - API to vendor abort scan
348  * @pdev: Pointer to pdev
349  * @data: pointer to data
350  * @data_len: Data length
351  *
352  * API to abort scan through vendor command
353  *
354  * Return: 0 for success, non zero for failure
355  */
356 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev,
357 				const void *data, int data_len);
358 
359 /**
360  * wlan_cfg80211_abort_scan() - API to abort scan through cfg80211
361  * @pdev: Pointer to pdev
362  *
363  * API to abort scan through cfg80211 request
364  *
365  * Return: 0 for success, non zero for failure
366  */
367 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev);
368 
369 /**
370  * wlan_abort_scan() - Generic API to abort scan request
371  * @pdev: Pointer to pdev
372  * @pdev_id: pdev id
373  * @vdev_id: vdev id
374  * @scan_id: scan id
375  * @sync: if wait for scan complete is required
376  *
377  * Generic API to abort scans
378  *
379  * Return: 0 for success, non zero for failure
380  */
381 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev,
382 				   uint32_t pdev_id,
383 				   uint32_t vdev_id,
384 				   wlan_scan_id scan_id,
385 				   bool sync);
386 
387 /**
388  * wlan_cfg80211_cleanup_scan_queue() - remove entries in scan queue
389  * @pdev: pdev pointer
390  * @dev: net device pointer
391  *
392  * Removes entries in scan queue depending on dev provided and sends scan
393  * complete event to NL.
394  * Removes all entries in scan queue, if dev provided is NULL
395  *
396  * Return: None
397  */
398 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev,
399 				      struct net_device *dev);
400 
401 /**
402  * wlan_scan_cfg80211_add_connected_pno_support() - Set connected PNO support
403  * @wiphy: Pointer to wireless phy
404  *
405  * This function is used to set connected PNO support to kernel
406  *
407  * Return: None
408  */
409 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \
410 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
411 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy);
412 
413 #else
414 static inline
415 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy)
416 {
417 }
418 #endif
419 
420 #if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \
421 		defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \
422 		defined(FEATURE_WLAN_SCAN_PNO)
423 /**
424  * wlan_config_sched_scan_plans_to_wiphy() - configure sched scan plans to wiphy
425  * @wiphy: pointer to wiphy
426  * @psoc: pointer to psoc object
427  *
428  * Return: None
429  */
430 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
431 					   struct wlan_objmgr_psoc *psoc);
432 #else
433 static inline
434 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
435 					   struct wlan_objmgr_psoc *psoc)
436 {
437 }
438 #endif /* FEATURE_WLAN_SCAN_PNO */
439 
440 /**
441  * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211
442  * @netdev: Net device
443  * @req : Scan request
444  * @aborted : true scan aborted false scan success
445  * @osif_priv: OS private structure
446  *
447  * This function notifies scan done to cfg80211
448  *
449  * Return: none
450  */
451 void wlan_cfg80211_scan_done(struct net_device *netdev,
452 			     struct cfg80211_scan_request *req,
453 			     bool aborted, struct pdev_osif_priv *osif_priv);
454 
455 /**
456  * convert_nl_scan_priority_to_internal() - Convert NL80211 based scan prioirty
457  * value to internal scan priority value
458  * @nl_scan_priority : Scan priority value received in vendor attribute
459  *
460  * Return: Internal scan priority value
461  */
462 enum scan_priority convert_nl_scan_priority_to_internal(
463 	enum qca_wlan_vendor_scan_priority nl_scan_priority);
464 #endif
465