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 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 */ 157 struct scan_params { 158 uint8_t source; 159 struct element_info default_ie; 160 struct element_info vendor_ie; 161 enum scan_priority priority; 162 bool half_rate; 163 bool quarter_rate; 164 bool strict_pscan; 165 uint32_t dwell_time_active; 166 uint32_t dwell_time_active_2g; 167 uint32_t dwell_time_passive; 168 uint32_t dwell_time_active_6g; 169 uint32_t dwell_time_passive_6g; 170 }; 171 172 /** 173 * struct wlan_cfg80211_inform_bss - BSS inform data 174 * @chan: channel the frame was received on 175 * @mgmt: beacon/probe resp frame 176 * @frame_len: frame length 177 * @rssi: signal strength in mBm (100*dBm) 178 * @boottime_ns: timestamp (CLOCK_BOOTTIME) when the information was received. 179 * @per_chain_rssi: per chain rssi received 180 */ 181 struct wlan_cfg80211_inform_bss { 182 struct ieee80211_channel *chan; 183 struct ieee80211_mgmt *mgmt; 184 size_t frame_len; 185 int rssi; 186 uint64_t boottime_ns; 187 uint8_t per_chain_rssi[WLAN_MGMT_TXRX_HOST_MAX_ANTENNA]; 188 }; 189 190 191 #ifdef FEATURE_WLAN_SCAN_PNO 192 /** 193 * wlan_cfg80211_sched_scan_start() - cfg80211 scheduled scan(pno) start 194 * @vdev: vdev pointer 195 * @request: Pointer to cfg80211 scheduled scan start request 196 * @scan_backoff_multiplier: multiply scan period by this after max cycles 197 * 198 * Return: 0 for success, non zero for failure 199 */ 200 int wlan_cfg80211_sched_scan_start(struct wlan_objmgr_vdev *vdev, 201 struct cfg80211_sched_scan_request *request, 202 uint8_t scan_backoff_multiplier); 203 204 /** 205 * wlan_cfg80211_sched_scan_stop() - cfg80211 scheduled scan(pno) stop 206 * @vdev: vdev pointer 207 * 208 * Return: 0 for success, non zero for failure 209 */ 210 int wlan_cfg80211_sched_scan_stop(struct wlan_objmgr_vdev *vdev); 211 #endif 212 213 /** 214 * wlan_scan_runtime_pm_init() - API to initialize runtime pm context for scan 215 * @pdev: Pointer to pdev 216 * 217 * This will help to initialize scan runtime pm context separately. 218 * 219 * Return: QDF_STATUS 220 */ 221 QDF_STATUS wlan_scan_runtime_pm_init(struct wlan_objmgr_pdev *pdev); 222 223 /** 224 * wlan_scan_runtime_pm_deinit() - API to deinitialize runtime pm 225 * for scan. 226 * @pdev: Pointer to pdev 227 * 228 * This will help to deinitialize scan runtime pm before deinitialize 229 * HIF 230 * 231 * Return: void 232 */ 233 void wlan_scan_runtime_pm_deinit(struct wlan_objmgr_pdev *pdev); 234 235 /** 236 * wlan_cfg80211_scan_priv_init() - API to initialize cfg80211 scan 237 * @pdev: Pointer to net device 238 * 239 * API to initialize cfg80211 scan module. 240 * 241 * Return: QDF_STATUS 242 */ 243 QDF_STATUS wlan_cfg80211_scan_priv_init(struct wlan_objmgr_pdev *pdev); 244 245 /** 246 * wlan_cfg80211_scan_priv_deinit() - API to deinitialize cfg80211 scan 247 * @pdev: Pointer to net device 248 * 249 * API to deinitialize cfg80211 scan module. 250 * 251 * Return: QDF_STATUS 252 */ 253 QDF_STATUS wlan_cfg80211_scan_priv_deinit( 254 struct wlan_objmgr_pdev *pdev); 255 256 /** 257 * wlan_cfg80211_scan() - API to process cfg80211 scan request 258 * @vdev: Pointer to vdev 259 * @request: Pointer to scan request 260 * @params: scan params 261 * 262 * API to trigger scan and update cfg80211 scan database. 263 * scan dump command can be used to fetch scan results 264 * on receipt of scan complete event. 265 * 266 * Return: 0 for success, non zero for failure 267 */ 268 int wlan_cfg80211_scan(struct wlan_objmgr_vdev *vdev, 269 struct cfg80211_scan_request *request, 270 struct scan_params *params); 271 272 /** 273 * wlan_cfg80211_inform_bss_frame_data() - API to inform beacon to cfg80211 274 * @wiphy: wiphy 275 * @bss_data: bss data 276 * 277 * API to inform beacon to cfg80211 278 * 279 * Return: pointer to bss entry 280 */ 281 struct cfg80211_bss * 282 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy, 283 struct wlan_cfg80211_inform_bss *bss); 284 285 /** 286 * wlan_cfg80211_inform_bss_frame() - API to inform beacon to cfg80211 287 * @pdev: Pointer to pdev 288 * @scan_params: scan entry 289 * @request: Pointer to scan request 290 * 291 * API to inform beacon to cfg80211 292 * 293 * Return: void 294 */ 295 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev, 296 struct scan_cache_entry *scan_params); 297 298 /** 299 * __wlan_cfg80211_unlink_bss_list() - flush bss from the kernel cache 300 * @wiphy: wiphy 301 * @bssid: bssid of the BSS to find 302 * @ssid: ssid of the BSS to find 303 * @ssid_len: ssid len of of the BSS to find 304 * 305 * Return: None 306 */ 307 void __wlan_cfg80211_unlink_bss_list(struct wiphy *wiphy, uint8_t *bssid, 308 uint8_t *ssid, uint8_t ssid_len); 309 310 /** 311 * wlan_cfg80211_get_bss() - Get the bss entry matching the chan, bssid and ssid 312 * @wiphy: wiphy 313 * @channel: channel of the BSS to find 314 * @bssid: bssid of the BSS to find 315 * @ssid: ssid of the BSS to find 316 * @ssid_len: ssid len of of the BSS to find 317 * 318 * The API is a wrapper to get bss from kernel matching the chan, 319 * bssid and ssid 320 * 321 * Return: bss structure if found else NULL 322 */ 323 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy, 324 struct ieee80211_channel *channel, 325 const u8 *bssid, 326 const u8 *ssid, size_t ssid_len); 327 328 /* 329 * wlan_cfg80211_unlink_bss_list : flush bss from the kernel cache 330 * @pdev: Pointer to pdev 331 * @scan_entry: scan entry 332 * 333 * Return: bss which is unlinked from kernel cache 334 */ 335 void wlan_cfg80211_unlink_bss_list(struct wlan_objmgr_pdev *pdev, 336 struct scan_cache_entry *scan_entry); 337 338 /** 339 * wlan_vendor_abort_scan() - API to vendor abort scan 340 * @pdev: Pointer to pdev 341 * @data: pointer to data 342 * @data_len: Data length 343 * 344 * API to abort scan through vendor command 345 * 346 * Return: 0 for success, non zero for failure 347 */ 348 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev, 349 const void *data, int data_len); 350 351 /** 352 * wlan_cfg80211_abort_scan() - API to abort scan through cfg80211 353 * @pdev: Pointer to pdev 354 * 355 * API to abort scan through cfg80211 request 356 * 357 * Return: 0 for success, non zero for failure 358 */ 359 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev); 360 361 /** 362 * wlan_abort_scan() - Generic API to abort scan request 363 * @pdev: Pointer to pdev 364 * @pdev_id: pdev id 365 * @vdev_id: vdev id 366 * @scan_id: scan id 367 * @sync: if wait for scan complete is required 368 * 369 * Generic API to abort scans 370 * 371 * Return: 0 for success, non zero for failure 372 */ 373 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev, 374 uint32_t pdev_id, 375 uint32_t vdev_id, 376 wlan_scan_id scan_id, 377 bool sync); 378 379 /** 380 * wlan_cfg80211_cleanup_scan_queue() - remove entries in scan queue 381 * @pdev: pdev pointer 382 * @dev: net device pointer 383 * 384 * Removes entries in scan queue depending on dev provided and sends scan 385 * complete event to NL. 386 * Removes all entries in scan queue, if dev provided is NULL 387 * 388 * Return: None 389 */ 390 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev, 391 struct net_device *dev); 392 393 /** 394 * wlan_hdd_cfg80211_add_connected_pno_support() - Set connected PNO support 395 * @wiphy: Pointer to wireless phy 396 * 397 * This function is used to set connected PNO support to kernel 398 * 399 * Return: None 400 */ 401 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \ 402 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) 403 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy); 404 405 #else 406 static inline 407 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy) 408 { 409 } 410 #endif 411 412 #if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \ 413 defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \ 414 defined(FEATURE_WLAN_SCAN_PNO) 415 /** 416 * hdd_config_sched_scan_plans_to_wiphy() - configure sched scan plans to wiphy 417 * @wiphy: pointer to wiphy 418 * @config: pointer to config 419 * 420 * Return: None 421 */ 422 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy, 423 struct wlan_objmgr_psoc *psoc); 424 #else 425 static inline 426 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy, 427 struct wlan_objmgr_psoc *psoc) 428 { 429 } 430 #endif /* FEATURE_WLAN_SCAN_PNO */ 431 432 /** 433 * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211 434 * @netdev: Net device 435 * @req : Scan request 436 * @aborted : true scan aborted false scan success 437 * 438 * This function notifies scan done to cfg80211 439 * 440 * Return: none 441 */ 442 void wlan_cfg80211_scan_done(struct net_device *netdev, 443 struct cfg80211_scan_request *req, 444 bool aborted); 445 #endif 446