Skip to content

Commit

Permalink
Add setMacAddress() method to Station and AccessPoint (#2249)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 authored Mar 8, 2021
1 parent d62642f commit 06320cc
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sming/Arch/Esp32/Platform/AccessPointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MacAddress&>(addr)[0]);
}

String AccessPointImpl::getSSID() const
{
wifi_config_t config{};
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Esp32/Platform/AccessPointImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Sming/Arch/Esp32/Platform/StationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MacAddress&>(addr)[0]);
}

IpAddress StationImpl::getNetworkBroadcast() const
{
esp_netif_ip_info_t info;
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Esp32/Platform/StationImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Sming/Arch/Esp8266/Platform/AccessPointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ MacAddress AccessPointImpl::getMacAddress() const
}
}

bool AccessPointImpl::setMacAddress(const MacAddress& addr) const
{
return wifi_set_macaddr(SOFTAP_IF, &const_cast<MacAddress&>(addr)[0]);
}

String AccessPointImpl::getSSID() const
{
softap_config config = {0};
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Esp8266/Platform/AccessPointImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Sming/Arch/Esp8266/Platform/StationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ MacAddress StationImpl::getMacAddress() const
}
}

bool StationImpl::setMacAddress(const MacAddress& addr) const
{
return wifi_set_macaddr(STATION_IF, &const_cast<MacAddress&>(addr)[0]);
}

IpAddress StationImpl::getNetworkBroadcast() const
{
struct ip_info info = {0};
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Esp8266/Platform/StationImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Sming/Arch/Host/Platform/AccessPointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Host/Platform/AccessPointImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Sming/Arch/Host/Platform/StationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Host/Platform/StationImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions Sming/Platform/AccessPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
14 changes: 14 additions & 0 deletions Sming/Platform/Station.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 06320cc

Please sign in to comment.