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