1 /* 2 * Copyright (c) 2017-2018 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 mandatory API from legacy 21 */ 22 23 #ifndef _WLAN_UTILITY_H_ 24 #define _WLAN_UTILITY_H_ 25 26 #include <qdf_types.h> 27 #include <wlan_objmgr_psoc_obj.h> 28 #include <wlan_objmgr_pdev_obj.h> 29 #include <wlan_objmgr_vdev_obj.h> 30 31 /** 32 * struct wlan_find_vdev_filter - find vdev filter object. this can be extended 33 * @ifname: interface name of vdev 34 * @found_vdev: found vdev object matching one or more of above params 35 */ 36 struct wlan_find_vdev_filter { 37 char *ifname; 38 struct wlan_objmgr_vdev *found_vdev; 39 }; 40 41 #ifdef CMN_VDEV_MLME_SM_ENABLE 42 /** 43 * struct wlan_vdev_ch_check_filter - vdev chan check filter object 44 * @flag: matches or not 45 * @vdev: vdev to be checked against all the active vdevs 46 */ 47 struct wlan_vdev_ch_check_filter { 48 uint8_t flag; 49 struct wlan_objmgr_vdev *vdev; 50 }; 51 #endif 52 53 /** 54 * wlan_chan_to_freq() - converts channel to frequency 55 * @chan: channel number 56 * 57 * @return frequency of the channel 58 */ 59 uint32_t wlan_chan_to_freq(uint8_t chan); 60 61 /** 62 * wlan_freq_to_chan() - converts frequency to channel 63 * @freq: frequency 64 * 65 * Return: channel of frequency 66 */ 67 uint8_t wlan_freq_to_chan(uint32_t freq); 68 69 /** 70 * wlan_is_ie_valid() - Determine if an IE sequence is valid 71 * @ie: Pointer to the IE buffer 72 * @ie_len: Length of the IE buffer @ie 73 * 74 * This function validates that the IE sequence is valid by verifying 75 * that the sum of the lengths of the embedded elements match the 76 * length of the sequence. 77 * 78 * Note well that a 0-length IE sequence is considered valid. 79 * 80 * Return: true if the IE sequence is valid, false if it is invalid 81 */ 82 bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len); 83 84 /** 85 * wlan_get_ie_ptr_from_eid() - Find out ie from eid 86 * @eid: element id 87 * @ie: source ie address 88 * @ie_len: source ie length 89 * 90 * Return: vendor ie address - success 91 * NULL - failure 92 */ 93 const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid, 94 const uint8_t *ie, 95 int ie_len); 96 97 /** 98 * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie 99 * @oui: oui buffer 100 * @oui_size: oui size 101 * @ie: source ie address 102 * @ie_len: source ie length 103 * 104 * This function find out vendor ie by pass source ie and vendor oui. 105 * 106 * Return: vendor ie address - success 107 * NULL - failure 108 */ 109 const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui, 110 uint8_t oui_size, 111 const uint8_t *ie, 112 uint16_t ie_len); 113 114 /** 115 * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie 116 * @oui: oui buffer 117 * @oui_size: oui size 118 * @ie: source ie address 119 * @ie_len: source ie length 120 * 121 * This function find out ext ie from ext id (passed oui) 122 * 123 * Return: vendor ie address - success 124 * NULL - failure 125 */ 126 const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui, 127 uint8_t oui_size, 128 const uint8_t *ie, 129 uint16_t ie_len); 130 131 /** 132 * wlan_is_emulation_platform() - check if platform is emulation based 133 * @phy_version - psoc nif phy_version 134 * 135 * Return: boolean value based on platform type 136 */ 137 bool wlan_is_emulation_platform(uint32_t phy_version); 138 139 /** 140 * wlan_get_pdev_id_from_vdev_id() - Helper func to derive pdev id from vdev_id 141 * @psoc: psoc object 142 * @vdev_id: vdev identifier 143 * @dbg_id: object manager debug id 144 * 145 * This function is used to derive the pdev id from vdev id for a psoc 146 * 147 * Return : pdev_id - +ve integer for success and WLAN_INVALID_PDEV_ID 148 * for failure 149 */ 150 uint32_t wlan_get_pdev_id_from_vdev_id(struct wlan_objmgr_psoc *psoc, 151 uint8_t vdev_id, 152 wlan_objmgr_ref_dbgid dbg_id); 153 154 /** 155 * wlan_util_get_vdev_by_ifname() - function to return vdev object from psoc 156 * matching given interface name 157 * @psoc: psoc object 158 * @ifname: interface name 159 * @ref_id: object manager ref id 160 * 161 * This function returns vdev object from psoc by interface name. If found this 162 * will also take reference with given ref_id 163 * 164 * Return : vdev object if found, NULL otherwise 165 */ 166 struct wlan_objmgr_vdev *wlan_util_get_vdev_by_ifname( 167 struct wlan_objmgr_psoc *psoc, char *ifname, 168 wlan_objmgr_ref_dbgid ref_id); 169 170 /** 171 * wlan_util_vdev_get_if_name() - get vdev's interface name 172 * @vdev: VDEV object 173 * 174 * API to get vdev's interface name 175 * 176 * Return: 177 * @id: vdev's interface name 178 */ 179 uint8_t *wlan_util_vdev_get_if_name(struct wlan_objmgr_vdev *vdev); 180 181 /* 182 * wlan_util_is_vdev_active() - Check for vdev active 183 * @pdev: pdev pointer 184 * @dbg_id: debug id for ref counting 185 * 186 * @Return: QDF_STATUS_SUCCESS in case of vdev active 187 */ 188 QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev, 189 wlan_objmgr_ref_dbgid dbg_id); 190 191 /* 192 * wlan_vdev_is_up() - Check for vdev is in UP state 193 * @vdev: vdev pointer 194 * 195 * @Return: true in case of vdev is in UP state 196 */ 197 bool wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev); 198 199 /** 200 * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches 201 * with other vdevs in pdev 202 * @pdev: pdev object 203 * @vdev: vdev object 204 * @ref_id: object manager ref id 205 * 206 * This function checks the vdev desired channel with other vdev channels 207 * 208 * Return : SUCCESS, if it matches, otherwise FAILURE 209 */ 210 QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev, 211 struct wlan_objmgr_vdev *vdev, 212 wlan_objmgr_ref_dbgid dbg_id); 213 214 /** 215 * wlan_util_change_map_index() - function to set/reset given index bit 216 * @map: bitmpap 217 * @id: bit index 218 * @set: 1 for set, 0 of reset 219 * 220 * This function set/reset given index bit 221 * 222 * Return : void 223 */ 224 void wlan_util_change_map_index(uint32_t *map, uint8_t id, uint8_t set); 225 226 /** 227 * wlan_util_map_index_is_set() - function to check whether given index bit is 228 * set 229 * @map: bitmpap 230 * @id: bit index 231 * 232 * This function checks the given index bit is set 233 * 234 * Return : true, if bit is set, otherwise false 235 */ 236 bool wlan_util_map_index_is_set(uint32_t *map, uint8_t id); 237 238 /** 239 * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change 240 * pending flag 241 * @pdev: pdev object 242 * @vdev_id_map: bitmap to derive channel change vdevs 243 * @ref_id: object manager ref id 244 * 245 * This function test/set channel change pending flag 246 * 247 * Return : SUCCESS, if it iterates through all vdevs, otherwise FAILURE 248 */ 249 QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev, 250 uint32_t *vdev_id_map, 251 wlan_objmgr_ref_dbgid dbg_id); 252 253 /** 254 * wlan_chan_eq() - function to check whether both channels are same 255 * @chan1: channel1 object 256 * @chan2: channel2 object 257 * 258 * This function checks the chan1 and chan2 are same 259 * 260 * Return : SUCCESS, if it matches, otherwise FAILURE 261 */ 262 QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2); 263 264 #endif /* _WLAN_UTILITY_H_ */ 265