xref: /wlan-dirver/qca-wifi-host-cmn/umac/scan/core/src/wlan_scan_cache_db.h (revision 449758b4de7a219dad7b7a0e20ce2ea1c8388e34)
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_db_init() - API to init scan db
199  * @psoc: psoc
200  *
201  * Return: QDF_STATUS
202  */
203 QDF_STATUS scm_db_init(struct wlan_objmgr_psoc *psoc);
204 
205 /**
206  * scm_db_deinit() - API to deinit scan db
207  * @psoc: psoc
208  *
209  * Return: QDF_STATUS
210  */
211 QDF_STATUS scm_db_deinit(struct wlan_objmgr_psoc *psoc);
212 
213 #ifdef FEATURE_6G_SCAN_CHAN_SORT_ALGO
214 
215 /**
216  * scm_get_rnr_channel_db() - API to get rnr db
217  * @psoc: psoc
218  *
219  * Return: rnr db
220  */
221 struct channel_list_db *scm_get_rnr_channel_db(struct wlan_objmgr_psoc *psoc);
222 
223 /**
224  * scm_get_chan_meta() - API to return channel meta
225  * @psoc: psoc
226  * @chan_freq: channel frequency
227  *
228  * Return: channel meta information
229  */
230 struct meta_rnr_channel *scm_get_chan_meta(struct wlan_objmgr_psoc *psoc,
231 					   uint32_t chan_freq);
232 
233 /**
234  * scm_channel_list_db_init() - API to init scan list priority list db
235  * @psoc: psoc
236  *
237  * Return: QDF_STATUS
238  */
239 QDF_STATUS scm_channel_list_db_init(struct wlan_objmgr_psoc *psoc);
240 
241 /**
242  * scm_channel_list_db_deinit() - API to deinit scan list priority list db
243  * @psoc: psoc
244  *
245  * Return: QDF_STATUS
246  */
247 QDF_STATUS scm_channel_list_db_deinit(struct wlan_objmgr_psoc *psoc);
248 
249 /**
250  * scm_rnr_db_flush() - API to flush rnr entries
251  * @psoc: psoc
252  *
253  * Return: QDF_STATUS
254  */
255 QDF_STATUS scm_rnr_db_flush(struct wlan_objmgr_psoc *psoc);
256 
257 /**
258  * scm_update_rnr_from_scan_cache() - API to update rnr info from scan cache
259  * @pdev: pdev
260  *
261  * Return: void
262  */
263 void scm_update_rnr_from_scan_cache(struct wlan_objmgr_pdev *pdev);
264 
265 /**
266  * scm_filter_rnr_flag_pno() - Remove FLAG_SCAN_ONLY_IF_RNR_FOUND flag
267  *                             in channel if ssid is different for colocated AP,
268  *                             during pno scan request
269  * @vdev: vdev
270  * @short_ssid: short ssid
271  * @chan_list: channel list
272  *
273  * Remove FLAG_SCAN_ONLY_IF_RNR_FOUND flag in channel if ssid is different for
274  * colocated AP, in pno scan request
275  *
276  * Return: None
277  */
278 void
279 scm_filter_rnr_flag_pno(struct wlan_objmgr_vdev *vdev,
280 			uint32_t short_ssid,
281 			struct chan_list *chan_list);
282 
283 #else
284 static inline QDF_STATUS scm_channel_list_db_init(struct wlan_objmgr_psoc *psoc)
285 {
286 	return QDF_STATUS_SUCCESS;
287 }
288 
289 static inline
290 QDF_STATUS scm_channel_list_db_deinit(struct wlan_objmgr_psoc *psoc)
291 {
292 	return QDF_STATUS_SUCCESS;
293 }
294 
295 static inline void
296 scm_filter_rnr_flag_pno(struct wlan_objmgr_vdev *vdev,
297 			uint32_t short_ssid,
298 			struct chan_list *chan_list)
299 {
300 }
301 #endif
302 
303 /**
304  * scm_scan_update_mlme_by_bssinfo() - updates scan entry with mlme data
305  * @pdev: pdev object
306  * @bss_info: BSS information
307  * @mlme: scan entry MLME info
308  *
309  * This function updates scan db with scan_entry->mlme_info
310  *
311  * Return: QDF_STATUS
312  */
313 QDF_STATUS scm_scan_update_mlme_by_bssinfo(struct wlan_objmgr_pdev *pdev,
314 		struct bss_info *bss_info, struct mlme_info *mlme);
315 
316 uint32_t scm_get_last_scan_time_per_channel(struct wlan_objmgr_vdev *vdev,
317 					    uint32_t freq);
318 
319 /**
320  * scm_scan_get_scan_entry_by_mac_freq() - Get scan entry by mac and freq
321  * @pdev: pdev info
322  * @bssid: BSSID of the bcn/probe response to be fetched from scan db
323  * @freq: freq for scan filter
324  *
325  * Return: scan entry if found, else NULL
326  */
327 struct scan_cache_entry *
328 scm_scan_get_scan_entry_by_mac_freq(struct wlan_objmgr_pdev *pdev,
329 				    struct qdf_mac_addr *bssid,
330 				    uint16_t freq);
331 
332 /**
333  * scm_scan_get_entry_by_mac_addr() - Get bcn/probe rsp from scan db
334  * @pdev: pdev info
335  * @bssid: BSSID of the bcn/probe response to be fetched from scan db
336  * @frame: Frame from scan db with given bssid.
337  *
338  * This API allocates the memory for bcn/probe rsp frame and returns
339  * to caller through @frame->ptr. It's caller responsibility to free
340  * the memory once it's done with the usage.
341  *
342  * Return: QDF_STATUS_SUCCESS if scan entry is present in db
343  */
344 QDF_STATUS
345 scm_scan_get_entry_by_mac_addr(struct wlan_objmgr_pdev *pdev,
346 			       struct qdf_mac_addr *bssid,
347 			       struct element_info *frame);
348 
349 /**
350  * scm_scan_get_entry_by_bssid() - function to get scan entry by bssid
351  * @pdev: pdev object
352  * @bssid: bssid to be fetched from scan db
353  *
354  * Return : scan entry if found, else NULL
355  */
356 struct scan_cache_entry *
357 scm_scan_get_entry_by_bssid(struct wlan_objmgr_pdev *pdev,
358 			    struct qdf_mac_addr *bssid);
359 
360 #ifdef WLAN_FEATURE_11BE_MLO
361 /**
362  * scm_get_mld_addr_by_link_addr() - function to fetch the peer mld address from
363  * the scan entry for the given link address.
364  * @pdev: pdev object
365  * @link_addr: link address
366  * @mld_mac_addr: pointer to mld_mac_address
367  *
368  * Return : scan entry if found, else NULL
369  */
370 QDF_STATUS
371 scm_get_mld_addr_by_link_addr(struct wlan_objmgr_pdev *pdev,
372 			      struct qdf_mac_addr *link_addr,
373 			      struct qdf_mac_addr *mld_mac_addr);
374 #else
375 static inline QDF_STATUS
376 scm_get_mld_addr_by_link_addr(struct wlan_objmgr_pdev *pdev,
377 			      struct qdf_mac_addr *link_addr,
378 			      struct qdf_mac_addr *mld_mac_addr)
379 {
380 	return QDF_STATUS_E_NOSUPPORT;
381 }
382 #endif
383 #endif
384