1 /* 2 * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /** 18 * DOC: Contains mandatory API from legacy 19 */ 20 21 #ifndef _WLAN_UTILITY_H_ 22 #define _WLAN_UTILITY_H_ 23 24 #include <qdf_types.h> 25 #include <wlan_objmgr_psoc_obj.h> 26 #include <wlan_objmgr_pdev_obj.h> 27 #include <wlan_objmgr_vdev_obj.h> 28 29 #define TGT_INVALID_SNR (0) 30 #define TGT_MAX_SNR (TGT_NOISE_FLOOR_DBM * (-1)) 31 #define TGT_NOISE_FLOOR_DBM (-96) 32 #define TGT_IS_VALID_SNR(x) ((x) >= 0 && (x) < TGT_MAX_SNR) 33 #define TGT_IS_VALID_RSSI(x) ((x) != 0xFF) 34 35 /** 36 * struct wlan_find_vdev_filter - find vdev filter object. this can be extended 37 * @ifname: interface name of vdev 38 * @found_vdev: found vdev object matching one or more of above params 39 */ 40 struct wlan_find_vdev_filter { 41 char *ifname; 42 struct wlan_objmgr_vdev *found_vdev; 43 }; 44 45 #ifdef CMN_VDEV_MLME_SM_ENABLE 46 /** 47 * struct wlan_vdev_ch_check_filter - vdev chan check filter object 48 * @flag: matches or not 49 * @vdev: vdev to be checked against all the active vdevs 50 */ 51 struct wlan_vdev_ch_check_filter { 52 uint8_t flag; 53 struct wlan_objmgr_vdev *vdev; 54 }; 55 #endif 56 57 /** 58 * wlan_chan_to_freq() - converts channel to frequency 59 * @chan: channel number 60 * 61 * @return frequency of the channel 62 */ 63 uint32_t wlan_chan_to_freq(uint8_t chan); 64 65 /** 66 * wlan_freq_to_chan() - converts frequency to channel 67 * @freq: frequency 68 * 69 * Return: channel of frequency 70 */ 71 uint8_t wlan_freq_to_chan(uint32_t freq); 72 73 /** 74 * wlan_is_ie_valid() - Determine if an IE sequence is valid 75 * @ie: Pointer to the IE buffer 76 * @ie_len: Length of the IE buffer @ie 77 * 78 * This function validates that the IE sequence is valid by verifying 79 * that the sum of the lengths of the embedded elements match the 80 * length of the sequence. 81 * 82 * Note well that a 0-length IE sequence is considered valid. 83 * 84 * Return: true if the IE sequence is valid, false if it is invalid 85 */ 86 bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len); 87 88 /** 89 * wlan_get_ie_ptr_from_eid() - Find out ie from eid 90 * @eid: element id 91 * @ie: source ie address 92 * @ie_len: source ie length 93 * 94 * Return: vendor ie address - success 95 * NULL - failure 96 */ 97 const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid, 98 const uint8_t *ie, 99 int ie_len); 100 101 /** 102 * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie 103 * @oui: oui buffer 104 * @oui_size: oui size 105 * @ie: source ie address 106 * @ie_len: source ie length 107 * 108 * This function find out vendor ie by pass source ie and vendor oui. 109 * 110 * Return: vendor ie address - success 111 * NULL - failure 112 */ 113 const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui, 114 uint8_t oui_size, 115 const uint8_t *ie, 116 uint16_t ie_len); 117 118 /** 119 * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie 120 * @oui: oui buffer 121 * @oui_size: oui size 122 * @ie: source ie address 123 * @ie_len: source ie length 124 * 125 * This function find out ext ie from ext id (passed oui) 126 * 127 * Return: vendor ie address - success 128 * NULL - failure 129 */ 130 const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui, 131 uint8_t oui_size, 132 const uint8_t *ie, 133 uint16_t ie_len); 134 135 /** 136 * wlan_is_emulation_platform() - check if platform is emulation based 137 * @phy_version - psoc nif phy_version 138 * 139 * Return: boolean value based on platform type 140 */ 141 bool wlan_is_emulation_platform(uint32_t phy_version); 142 143 /** 144 * wlan_get_pdev_id_from_vdev_id() - Helper func to derive pdev id from vdev_id 145 * @psoc: psoc object 146 * @vdev_id: vdev identifier 147 * @dbg_id: object manager debug id 148 * 149 * This function is used to derive the pdev id from vdev id for a psoc 150 * 151 * Return : pdev_id - +ve integer for success and WLAN_INVALID_PDEV_ID 152 * for failure 153 */ 154 uint32_t wlan_get_pdev_id_from_vdev_id(struct wlan_objmgr_psoc *psoc, 155 uint8_t vdev_id, 156 wlan_objmgr_ref_dbgid dbg_id); 157 158 /** 159 * wlan_util_get_vdev_by_ifname() - function to return vdev object from psoc 160 * matching given interface name 161 * @psoc: psoc object 162 * @ifname: interface name 163 * @ref_id: object manager ref id 164 * 165 * This function returns vdev object from psoc by interface name. If found this 166 * will also take reference with given ref_id 167 * 168 * Return : vdev object if found, NULL otherwise 169 */ 170 struct wlan_objmgr_vdev *wlan_util_get_vdev_by_ifname( 171 struct wlan_objmgr_psoc *psoc, char *ifname, 172 wlan_objmgr_ref_dbgid ref_id); 173 174 /** 175 * wlan_util_vdev_get_if_name() - get vdev's interface name 176 * @vdev: VDEV object 177 * 178 * API to get vdev's interface name 179 * 180 * Return: 181 * @id: vdev's interface name 182 */ 183 uint8_t *wlan_util_vdev_get_if_name(struct wlan_objmgr_vdev *vdev); 184 185 /** 186 * wlan_util_is_vdev_active() - Check for vdev active 187 * @pdev: pdev pointer 188 * @dbg_id: debug id for ref counting 189 * 190 * Return: QDF_STATUS_SUCCESS in case of vdev active 191 * QDF_STATUS_E_INVAL, if dev is not active 192 */ 193 QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev, 194 wlan_objmgr_ref_dbgid dbg_id); 195 196 /** 197 * wlan_vdev_is_up() - Check for vdev is in UP state 198 * @vdev: vdev pointer 199 * 200 * Return: QDF_STATUS_SUCCESS, if vdev is in up, otherwise QDF_STATUS_E_FAILURE 201 */ 202 QDF_STATUS wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev); 203 204 /** 205 * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches 206 * with other vdevs in pdev 207 * @pdev: pdev object 208 * @vdev: vdev object 209 * @ref_id: object manager ref id 210 * 211 * This function checks the vdev desired channel with other vdev channels 212 * 213 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 214 */ 215 QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev, 216 struct wlan_objmgr_vdev *vdev, 217 wlan_objmgr_ref_dbgid dbg_id); 218 219 /** 220 * wlan_util_change_map_index() - function to set/reset given index bit 221 * @map: bitmpap 222 * @id: bit index 223 * @set: 1 for set, 0 of reset 224 * 225 * This function set/reset given index bit 226 * 227 * Return: void 228 */ 229 void wlan_util_change_map_index(unsigned long *map, uint8_t id, uint8_t set); 230 231 /** 232 * wlan_util_map_index_is_set() - function to check whether given index bit is 233 * set 234 * @map: bitmpap 235 * @id: bit index 236 * 237 * This function checks the given index bit is set 238 * 239 * Return: true, if bit is set, otherwise false 240 */ 241 bool wlan_util_map_index_is_set(unsigned long *map, uint8_t id); 242 243 /** 244 * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change 245 * pending flag 246 * @pdev: pdev object 247 * @vdev_id_map: bitmap to derive channel change vdevs 248 * @ref_id: object manager ref id 249 * 250 * This function test/set channel change pending flag 251 * 252 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 253 * otherwise QDF_STATUS_E_FAILURE 254 */ 255 QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev, 256 unsigned long *vdev_id_map, 257 wlan_objmgr_ref_dbgid dbg_id); 258 259 /** 260 * wlan_chan_eq() - function to check whether both channels are same 261 * @chan1: channel1 object 262 * @chan2: channel2 object 263 * 264 * This function checks the chan1 and chan2 are same 265 * 266 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 267 */ 268 QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2); 269 270 /** 271 * wlan_chan_copy() - function to copy channel 272 * @tgt: target channel object 273 * @src: src achannel object 274 * 275 * This function copies channel data from src to tgt 276 * 277 * Return: void 278 */ 279 void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src); 280 281 /** 282 * wlan_vdev_get_active_channel() - derives the vdev operating channel 283 * @vdev: VDEV object 284 * 285 * This function checks vdev state and return the channel pointer accordingly 286 * 287 * Return: active channel, if vdev chan config is valid 288 * NULL, if VDEV is in INIT or STOP state 289 */ 290 struct wlan_channel *wlan_vdev_get_active_channel 291 (struct wlan_objmgr_vdev *vdev); 292 293 /** 294 * wlan_util_stats_get_rssi() - API to get rssi in dbm 295 * @db2dbm_enabled: If db2dbm capability is enabled 296 * @bcn_snr: beacon snr 297 * @dat_snr: data snr 298 * @rssi: rssi 299 * 300 * This function gets the rssi based on db2dbm support. If this feature is 301 * present in hw then it means firmware directly sends rssi and no converstion 302 * is required. If this capablity is not present then host needs to convert 303 * snr to rssi 304 * 305 * Return: None 306 */ 307 void 308 wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr, 309 int8_t *rssi); 310 311 /** 312 * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state 313 * @pdev: pdev pointer 314 * @dbg_id: module id 315 * 316 * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS 317 * substate 318 * 319 * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate 320 * otherwise QDF_STATUS_E_FAILURE 321 */ 322 QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev, 323 wlan_objmgr_ref_dbgid dbg_id); 324 325 /** 326 * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan 327 * @pdev: pdev pointer 328 * @dbg_id: module id 329 * 330 * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in 331 * S_UP state 332 * 333 * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE 334 */ 335 QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev, 336 wlan_objmgr_ref_dbgid dbg_id); 337 #endif /* _WLAN_UTILITY_H_ */ 338