From 275ff57bf149d1cec603cb302db9e466d7b6a4b5 Mon Sep 17 00:00:00 2001 From: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> Date: Fri, 31 Mar 2023 22:02:51 -0700 Subject: [PATCH] Address WoL issue 25793 (#25884) * Address WoL issue 25793 * User BytesToHex helper function * Fix to work with CI test assumptions * Restyled by gn (#25906) Co-authored-by: Restyled.io * remove build-time-flag for WoL in tv-app --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io --- examples/tv-app/linux/BUILD.gn | 7 ----- .../include/wake-on-lan/WakeOnLanManager.cpp | 29 ++++++++++++++----- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/examples/tv-app/linux/BUILD.gn b/examples/tv-app/linux/BUILD.gn index 6485f72d9b05dd..35f4af6c4542d7 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..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,8 @@ #include "WakeOnLanManager.h" #include #include +#include +#include #include using namespace chip; @@ -26,17 +28,28 @@ 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 + if (BytesToHex(&macBuffer[0], sizeof(macBuffer), &macStr[0], sizeof(macBuffer) * 2u, chip::Encoding::HexFlags::kUppercase) != + CHIP_NO_ERROR) + { + ChipLogProgress(Zcl, "WakeOnLanManager::getMacAddress hex conversion failed"); + return "0000000000"; + } + + 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 }