wlan_utility.h 9.3 KB

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