diff --git a/Sming/Arch/Esp32/Platform/AccessPointImpl.cpp b/Sming/Arch/Esp32/Platform/AccessPointImpl.cpp index a44cf2f6d9..8aaea9d431 100644 --- a/Sming/Arch/Esp32/Platform/AccessPointImpl.cpp +++ b/Sming/Arch/Esp32/Platform/AccessPointImpl.cpp @@ -143,6 +143,11 @@ MacAddress AccessPointImpl::getMacAddress() const return addr; } +bool AccessPointImpl::setMacAddress(const MacAddress& addr) const +{ + return esp_wifi_set_mac(ESP_IF_WIFI_AP, &const_cast(addr)[0]); +} + String AccessPointImpl::getSSID() const { wifi_config_t config{}; diff --git a/Sming/Arch/Esp32/Platform/AccessPointImpl.h b/Sming/Arch/Esp32/Platform/AccessPointImpl.h index a060e84760..832dfd3a1c 100644 --- a/Sming/Arch/Esp32/Platform/AccessPointImpl.h +++ b/Sming/Arch/Esp32/Platform/AccessPointImpl.h @@ -28,6 +28,7 @@ class AccessPointImpl : public AccessPointClass, protected ISystemReadyHandler IpAddress getIP() const override; bool setIP(IpAddress address) override; MacAddress getMacAddress() const override; + bool setMacAddress(const MacAddress& addr) const override; IpAddress getNetworkMask() const override; IpAddress getNetworkGateway() const override; IpAddress getNetworkBroadcast() const override; diff --git a/Sming/Arch/Esp32/Platform/StationImpl.cpp b/Sming/Arch/Esp32/Platform/StationImpl.cpp index e82ef32dea..362bd5cfc5 100644 --- a/Sming/Arch/Esp32/Platform/StationImpl.cpp +++ b/Sming/Arch/Esp32/Platform/StationImpl.cpp @@ -164,6 +164,11 @@ MacAddress StationImpl::getMacAddress() const return addr; } +bool StationImpl::setMacAddress(const MacAddress& addr) const +{ + return esp_wifi_set_mac(ESP_IF_WIFI_STA, &const_cast(addr)[0]); +} + IpAddress StationImpl::getNetworkBroadcast() const { esp_netif_ip_info_t info; diff --git a/Sming/Arch/Esp32/Platform/StationImpl.h b/Sming/Arch/Esp32/Platform/StationImpl.h index e785208713..b25831542d 100644 --- a/Sming/Arch/Esp32/Platform/StationImpl.h +++ b/Sming/Arch/Esp32/Platform/StationImpl.h @@ -38,6 +38,7 @@ class StationImpl : public StationClass, protected ISystemReadyHandler String getHostname() const override; IpAddress getIP() const override; MacAddress getMacAddress() const override; + bool setMacAddress(const MacAddress& addr) const override; IpAddress getNetworkMask() const override; IpAddress getNetworkGateway() const override; IpAddress getNetworkBroadcast() const override; diff --git a/Sming/Arch/Esp8266/Platform/AccessPointImpl.cpp b/Sming/Arch/Esp8266/Platform/AccessPointImpl.cpp index 40d5484c86..93f0a266c6 100644 --- a/Sming/Arch/Esp8266/Platform/AccessPointImpl.cpp +++ b/Sming/Arch/Esp8266/Platform/AccessPointImpl.cpp @@ -153,6 +153,11 @@ MacAddress AccessPointImpl::getMacAddress() const } } +bool AccessPointImpl::setMacAddress(const MacAddress& addr) const +{ + return wifi_set_macaddr(SOFTAP_IF, &const_cast(addr)[0]); +} + String AccessPointImpl::getSSID() const { softap_config config = {0}; diff --git a/Sming/Arch/Esp8266/Platform/AccessPointImpl.h b/Sming/Arch/Esp8266/Platform/AccessPointImpl.h index ce285fff2f..53dce75022 100644 --- a/Sming/Arch/Esp8266/Platform/AccessPointImpl.h +++ b/Sming/Arch/Esp8266/Platform/AccessPointImpl.h @@ -28,6 +28,7 @@ class AccessPointImpl : public AccessPointClass, protected ISystemReadyHandler IpAddress getIP() const override; bool setIP(IpAddress address) override; MacAddress getMacAddress() const override; + bool setMacAddress(const MacAddress& addr) const override; IpAddress getNetworkMask() const override; IpAddress getNetworkGateway() const override; IpAddress getNetworkBroadcast() const override; diff --git a/Sming/Arch/Esp8266/Platform/StationImpl.cpp b/Sming/Arch/Esp8266/Platform/StationImpl.cpp index 627f8324b0..cbb7450312 100644 --- a/Sming/Arch/Esp8266/Platform/StationImpl.cpp +++ b/Sming/Arch/Esp8266/Platform/StationImpl.cpp @@ -172,6 +172,11 @@ MacAddress StationImpl::getMacAddress() const } } +bool StationImpl::setMacAddress(const MacAddress& addr) const +{ + return wifi_set_macaddr(STATION_IF, &const_cast(addr)[0]); +} + IpAddress StationImpl::getNetworkBroadcast() const { struct ip_info info = {0}; diff --git a/Sming/Arch/Esp8266/Platform/StationImpl.h b/Sming/Arch/Esp8266/Platform/StationImpl.h index 2e370d2f32..4614a6c179 100644 --- a/Sming/Arch/Esp8266/Platform/StationImpl.h +++ b/Sming/Arch/Esp8266/Platform/StationImpl.h @@ -38,6 +38,7 @@ class StationImpl : public StationClass, protected ISystemReadyHandler String getHostname() const override; IpAddress getIP() const override; MacAddress getMacAddress() const override; + bool setMacAddress(const MacAddress& addr) const override; IpAddress getNetworkMask() const override; IpAddress getNetworkGateway() const override; IpAddress getNetworkBroadcast() const override; diff --git a/Sming/Arch/Host/Platform/AccessPointImpl.cpp b/Sming/Arch/Host/Platform/AccessPointImpl.cpp index edc9c043f4..77e52c94a6 100644 --- a/Sming/Arch/Host/Platform/AccessPointImpl.cpp +++ b/Sming/Arch/Host/Platform/AccessPointImpl.cpp @@ -58,6 +58,12 @@ MacAddress AccessPointImpl::getMacAddress() const return MACADDR_NONE; } +bool AccessPointImpl::setMacAddress(const MacAddress& addr) const +{ + debug_w("[HOST] setMacAddress not implemented"); + return false; +} + String AccessPointImpl::getSSID() const { return nullptr; diff --git a/Sming/Arch/Host/Platform/AccessPointImpl.h b/Sming/Arch/Host/Platform/AccessPointImpl.h index ff2f0a315d..c45b324102 100644 --- a/Sming/Arch/Host/Platform/AccessPointImpl.h +++ b/Sming/Arch/Host/Platform/AccessPointImpl.h @@ -22,6 +22,7 @@ class AccessPointImpl : public AccessPointClass IpAddress getIP() const override; bool setIP(IpAddress address) override; MacAddress getMacAddress() const override; + bool setMacAddress(const MacAddress& addr) const override; IpAddress getNetworkMask() const override; IpAddress getNetworkGateway() const override; IpAddress getNetworkBroadcast() const override; diff --git a/Sming/Arch/Host/Platform/StationImpl.cpp b/Sming/Arch/Host/Platform/StationImpl.cpp index aff69e4352..caca7f7934 100644 --- a/Sming/Arch/Host/Platform/StationImpl.cpp +++ b/Sming/Arch/Host/Platform/StationImpl.cpp @@ -257,6 +257,12 @@ MacAddress StationImpl::getMacAddress() const } } +bool StationImpl::setMacAddress(const MacAddress& addr) const +{ + debug_w("[HOST] setMacAddress not implemented"); + return false; +} + IpAddress StationImpl::getNetworkBroadcast() const { return ipaddr | ~netmask; diff --git a/Sming/Arch/Host/Platform/StationImpl.h b/Sming/Arch/Host/Platform/StationImpl.h index 1db69b0f67..6523f4e0b0 100644 --- a/Sming/Arch/Host/Platform/StationImpl.h +++ b/Sming/Arch/Host/Platform/StationImpl.h @@ -46,6 +46,7 @@ class StationImpl : public StationClass String getHostname() const override; IpAddress getIP() const override; MacAddress getMacAddress() const override; + bool setMacAddress(const MacAddress& addr) const override; IpAddress getNetworkMask() const override; IpAddress getNetworkGateway() const override; IpAddress getNetworkBroadcast() const override; diff --git a/Sming/Platform/AccessPoint.h b/Sming/Platform/AccessPoint.h index 9a0f475dda..9fb52210f8 100644 --- a/Sming/Platform/AccessPoint.h +++ b/Sming/Platform/AccessPoint.h @@ -81,6 +81,20 @@ class AccessPointClass */ String getMAC(char sep = '\0') const; + /** @brief Set Access Point MAC address + * @param addr The new MAC address + * @retval bool true on success + * + * Must be called from `init()` before activating Access Point. + * Espressif place certain limitations on MAC addresses: + * + * Bit 0 of the first byte of the MAC address can not be 1. For example: + * + * OK: "1a:XX:XX:XX:XX:XX" + * NOT OK: "15:XX:XX:XX:XX:XX" + */ + virtual bool setMacAddress(const MacAddress& addr) const = 0; + /** @brief Get WiFi AP network mask * @retval IpAddress WiFi AP network mask */ diff --git a/Sming/Platform/Station.h b/Sming/Platform/Station.h index 9a3138d94e..d81549c4f2 100644 --- a/Sming/Platform/Station.h +++ b/Sming/Platform/Station.h @@ -185,6 +185,20 @@ class StationClass */ String getMAC(char sep = '\0') const; + /** @brief Set WiFi station MAC address + * @param addr The new MAC address + * @retval bool true on success + * + * Must be called from `init()` before activating station. + * Espressif place certain limitations on MAC addresses: + * + * Bit 0 of the first byte of the MAC address can not be 1. For example: + * + * OK: "1a:XX:XX:XX:XX:XX" + * NOT OK: "15:XX:XX:XX:XX:XX" + */ + virtual bool setMacAddress(const MacAddress& addr) const = 0; + /** @brief Get WiFi station network mask * @retval IpAddress WiFi station network mask */