mirror of
https://github.com/esphome/esphome.git
synced 2025-09-12 08:12:22 +01:00
Store strings only used for logging in flash (#2274)
Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
@@ -327,20 +327,20 @@ class WiFiMockClass : public ESP8266WiFiGenericClass {
|
||||
static void _event_callback(void *event) { ESP8266WiFiGenericClass::_eventCallback(event); } // NOLINT
|
||||
};
|
||||
|
||||
const char *get_auth_mode_str(uint8_t mode) {
|
||||
const LogString *get_auth_mode_str(uint8_t mode) {
|
||||
switch (mode) {
|
||||
case AUTH_OPEN:
|
||||
return "OPEN";
|
||||
return LOG_STR("OPEN");
|
||||
case AUTH_WEP:
|
||||
return "WEP";
|
||||
return LOG_STR("WEP");
|
||||
case AUTH_WPA_PSK:
|
||||
return "WPA PSK";
|
||||
return LOG_STR("WPA PSK");
|
||||
case AUTH_WPA2_PSK:
|
||||
return "WPA2 PSK";
|
||||
return LOG_STR("WPA2 PSK");
|
||||
case AUTH_WPA_WPA2_PSK:
|
||||
return "WPA/WPA2 PSK";
|
||||
return LOG_STR("WPA/WPA2 PSK");
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
return LOG_STR("UNKNOWN");
|
||||
}
|
||||
}
|
||||
#ifdef ipv4_addr
|
||||
@@ -358,22 +358,22 @@ std::string format_ip_addr(struct ip_addr ip) {
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
const char *get_op_mode_str(uint8_t mode) {
|
||||
const LogString *get_op_mode_str(uint8_t mode) {
|
||||
switch (mode) {
|
||||
case WIFI_OFF:
|
||||
return "OFF";
|
||||
return LOG_STR("OFF");
|
||||
case WIFI_STA:
|
||||
return "STA";
|
||||
return LOG_STR("STA");
|
||||
case WIFI_AP:
|
||||
return "AP";
|
||||
return LOG_STR("AP");
|
||||
case WIFI_AP_STA:
|
||||
return "AP+STA";
|
||||
return LOG_STR("AP+STA");
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
return LOG_STR("UNKNOWN");
|
||||
}
|
||||
}
|
||||
// Note that this method returns PROGMEM strings, so use LOG_STR_ARG() to access them.
|
||||
const char *get_disconnect_reason_str(uint8_t reason) {
|
||||
|
||||
const LogString *get_disconnect_reason_str(uint8_t reason) {
|
||||
/* If this were one big switch statement, GCC would generate a lookup table for it. However, the values of the
|
||||
* REASON_* constants aren't continuous, and GCC will fill in the gap with the default value -- wasting 4 bytes of RAM
|
||||
* per entry. As there's ~175 default entries, this wastes 700 bytes of RAM.
|
||||
@@ -470,8 +470,8 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
|
||||
}
|
||||
case EVENT_STAMODE_AUTHMODE_CHANGE: {
|
||||
auto it = event->event_info.auth_change;
|
||||
ESP_LOGV(TAG, "Event: Changed AuthMode old=%s new=%s", get_auth_mode_str(it.old_mode),
|
||||
get_auth_mode_str(it.new_mode));
|
||||
ESP_LOGV(TAG, "Event: Changed AuthMode old=%s new=%s", LOG_STR_ARG(get_auth_mode_str(it.old_mode)),
|
||||
LOG_STR_ARG(get_auth_mode_str(it.new_mode)));
|
||||
// Mitigate CVE-2020-12638
|
||||
// https://lbsfilm.at/blog/wpa2-authenticationmode-downgrade-in-espressif-microprocessors
|
||||
if (it.old_mode != AUTH_OPEN && it.new_mode == AUTH_OPEN) {
|
||||
@@ -511,8 +511,8 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
|
||||
#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 4, 0)
|
||||
case EVENT_OPMODE_CHANGED: {
|
||||
auto it = event->event_info.opmode_changed;
|
||||
ESP_LOGV(TAG, "Event: Changed Mode old=%s new=%s", get_op_mode_str(it.old_opmode),
|
||||
get_op_mode_str(it.new_opmode));
|
||||
ESP_LOGV(TAG, "Event: Changed Mode old=%s new=%s", LOG_STR_ARG(get_op_mode_str(it.old_opmode)),
|
||||
LOG_STR_ARG(get_op_mode_str(it.new_opmode)));
|
||||
break;
|
||||
}
|
||||
case EVENT_SOFTAPMODE_DISTRIBUTE_STA_IP: {
|
||||
|
Reference in New Issue
Block a user