Skip to content

Commit

Permalink
Address WoL issue 25793 (#25884)
Browse files Browse the repository at this point in the history
* Address WoL issue 25793

* User BytesToHex helper function

* Fix to work with CI test assumptions

* Restyled by gn (#25906)

Co-authored-by: Restyled.io <[email protected]>

* 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 <[email protected]>
  • Loading branch information
3 people authored Apr 1, 2023
1 parent 55ecc6e commit 275ff57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
7 changes: 0 additions & 7 deletions examples/tv-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ 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 = [
".",
"${chip_root}/zzz_generated/chip-tv-app",
"${chip_root}/src/lib",
]

defines = [ "CHIP_ENABLE_WAKE_ON_LAN=${chip_enable_wake_on_lan}" ]

cflags = [ "-Wconversion" ]
}

Expand Down
29 changes: 21 additions & 8 deletions examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,37 @@
#include "WakeOnLanManager.h"
#include <fstream>
#include <iostream>
#include <lib/support/BytesToHex.h>
#include <platform/ConfigurationManager.h>
#include <string>

using namespace chip;
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
}

0 comments on commit 275ff57

Please sign in to comment.