@@ -60,6 +60,7 @@ static struct eap_sm *gEapSm = NULL;
6060
6161static int eap_peer_sm_init (void );
6262static void eap_peer_sm_deinit (void );
63+ static void eap_start_eapol (void * ctx , void * data );
6364
6465static int eap_sm_rx_eapol_internal (u8 * src_addr , u8 * buf , u32 len , uint8_t * bssid );
6566static int wpa2_start_eapol_internal (void );
@@ -529,6 +530,10 @@ static int eap_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len, uint8_t *bss
529530 return ESP_FAIL ;
530531 }
531532
533+ if (!sm -> eap_process_started ) {
534+ sm -> eap_process_started = true;
535+ eloop_cancel_timeout (eap_start_eapol , NULL , NULL );
536+ }
532537 if (len < sizeof (* hdr ) + sizeof (* ehdr )) {
533538 wpa_printf (MSG_DEBUG , "WPA: EAPOL frame too short to be a WPA "
534539 "EAPOL-Key (len %lu, expecting at least %lu)" ,
@@ -612,15 +617,28 @@ static int eap_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len, uint8_t *bss
612617 return ret ;
613618}
614619
615- static int wpa2_start_eapol (void )
620+ static void eap_start_eapol (void * ctx , void * data )
616621{
617622#ifdef USE_WPA2_TASK
618- return wpa2_post (SIG_WPA2_START , 0 );
623+ wpa2_post (SIG_WPA2_START , 0 );
619624#else
620- return wpa2_start_eapol_internal ();
625+ wpa2_start_eapol_internal ();
621626#endif
622627}
623628
629+ static int eap_start_eapol_timer (void )
630+ {
631+ /*
632+ * Do not send EAPOL-Start immediately since in most cases,
633+ * Authenticator is going to start authentication immediately
634+ * after association and an extra EAPOL-Start is just going to
635+ * delay authentication. Use a short timeout to send the first
636+ * EAPOL-Start if Authenticator does not start authentication.
637+ */
638+ eloop_register_timeout (2 , 0 , eap_start_eapol , NULL , NULL );
639+ return 0 ;
640+ }
641+
624642static int wpa2_start_eapol_internal (void )
625643{
626644 struct eap_sm * sm = gEapSm ;
@@ -739,6 +757,7 @@ static int eap_peer_sm_init(void)
739757 wpa_printf (MSG_INFO , "wifi_task prio:%d, stack:%d" , WPA2_TASK_PRIORITY , WPA2_TASK_STACK_SIZE );
740758#endif
741759 sm -> workaround = 1 ;
760+ sm -> eap_process_started = false;
742761 return ESP_OK ;
743762
744763_err :
@@ -806,7 +825,7 @@ static esp_err_t esp_client_enable_fn(void *arg)
806825 }
807826
808827 wpa2_cb -> wpa2_sm_rx_eapol = wpa2_ent_rx_eapol ;
809- wpa2_cb -> wpa2_start = wpa2_start_eapol ;
828+ wpa2_cb -> wpa2_start = eap_start_eapol_timer ;
810829 wpa2_cb -> wpa2_init = eap_peer_sm_init ;
811830 wpa2_cb -> wpa2_deinit = eap_peer_sm_deinit ;
812831
0 commit comments