| 
									
										
										
										
											2017-08-18 11:12:58 +03:00
										 |  |  | // Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | //
 | 
					
						
							|  |  |  | // 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_WPA2_H
 | 
					
						
							|  |  |  | #define ESP_WPA2_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-27 09:01:06 +02:00
										 |  |  | #include <stdbool.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | #include "esp_err.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-18 11:12:58 +03:00
										 |  |  | #include "esp_wifi_crypto_types.h"
 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 11:12:58 +03:00
										 |  |  | extern const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  |     const wpa2_crypto_funcs_t *crypto_funcs; | 
					
						
							|  |  |  | }esp_wpa2_config_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define WPA2_CONFIG_INIT_DEFAULT() { \
 | 
					
						
							|  |  |  |     .crypto_funcs = &g_wifi_default_wpa2_crypto_funcs \ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Enable wpa2 enterprise authentication. | 
					
						
							|  |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @attention 1. wpa2 enterprise authentication can only be used when ESP32 station is enabled. | 
					
						
							|  |  |  |   * @attention 2. wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method. | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed. | 
					
						
							|  |  |  |   *    - ESP_ERR_NO_MEM: fail(internal memory malloc fail) | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							| 
									
										
										
										
											2017-08-18 11:12:58 +03:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_enable(const esp_wpa2_config_t *config); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Disable wpa2 enterprise authentication. | 
					
						
							|  |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @attention 1. wpa2 enterprise authentication can only be used when ESP32 station is enabled. | 
					
						
							|  |  |  |   * @attention 2. wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method. | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed. | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							|  |  |  | esp_err_t esp_wifi_sta_wpa2_ent_disable(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set identity for PEAP/TTLS method. | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @attention The API only passes the parameter identity to the global pointer variable in wpa2 enterprise module. | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @param  identity: point to address where stores the identity; | 
					
						
							|  |  |  |   * @param  len: length of identity, limited to 1~127 | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed | 
					
						
							|  |  |  |   *    - ESP_ERR_INVALID_ARG: fail(len <= 0 or len >= 128) | 
					
						
							|  |  |  |   *    - ESP_ERR_NO_MEM: fail(internal memory malloc fail) | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   */ | 
					
						
							| 
									
										
										
										
											2017-10-16 21:25:41 +03:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_identity(const unsigned char *identity, int len); | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Clear identity for PEAP/TTLS method. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  | void esp_wifi_sta_wpa2_ent_clear_identity(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set username for PEAP/TTLS method. | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @attention The API only passes the parameter username to the global pointer variable in wpa2 enterprise module. | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @param  username: point to address where stores the username; | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @param  len: length of username, limited to 1~127 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed | 
					
						
							|  |  |  |   *    - ESP_ERR_INVALID_ARG: fail(len <= 0 or len >= 128) | 
					
						
							|  |  |  |   *    - ESP_ERR_NO_MEM: fail(internal memory malloc fail) | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							| 
									
										
										
										
											2017-10-16 21:25:41 +03:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_username(const unsigned char *username, int len); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Clear username for PEAP/TTLS method. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  | void esp_wifi_sta_wpa2_ent_clear_username(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set password for PEAP/TTLS method.. | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @attention The API only passes the parameter password to the global pointer variable in wpa2 enterprise module. | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @param  password: point to address where stores the password; | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @param  len: length of password(len > 0) | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed | 
					
						
							|  |  |  |   *    - ESP_ERR_INVALID_ARG: fail(len <= 0) | 
					
						
							|  |  |  |   *    - ESP_ERR_NO_MEM: fail(internal memory malloc fail) | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							| 
									
										
										
										
											2017-10-16 21:25:41 +03:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_password(const unsigned char *password, int len); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Clear password for PEAP/TTLS method.. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  | void esp_wifi_sta_wpa2_ent_clear_password(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set new password for MSCHAPv2 method.. | 
					
						
							|  |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @attention 1. The API only passes the parameter password to the global pointer variable in wpa2 enterprise module. | 
					
						
							|  |  |  |   * @attention 2. The new password is used to substitute the old password when eap-mschapv2 failure request message with error code ERROR_PASSWD_EXPIRED is received. | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2018-06-27 09:01:06 +02:00
										 |  |  |   * @param  new_password: point to address where stores the password; | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @param  len: length of password | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed | 
					
						
							|  |  |  |   *    - ESP_ERR_INVALID_ARG: fail(len <= 0) | 
					
						
							|  |  |  |   *    - ESP_ERR_NO_MEM: fail(internal memory malloc fail) | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-27 09:01:06 +02:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(const unsigned char *new_password, int len); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Clear new password for MSCHAPv2 method.. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  | void esp_wifi_sta_wpa2_ent_clear_new_password(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set CA certificate for PEAP/TTLS method. | 
					
						
							|  |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @attention 1. The API only passes the parameter ca_cert to the global pointer variable in wpa2 enterprise module. | 
					
						
							|  |  |  |   * @attention 2. The ca_cert should be zero terminated. | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							|  |  |  |   * @param  ca_cert: point to address where stores the CA certificate; | 
					
						
							| 
									
										
										
										
											2018-06-27 09:01:06 +02:00
										 |  |  |   * @param  ca_cert_len: length of ca_cert | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							| 
									
										
										
										
											2018-06-27 09:01:06 +02:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(const unsigned char *ca_cert, int ca_cert_len); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Clear CA certificate for PEAP/TTLS method. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  | void esp_wifi_sta_wpa2_ent_clear_ca_cert(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set client certificate and key. | 
					
						
							|  |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @attention 1. The API only passes the parameter client_cert, private_key and private_key_passwd to the global pointer variable in wpa2 enterprise module. | 
					
						
							|  |  |  |   * @attention 2. The client_cert, private_key and private_key_passwd should be zero terminated. | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							|  |  |  |   * @param  client_cert: point to address where stores the client certificate; | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @param  client_cert_len: length of client certificate; | 
					
						
							|  |  |  |   * @param  private_key: point to address where stores the private key; | 
					
						
							|  |  |  |   * @param  private_key_len: length of private key, limited to 1~2048; | 
					
						
							|  |  |  |   * @param  private_key_password: point to address where stores the private key password; | 
					
						
							|  |  |  |   * @param  private_key_password_len: length of private key password; | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @return | 
					
						
							| 
									
										
										
										
											2018-04-07 09:45:18 +03:00
										 |  |  |   *    - ESP_OK: succeed | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							| 
									
										
										
										
											2017-10-16 21:25:41 +03:00
										 |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_cert_key(const unsigned char *client_cert, int client_cert_len, const unsigned char *private_key, int private_key_len, const unsigned char *private_key_passwd, int private_key_passwd_len); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Clear client certificate and key. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  | void esp_wifi_sta_wpa2_ent_clear_cert_key(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Set wpa2 enterprise certs time check(disable or not). | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @param  true: disable wpa2 enterprise certs time check | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @param  false: enable wpa2 enterprise certs time check | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							|  |  |  |   *    - ESP_OK: succeed | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							|  |  |  | esp_err_t esp_wifi_sta_wpa2_ent_set_disable_time_check(bool disable); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   * @brief  Get wpa2 enterprise certs time check(disable or not). | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * @param  disable: store disable value | 
					
						
							|  |  |  |   * | 
					
						
							| 
									
										
										
										
											2017-01-16 16:03:13 +02:00
										 |  |  |   * @return | 
					
						
							|  |  |  |   *    - ESP_OK: succeed | 
					
						
							| 
									
										
										
										
											2016-12-02 14:50:43 +02:00
										 |  |  |   */ | 
					
						
							|  |  |  | esp_err_t esp_wifi_sta_wpa2_ent_get_disable_time_check(bool *disable); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif
 |