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_vdev_ch_check_filter - vdev chan check filter object 37 * @flag: matches or not 38 * @vdev: vdev to be checked against all the active vdevs 39 */ 40 struct wlan_vdev_ch_check_filter { 41 uint8_t flag; 42 struct wlan_objmgr_vdev *vdev; 43 }; 44 45 /** 46 * struct wlan_peer_count- vdev connected peer count 47 * @opmode: QDF mode 48 * @peer_count: peer count 49 **/ 50 struct wlan_op_mode_peer_count { 51 enum QDF_OPMODE opmode; 52 uint16_t peer_count; 53 }; 54 55 /** 56 * wlan_chan_to_freq() - converts channel to frequency 57 * @chan: channel number 58 * 59 * @return frequency of the channel 60 */ 61 uint32_t wlan_chan_to_freq(uint8_t chan); 62 63 /** 64 * wlan_freq_to_chan() - converts frequency to channel 65 * @freq: frequency 66 * 67 * Return: channel of frequency 68 */ 69 uint8_t wlan_freq_to_chan(uint32_t freq); 70 71 /** 72 * wlan_is_ie_valid() - Determine if an IE sequence is valid 73 * @ie: Pointer to the IE buffer 74 * @ie_len: Length of the IE buffer @ie 75 * 76 * This function validates that the IE sequence is valid by verifying 77 * that the sum of the lengths of the embedded elements match the 78 * length of the sequence. 79 * 80 * Note well that a 0-length IE sequence is considered valid. 81 * 82 * Return: true if the IE sequence is valid, false if it is invalid 83 */ 84 bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len); 85 86 /** 87 * wlan_get_ie_ptr_from_eid() - Find out ie from eid 88 * @eid: element id 89 * @ie: source ie address 90 * @ie_len: source ie length 91 * 92 * Return: vendor ie address - success 93 * NULL - failure 94 */ 95 const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid, 96 const uint8_t *ie, 97 int ie_len); 98 99 /** 100 * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie 101 * @oui: oui buffer 102 * @oui_size: oui size 103 * @ie: source ie address 104 * @ie_len: source ie length 105 * 106 * This function find out vendor ie by pass source ie and vendor oui. 107 * 108 * Return: vendor ie address - success 109 * NULL - failure 110 */ 111 const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui, 112 uint8_t oui_size, 113 const uint8_t *ie, 114 uint16_t ie_len); 115 116 /** 117 * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie 118 * @oui: oui buffer 119 * @oui_size: oui size 120 * @ie: source ie address 121 * @ie_len: source ie length 122 * 123 * This function find out ext ie from ext id (passed oui) 124 * 125 * Return: vendor ie address - success 126 * NULL - failure 127 */ 128 const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui, 129 uint8_t oui_size, 130 const uint8_t *ie, 131 uint16_t ie_len); 132 133 /** 134 * wlan_is_emulation_platform() - check if platform is emulation based 135 * @phy_version - psoc nif phy_version 136 * 137 * Return: boolean value based on platform type 138 */ 139 bool wlan_is_emulation_platform(uint32_t phy_version); 140 141 /** 142 * wlan_get_pdev_id_from_vdev_id() - Helper func to derive pdev id from vdev_id 143 * @psoc: psoc object 144 * @vdev_id: vdev identifier 145 * @dbg_id: object manager debug id 146 * 147 * This function is used to derive the pdev id from vdev id for a psoc 148 * 149 * Return : pdev_id - +ve integer for success and WLAN_INVALID_PDEV_ID 150 * for failure 151 */ 152 uint32_t wlan_get_pdev_id_from_vdev_id(struct wlan_objmgr_psoc *psoc, 153 uint8_t vdev_id, 154 wlan_objmgr_ref_dbgid dbg_id); 155 156 /** 157 * wlan_util_is_vdev_active() - Check for vdev active 158 * @pdev: pdev pointer 159 * @dbg_id: debug id for ref counting 160 * 161 * Return: QDF_STATUS_SUCCESS in case of vdev active 162 * QDF_STATUS_E_INVAL, if dev is not active 163 */ 164 QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev, 165 wlan_objmgr_ref_dbgid dbg_id); 166 167 /** 168 * wlan_vdev_is_up() - Check for vdev is in UP state 169 * @vdev: vdev pointer 170 * 171 * Return: QDF_STATUS_SUCCESS, if vdev is in up, otherwise QDF_STATUS_E_FAILURE 172 */ 173 QDF_STATUS wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev); 174 175 /** 176 * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches 177 * with other vdevs in pdev 178 * @pdev: pdev object 179 * @vdev: vdev object 180 * @ref_id: object manager ref id 181 * 182 * This function checks the vdev desired channel with other vdev channels 183 * 184 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 185 */ 186 QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev, 187 struct wlan_objmgr_vdev *vdev, 188 wlan_objmgr_ref_dbgid dbg_id); 189 190 /** 191 * wlan_util_change_map_index() - function to set/reset given index bit 192 * @map: bitmpap 193 * @id: bit index 194 * @set: 1 for set, 0 of reset 195 * 196 * This function set/reset given index bit 197 * 198 * Return: void 199 */ 200 void wlan_util_change_map_index(unsigned long *map, uint8_t id, uint8_t set); 201 202 /** 203 * wlan_util_map_index_is_set() - function to check whether given index bit is 204 * set 205 * @map: bitmpap 206 * @id: bit index 207 * 208 * This function checks the given index bit is set 209 * 210 * Return: true, if bit is set, otherwise false 211 */ 212 bool wlan_util_map_index_is_set(unsigned long *map, uint8_t id); 213 214 /** 215 * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change 216 * pending flag 217 * @pdev: pdev object 218 * @vdev_id_map: bitmap to derive channel change vdevs 219 * @ref_id: object manager ref id 220 * 221 * This function test/set channel change pending flag 222 * 223 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 224 * otherwise QDF_STATUS_E_FAILURE 225 */ 226 QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev, 227 unsigned long *vdev_id_map, 228 wlan_objmgr_ref_dbgid dbg_id); 229 230 /** 231 * wlan_chan_eq() - function to check whether both channels are same 232 * @chan1: channel1 object 233 * @chan2: channel2 object 234 * 235 * This function checks the chan1 and chan2 are same 236 * 237 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 238 */ 239 QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2); 240 241 /** 242 * wlan_chan_copy() - function to copy channel 243 * @tgt: target channel object 244 * @src: src achannel object 245 * 246 * This function copies channel data from src to tgt 247 * 248 * Return: void 249 */ 250 void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src); 251 252 /** 253 * wlan_vdev_get_active_channel() - derives the vdev operating channel 254 * @vdev: VDEV object 255 * 256 * This function checks vdev state and return the channel pointer accordingly 257 * 258 * Return: active channel, if vdev chan config is valid 259 * NULL, if VDEV is in INIT or STOP state 260 */ 261 struct wlan_channel *wlan_vdev_get_active_channel 262 (struct wlan_objmgr_vdev *vdev); 263 264 /** 265 * wlan_util_stats_get_rssi() - API to get rssi in dbm 266 * @db2dbm_enabled: If db2dbm capability is enabled 267 * @bcn_snr: beacon snr 268 * @dat_snr: data snr 269 * @rssi: rssi 270 * 271 * This function gets the rssi based on db2dbm support. If this feature is 272 * present in hw then it means firmware directly sends rssi and no converstion 273 * is required. If this capablity is not present then host needs to convert 274 * snr to rssi 275 * 276 * Return: None 277 */ 278 void 279 wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr, 280 int8_t *rssi); 281 282 /** 283 * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state 284 * @pdev: pdev pointer 285 * @dbg_id: module id 286 * 287 * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS 288 * substate 289 * 290 * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate 291 * otherwise QDF_STATUS_E_FAILURE 292 */ 293 QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev, 294 wlan_objmgr_ref_dbgid dbg_id); 295 296 /** 297 * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan 298 * @pdev: pdev pointer 299 * @dbg_id: module id 300 * 301 * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in 302 * S_UP state 303 * 304 * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE 305 */ 306 QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev, 307 wlan_objmgr_ref_dbgid dbg_id); 308 309 /** 310 * wlan_util_get_peer_count_for_mode - This api gives vdev mode specific 311 * peer count` 312 * @pdev: PDEV object 313 * @mode: Operation mode. 314 * 315 * Return: int- peer count for operating mode 316 */ 317 uint16_t wlan_util_get_peer_count_for_mode(struct wlan_objmgr_pdev *pdev, 318 enum QDF_OPMODE mode); 319 320 #endif /* _WLAN_UTILITY_H_ */ 321