1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  * Copyright 2024 NXP
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef ZEPHYR_SUPP_MGMT_H
9 #define ZEPHYR_SUPP_MGMT_H
10 
11 #include <zephyr/net/wifi_mgmt.h>
12 
13 #ifndef MAX_SSID_LEN
14 #define MAX_SSID_LEN 32
15 #endif
16 #ifndef MAC_ADDR_LEN
17 #define MAC_ADDR_LEN 6
18 #endif
19 
20 #define MAC_STR_LEN 18 /* for ':' or '-' separated MAC address string */
21 #define CHAN_NUM_LEN 6 /* for space-separated channel numbers string */
22 
23 /**
24  * @brief Get version
25  *
26  * @param dev: Wi-Fi interface name to use
27  * @param params: version to fill
28  *
29  * @return: 0 for OK; <0 for ERROR
30  */
31 int supplicant_get_version(const struct device *dev, struct wifi_version *params);
32 
33 /**
34  * @brief Request a connection
35  *
36  * @param dev: Wi-Fi interface name to use
37  * @param params: Connection details
38  *
39  * @return: 0 for OK; -1 for ERROR
40  */
41 int supplicant_connect(const struct device *dev, struct wifi_connect_req_params *params);
42 
43 /**
44  * @brief Forces station to disconnect and stops any subsequent scan
45  *  or connection attempts
46  *
47  * @param dev: Wi-Fi interface name to use
48  *
49  * @return: 0 for OK; -1 for ERROR
50  */
51 int supplicant_disconnect(const struct device *dev);
52 
53 /**
54  * @brief
55  *
56  * @param dev: Wi-Fi interface name to use
57  * @param status: Status structure to fill
58  *
59  * @return: 0 for OK; -1 for ERROR
60  */
61 int supplicant_status(const struct device *dev, struct wifi_iface_status *status);
62 
63 /**
64  * @brief Request a scan
65  *
66  * @param dev Wi-Fi interface name to use
67  * @param params Scan parameters
68  * @param cb Callback to be called for each scan result
69  *
70  * @return 0 for OK; -1 for ERROR
71  */
72 int supplicant_scan(const struct device *dev, struct wifi_scan_params *params,
73 		    scan_result_cb_t cb);
74 
75 #if defined(CONFIG_NET_STATISTICS_WIFI) || defined(__DOXYGEN__)
76 /**
77  * @brief Get Wi-Fi statistics
78  *
79  * @param dev Wi-Fi interface name to use
80  * @param stats Pointer to stats structure to fill
81  *
82  * @return 0 for OK; -1 for ERROR
83  */
84 int supplicant_get_stats(const struct device *dev, struct net_stats_wifi *stats);
85 /**
86  * @brief Reset Wi-Fi statistics
87  *
88  * @param dev Wi-Fi interface name to use
89  *
90  * @return 0 for OK; -1 for ERROR
91  */
92 int supplicant_reset_stats(const struct device *dev);
93 #endif /* CONFIG_NET_STATISTICS_WIFI || __DOXYGEN__ */
94 
95 /** Flush PMKSA cache entries
96  *
97  * @param dev Pointer to the device structure for the driver instance.
98  *
99  * @return 0 if ok, < 0 if error
100  */
101 int supplicant_pmksa_flush(const struct device *dev);
102 
103 /** Set or get 11K status
104  *
105  * @param dev Pointer to the device structure for the driver instance.
106  * @param params 11k parameters
107  *
108  * @return 0 if ok, < 0 if error
109  */
110 int supplicant_11k_cfg(const struct device *dev, struct wifi_11k_params *params);
111 
112 /** Send 11k neighbor request
113  *
114  * @param dev Pointer to the device structure for the driver instance.
115  * @param params 11k parameters
116  *
117  * @return 0 if ok, < 0 if error
118  */
119 int supplicant_11k_neighbor_request(const struct device *dev, struct wifi_11k_params *params);
120 
121 #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
122 /** Send candidate scan request
123  *
124  * @param dev Pointer to the device structure for the driver instance.
125  * @param params Scan parameters
126  *
127  * @return 0 if ok, < 0 if error
128  */
129 int supplicant_candidate_scan(const struct device *dev, struct wifi_scan_params *params);
130 
131 /** Send 11r roaming request
132  *
133  * @param dev Pointer to the device structure for the driver instance.
134  *
135  * @return 0 if ok, < 0 if error
136  */
137 int supplicant_11r_roaming(const struct device *dev);
138 #endif
139 
140 /**
141  * @brief Set Wi-Fi power save configuration
142  *
143  * @param dev Wi-Fi interface name to use
144  * @param params Power save parameters to set
145  *
146  * @return 0 for OK; -1 for ERROR
147  */
148 int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *params);
149 
150 /**
151  * @brief Set Wi-Fi TWT parameters
152  *
153  * @param dev Wi-Fi interface name to use
154  * @param params TWT parameters to set
155  * @return 0 for OK; -1 for ERROR
156  */
157 int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params);
158 
159 /**
160  * @brief Set Wi-Fi BTWT parameters
161  *
162  * @param dev Wi-Fi interface name to use
163  * @param params BTWT parameters to set
164  * @return 0 for OK; -1 for ERROR
165  */
166 int supplicant_set_btwt(const struct device *dev, struct wifi_twt_params *params);
167 
168 /**
169  * @brief Get Wi-Fi power save configuration
170  *
171  * @param dev Wi-Fi interface name to use
172  * @param config Address of power save configuration to fill
173  * @return 0 for OK; -1 for ERROR
174  */
175 int supplicant_get_power_save_config(const struct device *dev, struct wifi_ps_config *config);
176 
177 /**
178  * @brief Set Wi-Fi Regulatory domain
179  *
180  * @param dev Wi-Fi interface name to use
181  * @param reg_domain Regulatory domain to set
182  * @return 0 for OK; -1 for ERROR
183  */
184 int supplicant_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain);
185 
186 /**
187  * @brief Set Wi-Fi mode of operation
188  *
189  * @param dev Wi-Fi interface name to use
190  * @param mode Mode setting to set
191  * @return 0 for OK; -1 for ERROR
192  */
193 int supplicant_mode(const struct device *dev, struct wifi_mode_info *mode);
194 
195 #if defined CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE || \
196 	defined CONFIG_WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE
197 /** Set Wi-Fi enterprise mode CA/client Cert and key
198  *
199  * @param dev Pointer to the device structure for the driver instance
200  * @param file Pointer to the CA/client Cert and key.
201  *
202  * @return 0 if ok, < 0 if error
203  */
204 int supplicant_add_enterprise_creds(const struct device *dev,
205 		struct wifi_enterprise_creds_params *creds);
206 #endif
207 
208 /**
209  * @brief Set Wi-Fi packet filter for sniffing operation
210  *
211  * @param dev Wi-Fi interface name to use
212  * @param filter Filter settings to set
213  * @return 0 for OK; -1 for ERROR
214  */
215 int supplicant_filter(const struct device *dev, struct wifi_filter_info *filter);
216 
217 /**
218  * @brief Set Wi-Fi channel for monitor or TX injection mode
219  *
220  * @param dev Wi-Fi interface name to use
221  * @param channel Channel settings to set
222  * @return 0 for OK; -1 for ERROR
223  */
224 int supplicant_channel(const struct device *dev, struct wifi_channel_info *channel);
225 
226 /**
227  * @brief Set Wi-Fi RTS threshold
228  *
229  * @param dev Wi-Fi interface handle to use
230  * @param rts_threshold RTS threshold to set
231  * @return 0 for OK; -1 for ERROR
232  */
233 int supplicant_set_rts_threshold(const struct device *dev, unsigned int rts_threshold);
234 
235 /**
236  * @brief Get Wi-Fi RTS threshold
237  *
238  * @param dev Wi-Fi interface handle to use
239  * @param rts_threshold Pointer to the RTS threshold value.
240  * @return 0 for OK; -1 for ERROR
241  */
242 int supplicant_get_rts_threshold(const struct device *dev, unsigned int *rts_threshold);
243 
244 #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
245 /** Send bss transition query
246  *
247  * @param dev Pointer to the device structure for the driver instance.
248  * @param reason query reason
249  *
250  * @return 0 if ok, < 0 if error
251  */
252 int supplicant_btm_query(const struct device *dev, uint8_t reason);
253 #endif
254 
255 /** Send legacy roam
256  *
257  * @param dev Pointer to the device structure for the driver instance.
258  *
259  * @return 0 if ok, < 0 if error
260  */
261 int supplicant_legacy_roam(const struct device *dev);
262 
263 /** Judge ap whether support the capability
264  *
265  * @param dev Pointer to the device structure for the driver instance.
266  * @param capab is the capability to judge
267  *
268  * @return 1 if support, 0 if not support
269  */
270 int supplicant_bss_ext_capab(const struct device *dev, int capab);
271 
272 /** Get Wi-Fi connection parameters recently used
273  *
274  * @param dev Pointer to the device structure for the driver instance
275  * @param params the Wi-Fi connection parameters recently used
276  *
277  * @return 0 if ok, < 0 if error
278  */
279 int supplicant_get_wifi_conn_params(const struct device *dev,
280 			 struct wifi_connect_req_params *params);
281 
282 /** Start a WPS PBC/PIN connection
283  *
284  * @param dev Pointer to the device structure for the driver instance
285  * @param params wps operarion parameters
286  *
287  * @return 0 if ok, < 0 if error
288  */
289 int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
290 
291 #ifdef CONFIG_AP
292 #ifdef CONFIG_WIFI_NM_HOSTAPD_AP
293 /**
294  * @brief Get Wi-Fi AP Status
295  *
296  * @param dev Wi-Fi device
297  * @param params AP status
298  * @return 0 for OK; -1 for ERROR
299  */
300 int hapd_state(const struct device *dev, int *state);
301 
302 /**
303  * @brief Wi-Fi AP configuration parameter.
304  *
305  * @param dev Wi-Fi device
306  * @param params AP parameters
307  * @return 0 for OK; -1 for ERROR
308  */
309 int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_params *params);
310 #else
hapd_state(const struct device * dev,int * state)311 static inline int hapd_state(const struct device *dev, int *state)
312 {
313 	return -EINVAL;
314 }
315 #endif
316 
317 #ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
318 /** Start AP WPS PBC/PIN
319  *
320  * @param dev Pointer to the device structure for the driver instance
321  * @param params wps operarion parameters
322  *
323  * @return 0 if ok, < 0 if error
324  */
325 int supplicant_ap_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
326 #endif
327 
328 /**
329  * @brief Get Wi-Fi SAP status
330  *
331  * @param dev Wi-Fi device
332  * @param status SAP status
333  * @return 0 for OK; -1 for ERROR
334  */
335 int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status);
336 
337 /**
338  * @brief Set Wi-Fi AP configuration
339  *
340  * @param dev Wi-Fi interface name to use
341  * @param params AP configuration parameters to set
342  * @return 0 for OK; -1 for ERROR
343  */
344 int supplicant_ap_enable(const struct device *dev,
345 			 struct wifi_connect_req_params *params);
346 
347 /**
348  * @brief Disable Wi-Fi AP
349  * @param dev Wi-Fi interface name to use
350  * @return 0 for OK; -1 for ERROR
351  */
352 int supplicant_ap_disable(const struct device *dev);
353 
354 /**
355  * @brief Set Wi-Fi AP STA disconnect
356  * @param dev Wi-Fi interface name to use
357  * @param mac_addr MAC address of the station to disconnect
358  * @return 0 for OK; -1 for ERROR
359  */
360 int supplicant_ap_sta_disconnect(const struct device *dev,
361 				 const uint8_t *mac_addr);
362 
363 #endif /* CONFIG_AP */
364 
365 #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
366 /**
367  * @brief Dispatch DPP operations for STA
368  *
369  * @param dev Wi-Fi interface name to use
370  * @param dpp_params DPP action enum and params in string
371  * @return 0 for OK; -1 for ERROR
372  */
373 int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params);
374 
375 #ifdef CONFIG_WIFI_NM_HOSTAPD_AP
376 /**
377  * @brief Dispatch DPP operations for AP
378  *
379  * @param dev Wi-Fi interface name to use
380  * @param dpp_params DPP action enum and params in string
381  * @return 0 for OK; -1 for ERROR
382  */
383 int hapd_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params);
384 #endif /* CONFIG_WIFI_NM_HOSTAPD_AP */
385 #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */
386 #endif /* ZEPHYR_SUPP_MGMT_H */
387