// Copyright 2019 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef _ESP_WIFI_DRIVER_H_ #define _ESP_WIFI_DRIVER_H_ #include "esp_err.h" #include "esp_wifi.h" #if CONFIG_NEWLIB_NANO_FORMAT #define TASK_STACK_SIZE_ADD 0 #else #define TASK_STACK_SIZE_ADD 512 #endif #define WPA2_TASK_STACK_SIZE (6144 + TASK_STACK_SIZE_ADD) #define WPS_TASK_STACK_SIZE (12288 + TASK_STACK_SIZE_ADD) enum { WIFI_WPA_ALG_NONE = 0, WIFI_WPA_ALG_WEP40 = 1, WIFI_WPA_ALG_TKIP = 2, WIFI_WPA_ALG_CCMP = 3, WIFI_WPA_ALG_WAPI = 4, WIFI_WPA_ALG_WEP104 = 5, WIFI_WPA_ALG_WEP, WIFI_WPA_ALG_IGTK, WIFI_WPA_ALG_PMK, WIFI_WPA_ALG_GCMP }; enum { WIFI_APPIE_PROBEREQ = 0, WIFI_APPIE_ASSOC_REQ, WIFI_APPIE_ASSOC_RESP, WIFI_APPIE_WPA, WIFI_APPIE_RSN, WIFI_APPIE_WPS_PR, WIFI_APPIE_WPS_AR, WIFI_APPIE_MESH_QUICK, WIFI_APPIE_FREQ_ERROR, WIFI_APPIE_ESP_MANUFACTOR, WIFI_APPIE_COUNTRY, WIFI_APPIE_MAX, }; enum { NONE_AUTH = 0x01, WPA_AUTH_UNSPEC = 0x02, WPA_AUTH_PSK = 0x03, WPA2_AUTH_ENT = 0x04, WPA2_AUTH_PSK = 0x05, WPA_AUTH_CCKM = 0x06, WPA2_AUTH_CCKM = 0x07, WPA2_AUTH_PSK_SHA256= 0x08, WPA3_AUTH_PSK = 0x09, WPA2_AUTH_INVALID = 0x0a, }; typedef enum { WPA2_ENT_EAP_STATE_NOT_START, WPA2_ENT_EAP_STATE_IN_PROGRESS, WPA2_ENT_EAP_STATE_SUCCESS, WPA2_ENT_EAP_STATE_FAIL, } wpa2_ent_eap_state_t; struct wifi_appie { uint16_t ie_len; uint8_t ie_data[]; }; struct wifi_ssid { int len; uint8_t ssid[32]; }; struct wps_scan_ie { uint8_t *bssid; uint8_t chan; uint16_t capinfo; uint8_t *ssid; uint8_t *wpa; uint8_t *rsn; uint8_t *wps; }; typedef struct { int proto; int pairwise_cipher; int group_cipher; int key_mgmt; int capabilities; size_t num_pmkid; const u8 *pmkid; int mgmt_group_cipher; } wifi_wpa_ie_t; struct wpa_funcs { bool (*wpa_sta_init)(void); bool (*wpa_sta_deinit)(void); void (*wpa_sta_connect)(uint8_t *bssid); void (*wpa_sta_disconnected_cb)(uint8_t reason_code); int (*wpa_sta_rx_eapol)(u8 *src_addr, u8 *buf, u32 len); bool (*wpa_sta_in_4way_handshake)(void); void *(*wpa_ap_init)(void); bool (*wpa_ap_deinit)(void *data); bool (*wpa_ap_join)(void **sm, u8 *bssid, u8 *wpa_ie, u8 wpa_ie_len); bool (*wpa_ap_remove)(void *sm); uint8_t *(*wpa_ap_get_wpa_ie)(uint8_t *len); bool (*wpa_ap_rx_eapol)(void *hapd_data, void *sm, u8 *data, size_t data_len); char *(*wpa_config_parse_string)(const char *value, size_t *len); int (*wpa_parse_wpa_ie)(const u8 *wpa_ie, size_t wpa_ie_len, wifi_wpa_ie_t *data); int (*wpa_config_bss)(u8 *bssid); int (*wpa_michael_mic_failure)(u16 is_unicast); uint8_t *(*wpa3_build_sae_msg)(uint8_t *bssid, uint32_t type, size_t *len); int (*wpa3_parse_sae_msg)(uint8_t *buf, size_t len, uint32_t type, uint16_t status); }; struct wpa2_funcs { int (*wpa2_sm_rx_eapol)(u8 *src_addr, u8 *buf, u32 len, u8 *bssid); int (*wpa2_start)(void); u8 (*wpa2_get_state)(void); int (*wpa2_init)(void); void (*wpa2_deinit)(void); }; struct wps_funcs { bool (*wps_parse_scan_result)(struct wps_scan_ie *scan); int (*wifi_station_wps_start)(void); int (*wps_sm_rx_eapol)(u8 *src_addr, u8 *buf, u32 len); int (*wps_start_pending)(void); }; typedef esp_err_t (*wifi_wpa2_fn_t)(void *); typedef struct { wifi_wpa2_fn_t fn; void *param; } wifi_wpa2_param_t; #define IS_WPS_REGISTRAR(type) (((type)>WPS_TYPE_MAX)?(((type)WPS_TYPE_DISABLE)?(((type)