wlan_utility.h 9.3 KB

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