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