mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	[wifi] fix 32 char SSIDs (#7834)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
		@@ -137,8 +137,16 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
 | 
				
			|||||||
  // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t
 | 
					  // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t
 | 
				
			||||||
  wifi_config_t conf;
 | 
					  wifi_config_t conf;
 | 
				
			||||||
  memset(&conf, 0, sizeof(conf));
 | 
					  memset(&conf, 0, sizeof(conf));
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.sta.ssid), sizeof(conf.sta.ssid), "%s", ap.get_ssid().c_str());
 | 
					  if (ap.get_ssid().size() > sizeof(conf.sta.ssid)) {
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.sta.password), sizeof(conf.sta.password), "%s", ap.get_password().c_str());
 | 
					    ESP_LOGE(TAG, "SSID is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (ap.get_password().size() > sizeof(conf.sta.password)) {
 | 
				
			||||||
 | 
					    ESP_LOGE(TAG, "password is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.sta.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.sta.password), ap.get_password().c_str(), ap.get_password().size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // The weakest authmode to accept in the fast scan mode
 | 
					  // The weakest authmode to accept in the fast scan mode
 | 
				
			||||||
  if (ap.get_password().empty()) {
 | 
					  if (ap.get_password().empty()) {
 | 
				
			||||||
@@ -746,7 +754,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  wifi_config_t conf;
 | 
					  wifi_config_t conf;
 | 
				
			||||||
  memset(&conf, 0, sizeof(conf));
 | 
					  memset(&conf, 0, sizeof(conf));
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.ap.ssid), sizeof(conf.ap.ssid), "%s", ap.get_ssid().c_str());
 | 
					  if (ap.get_ssid().size() > sizeof(conf.ap.ssid)) {
 | 
				
			||||||
 | 
					    ESP_LOGE(TAG, "AP SSID is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.ap.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
 | 
				
			||||||
  conf.ap.channel = ap.get_channel().value_or(1);
 | 
					  conf.ap.channel = ap.get_channel().value_or(1);
 | 
				
			||||||
  conf.ap.ssid_hidden = ap.get_ssid().size();
 | 
					  conf.ap.ssid_hidden = ap.get_ssid().size();
 | 
				
			||||||
  conf.ap.max_connection = 5;
 | 
					  conf.ap.max_connection = 5;
 | 
				
			||||||
@@ -757,7 +769,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
 | 
				
			|||||||
    *conf.ap.password = 0;
 | 
					    *conf.ap.password = 0;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
 | 
					    conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
 | 
				
			||||||
    snprintf(reinterpret_cast<char *>(conf.ap.password), sizeof(conf.ap.password), "%s", ap.get_password().c_str());
 | 
					    if (ap.get_password().size() > sizeof(conf.ap.password)) {
 | 
				
			||||||
 | 
					      ESP_LOGE(TAG, "AP password is too long");
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    memcpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), ap.get_password().size());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // pairwise cipher of SoftAP, group cipher will be derived using this.
 | 
					  // pairwise cipher of SoftAP, group cipher will be derived using this.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -236,8 +236,16 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  struct station_config conf {};
 | 
					  struct station_config conf {};
 | 
				
			||||||
  memset(&conf, 0, sizeof(conf));
 | 
					  memset(&conf, 0, sizeof(conf));
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.ssid), sizeof(conf.ssid), "%s", ap.get_ssid().c_str());
 | 
					  if (ap.get_ssid().size() > sizeof(conf.ssid)) {
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.password), sizeof(conf.password), "%s", ap.get_password().c_str());
 | 
					    ESP_LOGE(TAG, "SSID is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (ap.get_password().size() > sizeof(conf.password)) {
 | 
				
			||||||
 | 
					    ESP_LOGE(TAG, "password is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.password), ap.get_password().c_str(), ap.get_password().size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (ap.get_bssid().has_value()) {
 | 
					  if (ap.get_bssid().has_value()) {
 | 
				
			||||||
    conf.bssid_set = 1;
 | 
					    conf.bssid_set = 1;
 | 
				
			||||||
@@ -775,7 +783,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  struct softap_config conf {};
 | 
					  struct softap_config conf {};
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.ssid), sizeof(conf.ssid), "%s", ap.get_ssid().c_str());
 | 
					  if (ap.get_ssid().size() > sizeof(conf.ssid)) {
 | 
				
			||||||
 | 
					    ESP_LOGE(TAG, "AP SSID is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
 | 
				
			||||||
  conf.ssid_len = static_cast<uint8>(ap.get_ssid().size());
 | 
					  conf.ssid_len = static_cast<uint8>(ap.get_ssid().size());
 | 
				
			||||||
  conf.channel = ap.get_channel().value_or(1);
 | 
					  conf.channel = ap.get_channel().value_or(1);
 | 
				
			||||||
  conf.ssid_hidden = ap.get_hidden();
 | 
					  conf.ssid_hidden = ap.get_hidden();
 | 
				
			||||||
@@ -787,7 +799,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
 | 
				
			|||||||
    *conf.password = 0;
 | 
					    *conf.password = 0;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    conf.authmode = AUTH_WPA2_PSK;
 | 
					    conf.authmode = AUTH_WPA2_PSK;
 | 
				
			||||||
    snprintf(reinterpret_cast<char *>(conf.password), sizeof(conf.password), "%s", ap.get_password().c_str());
 | 
					    if (ap.get_password().size() > sizeof(conf.password)) {
 | 
				
			||||||
 | 
					      ESP_LOGE(TAG, "AP password is too long");
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    memcpy(reinterpret_cast<char *>(conf.password), ap.get_password().c_str(), ap.get_password().size());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ETS_UART_INTR_DISABLE();
 | 
					  ETS_UART_INTR_DISABLE();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -289,8 +289,16 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
 | 
				
			|||||||
  // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t
 | 
					  // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t
 | 
				
			||||||
  wifi_config_t conf;
 | 
					  wifi_config_t conf;
 | 
				
			||||||
  memset(&conf, 0, sizeof(conf));
 | 
					  memset(&conf, 0, sizeof(conf));
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.sta.ssid), sizeof(conf.sta.ssid), "%s", ap.get_ssid().c_str());
 | 
					  if (ap.get_ssid().size() > sizeof(conf.sta.ssid)) {
 | 
				
			||||||
  snprintf(reinterpret_cast<char *>(conf.sta.password), sizeof(conf.sta.password), "%s", ap.get_password().c_str());
 | 
					    ESP_LOGE(TAG, "SSID is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (ap.get_password().size() > sizeof(conf.sta.password)) {
 | 
				
			||||||
 | 
					    ESP_LOGE(TAG, "password is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.sta.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.sta.password), ap.get_password().c_str(), ap.get_password().size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // The weakest authmode to accept in the fast scan mode
 | 
					  // The weakest authmode to accept in the fast scan mode
 | 
				
			||||||
  if (ap.get_password().empty()) {
 | 
					  if (ap.get_password().empty()) {
 | 
				
			||||||
@@ -902,7 +910,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  wifi_config_t conf;
 | 
					  wifi_config_t conf;
 | 
				
			||||||
  memset(&conf, 0, sizeof(conf));
 | 
					  memset(&conf, 0, sizeof(conf));
 | 
				
			||||||
  strncpy(reinterpret_cast<char *>(conf.ap.ssid), ap.get_ssid().c_str(), sizeof(conf.ap.ssid));
 | 
					  if (ap.get_ssid().size() > sizeof(conf.ap.ssid)) {
 | 
				
			||||||
 | 
					    ESP_LOGE(TAG, "AP SSID is too long");
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  memcpy(reinterpret_cast<char *>(conf.ap.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
 | 
				
			||||||
  conf.ap.channel = ap.get_channel().value_or(1);
 | 
					  conf.ap.channel = ap.get_channel().value_or(1);
 | 
				
			||||||
  conf.ap.ssid_hidden = ap.get_ssid().size();
 | 
					  conf.ap.ssid_hidden = ap.get_ssid().size();
 | 
				
			||||||
  conf.ap.max_connection = 5;
 | 
					  conf.ap.max_connection = 5;
 | 
				
			||||||
@@ -913,7 +925,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
 | 
				
			|||||||
    *conf.ap.password = 0;
 | 
					    *conf.ap.password = 0;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
 | 
					    conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
 | 
				
			||||||
    strncpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), sizeof(conf.ap.password));
 | 
					    if (ap.get_password().size() > sizeof(conf.ap.password)) {
 | 
				
			||||||
 | 
					      ESP_LOGE(TAG, "AP password is too long");
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    memcpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), ap.get_password().size());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // pairwise cipher of SoftAP, group cipher will be derived using this.
 | 
					  // pairwise cipher of SoftAP, group cipher will be derived using this.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user