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 /** @cond INTERNAL_HIDDEN */ 32 33 #define _NET_WIFI_LAYER NET_MGMT_LAYER_L2 34 #define _NET_WIFI_CODE 0x156 35 #define _NET_WIFI_BASE (NET_MGMT_IFACE_BIT | \ 36 NET_MGMT_LAYER(_NET_WIFI_LAYER) | \ 37 NET_MGMT_LAYER_CODE(_NET_WIFI_CODE)) 38 #define _NET_WIFI_EVENT (_NET_WIFI_BASE | NET_MGMT_EVENT_BIT) 39 40 #ifdef CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX 41 #define WIFI_MGMT_SCAN_SSID_FILT_MAX CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX 42 #else 43 #define WIFI_MGMT_SCAN_SSID_FILT_MAX 1 44 #endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */ 45 46 #ifdef CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 47 #define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 48 #else 49 #define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 1 50 #endif /* CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL */ 51 52 #define WIFI_MGMT_BAND_STR_SIZE_MAX 8 53 #define WIFI_MGMT_SCAN_MAX_BSS_CNT 65535 54 55 #define WIFI_MGMT_SKIP_INACTIVITY_POLL IS_ENABLED(CONFIG_WIFI_MGMT_AP_STA_SKIP_INACTIVITY_POLL) 56 /** @endcond */ 57 58 /** @brief Wi-Fi management commands */ 59 enum net_request_wifi_cmd { 60 /** Scan for Wi-Fi networks */ 61 NET_REQUEST_WIFI_CMD_SCAN = 1, 62 /** Connect to a Wi-Fi network */ 63 NET_REQUEST_WIFI_CMD_CONNECT, 64 /** Disconnect from a Wi-Fi network */ 65 NET_REQUEST_WIFI_CMD_DISCONNECT, 66 /** Enable AP mode */ 67 NET_REQUEST_WIFI_CMD_AP_ENABLE, 68 /** Disable AP mode */ 69 NET_REQUEST_WIFI_CMD_AP_DISABLE, 70 /** Get interface status */ 71 NET_REQUEST_WIFI_CMD_IFACE_STATUS, 72 /** Set power save status */ 73 NET_REQUEST_WIFI_CMD_PS, 74 /** Setup or teardown TWT flow */ 75 NET_REQUEST_WIFI_CMD_TWT, 76 /** Get power save config */ 77 NET_REQUEST_WIFI_CMD_PS_CONFIG, 78 /** Set or get regulatory domain */ 79 NET_REQUEST_WIFI_CMD_REG_DOMAIN, 80 /** Set or get Mode of operation */ 81 NET_REQUEST_WIFI_CMD_MODE, 82 /** Set or get packet filter setting for current mode */ 83 NET_REQUEST_WIFI_CMD_PACKET_FILTER, 84 /** Set or get Wi-Fi channel for Monitor or TX-Injection mode */ 85 NET_REQUEST_WIFI_CMD_CHANNEL, 86 /** Disconnect a STA from AP */ 87 NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT, 88 /** Get Wi-Fi driver and Firmware versions */ 89 NET_REQUEST_WIFI_CMD_VERSION, 90 /** Set RTS threshold */ 91 NET_REQUEST_WIFI_CMD_RTS_THRESHOLD, 92 /** Configure AP parameter */ 93 NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM, 94 /** @cond INTERNAL_HIDDEN */ 95 NET_REQUEST_WIFI_CMD_MAX 96 /** @endcond */ 97 }; 98 99 /** Request a Wi-Fi scan */ 100 #define NET_REQUEST_WIFI_SCAN \ 101 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_SCAN) 102 103 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_SCAN); 104 105 /** Request a Wi-Fi connect */ 106 #define NET_REQUEST_WIFI_CONNECT \ 107 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CONNECT) 108 109 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CONNECT); 110 111 /** Request a Wi-Fi disconnect */ 112 #define NET_REQUEST_WIFI_DISCONNECT \ 113 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_DISCONNECT) 114 115 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_DISCONNECT); 116 117 /** Request a Wi-Fi access point enable */ 118 #define NET_REQUEST_WIFI_AP_ENABLE \ 119 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_ENABLE) 120 121 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_ENABLE); 122 123 /** Request a Wi-Fi access point disable */ 124 #define NET_REQUEST_WIFI_AP_DISABLE \ 125 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_DISABLE) 126 127 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_DISABLE); 128 129 /** Request a Wi-Fi network interface status */ 130 #define NET_REQUEST_WIFI_IFACE_STATUS \ 131 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_IFACE_STATUS) 132 133 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_IFACE_STATUS); 134 135 /** Request a Wi-Fi power save */ 136 #define NET_REQUEST_WIFI_PS \ 137 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS) 138 139 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS); 140 141 /** Request a Wi-Fi TWT */ 142 #define NET_REQUEST_WIFI_TWT \ 143 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_TWT) 144 145 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT); 146 147 /** Request a Wi-Fi power save configuration */ 148 #define NET_REQUEST_WIFI_PS_CONFIG \ 149 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS_CONFIG) 150 151 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_CONFIG); 152 153 /** Request a Wi-Fi regulatory domain */ 154 #define NET_REQUEST_WIFI_REG_DOMAIN \ 155 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_REG_DOMAIN) 156 157 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_REG_DOMAIN); 158 159 /** Request current Wi-Fi mode */ 160 #define NET_REQUEST_WIFI_MODE \ 161 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_MODE) 162 163 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE); 164 165 /** Request Wi-Fi packet filter */ 166 #define NET_REQUEST_WIFI_PACKET_FILTER \ 167 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PACKET_FILTER) 168 169 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER); 170 171 /** Request a Wi-Fi channel */ 172 #define NET_REQUEST_WIFI_CHANNEL \ 173 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CHANNEL) 174 175 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL); 176 177 /** Request a Wi-Fi access point to disconnect a station */ 178 #define NET_REQUEST_WIFI_AP_STA_DISCONNECT \ 179 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT) 180 181 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT); 182 183 /** Request a Wi-Fi version */ 184 #define NET_REQUEST_WIFI_VERSION \ 185 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_VERSION) 186 187 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION); 188 189 /** Request a Wi-Fi RTS threshold */ 190 #define NET_REQUEST_WIFI_RTS_THRESHOLD \ 191 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_RTS_THRESHOLD) 192 193 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD); 194 195 /** Request a Wi-Fi AP parameters configuration */ 196 #define NET_REQUEST_WIFI_AP_CONFIG_PARAM \ 197 (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM) 198 199 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM); 200 201 /** @brief Wi-Fi management events */ 202 enum net_event_wifi_cmd { 203 /** Scan results available */ 204 NET_EVENT_WIFI_CMD_SCAN_RESULT = 1, 205 /** Scan done */ 206 NET_EVENT_WIFI_CMD_SCAN_DONE, 207 /** Connect result */ 208 NET_EVENT_WIFI_CMD_CONNECT_RESULT, 209 /** Disconnect result */ 210 NET_EVENT_WIFI_CMD_DISCONNECT_RESULT, 211 /** Interface status */ 212 NET_EVENT_WIFI_CMD_IFACE_STATUS, 213 /** TWT events */ 214 NET_EVENT_WIFI_CMD_TWT, 215 /** TWT sleep status: awake or sleeping, can be used by application 216 * to determine if it can send data or not. 217 */ 218 NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE, 219 /** Raw scan results available */ 220 NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT, 221 /** Disconnect complete */ 222 NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE, 223 /** AP mode enable result */ 224 NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, 225 /** AP mode disable result */ 226 NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, 227 /** STA connected to AP */ 228 NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, 229 /** STA disconnected from AP */ 230 NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, 231 }; 232 233 /** Event emitted for Wi-Fi scan result */ 234 #define NET_EVENT_WIFI_SCAN_RESULT \ 235 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_SCAN_RESULT) 236 237 /** Event emitted when Wi-Fi scan is done */ 238 #define NET_EVENT_WIFI_SCAN_DONE \ 239 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_SCAN_DONE) 240 241 /** Event emitted for Wi-Fi connect result */ 242 #define NET_EVENT_WIFI_CONNECT_RESULT \ 243 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_CONNECT_RESULT) 244 245 /** Event emitted for Wi-Fi disconnect result */ 246 #define NET_EVENT_WIFI_DISCONNECT_RESULT \ 247 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_RESULT) 248 249 /** Event emitted for Wi-Fi network interface status */ 250 #define NET_EVENT_WIFI_IFACE_STATUS \ 251 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_IFACE_STATUS) 252 253 /** Event emitted for Wi-Fi TWT information */ 254 #define NET_EVENT_WIFI_TWT \ 255 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_TWT) 256 257 /** Event emitted for Wi-Fi TWT sleep state */ 258 #define NET_EVENT_WIFI_TWT_SLEEP_STATE \ 259 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE) 260 261 /** Event emitted for Wi-Fi raw scan result */ 262 #define NET_EVENT_WIFI_RAW_SCAN_RESULT \ 263 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT) 264 265 /** Event emitted Wi-Fi disconnect is completed */ 266 #define NET_EVENT_WIFI_DISCONNECT_COMPLETE \ 267 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE) 268 269 /** Event emitted for Wi-Fi access point enable result */ 270 #define NET_EVENT_WIFI_AP_ENABLE_RESULT \ 271 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT) 272 273 /** Event emitted for Wi-Fi access point disable result */ 274 #define NET_EVENT_WIFI_AP_DISABLE_RESULT \ 275 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) 276 277 /** Event emitted when Wi-Fi station is connected in AP mode */ 278 #define NET_EVENT_WIFI_AP_STA_CONNECTED \ 279 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_CONNECTED) 280 281 /** Event emitted Wi-Fi station is disconnected from AP */ 282 #define NET_EVENT_WIFI_AP_STA_DISCONNECTED \ 283 (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED) 284 285 /** @brief Wi-Fi version */ 286 struct wifi_version { 287 /** Driver version */ 288 const char *drv_version; 289 /** Firmware version */ 290 const char *fw_version; 291 }; 292 293 /** 294 * @brief Wi-Fi structure to uniquely identify a band-channel pair 295 */ 296 struct wifi_band_channel { 297 /** Frequency band */ 298 uint8_t band; 299 /** Channel */ 300 uint8_t channel; 301 }; 302 303 /** 304 * @brief Wi-Fi scan parameters structure. 305 * Used to specify parameters which can control how the Wi-Fi scan 306 * is performed. 307 */ 308 struct wifi_scan_params { 309 /** Scan type, see enum wifi_scan_type. 310 * 311 * The scan_type is only a hint to the underlying Wi-Fi chip for the 312 * preferred mode of scan. The actual mode of scan can depend on factors 313 * such as the Wi-Fi chip implementation support, regulatory domain 314 * restrictions etc. 315 */ 316 enum wifi_scan_type scan_type; 317 /** Bitmap of bands to be scanned. 318 * Refer to ::wifi_frequency_bands for bit position of each band. 319 */ 320 uint8_t bands; 321 /** Active scan dwell time (in ms) on a channel. 322 */ 323 uint16_t dwell_time_active; 324 /** Passive scan dwell time (in ms) on a channel. 325 */ 326 uint16_t dwell_time_passive; 327 /** Array of SSID strings to scan. 328 */ 329 const char *ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX]; 330 /** Specifies the maximum number of scan results to return. These results would be the 331 * BSSIDS with the best RSSI values, in all the scanned channels. This should only be 332 * used to limit the number of returned scan results, and cannot be counted upon to limit 333 * the scan time, since the underlying Wi-Fi chip might have to scan all the channels to 334 * find the max_bss_cnt number of APs with the best signal strengths. A value of 0 335 * signifies that there is no restriction on the number of scan results to be returned. 336 */ 337 uint16_t max_bss_cnt; 338 /** Channel information array indexed on Wi-Fi frequency bands and channels within that 339 * band. 340 * E.g. to scan channel 6 and 11 on the 2.4 GHz band, channel 36 on the 5 GHz band: 341 * @code{.c} 342 * chan[0] = {WIFI_FREQ_BAND_2_4_GHZ, 6}; 343 * chan[1] = {WIFI_FREQ_BAND_2_4_GHZ, 11}; 344 * chan[2] = {WIFI_FREQ_BAND_5_GHZ, 36}; 345 * @endcode 346 * 347 * This list specifies the channels to be __considered for scan__. The underlying 348 * Wi-Fi chip can silently omit some channels due to various reasons such as channels 349 * not conforming to regulatory restrictions etc. The invoker of the API should 350 * ensure that the channels specified follow regulatory rules. 351 */ 352 struct wifi_band_channel band_chan[WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; 353 }; 354 355 /** @brief Wi-Fi scan result, each result is provided to the net_mgmt_event_callback 356 * via its info attribute (see net_mgmt.h) 357 */ 358 struct wifi_scan_result { 359 /** SSID */ 360 uint8_t ssid[WIFI_SSID_MAX_LEN]; 361 /** SSID length */ 362 uint8_t ssid_length; 363 /** Frequency band */ 364 uint8_t band; 365 /** Channel */ 366 uint8_t channel; 367 /** Security type */ 368 enum wifi_security_type security; 369 /** MFP options */ 370 enum wifi_mfp_options mfp; 371 /** RSSI */ 372 int8_t rssi; 373 /** BSSID */ 374 uint8_t mac[WIFI_MAC_ADDR_LEN]; 375 /** BSSID length */ 376 uint8_t mac_length; 377 }; 378 379 /** @brief Wi-Fi connect request parameters */ 380 struct wifi_connect_req_params { 381 /** SSID */ 382 const uint8_t *ssid; 383 /** SSID length */ 384 uint8_t ssid_length; /* Max 32 */ 385 /** Pre-shared key */ 386 const uint8_t *psk; 387 /** Pre-shared key length */ 388 uint8_t psk_length; /* Min 8 - Max 64 */ 389 /** SAE password (same as PSK but with no length restrictions), optional */ 390 const uint8_t *sae_password; 391 /** SAE password length */ 392 uint8_t sae_password_length; /* No length restrictions */ 393 /** Frequency band */ 394 uint8_t band; 395 /** Channel */ 396 uint8_t channel; 397 /** Security type */ 398 enum wifi_security_type security; 399 /** MFP options */ 400 enum wifi_mfp_options mfp; 401 /** BSSID */ 402 uint8_t bssid[WIFI_MAC_ADDR_LEN]; 403 /** Connect timeout in seconds, SYS_FOREVER_MS for no timeout */ 404 int timeout; 405 }; 406 407 /** @brief Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status 408 * in the connect result event for detailed status. 409 */ 410 enum wifi_conn_status { 411 /** Connection successful */ 412 WIFI_STATUS_CONN_SUCCESS = 0, 413 /** Connection failed - generic failure */ 414 WIFI_STATUS_CONN_FAIL, 415 /** Connection failed - wrong password 416 * Few possible reasons for 4-way handshake failure that we can guess are as follows: 417 * 1) Incorrect key 418 * 2) EAPoL frames lost causing timeout 419 * 420 * #1 is the likely cause, so, we convey to the user that it is due to 421 * Wrong passphrase/password. 422 */ 423 WIFI_STATUS_CONN_WRONG_PASSWORD, 424 /** Connection timed out */ 425 WIFI_STATUS_CONN_TIMEOUT, 426 /** Connection failed - AP not found */ 427 WIFI_STATUS_CONN_AP_NOT_FOUND, 428 /** Last connection status */ 429 WIFI_STATUS_CONN_LAST_STATUS, 430 /** Connection disconnected status */ 431 WIFI_STATUS_DISCONN_FIRST_STATUS = WIFI_STATUS_CONN_LAST_STATUS, 432 }; 433 434 /** @brief Wi-Fi disconnect reason codes. To be overlaid on top of \ref wifi_status 435 * in the disconnect result event for detailed reason. 436 */ 437 enum wifi_disconn_reason { 438 /** Success, overload status as reason */ 439 WIFI_REASON_DISCONN_SUCCESS = 0, 440 /** Unspecified reason */ 441 WIFI_REASON_DISCONN_UNSPECIFIED, 442 /** Disconnected due to user request */ 443 WIFI_REASON_DISCONN_USER_REQUEST, 444 /** Disconnected due to AP leaving */ 445 WIFI_REASON_DISCONN_AP_LEAVING, 446 /** Disconnected due to inactivity */ 447 WIFI_REASON_DISCONN_INACTIVITY, 448 }; 449 450 /** @brief Wi-Fi AP mode result codes. To be overlaid on top of \ref wifi_status 451 * in the AP mode enable or disable result event for detailed status. 452 */ 453 enum wifi_ap_status { 454 /** AP mode enable or disable successful */ 455 WIFI_STATUS_AP_SUCCESS = 0, 456 /** AP mode enable or disable failed - generic failure */ 457 WIFI_STATUS_AP_FAIL, 458 /** AP mode enable failed - channel not supported */ 459 WIFI_STATUS_AP_CHANNEL_NOT_SUPPORTED, 460 /** AP mode enable failed - channel not allowed */ 461 WIFI_STATUS_AP_CHANNEL_NOT_ALLOWED, 462 /** AP mode enable failed - SSID not allowed */ 463 WIFI_STATUS_AP_SSID_NOT_ALLOWED, 464 /** AP mode enable failed - authentication type not supported */ 465 WIFI_STATUS_AP_AUTH_TYPE_NOT_SUPPORTED, 466 /** AP mode enable failed - operation not supported */ 467 WIFI_STATUS_AP_OP_NOT_SUPPORTED, 468 /** AP mode enable failed - operation not permitted */ 469 WIFI_STATUS_AP_OP_NOT_PERMITTED, 470 }; 471 472 /** @brief Generic Wi-Fi status for commands and events */ 473 struct wifi_status { 474 union { 475 /** Status value */ 476 int status; 477 /** Connection status */ 478 enum wifi_conn_status conn_status; 479 /** Disconnection reason status */ 480 enum wifi_disconn_reason disconn_reason; 481 /** Access point status */ 482 enum wifi_ap_status ap_status; 483 }; 484 }; 485 486 /** @brief Wi-Fi interface status */ 487 struct wifi_iface_status { 488 /** Interface state, see enum wifi_iface_state */ 489 int state; 490 /** SSID length */ 491 unsigned int ssid_len; 492 /** SSID */ 493 char ssid[WIFI_SSID_MAX_LEN]; 494 /** BSSID */ 495 char bssid[WIFI_MAC_ADDR_LEN]; 496 /** Frequency band */ 497 enum wifi_frequency_bands band; 498 /** Channel */ 499 unsigned int channel; 500 /** Interface mode, see enum wifi_iface_mode */ 501 enum wifi_iface_mode iface_mode; 502 /** Link mode, see enum wifi_link_mode */ 503 enum wifi_link_mode link_mode; 504 /** Security type, see enum wifi_security_type */ 505 enum wifi_security_type security; 506 /** MFP options, see enum wifi_mfp_options */ 507 enum wifi_mfp_options mfp; 508 /** RSSI */ 509 int rssi; 510 /** DTIM period */ 511 unsigned char dtim_period; 512 /** Beacon interval */ 513 unsigned short beacon_interval; 514 /** is TWT capable? */ 515 bool twt_capable; 516 }; 517 518 /** @brief Wi-Fi power save parameters */ 519 struct wifi_ps_params { 520 /** Power save state */ 521 enum wifi_ps enabled; 522 /** Listen interval */ 523 unsigned short listen_interval; 524 /** Wi-Fi power save wakeup mode */ 525 enum wifi_ps_wakeup_mode wakeup_mode; 526 /** Wi-Fi power save mode */ 527 enum wifi_ps_mode mode; 528 /** Wi-Fi power save timeout 529 * 530 * This is the time out to wait after sending a TX packet 531 * before going back to power save (in ms) to receive any replies 532 * from the AP. Zero means this feature is disabled. 533 * 534 * It's a tradeoff between power consumption and latency. 535 */ 536 unsigned int timeout_ms; 537 /** Wi-Fi power save type */ 538 enum wifi_ps_param_type type; 539 /** Wi-Fi power save fail reason */ 540 enum wifi_config_ps_param_fail_reason fail_reason; 541 }; 542 543 /** @brief Wi-Fi TWT parameters */ 544 struct wifi_twt_params { 545 /** TWT operation, see enum wifi_twt_operation */ 546 enum wifi_twt_operation operation; 547 /** TWT negotiation type, see enum wifi_twt_negotiation_type */ 548 enum wifi_twt_negotiation_type negotiation_type; 549 /** TWT setup command, see enum wifi_twt_setup_cmd */ 550 enum wifi_twt_setup_cmd setup_cmd; 551 /** TWT setup response status, see enum wifi_twt_setup_resp_status */ 552 enum wifi_twt_setup_resp_status resp_status; 553 /** TWT teardown cmd status, see enum wifi_twt_teardown_status */ 554 enum wifi_twt_teardown_status teardown_status; 555 /** Dialog token, used to map requests to responses */ 556 uint8_t dialog_token; 557 /** Flow ID, used to map setup with teardown */ 558 uint8_t flow_id; 559 union { 560 /** Setup specific parameters */ 561 struct { 562 /**Interval = Wake up time + Sleeping time */ 563 uint64_t twt_interval; 564 /** Requestor or responder */ 565 bool responder; 566 /** Trigger enabled or disabled */ 567 bool trigger; 568 /** Implicit or explicit */ 569 bool implicit; 570 /** Announced or unannounced */ 571 bool announce; 572 /** Wake up time */ 573 uint32_t twt_wake_interval; 574 /** Wake ahead notification is sent earlier than 575 * TWT Service period (SP) start based on this duration. 576 * This should give applications ample time to 577 * prepare the data before TWT SP starts. 578 */ 579 uint32_t twt_wake_ahead_duration; 580 } setup; 581 /** Teardown specific parameters */ 582 struct { 583 /** Teardown all flows */ 584 bool teardown_all; 585 } teardown; 586 }; 587 /** TWT fail reason, see enum wifi_twt_fail_reason */ 588 enum wifi_twt_fail_reason fail_reason; 589 }; 590 591 /** @cond INTERNAL_HIDDEN */ 592 593 /* Flow ID is only 3 bits */ 594 #define WIFI_MAX_TWT_FLOWS 8 595 #define WIFI_MAX_TWT_INTERVAL_US (LONG_MAX - 1) 596 /* 256 (u8) * 1TU */ 597 #define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144 598 #define WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US (LONG_MAX - 1) 599 600 /** @endcond */ 601 602 /** @brief Wi-Fi TWT flow information */ 603 struct wifi_twt_flow_info { 604 /** Interval = Wake up time + Sleeping time */ 605 uint64_t twt_interval; 606 /** Dialog token, used to map requests to responses */ 607 uint8_t dialog_token; 608 /** Flow ID, used to map setup with teardown */ 609 uint8_t flow_id; 610 /** TWT negotiation type, see enum wifi_twt_negotiation_type */ 611 enum wifi_twt_negotiation_type negotiation_type; 612 /** Requestor or responder */ 613 bool responder; 614 /** Trigger enabled or disabled */ 615 bool trigger; 616 /** Implicit or explicit */ 617 bool implicit; 618 /** Announced or unannounced */ 619 bool announce; 620 /** Wake up time */ 621 uint32_t twt_wake_interval; 622 /** Wake ahead duration */ 623 uint32_t twt_wake_ahead_duration; 624 }; 625 626 /** @brief Wi-Fi power save configuration */ 627 struct wifi_ps_config { 628 /** Number of TWT flows */ 629 char num_twt_flows; 630 /** TWT flow details */ 631 struct wifi_twt_flow_info twt_flows[WIFI_MAX_TWT_FLOWS]; 632 /** Power save configuration */ 633 struct wifi_ps_params ps_params; 634 }; 635 636 /** @brief Generic get/set operation for any command*/ 637 enum wifi_mgmt_op { 638 /** Get operation */ 639 WIFI_MGMT_GET = 0, 640 /** Set operation */ 641 WIFI_MGMT_SET = 1, 642 }; 643 644 /** Max regulatory channel number */ 645 #define MAX_REG_CHAN_NUM 42 646 647 /** @brief Per-channel regulatory attributes */ 648 struct wifi_reg_chan_info { 649 /** Center frequency in MHz */ 650 unsigned short center_frequency; 651 /** Maximum transmission power (in dBm) */ 652 unsigned short max_power:8; 653 /** Is channel supported or not */ 654 unsigned short supported:1; 655 /** Passive transmissions only */ 656 unsigned short passive_only:1; 657 /** Is a DFS channel */ 658 unsigned short dfs:1; 659 } __packed; 660 661 /** @brief Regulatory domain information or configuration */ 662 struct wifi_reg_domain { 663 /** Regulatory domain operation */ 664 enum wifi_mgmt_op oper; 665 /** Ignore all other regulatory hints over this one */ 666 bool force; 667 /** Country code: ISO/IEC 3166-1 alpha-2 */ 668 uint8_t country_code[WIFI_COUNTRY_CODE_LEN]; 669 /** Number of channels supported */ 670 unsigned int num_channels; 671 /** Channels information */ 672 struct wifi_reg_chan_info *chan_info; 673 }; 674 675 /** @brief Wi-Fi TWT sleep states */ 676 enum wifi_twt_sleep_state { 677 /** TWT sleep state: sleeping */ 678 WIFI_TWT_STATE_SLEEP = 0, 679 /** TWT sleep state: awake */ 680 WIFI_TWT_STATE_AWAKE = 1, 681 }; 682 683 #if defined(CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS) || defined(__DOXYGEN__) 684 /** @brief Wi-Fi raw scan result */ 685 struct wifi_raw_scan_result { 686 /** RSSI */ 687 int8_t rssi; 688 /** Frame length */ 689 int frame_length; 690 /** Frequency */ 691 unsigned short frequency; 692 /** Raw scan data */ 693 uint8_t data[CONFIG_WIFI_MGMT_RAW_SCAN_RESULT_LENGTH]; 694 }; 695 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ 696 697 /** @brief AP mode - connected STA details */ 698 struct wifi_ap_sta_info { 699 /** Link mode, see enum wifi_link_mode */ 700 enum wifi_link_mode link_mode; 701 /** MAC address */ 702 uint8_t mac[WIFI_MAC_ADDR_LEN]; 703 /** MAC address length */ 704 uint8_t mac_length; 705 /** is TWT capable ? */ 706 bool twt_capable; 707 }; 708 709 /** @cond INTERNAL_HIDDEN */ 710 711 /* for use in max info size calculations */ 712 union wifi_mgmt_events { 713 struct wifi_scan_result scan_result; 714 struct wifi_status connect_status; 715 struct wifi_iface_status iface_status; 716 #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS 717 struct wifi_raw_scan_result raw_scan_result; 718 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ 719 struct wifi_twt_params twt_params; 720 struct wifi_ap_sta_info ap_sta_info; 721 }; 722 723 /** @endcond */ 724 725 /** @brief Wi-Fi mode setup */ 726 struct wifi_mode_info { 727 /** Mode setting for a specific mode of operation */ 728 uint8_t mode; 729 /** Interface index */ 730 uint8_t if_index; 731 /** Get or set operation */ 732 enum wifi_mgmt_op oper; 733 }; 734 735 /** @brief Wi-Fi filter setting for monitor, prmoiscuous, TX-injection modes */ 736 struct wifi_filter_info { 737 /** Filter setting */ 738 uint8_t filter; 739 /** Interface index */ 740 uint8_t if_index; 741 /** Filter buffer size */ 742 uint16_t buffer_size; 743 /** Get or set operation */ 744 enum wifi_mgmt_op oper; 745 }; 746 747 /** @brief Wi-Fi channel setting for monitor and TX-injection modes */ 748 struct wifi_channel_info { 749 /** Channel value to set */ 750 uint16_t channel; 751 /** Interface index */ 752 uint8_t if_index; 753 /** Get or set operation */ 754 enum wifi_mgmt_op oper; 755 }; 756 757 /** @cond INTERNAL_HIDDEN */ 758 #define WIFI_AP_STA_MAX_INACTIVITY (LONG_MAX - 1) 759 /** @endcond */ 760 761 /** @brief Wi-Fi AP configuration parameter */ 762 struct wifi_ap_config_params { 763 /** Parameter used to identify the different AP parameters */ 764 enum wifi_ap_config_param type; 765 /** Parameter used for setting maximum inactivity duration for stations */ 766 uint32_t max_inactivity; 767 /** Parameter used for setting maximum number of stations */ 768 uint32_t max_num_sta; 769 }; 770 771 #include <zephyr/net/net_if.h> 772 773 /** Scan result callback 774 * 775 * @param iface Network interface 776 * @param status Scan result status 777 * @param entry Scan result entry 778 */ 779 typedef void (*scan_result_cb_t)(struct net_if *iface, int status, 780 struct wifi_scan_result *entry); 781 782 #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS 783 /** Raw scan result callback 784 * 785 * @param iface Network interface 786 * @param status Raw scan result status 787 * @param entry Raw scan result entry 788 */ 789 typedef void (*raw_scan_result_cb_t)(struct net_if *iface, int status, 790 struct wifi_raw_scan_result *entry); 791 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ 792 793 /** Wi-Fi management API */ 794 struct wifi_mgmt_ops { 795 /** Scan for Wi-Fi networks 796 * 797 * @param dev Pointer to the device structure for the driver instance. 798 * @param params Scan parameters 799 * @param cb Callback to be called for each result 800 * cb parameter is the cb that should be called for each 801 * result by the driver. The wifi mgmt part will take care of 802 * raising the necessary event etc. 803 * 804 * @return 0 if ok, < 0 if error 805 */ 806 int (*scan)(const struct device *dev, 807 struct wifi_scan_params *params, 808 scan_result_cb_t cb); 809 /** Connect to a Wi-Fi network 810 * 811 * @param dev Pointer to the device structure for the driver instance. 812 * @param params Connect parameters 813 * 814 * @return 0 if ok, < 0 if error 815 */ 816 int (*connect)(const struct device *dev, 817 struct wifi_connect_req_params *params); 818 /** Disconnect from a Wi-Fi network 819 * 820 * @param dev Pointer to the device structure for the driver instance. 821 * 822 * @return 0 if ok, < 0 if error 823 */ 824 int (*disconnect)(const struct device *dev); 825 /** Enable AP mode 826 * 827 * @param dev Pointer to the device structure for the driver instance. 828 * @param params AP mode parameters 829 * 830 * @return 0 if ok, < 0 if error 831 */ 832 int (*ap_enable)(const struct device *dev, 833 struct wifi_connect_req_params *params); 834 /** Disable AP mode 835 * 836 * @param dev Pointer to the device structure for the driver instance. 837 * 838 * @return 0 if ok, < 0 if error 839 */ 840 int (*ap_disable)(const struct device *dev); 841 /** Disconnect a STA from AP 842 * 843 * @param dev Pointer to the device structure for the driver instance. 844 * @param mac MAC address of the STA to disconnect 845 * 846 * @return 0 if ok, < 0 if error 847 */ 848 int (*ap_sta_disconnect)(const struct device *dev, const uint8_t *mac); 849 /** Get interface status 850 * 851 * @param dev Pointer to the device structure for the driver instance. 852 * @param status Interface status 853 * 854 * @return 0 if ok, < 0 if error 855 */ 856 int (*iface_status)(const struct device *dev, struct wifi_iface_status *status); 857 #if defined(CONFIG_NET_STATISTICS_WIFI) || defined(__DOXYGEN__) 858 /** Get Wi-Fi statistics 859 * 860 * @param dev Pointer to the device structure for the driver instance. 861 * @param stats Wi-Fi statistics 862 * 863 * @return 0 if ok, < 0 if error 864 */ 865 int (*get_stats)(const struct device *dev, struct net_stats_wifi *stats); 866 #endif /* CONFIG_NET_STATISTICS_WIFI */ 867 /** Set power save status 868 * 869 * @param dev Pointer to the device structure for the driver instance. 870 * @param params Power save parameters 871 * 872 * @return 0 if ok, < 0 if error 873 */ 874 int (*set_power_save)(const struct device *dev, struct wifi_ps_params *params); 875 /** Setup or teardown TWT flow 876 * 877 * @param dev Pointer to the device structure for the driver instance. 878 * @param params TWT parameters 879 * 880 * @return 0 if ok, < 0 if error 881 */ 882 int (*set_twt)(const struct device *dev, struct wifi_twt_params *params); 883 /** Get power save config 884 * 885 * @param dev Pointer to the device structure for the driver instance. 886 * @param config Power save config 887 * 888 * @return 0 if ok, < 0 if error 889 */ 890 int (*get_power_save_config)(const struct device *dev, struct wifi_ps_config *config); 891 /** Set or get regulatory domain 892 * 893 * @param dev Pointer to the device structure for the driver instance. 894 * @param reg_domain Regulatory domain 895 * 896 * @return 0 if ok, < 0 if error 897 */ 898 int (*reg_domain)(const struct device *dev, struct wifi_reg_domain *reg_domain); 899 /** Set or get packet filter settings for monitor and promiscuous modes 900 * 901 * @param dev Pointer to the device structure for the driver instance. 902 * @param packet filter settings 903 * 904 * @return 0 if ok, < 0 if error 905 */ 906 int (*filter)(const struct device *dev, struct wifi_filter_info *filter); 907 /** Set or get mode of operation 908 * 909 * @param dev Pointer to the device structure for the driver instance. 910 * @param mode settings 911 * 912 * @return 0 if ok, < 0 if error 913 */ 914 int (*mode)(const struct device *dev, struct wifi_mode_info *mode); 915 /** Set or get current channel of operation 916 * 917 * @param dev Pointer to the device structure for the driver instance. 918 * @param channel settings 919 * 920 * @return 0 if ok, < 0 if error 921 */ 922 int (*channel)(const struct device *dev, struct wifi_channel_info *channel); 923 /** Get Version of WiFi driver and Firmware 924 * 925 * The driver that implements the get_version function must not use stack to allocate the 926 * version information pointers that are returned as params struct members. 927 * The version pointer parameters should point to a static memory either in ROM (preferred) 928 * or in RAM. 929 * 930 * @param dev Pointer to the device structure for the driver instance 931 * @param params Version parameters 932 * 933 * @return 0 if ok, < 0 if error 934 */ 935 int (*get_version)(const struct device *dev, struct wifi_version *params); 936 /** Set RTS threshold value 937 * 938 * @param dev Pointer to the device structure for the driver instance. 939 * @param RTS threshold value 940 * 941 * @return 0 if ok, < 0 if error 942 */ 943 int (*set_rts_threshold)(const struct device *dev, unsigned int rts_threshold); 944 /** Configure AP parameter 945 * 946 * @param dev Pointer to the device structure for the driver instance. 947 * @param params AP mode parameter configuration parameter info 948 * 949 * @return 0 if ok, < 0 if error 950 */ 951 int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params); 952 }; 953 954 /** Wi-Fi management offload API */ 955 struct net_wifi_mgmt_offload { 956 /** 957 * Mandatory to get in first position. 958 * A network device should indeed provide a pointer on such 959 * net_if_api structure. So we make current structure pointer 960 * that can be casted to a net_if_api structure pointer. 961 */ 962 #if defined(CONFIG_WIFI_USE_NATIVE_NETWORKING) || defined(__DOXYGEN__) 963 /** Ethernet API */ 964 struct ethernet_api wifi_iface; 965 #else 966 /** Offloaded network device API */ 967 struct offloaded_if_api wifi_iface; 968 #endif 969 /** Wi-Fi management API */ 970 const struct wifi_mgmt_ops *const wifi_mgmt_api; 971 972 #if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT) || defined(__DOXYGEN__) 973 /** Wi-Fi supplicant driver API */ 974 const void *wifi_drv_ops; 975 #endif 976 }; 977 978 #if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT) 979 /* Make sure wifi_drv_ops is after wifi_mgmt_api */ 980 BUILD_ASSERT(offsetof(struct net_wifi_mgmt_offload, wifi_mgmt_api) < 981 offsetof(struct net_wifi_mgmt_offload, wifi_drv_ops)); 982 #endif 983 984 /* Make sure that the network interface API is properly setup inside 985 * Wifi mgmt offload API struct (it is the first one). 986 */ 987 BUILD_ASSERT(offsetof(struct net_wifi_mgmt_offload, wifi_iface) == 0); 988 989 /** Wi-Fi management connect result event 990 * 991 * @param iface Network interface 992 * @param status Connect result status 993 */ 994 void wifi_mgmt_raise_connect_result_event(struct net_if *iface, int status); 995 996 /** Wi-Fi management disconnect result event 997 * 998 * @param iface Network interface 999 * @param status Disconnect result status 1000 */ 1001 void wifi_mgmt_raise_disconnect_result_event(struct net_if *iface, int status); 1002 1003 /** Wi-Fi management interface status event 1004 * 1005 * @param iface Network interface 1006 * @param iface_status Interface status 1007 */ 1008 void wifi_mgmt_raise_iface_status_event(struct net_if *iface, 1009 struct wifi_iface_status *iface_status); 1010 1011 /** Wi-Fi management TWT event 1012 * 1013 * @param iface Network interface 1014 * @param twt_params TWT parameters 1015 */ 1016 void wifi_mgmt_raise_twt_event(struct net_if *iface, 1017 struct wifi_twt_params *twt_params); 1018 1019 /** Wi-Fi management TWT sleep state event 1020 * 1021 * @param iface Network interface 1022 * @param twt_sleep_state TWT sleep state 1023 */ 1024 void wifi_mgmt_raise_twt_sleep_state(struct net_if *iface, int twt_sleep_state); 1025 1026 #if defined(CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS) || defined(__DOXYGEN__) 1027 /** Wi-Fi management raw scan result event 1028 * 1029 * @param iface Network interface 1030 * @param raw_scan_info Raw scan result 1031 */ 1032 void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, 1033 struct wifi_raw_scan_result *raw_scan_info); 1034 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ 1035 1036 /** Wi-Fi management disconnect complete event 1037 * 1038 * @param iface Network interface 1039 * @param status Disconnect complete status 1040 */ 1041 void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status); 1042 1043 /** Wi-Fi management AP mode enable result event 1044 * 1045 * @param iface Network interface 1046 * @param status AP mode enable result status 1047 */ 1048 void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_status status); 1049 1050 /** Wi-Fi management AP mode disable result event 1051 * 1052 * @param iface Network interface 1053 * @param status AP mode disable result status 1054 */ 1055 void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); 1056 1057 /** Wi-Fi management AP mode STA connected event 1058 * 1059 * @param iface Network interface 1060 * @param sta_info STA information 1061 */ 1062 void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, 1063 struct wifi_ap_sta_info *sta_info); 1064 1065 /** Wi-Fi management AP mode STA disconnected event 1066 * @param iface Network interface 1067 * @param sta_info STA information 1068 */ 1069 void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, 1070 struct wifi_ap_sta_info *sta_info); 1071 1072 /** 1073 * @} 1074 */ 1075 #ifdef __cplusplus 1076 } 1077 #endif 1078 1079 #endif /* ZEPHYR_INCLUDE_NET_WIFI_MGMT_H_ */ 1080