xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/utils/inc/wlan_utility.h (revision a175314c51a4ce5cec2835cc8a8c7dc0c1810915)
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 /**
32  * struct wlan_find_vdev_filter - find vdev filter object. this can be extended
33  * @ifname:           interface name of vdev
34  * @found_vdev:       found vdev object matching one or more of above params
35  */
36 struct wlan_find_vdev_filter {
37 	char *ifname;
38 	struct wlan_objmgr_vdev *found_vdev;
39 };
40 
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 /**
50  * wlan_freq_to_chan() - converts frequency to channel
51  * @freq: frequency
52  *
53  * Return: channel of frequency
54  */
55 uint8_t wlan_freq_to_chan(uint32_t freq);
56 
57 /**
58  * wlan_is_ie_valid() - Determine if an IE sequence is valid
59  * @ie: Pointer to the IE buffer
60  * @ie_len: Length of the IE buffer @ie
61  *
62  * This function validates that the IE sequence is valid by verifying
63  * that the sum of the lengths of the embedded elements match the
64  * length of the sequence.
65  *
66  * Note well that a 0-length IE sequence is considered valid.
67  *
68  * Return: true if the IE sequence is valid, false if it is invalid
69  */
70 bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len);
71 
72 /**
73  * wlan_get_ie_ptr_from_eid() - Find out ie from eid
74  * @eid: element id
75  * @ie: source ie address
76  * @ie_len: source ie length
77  *
78  * Return: vendor ie address - success
79  *         NULL - failure
80  */
81 const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid,
82 					const uint8_t *ie,
83 					int ie_len);
84 
85 /**
86  * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie
87  * @oui: oui buffer
88  * @oui_size: oui size
89  * @ie: source ie address
90  * @ie_len: source ie length
91  *
92  * This function find out vendor ie by pass source ie and vendor oui.
93  *
94  * Return: vendor ie address - success
95  *         NULL - failure
96  */
97 const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui,
98 					       uint8_t oui_size,
99 					       const uint8_t *ie,
100 					       uint16_t ie_len);
101 
102 /**
103  * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie
104  * @oui: oui buffer
105  * @oui_size: oui size
106  * @ie: source ie address
107  * @ie_len: source ie length
108  *
109  * This function find out ext ie from ext id (passed oui)
110  *
111  * Return: vendor ie address - success
112  *         NULL - failure
113  */
114 const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui,
115 					       uint8_t oui_size,
116 					       const uint8_t *ie,
117 					       uint16_t ie_len);
118 
119 /**
120  * wlan_is_emulation_platform() - check if platform is emulation based
121  * @phy_version - psoc nif phy_version
122  *
123  * Return: boolean value based on platform type
124  */
125 bool wlan_is_emulation_platform(uint32_t phy_version);
126 
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 /**
143  * wlan_util_get_vdev_by_ifname() - function to return vdev object from psoc
144  * matching given interface name
145  * @psoc    : psoc object
146  * @ifname  : interface name
147  * @ref_id  : object manager ref id
148  *
149  * This function returns vdev object from psoc by interface name. If found this
150  * will also take reference with given ref_id
151  *
152  * Return : vdev object if found, NULL otherwise
153  */
154 struct wlan_objmgr_vdev *wlan_util_get_vdev_by_ifname(
155 				struct wlan_objmgr_psoc *psoc, char *ifname,
156 				wlan_objmgr_ref_dbgid ref_id);
157 
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 /*
170  * wlan_util_is_vap_active() - Check for vap active
171  * @pdev: pdev pointer
172  * @dbg_id: debug id for ref counting
173  *
174  * @Return: QDF_STATUS_SUCCESS in case of vap active
175  */
176 QDF_STATUS wlan_util_is_vap_active(struct wlan_objmgr_pdev *pdev,
177 				   wlan_objmgr_ref_dbgid dbg_id);
178 #endif /* _WLAN_UTILITY_H_ */
179