3838#include "esp_wpas_glue.h"
3939#include "esp_eap_client_i.h"
4040#include "esp_eap_client.h"
41+ #include "eloop.h"
4142
4243#define WPA2_VERSION "v2.0"
4344
@@ -63,6 +64,7 @@ static void eap_peer_sm_deinit(void);
6364static int eap_sm_rx_eapol_internal (u8 * src_addr , u8 * buf , u32 len , uint8_t * bssid );
6465static int wpa2_start_eapol_internal (void );
6566int wpa2_post (uint32_t sig , uint32_t par );
67+ extern bool g_wpa_config_changed ;
6668
6769#ifdef USE_WPA2_TASK
6870#define WPA2_TASK_PRIORITY 7
@@ -73,6 +75,11 @@ static void *s_wpa2_api_lock = NULL;
7375static void * s_wifi_wpa2_sync_sem = NULL ;
7476static bool s_disable_time_check = true;
7577
78+ static void config_changed_handler (void * ctx , void * data )
79+ {
80+ g_wpa_config_changed = true;
81+ }
82+
7683static void wpa2_api_lock (void )
7784{
7885 if (s_wpa2_api_lock == NULL ) {
@@ -812,6 +819,7 @@ static esp_err_t esp_client_enable_fn(void *arg)
812819 wpa_printf (MSG_ERROR , "Register EAP Peer methods Failure" );
813820 }
814821#endif
822+ g_wpa_config_changed = true;
815823 return ESP_OK ;
816824}
817825
@@ -875,6 +883,7 @@ static esp_err_t eap_client_disable_fn(void *param)
875883#endif
876884
877885 sm -> wpa_sm_eap_disable = NULL ;
886+ g_wpa_config_changed = true;
878887 return ESP_OK ;
879888}
880889
@@ -922,6 +931,7 @@ esp_err_t esp_eap_client_set_certificate_and_key(const unsigned char *client_cer
922931 g_wpa_private_key_passwd = private_key_passwd ;
923932 g_wpa_private_key_passwd_len = private_key_passwd_len ;
924933 }
934+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
925935
926936 return ESP_OK ;
927937}
@@ -937,6 +947,7 @@ void esp_eap_client_clear_certificate_and_key(void)
937947 os_free (g_wpa_pac_file );
938948 g_wpa_pac_file = NULL ;
939949 g_wpa_pac_file_len = 0 ;
950+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
940951}
941952
942953esp_err_t esp_eap_client_set_ca_cert (const unsigned char * ca_cert , int ca_cert_len )
@@ -946,13 +957,17 @@ esp_err_t esp_eap_client_set_ca_cert(const unsigned char *ca_cert, int ca_cert_l
946957 g_wpa_ca_cert_len = ca_cert_len ;
947958 }
948959
960+ /* CA certs Set/updated, flushing current PMK cache */
961+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
962+
949963 return ESP_OK ;
950964}
951965
952966void esp_eap_client_clear_ca_cert (void )
953967{
954968 g_wpa_ca_cert = NULL ;
955969 g_wpa_ca_cert_len = 0 ;
970+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
956971}
957972
958973#define ANONYMOUS_ID_LEN_MAX 128
@@ -969,23 +984,27 @@ esp_err_t esp_eap_client_set_identity(const unsigned char *identity, int len)
969984
970985 g_wpa_anonymous_identity = (u8 * )os_zalloc (len );
971986 if (g_wpa_anonymous_identity == NULL ) {
987+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
972988 return ESP_ERR_NO_MEM ;
973989 }
974990
975991 os_memcpy (g_wpa_anonymous_identity , identity , len );
976992 g_wpa_anonymous_identity_len = len ;
993+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
977994
978995 return ESP_OK ;
979996}
980997
981998void esp_eap_client_clear_identity (void )
982999{
983- if (g_wpa_anonymous_identity ) {
984- os_free ( g_wpa_anonymous_identity ) ;
1000+ if (! g_wpa_anonymous_identity ) {
1001+ return ;
9851002 }
9861003
1004+ os_free (g_wpa_anonymous_identity );
9871005 g_wpa_anonymous_identity = NULL ;
9881006 g_wpa_anonymous_identity_len = 0 ;
1007+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
9891008}
9901009
9911010#define USERNAME_LEN_MAX 128
@@ -1002,11 +1021,13 @@ esp_err_t esp_eap_client_set_username(const unsigned char *username, int len)
10021021
10031022 g_wpa_username = (u8 * )os_zalloc (len );
10041023 if (g_wpa_username == NULL ) {
1024+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10051025 return ESP_ERR_NO_MEM ;
10061026 }
10071027
10081028 os_memcpy (g_wpa_username , username , len );
10091029 g_wpa_username_len = len ;
1030+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10101031
10111032 return ESP_OK ;
10121033}
@@ -1019,6 +1040,7 @@ void esp_eap_client_clear_username(void)
10191040
10201041 g_wpa_username = NULL ;
10211042 g_wpa_username_len = 0 ;
1043+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10221044}
10231045
10241046esp_err_t esp_eap_client_set_password (const unsigned char * password , int len )
@@ -1034,11 +1056,13 @@ esp_err_t esp_eap_client_set_password(const unsigned char *password, int len)
10341056
10351057 g_wpa_password = (u8 * )os_zalloc (len );
10361058 if (g_wpa_password == NULL ) {
1059+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10371060 return ESP_ERR_NO_MEM ;
10381061 }
10391062
10401063 os_memcpy (g_wpa_password , password , len );
10411064 g_wpa_password_len = len ;
1065+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10421066
10431067 return ESP_OK ;
10441068}
@@ -1050,6 +1074,7 @@ void esp_eap_client_clear_password(void)
10501074 }
10511075 g_wpa_password = NULL ;
10521076 g_wpa_password_len = 0 ;
1077+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10531078}
10541079
10551080esp_err_t esp_eap_client_set_new_password (const unsigned char * new_password , int len )
@@ -1065,11 +1090,13 @@ esp_err_t esp_eap_client_set_new_password(const unsigned char *new_password, int
10651090
10661091 g_wpa_new_password = (u8 * )os_zalloc (len );
10671092 if (g_wpa_new_password == NULL ) {
1093+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10681094 return ESP_ERR_NO_MEM ;
10691095 }
10701096
10711097 os_memcpy (g_wpa_new_password , new_password , len );
10721098 g_wpa_password_len = len ;
1099+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10731100
10741101 return ESP_OK ;
10751102}
@@ -1081,11 +1108,13 @@ void esp_eap_client_clear_new_password(void)
10811108 }
10821109 g_wpa_new_password = NULL ;
10831110 g_wpa_new_password_len = 0 ;
1111+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10841112}
10851113
10861114esp_err_t esp_eap_client_set_disable_time_check (bool disable )
10871115{
10881116 s_disable_time_check = disable ;
1117+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
10891118 return ESP_OK ;
10901119}
10911120
@@ -1122,13 +1151,15 @@ esp_err_t esp_eap_client_set_ttls_phase2_method(esp_eap_ttls_phase2_types type)
11221151 g_wpa_ttls_phase2_type = "auth=MSCHAPV2" ;
11231152 break ;
11241153 }
1154+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
11251155 return ESP_OK ;
11261156}
11271157
11281158esp_err_t esp_eap_client_set_suiteb_192bit_certification (bool enable )
11291159{
11301160#ifdef CONFIG_SUITEB192
11311161 g_wpa_suiteb_certification = enable ;
1162+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
11321163 return ESP_OK ;
11331164#else
11341165 return ESP_FAIL ;
@@ -1147,6 +1178,7 @@ esp_err_t esp_eap_client_set_pac_file(const unsigned char *pac_file, int pac_fil
11471178 } else { // The file contains pac data
11481179 g_wpa_pac_file = (u8 * )os_zalloc (pac_file_len );
11491180 if (g_wpa_pac_file == NULL ) {
1181+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
11501182 return ESP_ERR_NO_MEM ;
11511183 }
11521184 os_memcpy (g_wpa_pac_file , pac_file , pac_file_len );
@@ -1155,6 +1187,7 @@ esp_err_t esp_eap_client_set_pac_file(const unsigned char *pac_file, int pac_fil
11551187 } else {
11561188 return ESP_FAIL ;
11571189 }
1190+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
11581191
11591192 return ESP_OK ;
11601193}
@@ -1184,9 +1217,11 @@ esp_err_t esp_eap_client_set_fast_params(esp_eap_fast_config config)
11841217 }
11851218 g_wpa_phase1_options = (char * )os_zalloc (sizeof (config_for_supplicant ));
11861219 if (g_wpa_phase1_options == NULL ) {
1220+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
11871221 return ESP_ERR_NO_MEM ;
11881222 }
11891223 os_memcpy (g_wpa_phase1_options , & config_for_supplicant , sizeof (config_for_supplicant ));
1224+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
11901225 return ESP_OK ;
11911226
11921227}
@@ -1200,8 +1235,43 @@ esp_err_t esp_eap_client_use_default_cert_bundle(bool use_default_bundle)
12001235 } else {
12011236 esp_crt_bundle_attach_fn = NULL ;
12021237 }
1238+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
12031239 return ESP_OK ;
12041240#else
12051241 return ESP_FAIL ;
12061242#endif
12071243}
1244+
1245+ #define MAX_DOMAIN_MATCH_LEN 255 /* Maximum host name defined in RFC 1035 */
1246+ esp_err_t esp_eap_client_set_domain_name (const char * domain_name )
1247+ {
1248+ #ifdef CONFIG_TLS_INTERNAL_CLIENT
1249+ return ESP_ERR_NOT_SUPPORTED ;
1250+ #else
1251+ int len = domain_name ? os_strnlen (domain_name , MAX_DOMAIN_MATCH_LEN + 1 ) : 0 ;
1252+ if (len > MAX_DOMAIN_MATCH_LEN ) {
1253+ return ESP_ERR_INVALID_ARG ;
1254+ }
1255+ if (g_wpa_domain_match && domain_name && os_strcmp (g_wpa_domain_match , domain_name ) == 0 ) {
1256+ return ESP_OK ;
1257+ }
1258+ if (g_wpa_domain_match ) {
1259+ os_free (g_wpa_domain_match );
1260+ g_wpa_domain_match = NULL ;
1261+ }
1262+
1263+ if (!domain_name ) {
1264+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
1265+ return ESP_OK ;
1266+ }
1267+ g_wpa_domain_match = os_strdup (domain_name );
1268+ if (!g_wpa_domain_match ) {
1269+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
1270+ return ESP_ERR_NO_MEM ;
1271+ }
1272+
1273+ eloop_register_timeout (0 , 0 , config_changed_handler , NULL , NULL );
1274+
1275+ return ESP_OK ;
1276+ #endif
1277+ }
0 commit comments