From ec5e6d82f10cab68c1669ea011d985a79958e941 Mon Sep 17 00:00:00 2001 From: chrisdecenzo Date: Wed, 29 Mar 2023 13:03:16 -0700 Subject: [PATCH 1/5] Address WoL issue 25793 --- examples/tv-app/linux/BUILD.gn | 7 ---- .../include/wake-on-lan/WakeOnLanManager.cpp | 33 ++++++++++++++----- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/examples/tv-app/linux/BUILD.gn b/examples/tv-app/linux/BUILD.gn index 945473c835c1b4..db3ea2f3cd5646 100644 --- a/examples/tv-app/linux/BUILD.gn +++ b/examples/tv-app/linux/BUILD.gn @@ -20,11 +20,6 @@ import("${chip_root}/build/chip/tools.gni") assert(chip_build_tools) -declare_args() { - # Enable Wake on LAN cluster - chip_enable_wake_on_lan = false -} - config("config") { include_dirs = [ ".", @@ -32,8 +27,6 @@ config("config") { "${chip_root}/src/lib", ] - defines = [ "CHIP_ENABLE_WAKE_ON_LAN=${chip_enable_wake_on_lan}" ] - cflags = [ "-Wconversion" ] } diff --git a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp index 1f50d300edfa16..8d4206ab355a27 100644 --- a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp +++ b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp @@ -19,6 +19,7 @@ #include "WakeOnLanManager.h" #include #include +#include #include using namespace chip; @@ -26,17 +27,33 @@ using namespace chip::app::Clusters::WakeOnLan; std::string getMacAddress() { - std::ifstream input("/sys/class/net/eth0/address"); - std::string line; - std::getline(input, line); - return line; + uint8_t macBuffer[chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength]; + MutableByteSpan mac(macBuffer); + if (chip::DeviceLayer::ConfigurationMgr().GetPrimaryMACAddress(mac) != CHIP_NO_ERROR) + { + ChipLogProgress(Zcl, "WakeOnLanManager::getMacAddress no primary MAC configured by DeviceLayer"); + return "0000000000"; + } + + char macStr[chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength * 2 + 1] = { 0 }; // added null char + + uint8_t j = 0; + for (uint8_t i = 0; i < sizeof(macBuffer); i++) + { + j = i * 2; + macStr[j] = (((macBuffer[i] & 0xF0) >> 4) & 0xF); + macStr[j] += (macStr[j] <= 9) ? '0' : ('A' - 10); + j++; + macStr[j] = (macBuffer[i] & 0x0F); + macStr[j] += (macStr[j] <= 9) ? '0' : ('A' - 10); + } + + return std::string(macStr); } CHIP_ERROR WakeOnLanManager::HandleGetMacAddress(chip::app::AttributeValueEncoder & aEncoder) { -#if CHIP_ENABLE_WAKE_ON_LAN + ChipLogProgress(Zcl, "WakeOnLanManager::HandleGetMacAddress"); + return aEncoder.Encode(CharSpan::fromCharString(getMacAddress().c_str())); -#else - return aEncoder.Encode(CharSpan::fromCharString("00:00:00:00:00")); -#endif // CHIP_ENABLE_WAKE_ON_LAN } From 4ebeb8d0a6662dbb35338ed1fe1c132fa482a5fd Mon Sep 17 00:00:00 2001 From: chrisdecenzo Date: Wed, 29 Mar 2023 15:55:51 -0700 Subject: [PATCH 2/5] User BytesToHex helper function --- .../linux/include/wake-on-lan/WakeOnLanManager.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp index 8d4206ab355a27..c851e0674d6697 100644 --- a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp +++ b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp @@ -19,6 +19,7 @@ #include "WakeOnLanManager.h" #include #include +#include #include #include @@ -36,16 +37,11 @@ std::string getMacAddress() } char macStr[chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength * 2 + 1] = { 0 }; // added null char - - uint8_t j = 0; - for (uint8_t i = 0; i < sizeof(macBuffer); i++) + if (BytesToHex(&macBuffer[0], sizeof(macBuffer), &macStr[0], sizeof(macBuffer) * 2u, chip::Encoding::HexFlags::kUppercase) != + CHIP_NO_ERROR) { - j = i * 2; - macStr[j] = (((macBuffer[i] & 0xF0) >> 4) & 0xF); - macStr[j] += (macStr[j] <= 9) ? '0' : ('A' - 10); - j++; - macStr[j] = (macBuffer[i] & 0x0F); - macStr[j] += (macStr[j] <= 9) ? '0' : ('A' - 10); + ChipLogProgress(Zcl, "WakeOnLanManager::getMacAddress hex conversion failed"); + return "0000000000"; } return std::string(macStr); From 0865708c76f6414e71249647f24b12827e4553e1 Mon Sep 17 00:00:00 2001 From: chrisdecenzo Date: Thu, 30 Mar 2023 12:04:32 -0700 Subject: [PATCH 3/5] Fix to work with CI test assumptions --- examples/tv-app/linux/BUILD.gn | 7 +++++++ .../tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/examples/tv-app/linux/BUILD.gn b/examples/tv-app/linux/BUILD.gn index db3ea2f3cd5646..ea2f8cb3b62074 100644 --- a/examples/tv-app/linux/BUILD.gn +++ b/examples/tv-app/linux/BUILD.gn @@ -20,6 +20,11 @@ import("${chip_root}/build/chip/tools.gni") assert(chip_build_tools) +declare_args() { + # Enable Wake on LAN cluster + chip_enable_wake_on_lan = false +} + config("config") { include_dirs = [ ".", @@ -27,6 +32,8 @@ config("config") { "${chip_root}/src/lib", ] + defines = [ "CHIP_ENABLE_WAKE_ON_LAN=${chip_enable_wake_on_lan}" ] + cflags = [ "-Wconversion" ] } diff --git a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp index c851e0674d6697..321c8396dacb0c 100644 --- a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp +++ b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp @@ -51,5 +51,9 @@ CHIP_ERROR WakeOnLanManager::HandleGetMacAddress(chip::app::AttributeValueEncode { ChipLogProgress(Zcl, "WakeOnLanManager::HandleGetMacAddress"); +#if CHIP_ENABLE_WAKE_ON_LAN return aEncoder.Encode(CharSpan::fromCharString(getMacAddress().c_str())); +#else + return aEncoder.Encode(CharSpan::fromCharString("00:00:00:00:00")); +#endif // CHIP_ENABLE_WAKE_ON_LAN } From 97468d6195c6ab9179aa0af024477d9d297e54f5 Mon Sep 17 00:00:00 2001 From: "restyled-io[bot]" <32688539+restyled-io[bot]@users.noreply.github.com> Date: Thu, 30 Mar 2023 15:37:28 -0700 Subject: [PATCH 4/5] Restyled by gn (#25906) Co-authored-by: Restyled.io --- examples/tv-app/linux/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/tv-app/linux/BUILD.gn b/examples/tv-app/linux/BUILD.gn index ea2f8cb3b62074..945473c835c1b4 100644 --- a/examples/tv-app/linux/BUILD.gn +++ b/examples/tv-app/linux/BUILD.gn @@ -21,10 +21,10 @@ import("${chip_root}/build/chip/tools.gni") assert(chip_build_tools) declare_args() { - # Enable Wake on LAN cluster - chip_enable_wake_on_lan = false + # Enable Wake on LAN cluster + chip_enable_wake_on_lan = false } - + config("config") { include_dirs = [ ".", From d67ddb12a70804ce444db97c9546951bd5b3fc64 Mon Sep 17 00:00:00 2001 From: chrisdecenzo Date: Fri, 31 Mar 2023 13:53:40 -0700 Subject: [PATCH 5/5] remove build-time-flag for WoL in tv-app --- examples/tv-app/linux/BUILD.gn | 7 ------- .../tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp | 4 ---- 2 files changed, 11 deletions(-) diff --git a/examples/tv-app/linux/BUILD.gn b/examples/tv-app/linux/BUILD.gn index ea2f8cb3b62074..db3ea2f3cd5646 100644 --- a/examples/tv-app/linux/BUILD.gn +++ b/examples/tv-app/linux/BUILD.gn @@ -20,11 +20,6 @@ import("${chip_root}/build/chip/tools.gni") assert(chip_build_tools) -declare_args() { - # Enable Wake on LAN cluster - chip_enable_wake_on_lan = false -} - config("config") { include_dirs = [ ".", @@ -32,8 +27,6 @@ config("config") { "${chip_root}/src/lib", ] - defines = [ "CHIP_ENABLE_WAKE_ON_LAN=${chip_enable_wake_on_lan}" ] - cflags = [ "-Wconversion" ] } diff --git a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp index 321c8396dacb0c..c851e0674d6697 100644 --- a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp +++ b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp @@ -51,9 +51,5 @@ CHIP_ERROR WakeOnLanManager::HandleGetMacAddress(chip::app::AttributeValueEncode { ChipLogProgress(Zcl, "WakeOnLanManager::HandleGetMacAddress"); -#if CHIP_ENABLE_WAKE_ON_LAN return aEncoder.Encode(CharSpan::fromCharString(getMacAddress().c_str())); -#else - return aEncoder.Encode(CharSpan::fromCharString("00:00:00:00:00")); -#endif // CHIP_ENABLE_WAKE_ON_LAN }