1 /* 2 * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022-2023 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: contains scan cache entry api 22 */ 23 24 #ifndef _WLAN_SCAN_CACHE_DB_H_ 25 #define _WLAN_SCAN_CACHE_DB_H_ 26 27 #include <scheduler_api.h> 28 #include <wlan_objmgr_psoc_obj.h> 29 #include <wlan_objmgr_pdev_obj.h> 30 #include <wlan_objmgr_vdev_obj.h> 31 #include <wlan_scan_public_structs.h> 32 33 #define SCAN_HASH_SIZE 64 34 #define SCAN_GET_HASH(addr) \ 35 (((const uint8_t *)(addr))[QDF_MAC_ADDR_SIZE - 1] % SCAN_HASH_SIZE) 36 37 #define ADJACENT_CHANNEL_RSSI_THRESHOLD -80 38 #define ADJACENT_CHANNEL_RSSI_DIFF_THRESHOLD 40 39 40 /** 41 * struct scan_dbs - scan cache data base definition 42 * @num_entries: number of scan entries 43 * @scan_db_lock: lock for @scan_hash_tbl 44 * @scan_hash_tbl: link list of bssid hashed scan cache entries for a pdev 45 */ 46 struct scan_dbs { 47 uint32_t num_entries; 48 qdf_spinlock_t scan_db_lock; 49 qdf_list_t scan_hash_tbl[SCAN_HASH_SIZE]; 50 }; 51 52 /** 53 * struct scan_bcn_probe_event - beacon/probe info 54 * @frm_type: frame type 55 * @rx_data: mgmt rx data 56 * @psoc: psoc pointer 57 * @buf: rx frame 58 */ 59 struct scan_bcn_probe_event { 60 uint32_t frm_type; 61 struct mgmt_rx_event_params *rx_data; 62 struct wlan_objmgr_psoc *psoc; 63 qdf_nbuf_t buf; 64 }; 65 66 /** 67 * scm_handle_bcn_probe() - Process beacon and probe rsp 68 * @msg: schedular msg with bcn info; 69 * 70 * API to handle the beacon/probe resp. msg->bodyptr will be consumed and freed 71 * by this func 72 * 73 * Return: QDF status. 74 */ 75 QDF_STATUS scm_handle_bcn_probe(struct scheduler_msg *msg); 76 77 /** 78 * __scm_handle_bcn_probe() - Process beacon and probe rsp 79 * @bcn: beacon info; 80 * 81 * API to handle the beacon/probe resp. bcn will be consumed and freed by this 82 * func 83 * 84 * Return: QDF status. 85 */ 86 QDF_STATUS __scm_handle_bcn_probe(struct scan_bcn_probe_event *bcn); 87 88 /** 89 * scm_age_out_entries() - Age out entries older than aging time 90 * @psoc: psoc pointer 91 * @scan_db: scan database 92 * 93 * Return: void. 94 */ 95 void scm_age_out_entries(struct wlan_objmgr_psoc *psoc, 96 struct scan_dbs *scan_db); 97 98 /** 99 * scm_get_scan_result() - fetches scan result 100 * @pdev: pdev info 101 * @filter: Filters 102 * 103 * This function fetches scan result 104 * 105 * Return: scan list 106 */ 107 qdf_list_t *scm_get_scan_result(struct wlan_objmgr_pdev *pdev, 108 struct scan_filter *filter); 109 110 /** 111 * scm_purge_scan_results() - purge the scan list 112 * @scan_result: scan list to be purged 113 * 114 * This function purge the temp scan list 115 * 116 * Return: QDF_STATUS 117 */ 118 QDF_STATUS scm_purge_scan_results(qdf_list_t *scan_result); 119 120 /** 121 * scm_update_scan_mlme_info() - updates scan entry with mlme data 122 * @pdev: pdev object 123 * @scan_entry: source scan entry to read mlme info 124 * 125 * This function updates scan db with scan_entry->mlme_info 126 * 127 * Return: QDF_STATUS 128 */ 129 QDF_STATUS scm_update_scan_mlme_info(struct wlan_objmgr_pdev *pdev, 130 struct scan_cache_entry *scan_entry); 131 132 /** 133 * scm_flush_results() - flush scan entries matching the filter 134 * @pdev: vdev object 135 * @filter: filter to flush the scan entries 136 * 137 * Flush scan entries matching the filter. 138 * 139 * Return: QDF status. 140 */ 141 QDF_STATUS scm_flush_results(struct wlan_objmgr_pdev *pdev, 142 struct scan_filter *filter); 143 144 /** 145 * scm_filter_valid_channel() - The Public API to filter scan result 146 * based on valid channel list 147 * @pdev: pdev object 148 * @chan_freq_list: valid channel frequency (in MHz) list 149 * @num_chan: number of valid channels 150 * 151 * The Public API to to filter scan result 152 * based on valid channel list. 153 * 154 * Return: void. 155 */ 156 void scm_filter_valid_channel(struct wlan_objmgr_pdev *pdev, 157 uint32_t *chan_freq_list, uint32_t num_chan); 158 159 /** 160 * scm_iterate_scan_db() - function to iterate scan table 161 * @pdev: pdev object 162 * @func: iterator function pointer 163 * @arg: argument to be passed to func() 164 * 165 * API, this API iterates scan table and invokes func 166 * on each scan enetry by passing scan entry and arg. 167 * 168 * Return: QDF_STATUS 169 */ 170 QDF_STATUS 171 scm_iterate_scan_db(struct wlan_objmgr_pdev *pdev, 172 scan_iterator_func func, void *arg); 173 174 /** 175 * scm_scan_register_bcn_cb() - API to register api to indicate bcn/probe 176 * as soon as they are received 177 * @psoc: psoc 178 * @cb: callback to be registered 179 * @type: Type of callback to be registered 180 * 181 * Return: enum scm_scan_status 182 */ 183 QDF_STATUS scm_scan_register_bcn_cb(struct wlan_objmgr_psoc *psoc, 184 update_beacon_cb cb, enum scan_cb_type type); 185 186 /** 187 * scm_scan_register_mbssid_cb() - API to register api to handle bcn/probe 188 * as soon as they are generated 189 * @psoc: psoc object 190 * @cb: callback to be registered 191 * 192 * Return: QDF_STATUS 193 */ 194 QDF_STATUS scm_scan_register_mbssid_cb(struct wlan_objmgr_psoc *psoc, 195 update_mbssid_bcn_prb_rsp cb); 196 197 /** 198 * scm_reset_scan_chan_info() - API to reset the scan channel info 199 * @psoc: psoc object 200 * @pdev_id: pdev id of which info need to be reset 201 * 202 * Return: void 203 */ 204 void scm_reset_scan_chan_info(struct wlan_objmgr_psoc *psoc, uint8_t pdev_id); 205 206 /** 207 * scm_db_init() - API to init scan db 208 * @psoc: psoc 209 * 210 * Return: QDF_STATUS 211 */ 212 QDF_STATUS scm_db_init(struct wlan_objmgr_psoc *psoc); 213 214 /** 215 * scm_db_deinit() - API to deinit scan db 216 * @psoc: psoc 217 * 218 * Return: QDF_STATUS 219 */ 220 QDF_STATUS scm_db_deinit(struct wlan_objmgr_psoc *psoc); 221 222 #ifdef FEATURE_6G_SCAN_CHAN_SORT_ALGO 223 224 /** 225 * scm_get_rnr_channel_db() - API to get rnr db 226 * @psoc: psoc 227 * 228 * Return: rnr db 229 */ 230 struct channel_list_db *scm_get_rnr_channel_db(struct wlan_objmgr_psoc *psoc); 231 232 /** 233 * scm_get_chan_meta() - API to return channel meta 234 * @psoc: psoc 235 * @chan_freq: channel frequency 236 * 237 * Return: channel meta information 238 */ 239 struct meta_rnr_channel *scm_get_chan_meta(struct wlan_objmgr_psoc *psoc, 240 uint32_t chan_freq); 241 242 /** 243 * scm_channel_list_db_init() - API to init scan list priority list db 244 * @psoc: psoc 245 * 246 * Return: QDF_STATUS 247 */ 248 QDF_STATUS scm_channel_list_db_init(struct wlan_objmgr_psoc *psoc); 249 250 /** 251 * scm_channel_list_db_deinit() - API to deinit scan list priority list db 252 * @psoc: psoc 253 * 254 * Return: QDF_STATUS 255 */ 256 QDF_STATUS scm_channel_list_db_deinit(struct wlan_objmgr_psoc *psoc); 257 258 /** 259 * scm_rnr_db_flush() - API to flush rnr entries 260 * @psoc: psoc 261 * 262 * Return: QDF_STATUS 263 */ 264 QDF_STATUS scm_rnr_db_flush(struct wlan_objmgr_psoc *psoc); 265 266 /** 267 * scm_update_rnr_from_scan_cache() - API to update rnr info from scan cache 268 * @pdev: pdev 269 * 270 * Return: void 271 */ 272 void scm_update_rnr_from_scan_cache(struct wlan_objmgr_pdev *pdev); 273 274 /** 275 * scm_filter_rnr_flag_pno() - Remove FLAG_SCAN_ONLY_IF_RNR_FOUND flag 276 * in channel if ssid is different for colocated AP, 277 * during pno scan request 278 * @vdev: vdev 279 * @short_ssid: short ssid 280 * @chan_list: channel list 281 * 282 * Remove FLAG_SCAN_ONLY_IF_RNR_FOUND flag in channel if ssid is different for 283 * colocated AP, in pno scan request 284 * 285 * Return: None 286 */ 287 void 288 scm_filter_rnr_flag_pno(struct wlan_objmgr_vdev *vdev, 289 uint32_t short_ssid, 290 struct chan_list *chan_list); 291 292 #else 293 static inline QDF_STATUS scm_channel_list_db_init(struct wlan_objmgr_psoc *psoc) 294 { 295 return QDF_STATUS_SUCCESS; 296 } 297 298 static inline 299 QDF_STATUS scm_channel_list_db_deinit(struct wlan_objmgr_psoc *psoc) 300 { 301 return QDF_STATUS_SUCCESS; 302 } 303 304 static inline void 305 scm_filter_rnr_flag_pno(struct wlan_objmgr_vdev *vdev, 306 uint32_t short_ssid, 307 struct chan_list *chan_list) 308 { 309 } 310 #endif 311 312 /** 313 * scm_scan_update_mlme_by_bssinfo() - updates scan entry with mlme data 314 * @pdev: pdev object 315 * @bss_info: BSS information 316 * @mlme: scan entry MLME info 317 * 318 * This function updates scan db with scan_entry->mlme_info 319 * 320 * Return: QDF_STATUS 321 */ 322 QDF_STATUS scm_scan_update_mlme_by_bssinfo(struct wlan_objmgr_pdev *pdev, 323 struct bss_info *bss_info, struct mlme_info *mlme); 324 325 uint32_t scm_get_last_scan_time_per_channel(struct wlan_objmgr_vdev *vdev, 326 uint32_t freq); 327 328 /** 329 * scm_scan_get_scan_entry_by_mac_freq() - Get scan entry by mac and freq 330 * @pdev: pdev info 331 * @bssid: BSSID of the bcn/probe response to be fetched from scan db 332 * @freq: freq for scan filter 333 * 334 * Return: scan entry if found, else NULL 335 */ 336 struct scan_cache_entry * 337 scm_scan_get_scan_entry_by_mac_freq(struct wlan_objmgr_pdev *pdev, 338 struct qdf_mac_addr *bssid, 339 uint16_t freq); 340 341 /** 342 * scm_scan_get_entry_by_mac_addr() - Get bcn/probe rsp from scan db 343 * @pdev: pdev info 344 * @bssid: BSSID of the bcn/probe response to be fetched from scan db 345 * @frame: Frame from scan db with given bssid. 346 * 347 * This API allocates the memory for bcn/probe rsp frame and returns 348 * to caller through @frame->ptr. It's caller responsibility to free 349 * the memory once it's done with the usage. 350 * 351 * Return: QDF_STATUS_SUCCESS if scan entry is present in db 352 */ 353 QDF_STATUS 354 scm_scan_get_entry_by_mac_addr(struct wlan_objmgr_pdev *pdev, 355 struct qdf_mac_addr *bssid, 356 struct element_info *frame); 357 358 /** 359 * scm_scan_get_entry_by_bssid() - function to get scan entry by bssid 360 * @pdev: pdev object 361 * @bssid: bssid to be fetched from scan db 362 * 363 * Return : scan entry if found, else NULL 364 */ 365 struct scan_cache_entry * 366 scm_scan_get_entry_by_bssid(struct wlan_objmgr_pdev *pdev, 367 struct qdf_mac_addr *bssid); 368 369 #ifdef WLAN_FEATURE_11BE_MLO 370 /** 371 * scm_get_mld_addr_by_link_addr() - function to fetch the peer mld address from 372 * the scan entry for the given link address. 373 * @pdev: pdev object 374 * @link_addr: link address 375 * @mld_mac_addr: pointer to mld_mac_address 376 * 377 * Return : scan entry if found, else NULL 378 */ 379 QDF_STATUS 380 scm_get_mld_addr_by_link_addr(struct wlan_objmgr_pdev *pdev, 381 struct qdf_mac_addr *link_addr, 382 struct qdf_mac_addr *mld_mac_addr); 383 #else 384 static inline QDF_STATUS 385 scm_get_mld_addr_by_link_addr(struct wlan_objmgr_pdev *pdev, 386 struct qdf_mac_addr *link_addr, 387 struct qdf_mac_addr *mld_mac_addr) 388 { 389 return QDF_STATUS_E_NOSUPPORT; 390 } 391 #endif 392 #endif 393