1 /* 2 * Copyright (c) 2017-2020 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 /* GPS application requirement */ 41 #define QCOM_VENDOR_IE_ID 221 42 #define QCOM_OUI1 0x00 43 #define QCOM_OUI2 0xA0 44 #define QCOM_OUI3 0xC6 45 #define QCOM_VENDOR_IE_AGE_TYPE 0x100 46 #define QCOM_VENDOR_IE_AGE_LEN (sizeof(qcom_ie_age) - 2) 47 #define SCAN_DONE_EVENT_BUF_SIZE 4096 48 #define SCAN_WAKE_LOCK_CONNECT_DURATION (1 * 1000) /* in msec */ 49 #define SCAN_WAKE_LOCK_SCAN_DURATION (5 * 1000) /* in msec */ 50 51 /** 52 * typedef struct qcom_ie_age - age ie 53 * 54 * @element_id: Element id 55 * @len: Length 56 * @oui_1: OUI 1 57 * @oui_2: OUI 2 58 * @oui_3: OUI 3 59 * @type: Type 60 * @age: Age 61 * @tsf_delta: tsf delta from FW 62 * @beacon_tsf: original beacon TSF 63 * @seq_ctrl: sequence control field 64 */ 65 typedef struct { 66 u8 element_id; 67 u8 len; 68 u8 oui_1; 69 u8 oui_2; 70 u8 oui_3; 71 u32 type; 72 u32 age; 73 u32 tsf_delta; 74 u64 beacon_tsf; 75 u16 seq_ctrl; 76 } __attribute__ ((packed)) qcom_ie_age; 77 78 /** 79 * struct osif_scan_pdev - OS scan private strcutre 80 * scan_req_q: Scan request queue 81 * scan_req_q_lock: Protect scan request queue 82 * req_id: Scan request Id 83 * runtime_pm_lock: Runtime suspend lock 84 * scan_wake_lock: Scan wake lock 85 */ 86 struct osif_scan_pdev{ 87 qdf_list_t scan_req_q; 88 qdf_mutex_t scan_req_q_lock; 89 wlan_scan_requester req_id; 90 qdf_runtime_lock_t runtime_pm_lock; 91 qdf_wake_lock_t scan_wake_lock; 92 }; 93 94 /* 95 * enum scan_source - scan request source 96 * @NL_SCAN: Scan initiated from NL 97 * @VENDOR_SCAN: Scan intiated from vendor command 98 */ 99 enum scan_source { 100 NL_SCAN, 101 VENDOR_SCAN, 102 }; 103 104 /** 105 * struct scan_req - Scan Request entry 106 * @node : List entry element 107 * @scan_request: scan request holder 108 * @scan_id: scan identifier used across host layers which is generated at WMI 109 * @source: scan request originator (NL/Vendor scan) 110 * @dev: net device (same as what is in scan_request) 111 * 112 * Scan request linked list element 113 */ 114 struct scan_req { 115 qdf_list_node_t node; 116 struct cfg80211_scan_request *scan_request; 117 uint32_t scan_id; 118 uint8_t source; 119 struct net_device *dev; 120 }; 121 122 /** 123 * struct scan_params - Scan params 124 * @source: scan request source 125 * @default_ie: default scan ie 126 * @vendor_ie: vendor ie 127 * @priority: scan priority 128 * @half_rate: Half rate flag 129 * @quarter_rate: Quarter rate flag 130 * @strict_pscan: strict passive scan flag 131 * @dwell_time_active: Active dwell time. Ignored if zero or inapplicable. 132 * @dwell_time_active_2g: 2.4 GHz specific active dwell time. Ignored if zero or 133 * inapplicable. 134 * @dwell_time_passive: Passive dwell time. Ignored if zero or inapplicable. 135 * @dwell_time_active_6g: 6 GHz specific active dwell time. Ignored if zero or 136 * inapplicable. 137 * @dwell_time_passive_6g: 6 GHz specific passive dwell time. Ignored if zero or 138 * inapplicable. 139 */ 140 struct scan_params { 141 uint8_t source; 142 struct element_info default_ie; 143 struct element_info vendor_ie; 144 enum scan_priority priority; 145 bool half_rate; 146 bool quarter_rate; 147 bool strict_pscan; 148 uint32_t dwell_time_active; 149 uint32_t dwell_time_active_2g; 150 uint32_t dwell_time_passive; 151 uint32_t dwell_time_active_6g; 152 uint32_t dwell_time_passive_6g; 153 }; 154 155 /** 156 * struct wlan_cfg80211_inform_bss - BSS inform data 157 * @chan: channel the frame was received on 158 * @mgmt: beacon/probe resp frame 159 * @frame_len: frame length 160 * @rssi: signal strength in mBm (100*dBm) 161 * @boottime_ns: timestamp (CLOCK_BOOTTIME) when the information was received. 162 * @per_chain_rssi: per chain rssi received 163 */ 164 struct wlan_cfg80211_inform_bss { 165 struct ieee80211_channel *chan; 166 struct ieee80211_mgmt *mgmt; 167 size_t frame_len; 168 int rssi; 169 uint64_t boottime_ns; 170 uint8_t per_chain_rssi[WLAN_MGMT_TXRX_HOST_MAX_ANTENNA]; 171 }; 172 173 174 #ifdef FEATURE_WLAN_SCAN_PNO 175 /** 176 * wlan_cfg80211_sched_scan_start() - cfg80211 scheduled scan(pno) start 177 * @vdev: vdev pointer 178 * @request: Pointer to cfg80211 scheduled scan start request 179 * @scan_backoff_multiplier: multiply scan period by this after max cycles 180 * 181 * Return: 0 for success, non zero for failure 182 */ 183 int wlan_cfg80211_sched_scan_start(struct wlan_objmgr_vdev *vdev, 184 struct cfg80211_sched_scan_request *request, 185 uint8_t scan_backoff_multiplier); 186 187 /** 188 * wlan_cfg80211_sched_scan_stop() - cfg80211 scheduled scan(pno) stop 189 * @vdev: vdev pointer 190 * 191 * Return: 0 for success, non zero for failure 192 */ 193 int wlan_cfg80211_sched_scan_stop(struct wlan_objmgr_vdev *vdev); 194 #endif 195 196 /** 197 * wlan_scan_runtime_pm_init() - API to initialize runtime pm context for scan 198 * @pdev: Pointer to pdev 199 * 200 * This will help to initialize scan runtime pm context separately. 201 * 202 * Return: QDF_STATUS 203 */ 204 QDF_STATUS wlan_scan_runtime_pm_init(struct wlan_objmgr_pdev *pdev); 205 206 /** 207 * wlan_scan_runtime_pm_deinit() - API to deinitialize runtime pm 208 * for scan. 209 * @pdev: Pointer to pdev 210 * 211 * This will help to deinitialize scan runtime pm before deinitialize 212 * HIF 213 * 214 * Return: void 215 */ 216 void wlan_scan_runtime_pm_deinit(struct wlan_objmgr_pdev *pdev); 217 218 /** 219 * wlan_cfg80211_scan_priv_init() - API to initialize cfg80211 scan 220 * @pdev: Pointer to net device 221 * 222 * API to initialize cfg80211 scan module. 223 * 224 * Return: QDF_STATUS 225 */ 226 QDF_STATUS wlan_cfg80211_scan_priv_init(struct wlan_objmgr_pdev *pdev); 227 228 /** 229 * wlan_cfg80211_scan_priv_deinit() - API to deinitialize cfg80211 scan 230 * @pdev: Pointer to net device 231 * 232 * API to deinitialize cfg80211 scan module. 233 * 234 * Return: QDF_STATUS 235 */ 236 QDF_STATUS wlan_cfg80211_scan_priv_deinit( 237 struct wlan_objmgr_pdev *pdev); 238 239 /** 240 * wlan_cfg80211_scan() - API to process cfg80211 scan request 241 * @vdev: Pointer to vdev 242 * @request: Pointer to scan request 243 * @params: scan params 244 * 245 * API to trigger scan and update cfg80211 scan database. 246 * scan dump command can be used to fetch scan results 247 * on receipt of scan complete event. 248 * 249 * Return: 0 for success, non zero for failure 250 */ 251 int wlan_cfg80211_scan(struct wlan_objmgr_vdev *vdev, 252 struct cfg80211_scan_request *request, 253 struct scan_params *params); 254 255 /** 256 * wlan_cfg80211_inform_bss_frame_data() - API to inform beacon to cfg80211 257 * @wiphy: wiphy 258 * @bss_data: bss data 259 * 260 * API to inform beacon to cfg80211 261 * 262 * Return: pointer to bss entry 263 */ 264 struct cfg80211_bss * 265 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy, 266 struct wlan_cfg80211_inform_bss *bss); 267 268 /** 269 * wlan_cfg80211_inform_bss_frame() - API to inform beacon to cfg80211 270 * @pdev: Pointer to pdev 271 * @scan_params: scan entry 272 * @request: Pointer to scan request 273 * 274 * API to inform beacon to cfg80211 275 * 276 * Return: void 277 */ 278 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev, 279 struct scan_cache_entry *scan_params); 280 281 /** 282 * __wlan_cfg80211_unlink_bss_list() - flush bss from the kernel cache 283 * @wiphy: wiphy 284 * @bssid: bssid of the BSS to find 285 * @ssid: ssid of the BSS to find 286 * @ssid_len: ssid len of of the BSS to find 287 * 288 * Return: None 289 */ 290 void __wlan_cfg80211_unlink_bss_list(struct wiphy *wiphy, uint8_t *bssid, 291 uint8_t *ssid, uint8_t ssid_len); 292 293 /** 294 * wlan_cfg80211_get_bss() - Get the bss entry matching the chan, bssid and ssid 295 * @wiphy: wiphy 296 * @channel: channel of the BSS to find 297 * @bssid: bssid of the BSS to find 298 * @ssid: ssid of the BSS to find 299 * @ssid_len: ssid len of of the BSS to find 300 * 301 * The API is a wrapper to get bss from kernel matching the chan, 302 * bssid and ssid 303 * 304 * Return: bss structure if found else NULL 305 */ 306 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy, 307 struct ieee80211_channel *channel, 308 const u8 *bssid, 309 const u8 *ssid, size_t ssid_len); 310 311 /* 312 * wlan_cfg80211_unlink_bss_list : flush bss from the kernel cache 313 * @pdev: Pointer to pdev 314 * @scan_entry: scan entry 315 * 316 * Return: bss which is unlinked from kernel cache 317 */ 318 void wlan_cfg80211_unlink_bss_list(struct wlan_objmgr_pdev *pdev, 319 struct scan_cache_entry *scan_entry); 320 321 /** 322 * wlan_vendor_abort_scan() - API to vendor abort scan 323 * @pdev: Pointer to pdev 324 * @data: pointer to data 325 * @data_len: Data length 326 * 327 * API to abort scan through vendor command 328 * 329 * Return: 0 for success, non zero for failure 330 */ 331 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev, 332 const void *data, int data_len); 333 334 /** 335 * wlan_cfg80211_abort_scan() - API to abort scan through cfg80211 336 * @pdev: Pointer to pdev 337 * 338 * API to abort scan through cfg80211 request 339 * 340 * Return: 0 for success, non zero for failure 341 */ 342 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev); 343 344 /** 345 * wlan_abort_scan() - Generic API to abort scan request 346 * @pdev: Pointer to pdev 347 * @pdev_id: pdev id 348 * @vdev_id: vdev id 349 * @scan_id: scan id 350 * @sync: if wait for scan complete is required 351 * 352 * Generic API to abort scans 353 * 354 * Return: 0 for success, non zero for failure 355 */ 356 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev, 357 uint32_t pdev_id, 358 uint32_t vdev_id, 359 wlan_scan_id scan_id, 360 bool sync); 361 362 /** 363 * wlan_cfg80211_cleanup_scan_queue() - remove entries in scan queue 364 * @pdev: pdev pointer 365 * @dev: net device pointer 366 * 367 * Removes entries in scan queue depending on dev provided and sends scan 368 * complete event to NL. 369 * Removes all entries in scan queue, if dev provided is NULL 370 * 371 * Return: None 372 */ 373 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev, 374 struct net_device *dev); 375 376 /** 377 * wlan_hdd_cfg80211_add_connected_pno_support() - Set connected PNO support 378 * @wiphy: Pointer to wireless phy 379 * 380 * This function is used to set connected PNO support to kernel 381 * 382 * Return: None 383 */ 384 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \ 385 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) 386 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy); 387 388 #else 389 static inline 390 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy) 391 { 392 } 393 #endif 394 395 #if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \ 396 defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \ 397 defined(FEATURE_WLAN_SCAN_PNO) 398 /** 399 * hdd_config_sched_scan_plans_to_wiphy() - configure sched scan plans to wiphy 400 * @wiphy: pointer to wiphy 401 * @config: pointer to config 402 * 403 * Return: None 404 */ 405 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy, 406 struct wlan_objmgr_psoc *psoc); 407 #else 408 static inline 409 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy, 410 struct wlan_objmgr_psoc *psoc) 411 { 412 } 413 #endif /* FEATURE_WLAN_SCAN_PNO */ 414 415 #endif 416