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