wlan_utility.h 8.7 KB

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