1 /*
2  * Copyright (c) 2017 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief WiFi L2 stack public header
10  */
11 
12 #ifndef ZEPHYR_INCLUDE_NET_WIFI_MGMT_H_
13 #define ZEPHYR_INCLUDE_NET_WIFI_MGMT_H_
14 
15 #include <zephyr/net/net_mgmt.h>
16 #include <zephyr/net/wifi.h>
17 #include <zephyr/net/ethernet.h>
18 #include <zephyr/net/offloaded_netdev.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /**
25  * @addtogroup wifi_mgmt
26  * @{
27  */
28 
29 /* Management part definitions */
30 
31 #define _NET_WIFI_LAYER	NET_MGMT_LAYER_L2
32 #define _NET_WIFI_CODE	0x156
33 #define _NET_WIFI_BASE	(NET_MGMT_IFACE_BIT |			\
34 			 NET_MGMT_LAYER(_NET_WIFI_LAYER) |	\
35 			 NET_MGMT_LAYER_CODE(_NET_WIFI_CODE))
36 #define _NET_WIFI_EVENT	(_NET_WIFI_BASE | NET_MGMT_EVENT_BIT)
37 
38 #ifdef CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX
39 #define WIFI_MGMT_SCAN_SSID_FILT_MAX CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX
40 #else
41 #define WIFI_MGMT_SCAN_SSID_FILT_MAX 1
42 #endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */
43 
44 #ifdef CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL
45 #define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL
46 #else
47 #define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 1
48 #endif /* CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL */
49 
50 #define WIFI_MGMT_BAND_STR_SIZE_MAX 8
51 
52 /** Wi-Fi management commands */
53 enum net_request_wifi_cmd {
54 	/** Scan for Wi-Fi networks */
55 	NET_REQUEST_WIFI_CMD_SCAN = 1,
56 	/** Connect to a Wi-Fi network */
57 	NET_REQUEST_WIFI_CMD_CONNECT,
58 	/** Disconnect from a Wi-Fi network */
59 	NET_REQUEST_WIFI_CMD_DISCONNECT,
60 	/** Enable AP mode */
61 	NET_REQUEST_WIFI_CMD_AP_ENABLE,
62 	/** Disable AP mode */
63 	NET_REQUEST_WIFI_CMD_AP_DISABLE,
64 	/** Get interface status */
65 	NET_REQUEST_WIFI_CMD_IFACE_STATUS,
66 	/** Set power save status */
67 	NET_REQUEST_WIFI_CMD_PS,
68 	/** Set power save mode */
69 	NET_REQUEST_WIFI_CMD_PS_MODE,
70 	/** Setup or teardown TWT flow */
71 	NET_REQUEST_WIFI_CMD_TWT,
72 	/** Get power save config */
73 	NET_REQUEST_WIFI_CMD_PS_CONFIG,
74 	/** Set or get regulatory domain */
75 	NET_REQUEST_WIFI_CMD_REG_DOMAIN,
76 	/** Set power save timeout */
77 	NET_REQUEST_WIFI_CMD_PS_TIMEOUT,
78 	/** Set or get Mode of operation */
79 	NET_REQUEST_WIFI_CMD_MODE,
80 	/** Set or get packet filter setting for current mode */
81 	NET_REQUEST_WIFI_CMD_PACKET_FILTER,
82 	/** Set or get Wi-Fi channel for Monitor or TX-Injection mode */
83 	NET_REQUEST_WIFI_CMD_CHANNEL,
84 	NET_REQUEST_WIFI_CMD_MAX
85 };
86 
87 #define NET_REQUEST_WIFI_SCAN					\
88 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_SCAN)
89 
90 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_SCAN);
91 
92 #define NET_REQUEST_WIFI_CONNECT				\
93 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CONNECT)
94 
95 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CONNECT);
96 
97 #define NET_REQUEST_WIFI_DISCONNECT				\
98 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_DISCONNECT)
99 
100 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_DISCONNECT);
101 
102 #define NET_REQUEST_WIFI_AP_ENABLE				\
103 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_ENABLE)
104 
105 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_ENABLE);
106 
107 #define NET_REQUEST_WIFI_AP_DISABLE				\
108 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_DISABLE)
109 
110 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_DISABLE);
111 
112 #define NET_REQUEST_WIFI_IFACE_STATUS				\
113 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_IFACE_STATUS)
114 
115 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_IFACE_STATUS);
116 
117 #define NET_REQUEST_WIFI_PS				\
118 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS)
119 
120 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS);
121 
122 #define NET_REQUEST_WIFI_PS_MODE			\
123 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS_MODE)
124 
125 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_MODE);
126 
127 #define NET_REQUEST_WIFI_TWT			\
128 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_TWT)
129 
130 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT);
131 
132 #define NET_REQUEST_WIFI_PS_CONFIG				\
133 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS_CONFIG)
134 
135 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_CONFIG);
136 #define NET_REQUEST_WIFI_REG_DOMAIN				\
137 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_REG_DOMAIN)
138 
139 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_REG_DOMAIN);
140 
141 #define NET_REQUEST_WIFI_PS_TIMEOUT			\
142 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS_TIMEOUT)
143 
144 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_TIMEOUT);
145 
146 #define NET_REQUEST_WIFI_MODE				\
147 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_MODE)
148 
149 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE);
150 
151 #define NET_REQUEST_WIFI_PACKET_FILTER			\
152 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PACKET_FILTER)
153 
154 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER);
155 
156 #define NET_REQUEST_WIFI_CHANNEL			\
157 	(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CHANNEL)
158 
159 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL);
160 
161 /** Wi-Fi management events */
162 enum net_event_wifi_cmd {
163 	/** Scan results available */
164 	NET_EVENT_WIFI_CMD_SCAN_RESULT = 1,
165 	/** Scan done */
166 	NET_EVENT_WIFI_CMD_SCAN_DONE,
167 	/** Connect result */
168 	NET_EVENT_WIFI_CMD_CONNECT_RESULT,
169 	/** Disconnect result */
170 	NET_EVENT_WIFI_CMD_DISCONNECT_RESULT,
171 	/** Interface status */
172 	NET_EVENT_WIFI_CMD_IFACE_STATUS,
173 	/** TWT events */
174 	NET_EVENT_WIFI_CMD_TWT,
175 	/** TWT sleep status: awake or sleeping, can be used by application
176 	 * to determine if it can send data or not.
177 	 */
178 	NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE,
179 	/** Raw scan results available */
180 	NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT,
181 	/** Disconnect complete */
182 	NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE,
183 };
184 
185 #define NET_EVENT_WIFI_SCAN_RESULT				\
186 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_SCAN_RESULT)
187 
188 #define NET_EVENT_WIFI_SCAN_DONE				\
189 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_SCAN_DONE)
190 
191 #define NET_EVENT_WIFI_CONNECT_RESULT				\
192 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_CONNECT_RESULT)
193 
194 #define NET_EVENT_WIFI_DISCONNECT_RESULT			\
195 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_RESULT)
196 
197 #define NET_EVENT_WIFI_IFACE_STATUS						\
198 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_IFACE_STATUS)
199 
200 #define NET_EVENT_WIFI_TWT					\
201 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_TWT)
202 
203 #define NET_EVENT_WIFI_TWT_SLEEP_STATE				\
204 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE)
205 
206 #define NET_EVENT_WIFI_RAW_SCAN_RESULT                          \
207 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT)
208 
209 #define NET_EVENT_WIFI_DISCONNECT_COMPLETE			\
210 	(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE)
211 
212 /**
213  * @brief Wi-Fi structure to uniquely identify a band-channel pair
214  */
215 struct wifi_band_channel {
216 	/** Frequency band */
217 	uint8_t band;
218 	/** Channel */
219 	uint8_t channel;
220 };
221 
222 /**
223  * @brief Wi-Fi scan parameters structure.
224  * Used to specify parameters which can control how the Wi-Fi scan
225  * is performed.
226  */
227 struct wifi_scan_params {
228 	/** Scan type, see enum wifi_scan_type.
229 	 *
230 	 * The scan_type is only a hint to the underlying Wi-Fi chip for the
231 	 * preferred mode of scan. The actual mode of scan can depend on factors
232 	 * such as the Wi-Fi chip implementation support, regulatory domain
233 	 * restrictions etc.
234 	 */
235 	enum wifi_scan_type scan_type;
236 	/** Bitmap of bands to be scanned.
237 	 *  Refer to ::wifi_frequency_bands for bit position of each band.
238 	 */
239 	uint8_t bands;
240 	/** Active scan dwell time (in ms) on a channel.
241 	 */
242 	uint16_t dwell_time_active;
243 	/** Passive scan dwell time (in ms) on a channel.
244 	 */
245 	uint16_t dwell_time_passive;
246 	/** Array of SSID strings to scan.
247 	 */
248 	const char *ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX];
249 	/** Specifies the maximum number of scan results to return. These results would be the
250 	 * BSSIDS with the best RSSI values, in all the scanned channels. This should only be
251 	 * used to limit the number of returned scan results, and cannot be counted upon to limit
252 	 * the scan time, since the underlying Wi-Fi chip might have to scan all the channels to
253 	 * find the max_bss_cnt number of APs with the best signal strengths. A value of 0
254 	 * signifies that there is no restriction on the number of scan results to be returned.
255 	 */
256 	uint16_t max_bss_cnt;
257 	/** Channel information array indexed on Wi-Fi frequency bands and channels within that
258 	 * band.
259 	 * E.g. to scan channel 6 and 11 on the 2.4 GHz band, channel 36 on the 5 GHz band:
260 	 * @code{.c}
261 	 *     chan[0] = {WIFI_FREQ_BAND_2_4_GHZ, 6};
262 	 *     chan[1] = {WIFI_FREQ_BAND_2_4_GHZ, 11};
263 	 *     chan[2] = {WIFI_FREQ_BAND_5_GHZ, 36};
264 	 * @endcode
265 	 *
266 	 *  This list specifies the channels to be __considered for scan__. The underlying
267 	 *  Wi-Fi chip can silently omit some channels due to various reasons such as channels
268 	 *  not conforming to regulatory restrictions etc. The invoker of the API should
269 	 *  ensure that the channels specified follow regulatory rules.
270 	 */
271 	struct wifi_band_channel band_chan[WIFI_MGMT_SCAN_CHAN_MAX_MANUAL];
272 };
273 
274 /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback
275  * via its info attribute (see net_mgmt.h)
276  */
277 struct wifi_scan_result {
278 	/** SSID */
279 	uint8_t ssid[WIFI_SSID_MAX_LEN];
280 	/** SSID length */
281 	uint8_t ssid_length;
282 	/** Frequency band */
283 	uint8_t band;
284 	/** Channel */
285 	uint8_t channel;
286 	/** Security type */
287 	enum wifi_security_type security;
288 	/** MFP options */
289 	enum wifi_mfp_options mfp;
290 	/** RSSI */
291 	int8_t rssi;
292 	/** BSSID */
293 	uint8_t mac[WIFI_MAC_ADDR_LEN];
294 	/** BSSID length */
295 	uint8_t mac_length;
296 };
297 
298 /** Wi-Fi connect request parameters */
299 struct wifi_connect_req_params {
300 	/** SSID */
301 	const uint8_t *ssid;
302 	/** SSID length */
303 	uint8_t ssid_length; /* Max 32 */
304 	/** Pre-shared key */
305 	uint8_t *psk;
306 	/** Pre-shared key length */
307 	uint8_t psk_length; /* Min 8 - Max 64 */
308 	/** SAE password (same as PSK but with no length restrictions), optional */
309 	uint8_t *sae_password;
310 	/** SAE password length */
311 	uint8_t sae_password_length; /* No length restrictions */
312 	/** Frequency band */
313 	uint8_t band;
314 	/** Channel */
315 	uint8_t channel;
316 	/** Security type */
317 	enum wifi_security_type security;
318 	/** MFP options */
319 	enum wifi_mfp_options mfp;
320 	/** Connect timeout in seconds, SYS_FOREVER_MS for no timeout */
321 	int timeout;
322 };
323 
324 /** Generic Wi-Fi status for commands and events */
325 struct wifi_status {
326 	int status;
327 };
328 
329 /** Wi-Fi interface status */
330 struct wifi_iface_status {
331 	/** Interface state, see enum wifi_iface_state */
332 	int state;
333 	/** SSID length */
334 	unsigned int ssid_len;
335 	/** SSID */
336 	char ssid[WIFI_SSID_MAX_LEN];
337 	/** BSSID */
338 	char bssid[WIFI_MAC_ADDR_LEN];
339 	/** Frequency band */
340 	enum wifi_frequency_bands band;
341 	/** Channel */
342 	unsigned int channel;
343 	/** Interface mode, see enum wifi_iface_mode */
344 	enum wifi_iface_mode iface_mode;
345 	/** Link mode, see enum wifi_link_mode */
346 	enum wifi_link_mode link_mode;
347 	/** Security type, see enum wifi_security_type */
348 	enum wifi_security_type security;
349 	/** MFP options, see enum wifi_mfp_options */
350 	enum wifi_mfp_options mfp;
351 	/** RSSI */
352 	int rssi;
353 	/** DTIM period */
354 	unsigned char dtim_period;
355 	/** Beacon interval */
356 	unsigned short beacon_interval;
357 	/** is TWT capable? */
358 	bool twt_capable;
359 };
360 
361 /** Wi-Fi power save parameters */
362 struct wifi_ps_params {
363 	/* Power save state */
364 	enum wifi_ps enabled;
365 	/* Listen interval */
366 	unsigned short listen_interval;
367 	/** Wi-Fi power save wakeup mode */
368 	enum wifi_ps_wakeup_mode wakeup_mode;
369 	/** Wi-Fi power save mode */
370 	enum wifi_ps_mode mode;
371 	/** Wi-Fi power save timeout
372 	 *
373 	 * This is the time out to wait after sending a TX packet
374 	 * before going back to power save (in ms) to receive any replies
375 	 * from the AP. Zero means this feature is disabled.
376 	 *
377 	 * It's a tradeoff between power consumption and latency.
378 	 */
379 	unsigned int timeout_ms;
380 	/** Wi-Fi power save type */
381 	enum wifi_ps_param_type type;
382 	/** Wi-Fi power save fail reason */
383 	enum wifi_config_ps_param_fail_reason fail_reason;
384 };
385 
386 /** Wi-Fi TWT parameters */
387 struct wifi_twt_params {
388 	/** TWT operation, see enum wifi_twt_operation */
389 	enum wifi_twt_operation operation;
390 	/** TWT negotiation type, see enum wifi_twt_negotiation_type */
391 	enum wifi_twt_negotiation_type negotiation_type;
392 	/** TWT setup command, see enum wifi_twt_setup_cmd */
393 	enum wifi_twt_setup_cmd setup_cmd;
394 	/** TWT setup response status, see enum wifi_twt_setup_resp_status */
395 	enum wifi_twt_setup_resp_status resp_status;
396 	/** Dialog token, used to map requests to responses */
397 	uint8_t dialog_token;
398 	/** Flow ID, used to map setup with teardown */
399 	uint8_t flow_id;
400 	union {
401 		/** Setup specific parameters */
402 		struct {
403 			/**Interval = Wake up time + Sleeping time */
404 			uint64_t twt_interval;
405 			/** Requestor or responder */
406 			bool responder;
407 			/** Trigger enabled or disabled */
408 			bool trigger;
409 			/** Implicit or explicit */
410 			bool implicit;
411 			/** Announced or unannounced */
412 			bool announce;
413 			/** Wake up time */
414 			uint32_t twt_wake_interval;
415 		} setup;
416 		/** Teardown specific parameters */
417 		struct {
418 			/** Teardown all flows */
419 			bool teardown_all;
420 		} teardown;
421 	};
422 	/** TWT fail reason, see enum wifi_twt_fail_reason */
423 	enum wifi_twt_fail_reason fail_reason;
424 };
425 
426 /* Flow ID is only 3 bits */
427 #define WIFI_MAX_TWT_FLOWS 8
428 #define WIFI_MAX_TWT_INTERVAL_US (LONG_MAX - 1)
429 /* 256 (u8) * 1TU */
430 #define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144
431 
432 /** Wi-Fi TWT flow information */
433 struct wifi_twt_flow_info {
434 	/** Interval = Wake up time + Sleeping time */
435 	uint64_t  twt_interval;
436 	/** Dialog token, used to map requests to responses */
437 	uint8_t dialog_token;
438 	/** Flow ID, used to map setup with teardown */
439 	uint8_t flow_id;
440 	/** TWT negotiation type, see enum wifi_twt_negotiation_type */
441 	enum wifi_twt_negotiation_type negotiation_type;
442 	/** Requestor or responder */
443 	bool responder;
444 	/** Trigger enabled or disabled */
445 	bool trigger;
446 	/** Implicit or explicit */
447 	bool implicit;
448 	/** Announced or unannounced */
449 	bool announce;
450 	/** Wake up time */
451 	uint32_t twt_wake_interval;
452 };
453 
454 /** Wi-Fi power save configuration */
455 struct wifi_ps_config {
456 	/** Number of TWT flows */
457 	char num_twt_flows;
458 	/** TWT flow details */
459 	struct wifi_twt_flow_info twt_flows[WIFI_MAX_TWT_FLOWS];
460 	/** Power save configuration */
461 	struct wifi_ps_params ps_params;
462 };
463 
464 /** Generic get/set operation for any command*/
465 enum wifi_mgmt_op {
466 	/** Get operation */
467 	WIFI_MGMT_GET = 0,
468 	/** Set operation */
469 	WIFI_MGMT_SET = 1,
470 };
471 
472 /** Regulatory domain information or configuration */
473 struct wifi_reg_domain {
474 	/* Regulatory domain operation */
475 	enum wifi_mgmt_op oper;
476 	/** Ignore all other regulatory hints over this one */
477 	bool force;
478 	/** Country code: ISO/IEC 3166-1 alpha-2 */
479 	uint8_t country_code[WIFI_COUNTRY_CODE_LEN];
480 };
481 
482 /** Wi-Fi TWT sleep states */
483 enum wifi_twt_sleep_state {
484 	/** TWT sleep state: sleeping */
485 	WIFI_TWT_STATE_SLEEP = 0,
486 	/** TWT sleep state: awake */
487 	WIFI_TWT_STATE_AWAKE = 1,
488 };
489 
490 #if defined(CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS) || defined(__DOXYGEN__)
491 /** Wi-Fi raw scan result */
492 struct wifi_raw_scan_result {
493 	/** RSSI */
494 	int8_t rssi;
495 	/** Frame length */
496 	int frame_length;
497 	/** Frequency */
498 	unsigned short frequency;
499 	/** Raw scan data */
500 	uint8_t data[CONFIG_WIFI_MGMT_RAW_SCAN_RESULT_LENGTH];
501 };
502 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
503 
504 /* for use in max info size calculations */
505 union wifi_mgmt_events {
506 	struct wifi_scan_result scan_result;
507 	struct wifi_status connect_status;
508 	struct wifi_iface_status iface_status;
509 #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
510 	struct wifi_raw_scan_result raw_scan_result;
511 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
512 	struct wifi_twt_params twt_params;
513 };
514 
515 /** Wi-Fi mode setup */
516 struct wifi_mode_info {
517 	/** Mode setting for a specific mode of operation */
518 	uint8_t mode;
519 	/** Interface index */
520 	uint8_t if_index;
521 	/** Get or set operation */
522 	enum wifi_mgmt_op oper;
523 };
524 
525 /** Wi-Fi filter setting for monitor, prmoiscuous, TX-injection modes */
526 struct wifi_filter_info {
527 	/** Filter setting */
528 	uint8_t filter;
529 	/** Interface index */
530 	uint8_t if_index;
531 	/** Filter buffer size */
532 	uint16_t buffer_size;
533 	/** Get or set operation */
534 	enum wifi_mgmt_op oper;
535 };
536 
537 /** Wi-Fi channel setting for monitor and TX-injection modes */
538 struct wifi_channel_info {
539 	/** Channel value to set */
540 	uint16_t channel;
541 	/** Interface index */
542 	uint8_t if_index;
543 	/** Get or set operation */
544 	enum wifi_mgmt_op oper;
545 };
546 
547 #include <zephyr/net/net_if.h>
548 
549 /** Scan result callback
550  *
551  * @param iface Network interface
552  * @param status Scan result status
553  * @param entry Scan result entry
554  */
555 typedef void (*scan_result_cb_t)(struct net_if *iface, int status,
556 				 struct wifi_scan_result *entry);
557 
558 #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
559 /** Raw scan result callback
560  *
561  * @param iface Network interface
562  * @param status Raw scan result status
563  * @param entry Raw scan result entry
564  */
565 typedef void (*raw_scan_result_cb_t)(struct net_if *iface, int status,
566 				     struct wifi_raw_scan_result *entry);
567 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
568 
569 /** Wi-Fi management API */
570 struct wifi_mgmt_ops {
571 	/** Scan for Wi-Fi networks
572 	 *
573 	 * @param dev Pointer to the device structure for the driver instance.
574 	 * @param params Scan parameters
575 	 * @param cb Callback to be called for each result
576 	 *           cb parameter is the cb that should be called for each
577 	 *           result by the driver. The wifi mgmt part will take care of
578 	 *           raising the necessary event etc.
579 	 *
580 	 * @return 0 if ok, < 0 if error
581 	 */
582 	int (*scan)(const struct device *dev,
583 		    struct wifi_scan_params *params,
584 		    scan_result_cb_t cb);
585 	/** Connect to a Wi-Fi network
586 	 *
587 	 * @param dev Pointer to the device structure for the driver instance.
588 	 * @param params Connect parameters
589 	 *
590 	 * @return 0 if ok, < 0 if error
591 	 */
592 	int (*connect)(const struct device *dev,
593 		       struct wifi_connect_req_params *params);
594 	/** Disconnect from a Wi-Fi network
595 	 *
596 	 * @param dev Pointer to the device structure for the driver instance.
597 	 *
598 	 * @return 0 if ok, < 0 if error
599 	 */
600 	int (*disconnect)(const struct device *dev);
601 	/** Enable AP mode
602 	 *
603 	 * @param dev Pointer to the device structure for the driver instance.
604 	 * @param params AP mode parameters
605 	 *
606 	 * @return 0 if ok, < 0 if error
607 	 */
608 	int (*ap_enable)(const struct device *dev,
609 			 struct wifi_connect_req_params *params);
610 	/** Disable AP mode
611 	 *
612 	 * @param dev Pointer to the device structure for the driver instance.
613 	 *
614 	 * @return 0 if ok, < 0 if error
615 	 */
616 	int (*ap_disable)(const struct device *dev);
617 	/** Get interface status
618 	 *
619 	 * @param dev Pointer to the device structure for the driver instance.
620 	 * @param status Interface status
621 	 *
622 	 * @return 0 if ok, < 0 if error
623 	 */
624 	int (*iface_status)(const struct device *dev, struct wifi_iface_status *status);
625 #if defined(CONFIG_NET_STATISTICS_WIFI) || defined(__DOXYGEN__)
626 	/** Get Wi-Fi statistics
627 	 *
628 	 * @param dev Pointer to the device structure for the driver instance.
629 	 * @param stats Wi-Fi statistics
630 	 *
631 	 * @return 0 if ok, < 0 if error
632 	 */
633 	int (*get_stats)(const struct device *dev, struct net_stats_wifi *stats);
634 #endif /* CONFIG_NET_STATISTICS_WIFI */
635 	/** Set power save status
636 	 *
637 	 * @param dev Pointer to the device structure for the driver instance.
638 	 * @param params Power save parameters
639 	 *
640 	 * @return 0 if ok, < 0 if error
641 	 */
642 	int (*set_power_save)(const struct device *dev, struct wifi_ps_params *params);
643 	/** Setup or teardown TWT flow
644 	 *
645 	 * @param dev Pointer to the device structure for the driver instance.
646 	 * @param params TWT parameters
647 	 *
648 	 * @return 0 if ok, < 0 if error
649 	 */
650 	int (*set_twt)(const struct device *dev, struct wifi_twt_params *params);
651 	/** Get power save config
652 	 *
653 	 * @param dev Pointer to the device structure for the driver instance.
654 	 * @param config Power save config
655 	 *
656 	 * @return 0 if ok, < 0 if error
657 	 */
658 	int (*get_power_save_config)(const struct device *dev, struct wifi_ps_config *config);
659 	/** Set or get regulatory domain
660 	 *
661 	 * @param dev Pointer to the device structure for the driver instance.
662 	 * @param reg_domain Regulatory domain
663 	 *
664 	 * @return 0 if ok, < 0 if error
665 	 */
666 	int (*reg_domain)(const struct device *dev, struct wifi_reg_domain *reg_domain);
667 	/** Set or get packet filter settings for monitor and promiscuous modes
668 	 *
669 	 * @param dev Pointer to the device structure for the driver instance.
670 	 * @param packet filter settings
671 	 *
672 	 * @return 0 if ok, < 0 if error
673 	 */
674 	int (*filter)(const struct device *dev, struct wifi_filter_info *filter);
675 	/** Set or get mode of operation
676 	 *
677 	 * @param dev Pointer to the device structure for the driver instance.
678 	 * @param mode settings
679 	 *
680 	 * @return 0 if ok, < 0 if error
681 	 */
682 	int (*mode)(const struct device *dev, struct wifi_mode_info *mode);
683 	/** Set or get current channel of operation
684 	 *
685 	 * @param dev Pointer to the device structure for the driver instance.
686 	 * @param channel settings
687 	 *
688 	 * @return 0 if ok, < 0 if error
689 	 */
690 	int (*channel)(const struct device *dev, struct wifi_channel_info *channel);
691 };
692 
693 /** Wi-Fi management offload API */
694 struct net_wifi_mgmt_offload {
695 	/**
696 	 * Mandatory to get in first position.
697 	 * A network device should indeed provide a pointer on such
698 	 * net_if_api structure. So we make current structure pointer
699 	 * that can be casted to a net_if_api structure pointer.
700 	 */
701 #if defined(CONFIG_WIFI_USE_NATIVE_NETWORKING) || defined(__DOXYGEN__)
702 	/** Ethernet API */
703 	struct ethernet_api wifi_iface;
704 #else
705 	/** Offloaded network device API */
706 	struct offloaded_if_api wifi_iface;
707 #endif
708 	/** Wi-Fi management API */
709 	const struct wifi_mgmt_ops *const wifi_mgmt_api;
710 };
711 
712 /* Make sure that the network interface API is properly setup inside
713  * Wifi mgmt offload API struct (it is the first one).
714  */
715 BUILD_ASSERT(offsetof(struct net_wifi_mgmt_offload, wifi_iface) == 0);
716 
717 /** Wi-Fi management connect result event
718  *
719  * @param iface Network interface
720  * @param status Connect result status
721  */
722 void wifi_mgmt_raise_connect_result_event(struct net_if *iface, int status);
723 
724 /** Wi-Fi management disconnect result event
725  *
726  * @param iface Network interface
727  * @param status Disconnect result status
728  */
729 void wifi_mgmt_raise_disconnect_result_event(struct net_if *iface, int status);
730 
731 /** Wi-Fi management interface status event
732  *
733  * @param iface Network interface
734  * @param iface_status Interface status
735  */
736 void wifi_mgmt_raise_iface_status_event(struct net_if *iface,
737 		struct wifi_iface_status *iface_status);
738 
739 /** Wi-Fi management TWT event
740  *
741  * @param iface Network interface
742  * @param twt_params TWT parameters
743  */
744 void wifi_mgmt_raise_twt_event(struct net_if *iface,
745 		struct wifi_twt_params *twt_params);
746 
747 /** Wi-Fi management TWT sleep state event
748  *
749  * @param iface Network interface
750  * @param twt_sleep_state TWT sleep state
751  */
752 void wifi_mgmt_raise_twt_sleep_state(struct net_if *iface, int twt_sleep_state);
753 
754 #if defined(CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS) || defined(__DOXYGEN__)
755 /** Wi-Fi management raw scan result event
756  *
757  * @param iface Network interface
758  * @param raw_scan_info Raw scan result
759  */
760 void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface,
761 		struct wifi_raw_scan_result *raw_scan_info);
762 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
763 
764 /** Wi-Fi management disconnect complete event
765  *
766  * @param iface Network interface
767  * @param status Disconnect complete status
768  */
769 void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status);
770 
771 /**
772  * @}
773  */
774 #ifdef __cplusplus
775 }
776 #endif
777 
778 #endif /* ZEPHYR_INCLUDE_NET_WIFI_MGMT_H_ */
779