1 /* 2 * Copyright (c) 2017 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: contains scan cache internal api 21 */ 22 23 #ifndef _WLAN_SCAN_CACHE_DB_I_H_ 24 #define _WLAN_SCAN_CACHE_DB_I_H_ 25 26 /** 27 * scm_filter_match() - private API to check if entry is match to filter 28 * @db_entry: db entry 29 * @filter: filter 30 * @security: negotiated security if match is found 31 * 32 * Return: true if entry match filter 33 */ 34 bool scm_filter_match(struct scan_cache_entry *db_entry, 35 struct scan_filter *filter, 36 struct security_info *security); 37 38 /** 39 * scm_get_bss_prefer_value() - Get the preference value for BSS 40 * @filter: scan filter 41 * @entry: entry 42 * 43 * Each BSS should be assigned a preference value ranging from 44 * 14-0, which will be used as an RSSI bucket score while sorting the 45 * scan results. 46 * 47 * Return: Preference value for the BSSID 48 */ 49 uint32_t scm_get_bss_prefer_value(struct scan_filter *filter, 50 struct scan_cache_entry *entry); 51 52 /** 53 * scm_is_better_bss() - Is bss1 better than bss2 54 * @filter: scan filter 55 * @bss1: Pointer to the first BSS. 56 * @bss2: Pointer to the second BSS. 57 * 58 * This routine helps in determining the preference value 59 * of a particular BSS in the scan result which is further 60 * used in the sorting logic of the final candidate AP's. 61 * 62 * Return: true, if bss1 is better than bss2 63 * false, if bss2 is better than bss1. 64 */ 65 bool scm_is_better_bss(struct scan_filter *filter, 66 struct scan_cache_entry *bss1, 67 struct scan_cache_entry *bss2); 68 69 /** 70 * scm_get_bss_cap_value() - get bss capability value 71 * @filter: filter 72 * @entry: scan entry entry 73 * 74 * Return: CapValue base on the capabilities of a BSS 75 */ 76 uint32_t scm_get_bss_cap_value(struct scan_filter *filter, 77 struct scan_cache_entry *entry); 78 79 /** 80 * is_channel_found_in_pcl() - to check if channel is present in pcl 81 * @channel_id: channel of bss 82 * @filter: pointer to filter created through profile 83 * 84 * to check if provided channel is present in pcl 85 * 86 * Return: true or false 87 */ 88 static inline bool is_channel_found_in_pcl(int channel_id, 89 struct scan_filter *filter) 90 { 91 int i; 92 bool status = false; 93 94 if (!filter) 95 return status; 96 97 for (i = 0; i < filter->num_of_pcl_channels; i++) { 98 if (filter->pcl_channel_list[i] == channel_id) { 99 status = true; 100 break; 101 } 102 } 103 104 return status; 105 } 106 107 /** 108 * scm_derive_prefer_value_from_rssi() - to derive prefer value 109 * @filter: filter 110 * @rssi: RSSI of the BSS 111 * 112 * This routine will derive preferred value from given rssi 113 * 114 * Return: value between 0 to 14 115 */ 116 static inline int scm_derive_prefer_value_from_rssi(struct scan_filter *filter, 117 int rssi) 118 { 119 int i = SCM_NUM_RSSI_CAT - 1, pref_val = 0; 120 121 while (i >= 0) { 122 if (rssi >= filter->rssi_cat[i]) { 123 pref_val = filter->bss_prefer_val[i]; 124 break; 125 } 126 i--; 127 }; 128 129 return pref_val; 130 } 131 132 /** 133 * scm_calc_pref_val_by_pcl() - to calculate preferred value 134 * @filter: filter to find match from scan result 135 * @bss_descr: pointer to bss descriptor 136 * 137 * this routine calculates the new preferred value to be given to 138 * provided bss if its channel falls under preferred channel list. 139 * Thump rule is higer the RSSI better the boost. 140 * 141 * Return: success or failure 142 */ 143 QDF_STATUS scm_calc_pref_val_by_pcl(struct scan_filter *filter, 144 struct scan_cache_entry *entry); 145 146 /** 147 * wlan_pdevid_get_scan_db() - private API to get scan db from pdev id 148 * @psoc: psoc object 149 * @pdev_id: Pdev_id 150 * Return: scan db for the pdev id 151 */ 152 static inline struct scan_dbs * 153 wlan_pdevid_get_scan_db(struct wlan_objmgr_psoc *psoc, uint8_t pdev_id) 154 { 155 struct wlan_scan_obj *scan_obj = NULL; 156 157 if (pdev_id > WLAN_UMAC_MAX_PDEVS) { 158 scm_err("invalid pdev_id %d", pdev_id); 159 return NULL; 160 } 161 scan_obj = wlan_psoc_get_scan_obj(psoc); 162 163 if (!scan_obj) 164 return NULL; 165 166 return &(scan_obj->scan_db[pdev_id]); 167 } 168 169 /** 170 * wlan_pdev_get_scan_db() - private API to get scan db from pdev 171 * @psoc: psoc object 172 * @pdev: Pdev 173 * 174 * Return: scan db for the pdev 175 */ 176 static inline struct scan_dbs * 177 wlan_pdev_get_scan_db(struct wlan_objmgr_psoc *psoc, 178 struct wlan_objmgr_pdev *pdev) 179 { 180 uint8_t pdev_id; 181 182 if (!pdev) { 183 scm_err("pdev is NULL"); 184 return NULL; 185 } 186 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 187 188 return wlan_pdevid_get_scan_db(psoc, pdev_id); 189 } 190 #endif 191