1 /*
2  * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: wlan_hdd_oemdata.h
22  *
23  * Internal includes for the oem data
24  */
25 
26 #ifndef __WLAN_HDD_OEM_DATA_H__
27 #define __WLAN_HDD_OEM_DATA_H__
28 
29 #include "wmi_unified_param.h"
30 
31 struct hdd_context;
32 
33 #ifdef FEATURE_OEM_DATA
34 #define WLAN_WAIT_TIME_GET_OEM_DATA 1000
35 #endif
36 #ifdef FEATURE_OEM_DATA_SUPPORT
37 
38 #ifndef OEM_DATA_REQ_SIZE
39 #define OEM_DATA_REQ_SIZE 500
40 #endif
41 
42 #ifndef OEM_DATA_RSP_SIZE
43 #define OEM_DATA_RSP_SIZE 1724
44 #endif
45 
46 #define OEM_APP_SIGNATURE_LEN      16
47 #define OEM_APP_SIGNATURE_STR      "QUALCOMM-OEM-APP"
48 
49 #define OEM_TARGET_SIGNATURE_LEN   8
50 #define OEM_TARGET_SIGNATURE       "QUALCOMM"
51 
52 #define OEM_CAP_MAX_NUM_CHANNELS   128
53 
54 /**
55  * enum oem_err_code - OEM error codes
56  * @OEM_ERR_NULL_CONTEXT: %NULL context
57  * @OEM_ERR_APP_NOT_REGISTERED: OEM App is not registered
58  * @OEM_ERR_INVALID_SIGNATURE: Invalid signature
59  * @OEM_ERR_NULL_MESSAGE_HEADER: Invalid message header
60  * @OEM_ERR_INVALID_MESSAGE_TYPE: Invalid message type
61  * @OEM_ERR_INVALID_MESSAGE_LENGTH: Invalid length in message body
62  */
63 enum oem_err_code {
64 	OEM_ERR_NULL_CONTEXT = 1,
65 	OEM_ERR_APP_NOT_REGISTERED,
66 	OEM_ERR_INVALID_SIGNATURE,
67 	OEM_ERR_NULL_MESSAGE_HEADER,
68 	OEM_ERR_INVALID_MESSAGE_TYPE,
69 	OEM_ERR_INVALID_MESSAGE_LENGTH
70 };
71 
72 /**
73  * struct driver_version - Driver version identifier (w.x.y.z)
74  * @major: Version ID major number
75  * @minor: Version ID minor number
76  * @patch: Version ID patch number
77  * @build: Version ID build number
78  */
79 struct driver_version {
80 	uint8_t major;
81 	uint8_t minor;
82 	uint8_t patch;
83 	uint8_t build;
84 };
85 
86 /**
87  * struct oem_data_cap - OEM Data Capabilities
88  * @oem_target_signature: Signature of chipset vendor, e.g. QUALCOMM
89  * @oem_target_type: Chip type
90  * @oem_fw_version: Firmware version
91  * @driver_version: Host software version
92  * @allowed_dwell_time_min: Channel dwell time - allowed minimum
93  * @allowed_dwell_time_max: Channel dwell time - allowed maximum
94  * @curr_dwell_time_min: Channel dwell time - current minimim
95  * @curr_dwell_time_max: Channel dwell time - current maximum
96  * @supported_bands: Supported bands, 2.4G or 5G Hz
97  * @num_channels: Num of channels IDs to follow
98  * @channel_list: List of channel IDs
99  */
100 struct oem_data_cap {
101 	uint8_t oem_target_signature[OEM_TARGET_SIGNATURE_LEN];
102 	uint32_t oem_target_type;
103 	uint32_t oem_fw_version;
104 	struct driver_version driver_version;
105 	uint16_t allowed_dwell_time_min;
106 	uint16_t allowed_dwell_time_max;
107 	uint16_t curr_dwell_time_min;
108 	uint16_t curr_dwell_time_max;
109 	uint16_t supported_bands;
110 	uint16_t num_channels;
111 	uint8_t channel_list[OEM_CAP_MAX_NUM_CHANNELS];
112 };
113 
114 /**
115  * struct hdd_channel_info - Channel information
116  * @reserved0: reserved for padding and future use
117  * @mhz: primary 20 MHz channel frequency in mhz
118  * @band_center_freq1: Center frequency 1 in MHz
119  * @band_center_freq2: Center frequency 2 in MHz, valid only for 11ac
120  *	VHT 80+80 mode
121  * @info: channel info
122  * @reg_info_1: regulatory information field 1 which contains min power,
123  *	max power, reg power and reg class id
124  * @reg_info_2: regulatory information field 2 which contains antennamax
125  */
126 struct hdd_channel_info {
127 	uint32_t reserved0;
128 	uint32_t mhz;
129 	uint32_t band_center_freq1;
130 	uint32_t band_center_freq2;
131 	uint32_t info;
132 	uint32_t reg_info_1;
133 	uint32_t reg_info_2;
134 };
135 
136 /**
137  * struct peer_status_info - Status information for a given peer
138  * @peer_mac_addr: peer mac address
139  * @peer_status: peer status: 1: CONNECTED, 2: DISCONNECTED
140  * @vdev_id: vdev_id for the peer mac
141  * @peer_capability: peer capability: 0: RTT/RTT2, 1: RTT3. Default is 0
142  * @reserved0: reserved0
143  * @peer_chan_info: channel info on which peer is connected
144  */
145 struct peer_status_info {
146 	uint8_t peer_mac_addr[ETH_ALEN];
147 	uint8_t peer_status;
148 	uint8_t vdev_id;
149 	uint32_t peer_capability;
150 	uint32_t reserved0;
151 	struct hdd_channel_info peer_chan_info;
152 };
153 
154 /**
155  * struct oem_get_capability_rsp - capabilities set by userspace and target.
156  * @target_cap: target capabilities
157  * @cap: capabilities set by userspace via set request
158  */
159 struct oem_get_capability_rsp {
160 	struct oem_data_cap target_cap;
161 	struct sme_oem_capability cap;
162 };
163 
164 /**
165  * hdd_send_peer_status_ind_to_oem_app() -
166  * Function to send peer status to a registered application
167  * @peer_mac: MAC address of peer
168  * @peer_status: ePeerConnected or ePeerDisconnected
169  * @peer_capability: 0: RTT/RTT2, 1: RTT3. Default is 0
170  * @vdev_id: vdev_id
171  * @chan_info: operating channel information
172  * @dev_mode: dev mode for which indication is sent
173  *
174  * Return: none
175  */
176 void hdd_send_peer_status_ind_to_oem_app(struct qdf_mac_addr *peer_mac,
177 					 uint8_t peer_status,
178 					 uint8_t peer_capability,
179 					 uint8_t vdev_id,
180 					 struct oem_channel_info *chan_info,
181 					 enum QDF_OPMODE dev_mode);
182 
183 int iw_get_oem_data_cap(struct net_device *dev, struct iw_request_info *info,
184 			union iwreq_data *wrqu, char *extra);
185 
186 /**
187  * oem_activate_service() - API to register the oem command handler
188  * @hdd_ctx: Pointer to HDD Context
189  *
190  * This API is used to register the handler to receive netlink message
191  * from an OEM application process
192  *
193  * Return: 0 on success and errno on failure
194  */
195 int oem_activate_service(struct hdd_context *hdd_ctx);
196 
197 /**
198  * oem_deactivate_service() - API to unregister the oem command handler
199  *
200  * This API is used to deregister the handler to receive netlink message
201  * from an OEM application process
202  *
203  * Return: 0 on success and errno on failure
204  */
205 int oem_deactivate_service(void);
206 
207 void hdd_send_oem_data_rsp_msg(struct oem_data_rsp *oem_rsp);
208 
209 /**
210  * hdd_update_channel_bw_info() - set bandwidth info for the chan
211  * @hdd_ctx: hdd context
212  * @chan_freq: channel freq for which info are required
213  * @hdd_chan_info: struct where the bandwidth info is filled
214  *
215  * This function finds the maximum bandwidth allowed, secondary
216  * channel offset and center freq for the channel as per regulatory
217  * domain and uses these info calculate the phy mode for the
218  * channel.
219  *
220  * Return: void
221  */
222 void hdd_update_channel_bw_info(struct hdd_context *hdd_ctx,
223 				uint32_t chan_freq,
224 				void *hdd_chan_info);
225 #else
oem_activate_service(struct hdd_context * hdd_ctx)226 static inline int oem_activate_service(struct hdd_context *hdd_ctx)
227 {
228 	return 0;
229 }
230 
oem_deactivate_service(void)231 static inline int oem_deactivate_service(void)
232 {
233 	return 0;
234 }
235 
hdd_send_oem_data_rsp_msg(void * oem_rsp)236 static inline void hdd_send_oem_data_rsp_msg(void *oem_rsp) {}
237 
hdd_update_channel_bw_info(struct hdd_context * hdd_ctx,uint32_t chan_freq,void * hdd_chan_info)238 static inline void hdd_update_channel_bw_info(struct hdd_context *hdd_ctx,
239 					      uint32_t chan_freq,
240 					      void *hdd_chan_info) {}
241 #endif /* FEATURE_OEM_DATA_SUPPORT */
242 
243 #ifdef FEATURE_OEM_DATA
244 #define OEM_DATA_MAX_SIZE 1500
245 /**
246  * wlan_hdd_cfg80211_oem_data_handler() - the handler for oem data
247  * @wiphy: wiphy structure pointer
248  * @wdev: Wireless device structure pointer
249  * @data: Pointer to the data received
250  * @data_len: Length of @data
251  *
252  * Return: 0 on success; errno on failure
253  */
254 int wlan_hdd_cfg80211_oem_data_handler(struct wiphy *wiphy,
255 				       struct wireless_dev *wdev,
256 				       const void *data, int data_len);
257 
258 extern const struct nla_policy
259 	oem_data_attr_policy
260 	[QCA_WLAN_VENDOR_ATTR_OEM_DATA_PARAMS_MAX + 1];
261 
262 #define FEATURE_OEM_DATA_VENDOR_COMMANDS                                \
263 {                                                                       \
264 	.info.vendor_id = QCA_NL80211_VENDOR_ID,                        \
265 	.info.subcmd = QCA_NL80211_VENDOR_SUBCMD_OEM_DATA,              \
266 	.flags = WIPHY_VENDOR_CMD_NEED_WDEV |                           \
267 		WIPHY_VENDOR_CMD_NEED_NETDEV |                          \
268 		WIPHY_VENDOR_CMD_NEED_RUNNING,                          \
269 	.doit = wlan_hdd_cfg80211_oem_data_handler,                     \
270 	vendor_command_policy(oem_data_attr_policy,                     \
271 			      QCA_WLAN_VENDOR_ATTR_OEM_DATA_PARAMS_MAX) \
272 },
273 #else
274 #define FEATURE_OEM_DATA_VENDOR_COMMANDS
275 #endif
276 
277 #ifdef FEATURE_OEM_DATA
278 /**
279  * hdd_oem_event_async_cb() - callback for oem data async event
280  * @oem_event_data: oem data received in the event from the FW
281  *
282  * Return: None
283  */
284 void hdd_oem_event_async_cb(const struct oem_data *oem_event_data);
285 
286 /**
287  * hdd_oem_event_handler_cb() - callback for oem data event
288  * @oem_event_data: oem data received in the event from the FW
289  * @vdev_id: vdev id
290  *
291  * Return: None
292  */
293 void hdd_oem_event_handler_cb(const struct oem_data *oem_event_data,
294 			      uint8_t vdev_id);
295 #else
hdd_oem_event_handler_cb(void * oem_event_data,uint8_t vdev_id)296 static inline void hdd_oem_event_handler_cb(void *oem_event_data,
297 					    uint8_t vdev_id)
298 {
299 }
300 
hdd_oem_event_async_cb(void * oem_event_data)301 static inline void hdd_oem_event_async_cb(void *oem_event_data)
302 {
303 }
304 #endif
305 #endif /* __WLAN_HDD_OEM_DATA_H__ */
306