wlan_utility.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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_find_vdev_filter - find vdev filter object. this can be extended
  32. * @ifname: interface name of vdev
  33. * @found_vdev: found vdev object matching one or more of above params
  34. */
  35. struct wlan_find_vdev_filter {
  36. char *ifname;
  37. struct wlan_objmgr_vdev *found_vdev;
  38. };
  39. #ifdef CMN_VDEV_MLME_SM_ENABLE
  40. /**
  41. * struct wlan_vdev_ch_check_filter - vdev chan check filter object
  42. * @flag: matches or not
  43. * @vdev: vdev to be checked against all the active vdevs
  44. */
  45. struct wlan_vdev_ch_check_filter {
  46. uint8_t flag;
  47. struct wlan_objmgr_vdev *vdev;
  48. };
  49. #endif
  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_get_vdev_by_ifname() - function to return vdev object from psoc
  145. * matching given interface name
  146. * @psoc: psoc object
  147. * @ifname: interface name
  148. * @ref_id: object manager ref id
  149. *
  150. * This function returns vdev object from psoc by interface name. If found this
  151. * will also take reference with given ref_id
  152. *
  153. * Return : vdev object if found, NULL otherwise
  154. */
  155. struct wlan_objmgr_vdev *wlan_util_get_vdev_by_ifname(
  156. struct wlan_objmgr_psoc *psoc, char *ifname,
  157. wlan_objmgr_ref_dbgid ref_id);
  158. /**
  159. * wlan_util_vdev_get_if_name() - get vdev's interface name
  160. * @vdev: VDEV object
  161. *
  162. * API to get vdev's interface name
  163. *
  164. * Return:
  165. * @id: vdev's interface name
  166. */
  167. uint8_t *wlan_util_vdev_get_if_name(struct wlan_objmgr_vdev *vdev);
  168. /**
  169. * wlan_util_is_vdev_active() - Check for vdev active
  170. * @pdev: pdev pointer
  171. * @dbg_id: debug id for ref counting
  172. *
  173. * Return: QDF_STATUS_SUCCESS in case of vdev active
  174. * QDF_STATUS_E_INVAL, if dev is not active
  175. */
  176. QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev,
  177. wlan_objmgr_ref_dbgid dbg_id);
  178. /**
  179. * wlan_vdev_is_up() - Check for vdev is in UP state
  180. * @vdev: vdev pointer
  181. *
  182. * Return: QDF_STATUS_SUCCESS, if vdev is in up, otherwise QDF_STATUS_E_FAILURE
  183. */
  184. QDF_STATUS wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev);
  185. /**
  186. * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches
  187. * with other vdevs in pdev
  188. * @pdev: pdev object
  189. * @vdev: vdev object
  190. * @ref_id: object manager ref id
  191. *
  192. * This function checks the vdev desired channel with other vdev channels
  193. *
  194. * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE
  195. */
  196. QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev,
  197. struct wlan_objmgr_vdev *vdev,
  198. wlan_objmgr_ref_dbgid dbg_id);
  199. /**
  200. * wlan_util_change_map_index() - function to set/reset given index bit
  201. * @map: bitmpap
  202. * @id: bit index
  203. * @set: 1 for set, 0 of reset
  204. *
  205. * This function set/reset given index bit
  206. *
  207. * Return: void
  208. */
  209. void wlan_util_change_map_index(unsigned long *map, uint8_t id, uint8_t set);
  210. /**
  211. * wlan_util_map_index_is_set() - function to check whether given index bit is
  212. * set
  213. * @map: bitmpap
  214. * @id: bit index
  215. *
  216. * This function checks the given index bit is set
  217. *
  218. * Return: true, if bit is set, otherwise false
  219. */
  220. bool wlan_util_map_index_is_set(unsigned long *map, uint8_t id);
  221. /**
  222. * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change
  223. * pending flag
  224. * @pdev: pdev object
  225. * @vdev_id_map: bitmap to derive channel change vdevs
  226. * @ref_id: object manager ref id
  227. *
  228. * This function test/set channel change pending flag
  229. *
  230. * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs,
  231. * otherwise QDF_STATUS_E_FAILURE
  232. */
  233. QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev,
  234. unsigned long *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: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE
  244. */
  245. QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2);
  246. /**
  247. * wlan_chan_copy() - function to copy channel
  248. * @tgt: target channel object
  249. * @src: src achannel object
  250. *
  251. * This function copies channel data from src to tgt
  252. *
  253. * Return: void
  254. */
  255. void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src);
  256. /**
  257. * wlan_vdev_get_active_channel() - derives the vdev operating channel
  258. * @vdev: VDEV object
  259. *
  260. * This function checks vdev state and return the channel pointer accordingly
  261. *
  262. * Return: active channel, if vdev chan config is valid
  263. * NULL, if VDEV is in INIT or STOP state
  264. */
  265. struct wlan_channel *wlan_vdev_get_active_channel
  266. (struct wlan_objmgr_vdev *vdev);
  267. /**
  268. * wlan_util_stats_get_rssi() - API to get rssi in dbm
  269. * @db2dbm_enabled: If db2dbm capability is enabled
  270. * @bcn_snr: beacon snr
  271. * @dat_snr: data snr
  272. * @rssi: rssi
  273. *
  274. * This function gets the rssi based on db2dbm support. If this feature is
  275. * present in hw then it means firmware directly sends rssi and no converstion
  276. * is required. If this capablity is not present then host needs to convert
  277. * snr to rssi
  278. *
  279. * Return: None
  280. */
  281. void
  282. wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr,
  283. int8_t *rssi);
  284. /**
  285. * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state
  286. * @pdev: pdev pointer
  287. * @dbg_id: module id
  288. *
  289. * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS
  290. * substate
  291. *
  292. * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate
  293. * otherwise QDF_STATUS_E_FAILURE
  294. */
  295. QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev,
  296. wlan_objmgr_ref_dbgid dbg_id);
  297. /**
  298. * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan
  299. * @pdev: pdev pointer
  300. * @dbg_id: module id
  301. *
  302. * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in
  303. * S_UP state
  304. *
  305. * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE
  306. */
  307. QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev,
  308. wlan_objmgr_ref_dbgid dbg_id);
  309. #endif /* _WLAN_UTILITY_H_ */