xref: /wlan-dirver/qca-wifi-host-cmn/os_if/linux/scan/inc/wlan_cfg80211_scan.h (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: declares driver functions interfacing with linux kernel
21  */
22 
23 
24 #ifndef _WLAN_CFG80211_SCAN_H_
25 #define _WLAN_CFG80211_SCAN_H_
26 
27 #include <linux/version.h>
28 #include <linux/netdevice.h>
29 #include <net/cfg80211.h>
30 #include <qca_vendor.h>
31 #include <wlan_scan_public_structs.h>
32 #include <qdf_list.h>
33 #include <qdf_types.h>
34 #include <wlan_scan_ucfg_api.h>
35 #include <wlan_mgmt_txrx_utils_api.h>
36 
37 /* Max number of scans allowed from userspace */
38 #define WLAN_MAX_SCAN_COUNT 8
39 
40 extern const struct nla_policy cfg80211_scan_policy[
41 			QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1];
42 
43 #define FEATURE_ABORT_SCAN_VENDOR_COMMANDS \
44 	{ \
45 		.info.vendor_id = QCA_NL80211_VENDOR_ID, \
46 		.info.subcmd = QCA_NL80211_VENDOR_SUBCMD_ABORT_SCAN, \
47 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | \
48 			WIPHY_VENDOR_CMD_NEED_NETDEV | \
49 			WIPHY_VENDOR_CMD_NEED_RUNNING, \
50 		.doit = wlan_hdd_vendor_abort_scan, \
51 		vendor_command_policy(cfg80211_scan_policy, \
52 				      QCA_WLAN_VENDOR_ATTR_SCAN_MAX) \
53 	},
54 
55 /* GPS application requirement */
56 #define QCOM_VENDOR_IE_ID 221
57 #define QCOM_OUI1         0x00
58 #define QCOM_OUI2         0xA0
59 #define QCOM_OUI3         0xC6
60 #define QCOM_VENDOR_IE_AGE_TYPE  0x100
61 #define QCOM_VENDOR_IE_AGE_LEN   (sizeof(qcom_ie_age) - 2)
62 #define SCAN_DONE_EVENT_BUF_SIZE 4096
63 #define SCAN_WAKE_LOCK_CONNECT_DURATION (1 * 1000) /* in msec */
64 #define SCAN_WAKE_LOCK_SCAN_DURATION (5 * 1000) /* in msec */
65 
66 /**
67  * typedef struct qcom_ie_age - age ie
68  *
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 strcutre
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_data: 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  * @request: Pointer to scan request
296  *
297  * API to inform beacon to cfg80211
298  *
299  * Return: void
300  */
301 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev,
302 	struct scan_cache_entry *scan_params);
303 
304 /**
305  * __wlan_cfg80211_unlink_bss_list() - flush bss from the kernel cache
306  * @wiphy: wiphy
307  * @pdev: pdev object
308  * @bssid: bssid of the BSS to find
309  * @ssid: ssid of the BSS to find
310  * @ssid_len: ssid len of of the BSS to find
311  *
312  * Return: QDF_STATUS
313  */
314 QDF_STATUS __wlan_cfg80211_unlink_bss_list(struct wiphy *wiphy,
315 					   struct wlan_objmgr_pdev *pdev,
316 					   uint8_t *bssid, uint8_t *ssid,
317 					   uint8_t ssid_len);
318 
319 /**
320  * wlan_cfg80211_get_bss() - Get the bss entry matching the chan, bssid and ssid
321  * @wiphy: wiphy
322  * @channel: channel of the BSS to find
323  * @bssid: bssid of the BSS to find
324  * @ssid: ssid of the BSS to find
325  * @ssid_len: ssid len of of the BSS to find
326  *
327  * The API is a wrapper to get bss from kernel matching the chan,
328  * bssid and ssid
329  *
330  * Return: bss structure if found else NULL
331  */
332 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy,
333 					   struct ieee80211_channel *channel,
334 					   const u8 *bssid,
335 					   const u8 *ssid, size_t ssid_len);
336 
337 /*
338  * wlan_cfg80211_unlink_bss_list : flush bss from the kernel cache
339  * @pdev: Pointer to pdev
340  * @scan_entry: scan entry
341  *
342  * Return: bss which is unlinked from kernel cache
343  */
344 void wlan_cfg80211_unlink_bss_list(struct wlan_objmgr_pdev *pdev,
345 				   struct scan_cache_entry *scan_entry);
346 
347 /**
348  * wlan_vendor_abort_scan() - API to vendor abort scan
349  * @pdev: Pointer to pdev
350  * @data: pointer to data
351  * @data_len: Data length
352  *
353  * API to abort scan through vendor command
354  *
355  * Return: 0 for success, non zero for failure
356  */
357 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev,
358 				const void *data, int data_len);
359 
360 /**
361  * wlan_cfg80211_abort_scan() - API to abort scan through cfg80211
362  * @pdev: Pointer to pdev
363  *
364  * API to abort scan through cfg80211 request
365  *
366  * Return: 0 for success, non zero for failure
367  */
368 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev);
369 
370 /**
371  * wlan_abort_scan() - Generic API to abort scan request
372  * @pdev: Pointer to pdev
373  * @pdev_id: pdev id
374  * @vdev_id: vdev id
375  * @scan_id: scan id
376  * @sync: if wait for scan complete is required
377  *
378  * Generic API to abort scans
379  *
380  * Return: 0 for success, non zero for failure
381  */
382 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev,
383 				   uint32_t pdev_id,
384 				   uint32_t vdev_id,
385 				   wlan_scan_id scan_id,
386 				   bool sync);
387 
388 /**
389  * wlan_cfg80211_cleanup_scan_queue() - remove entries in scan queue
390  * @pdev: pdev pointer
391  * @dev: net device pointer
392  *
393  * Removes entries in scan queue depending on dev provided and sends scan
394  * complete event to NL.
395  * Removes all entries in scan queue, if dev provided is NULL
396  *
397  * Return: None
398  */
399 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev,
400 				      struct net_device *dev);
401 
402 /**
403  * wlan_hdd_cfg80211_add_connected_pno_support() - Set connected PNO support
404  * @wiphy: Pointer to wireless phy
405  *
406  * This function is used to set connected PNO support to kernel
407  *
408  * Return: None
409  */
410 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \
411 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
412 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy);
413 
414 #else
415 static inline
416 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy)
417 {
418 }
419 #endif
420 
421 #if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \
422 		defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \
423 		defined(FEATURE_WLAN_SCAN_PNO)
424 /**
425  * hdd_config_sched_scan_plans_to_wiphy() - configure sched scan plans to wiphy
426  * @wiphy: pointer to wiphy
427  * @config: pointer to config
428  *
429  * Return: None
430  */
431 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
432 					   struct wlan_objmgr_psoc *psoc);
433 #else
434 static inline
435 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
436 					   struct wlan_objmgr_psoc *psoc)
437 {
438 }
439 #endif /* FEATURE_WLAN_SCAN_PNO */
440 
441 /**
442  * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211
443  * @netdev: Net device
444  * @req : Scan request
445  * @aborted : true scan aborted false scan success
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);
454 #endif
455