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