wlan_utility.h 8.9 KB

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