Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renesas lwip EthernetDriver #9

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/platform/renesas/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static_library("renesas") {
"DiagnosticDataProviderImpl.h",
"KeyValueStoreManagerImpl.cpp",
"KeyValueStoreManagerImpl.h",
"NetworkCommissioningDriver.cpp",
"PlatformManagerImpl.cpp",
"PlatformManagerImpl.h",
"SystemPlatformConfig.h",
Expand Down
56 changes: 56 additions & 0 deletions src/platform/renesas/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @copyright Copyright 2024, (C) Sensorfy B.V.
*/

#include <platform/renesas/NetworkCommissioningDriver.h>
#include <lwip/netif.h>

namespace chip {
namespace DeviceLayer {
namespace NetworkCommissioning {


netif* FindEthernetItf()
{
for(auto itf = netif_list; itf; itf = itf->next) {
if (itf->flags & (NETIF_FLAG_ETHERNET | NETIF_FLAG_ETHARP)) {
return itf;
}
}
return nullptr;
}

bool RenesasEthernetDriver::EthernetNetworkIterator::Next(Network & item)
{
if (exhausted)
return false;

auto netif = FindEthernetItf();
if (!netif)
return false;

char buf[NETIF_NAMESIZE];
char * ifname = netif_index_to_name(netif_get_index(netif), buf);

item.networkIDLen = static_cast<uint8_t>(strlen(ifname));
memcpy(item.networkID, ifname, item.networkIDLen);
item.connected = netif_is_up(netif);

exhausted = true;
return true;
}

CHIP_ERROR RenesasEthernetDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
{
// TODO: this could call ethernet_interface_bringup() (netif_set_up) instead of thread_manager
// the callback should be remembered to signal Matter of changes
return CHIP_NO_ERROR;
}
void RenesasEthernetDriver::Shutdown()
{
// TODO: This could call ethernet_interface_bringdown (netif_remove) if Ethernet is used alongside Wifi/Thread.
}

} // namespace NetworkCommissioning
} // namespace DeviceLayer
} // namespace chip
48 changes: 48 additions & 0 deletions src/platform/renesas/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @copyright Copyright 2024, (C) Sensorfy B.V.
*/

#pragma once

#include <lib/support/BitFlags.h>
#include <platform/NetworkCommissioning.h>

namespace chip {
namespace DeviceLayer {
namespace NetworkCommissioning {

class RenesasEthernetDriver : public EthernetDriver
{
public:
class EthernetNetworkIterator final : public NetworkIterator
{
public:
EthernetNetworkIterator(RenesasEthernetDriver * aDriver) : mDriver(aDriver) {}
size_t Count() { return 1; }
bool Next(Network & item) override;
void Release() override { delete this; }
~EthernetNetworkIterator() = default;

private:
RenesasEthernetDriver * mDriver;
bool exhausted = false;
};

// BaseDriver
NetworkIterator * GetNetworks() override { return new EthernetNetworkIterator(this); }
uint8_t GetMaxNetworks() override { return 1; }
CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback) override;
void Shutdown() override;

static RenesasEthernetDriver & GetInstance()
{
static RenesasEthernetDriver instance;
return instance;
}
virtual ~RenesasEthernetDriver() = default;
};


} // namespace NetworkCommissioning
} // namespace DeviceLayer
} // namespace chip