1 /* 2 * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _ESP_WIFI_DRIVER_H_ 8 #define _ESP_WIFI_DRIVER_H_ 9 10 #include "esp_err.h" 11 #include "esp_wifi.h" 12 13 #if CONFIG_NEWLIB_NANO_FORMAT 14 #define TASK_STACK_SIZE_ADD 0 15 #else 16 #define TASK_STACK_SIZE_ADD 512 17 #endif 18 19 #define WPA2_TASK_STACK_SIZE (6144 + TASK_STACK_SIZE_ADD) 20 #define WPS_TASK_STACK_SIZE (12288 + TASK_STACK_SIZE_ADD) 21 22 enum wpa_alg{ 23 WIFI_WPA_ALG_NONE = 0, 24 WIFI_WPA_ALG_WEP40 = 1, 25 WIFI_WPA_ALG_TKIP = 2, 26 WIFI_WPA_ALG_CCMP = 3, 27 WIFI_WAPI_ALG_SMS4 = 4, 28 WIFI_WPA_ALG_WEP104 = 5, 29 WIFI_WPA_ALG_WEP = 6, 30 WIFI_WPA_ALG_IGTK = 7, 31 WIFI_WPA_ALG_PMK = 8, 32 WIFI_WPA_ALG_GCMP = 9, 33 }; 34 35 typedef enum { 36 WIFI_APPIE_PROBEREQ = 0, 37 WIFI_APPIE_ASSOC_REQ, 38 WIFI_APPIE_ASSOC_RESP, 39 WIFI_APPIE_WPA, 40 WIFI_APPIE_RSN, 41 WIFI_APPIE_WPS_PR, 42 WIFI_APPIE_WPS_AR, 43 WIFI_APPIE_MESH_QUICK, 44 WIFI_APPIE_FREQ_ERROR, 45 WIFI_APPIE_ESP_MANUFACTOR, 46 WIFI_APPIE_COUNTRY, 47 WIFI_APPIE_MAX, 48 } wifi_appie_t; 49 50 /* wifi_appie_t is in rom code and can't be changed anymore, use wifi_appie_ram_t for new app IEs */ 51 typedef enum { 52 WIFI_APPIE_RAM_MAX = WIFI_APPIE_MAX, 53 } wifi_appie_ram_t; 54 55 enum { 56 NONE_AUTH = 0x01, 57 WPA_AUTH_UNSPEC = 0x02, 58 WPA_AUTH_PSK = 0x03, 59 WPA2_AUTH_ENT = 0x04, 60 WPA2_AUTH_PSK = 0x05, 61 WPA_AUTH_CCKM = 0x06, 62 WPA2_AUTH_CCKM = 0x07, 63 WPA2_AUTH_PSK_SHA256= 0x08, 64 WPA3_AUTH_PSK = 0x09, 65 WPA2_AUTH_ENT_SHA256= 0x0a, 66 WAPI_AUTH_PSK = 0x0b, 67 WAPI_AUTH_CERT = 0x0c, 68 WPA2_AUTH_ENT_SHA384_SUITE_B = 0x0d, 69 WPA2_AUTH_INVALID = 0x0e, 70 }; 71 72 typedef enum { 73 WPA2_ENT_EAP_STATE_NOT_START, 74 WPA2_ENT_EAP_STATE_IN_PROGRESS, 75 WPA2_ENT_EAP_STATE_SUCCESS, 76 WPA2_ENT_EAP_STATE_FAIL, 77 } wpa2_ent_eap_state_t; 78 79 struct wifi_appie { 80 uint16_t ie_len; 81 uint8_t ie_data[]; 82 }; 83 84 struct wifi_ssid { 85 int len; 86 uint8_t ssid[32]; 87 }; 88 89 struct wps_scan_ie { 90 uint8_t *bssid; 91 uint8_t chan; 92 uint16_t capinfo; 93 uint8_t *ssid; 94 uint8_t *wpa; 95 uint8_t *rsn; 96 uint8_t *wps; 97 }; 98 99 typedef struct { 100 int proto; 101 int pairwise_cipher; 102 int group_cipher; 103 int key_mgmt; 104 int capabilities; 105 size_t num_pmkid; 106 const u8 *pmkid; 107 int mgmt_group_cipher; 108 } wifi_wpa_ie_t; 109 110 struct wpa_funcs { 111 bool (*wpa_sta_init)(void); 112 bool (*wpa_sta_deinit)(void); 113 int (*wpa_sta_connect)(uint8_t *bssid); 114 void (*wpa_sta_disconnected_cb)(uint8_t reason_code); 115 int (*wpa_sta_rx_eapol)(u8 *src_addr, u8 *buf, u32 len); 116 bool (*wpa_sta_in_4way_handshake)(void); 117 void *(*wpa_ap_init)(void); 118 bool (*wpa_ap_deinit)(void *data); 119 bool (*wpa_ap_join)(void **sm, u8 *bssid, u8 *wpa_ie, u8 wpa_ie_len); 120 bool (*wpa_ap_remove)(void *sm); 121 uint8_t *(*wpa_ap_get_wpa_ie)(uint8_t *len); 122 bool (*wpa_ap_rx_eapol)(void *hapd_data, void *sm, u8 *data, size_t data_len); 123 void (*wpa_ap_get_peer_spp_msg)(void *sm, bool *spp_cap, bool *spp_req); 124 char *(*wpa_config_parse_string)(const char *value, size_t *len); 125 int (*wpa_parse_wpa_ie)(const u8 *wpa_ie, size_t wpa_ie_len, wifi_wpa_ie_t *data); 126 int (*wpa_config_bss)(u8 *bssid); 127 int (*wpa_michael_mic_failure)(u16 is_unicast); 128 uint8_t *(*wpa3_build_sae_msg)(uint8_t *bssid, uint32_t type, size_t *len); 129 int (*wpa3_parse_sae_msg)(uint8_t *buf, size_t len, uint32_t type, uint16_t status); 130 int (*wpa_sta_rx_mgmt)(u8 type, u8 *frame, size_t len, u8 *sender, u32 rssi, u8 channel, u64 current_tsf); 131 void (*wpa_config_done)(void); 132 bool (*wpa_sta_profile_match)(u8 *bssid); 133 }; 134 135 struct wpa2_funcs { 136 int (*wpa2_sm_rx_eapol)(u8 *src_addr, u8 *buf, u32 len, u8 *bssid); 137 int (*wpa2_start)(void); 138 u8 (*wpa2_get_state)(void); 139 int (*wpa2_init)(void); 140 void (*wpa2_deinit)(void); 141 }; 142 143 struct wps_funcs { 144 bool (*wps_parse_scan_result)(struct wps_scan_ie *scan); 145 int (*wifi_station_wps_start)(void); 146 int (*wps_sm_rx_eapol)(u8 *src_addr, u8 *buf, u32 len); 147 int (*wps_start_pending)(void); 148 }; 149 150 typedef esp_err_t (*wifi_wpa2_fn_t)(void *); 151 typedef struct { 152 wifi_wpa2_fn_t fn; 153 void *param; 154 } wifi_wpa2_param_t; 155 156 #define IS_WPS_REGISTRAR(type) (((type)>WPS_TYPE_MAX)?(((type)<WPS_TYPE_MAX)?true:false):false) 157 #define IS_WPS_ENROLLEE(type) (((type)>WPS_TYPE_DISABLE)?(((type)<WPS_TYPE_MAX)?true:false):false) 158 159 typedef enum wps_status { 160 WPS_STATUS_DISABLE = 0, 161 WPS_STATUS_SCANNING, 162 WPS_STATUS_PENDING, 163 WPS_STATUS_SUCCESS, 164 WPS_STATUS_MAX, 165 } WPS_STATUS_t; 166 167 #define WIFI_TXCB_EAPOL_ID 3 168 typedef void(*wifi_tx_cb_t)(void *); 169 typedef int (*wifi_ipc_fn_t)(void *); 170 typedef struct { 171 wifi_ipc_fn_t fn; 172 void *arg; 173 uint32_t arg_size; 174 } wifi_ipc_config_t; 175 176 #define WPA_IGTK_MAX_LEN 32 177 typedef struct { 178 uint8_t keyid[2]; 179 uint8_t pn[6]; 180 uint8_t igtk[WPA_IGTK_MAX_LEN]; 181 } wifi_wpa_igtk_t; 182 183 typedef struct { 184 wifi_interface_t ifx; 185 uint8_t subtype; 186 uint32_t data_len; 187 uint8_t data[0]; 188 } wifi_mgmt_frm_req_t; 189 190 enum key_flag { 191 KEY_FLAG_MODIFY = BIT(0), 192 KEY_FLAG_DEFAULT = BIT(1), 193 KEY_FLAG_RX = BIT(2), 194 KEY_FLAG_TX = BIT(3), 195 KEY_FLAG_GROUP = BIT(4), 196 KEY_FLAG_PAIRWISE = BIT(5), 197 KEY_FLAG_PMK = BIT(6), 198 }; 199 200 uint8_t *esp_wifi_ap_get_prof_pmk_internal(void); 201 struct wifi_ssid *esp_wifi_ap_get_prof_ap_ssid_internal(void); 202 uint8_t esp_wifi_ap_get_prof_authmode_internal(void); 203 uint8_t esp_wifi_sta_get_prof_authmode_internal(void); 204 uint8_t *esp_wifi_ap_get_prof_password_internal(void); 205 struct wifi_ssid *esp_wifi_sta_get_prof_ssid_internal(void); 206 uint8_t esp_wifi_sta_get_reset_param_internal(void); 207 uint8_t esp_wifi_sta_get_pairwise_cipher_internal(void); 208 uint8_t esp_wifi_sta_get_group_cipher_internal(void); 209 bool esp_wifi_sta_prof_is_wpa_internal(void); 210 int esp_wifi_get_macaddr_internal(uint8_t if_index, uint8_t *macaddr); 211 int esp_wifi_set_appie_internal(uint8_t type, uint8_t *ie, uint16_t len, uint8_t flag); 212 int esp_wifi_unset_appie_internal(uint8_t type); 213 struct wifi_appie *esp_wifi_get_appie_internal(uint8_t type); 214 void *esp_wifi_get_hostap_private_internal(void); //1 215 uint8_t *esp_wifi_sta_get_prof_password_internal(void); 216 void esp_wifi_deauthenticate_internal(u8 reason_code); 217 uint16_t esp_wifi_get_spp_attrubute_internal(uint8_t ifx); 218 bool esp_wifi_sta_is_running_internal(void); 219 bool esp_wifi_auth_done_internal(void); 220 int esp_wifi_set_ap_key_internal(int alg, const u8 *addr, int idx, u8 *key, size_t key_len); 221 int esp_wifi_set_sta_key_internal(int alg, u8 *addr, int key_idx, int set_tx, 222 u8 *seq, size_t seq_len, u8 *key, size_t key_len, enum key_flag key_flag); 223 int esp_wifi_get_sta_key_internal(uint8_t *ifx, int *alg, u8 *addr, int *key_idx, 224 u8 *key, size_t key_len, enum key_flag key_flag); 225 bool esp_wifi_wpa_ptk_init_done_internal(uint8_t *mac); 226 uint8_t esp_wifi_sta_set_reset_param_internal(uint8_t reset_flag); 227 uint8_t esp_wifi_get_sta_gtk_index_internal(void); 228 int esp_wifi_register_tx_cb_internal(wifi_tx_cb_t fn, u8 id); 229 int esp_wifi_register_wpa_cb_internal(struct wpa_funcs *cb); 230 int esp_wifi_unregister_wpa_cb_internal(void); 231 int esp_wifi_get_assoc_bssid_internal(uint8_t *bssid); 232 bool esp_wifi_sta_is_ap_notify_completed_rsne_internal(void); 233 int esp_wifi_ap_deauth_internal(uint8_t *mac, uint32_t reason); 234 int esp_wifi_ipc_internal(wifi_ipc_config_t *cfg, bool sync); 235 int esp_wifi_register_wpa2_cb_internal(struct wpa2_funcs *cb); 236 int esp_wifi_unregister_wpa2_cb_internal(void); 237 bool esp_wifi_sta_prof_is_wpa2_internal(void); 238 bool esp_wifi_sta_prof_is_wpa3_internal(void); 239 bool esp_wifi_sta_prof_is_wapi_internal(void); 240 esp_err_t esp_wifi_sta_wpa2_ent_disable_internal(wifi_wpa2_param_t *param); 241 esp_err_t esp_wifi_sta_wpa2_ent_enable_internal(wifi_wpa2_param_t *param); 242 esp_err_t esp_wifi_set_wpa2_ent_state_internal(wpa2_ent_eap_state_t state); 243 int esp_wifi_get_wps_type_internal(void); 244 int esp_wifi_set_wps_type_internal(uint32_t type); 245 int esp_wifi_get_wps_status_internal(void); 246 int esp_wifi_set_wps_status_internal(uint32_t status); 247 int esp_wifi_disarm_sta_connection_timer_internal(void); 248 bool esp_wifi_get_sniffer_internal(void); 249 int esp_wifi_set_wps_cb_internal(struct wps_funcs *wps_cb); 250 bool esp_wifi_enable_sta_privacy_internal(void); 251 uint8_t esp_wifi_get_user_init_flag_internal(void); 252 esp_err_t esp_wifi_internal_supplicant_header_md5_check(const char *md5); 253 int esp_wifi_sta_update_ap_info_internal(void); 254 uint8_t *esp_wifi_sta_get_ap_info_prof_pmk_internal(void); 255 esp_err_t esp_wifi_set_wps_start_flag_internal(bool start); 256 uint16_t esp_wifi_sta_pmf_enabled(void); 257 wifi_cipher_type_t esp_wifi_sta_get_mgmt_group_cipher(void); 258 int esp_wifi_set_igtk_internal(uint8_t if_index, const wifi_wpa_igtk_t *igtk); 259 esp_err_t esp_wifi_internal_issue_disconnect(uint8_t reason_code); 260 bool esp_wifi_skip_supp_pmkcaching(void); 261 bool esp_wifi_is_rm_enabled_internal(uint8_t if_index); 262 bool esp_wifi_is_btm_enabled_internal(uint8_t if_index); 263 esp_err_t esp_wifi_register_mgmt_frame_internal(uint32_t type, uint32_t subtype); 264 esp_err_t esp_wifi_send_mgmt_frm_internal(const wifi_mgmt_frm_req_t *req); 265 uint8_t esp_wifi_ap_get_prof_pairwise_cipher_internal(void); 266 esp_err_t esp_wifi_action_tx_req(uint8_t type, uint8_t channel, 267 uint32_t wait_time_ms, const wifi_action_tx_req_t *req); 268 esp_err_t esp_wifi_remain_on_channel(uint8_t ifx, uint8_t type, uint8_t channel, 269 uint32_t wait_time_ms, wifi_action_rx_cb_t rx_cb); 270 bool esp_wifi_is_mbo_enabled_internal(uint8_t if_index); 271 272 #endif /* _ESP_WIFI_DRIVER_H_ */ 273