-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen] Eth driver for network commissioning cluster (#21151)
* [Tizen] Eth driver for network commissioning cluster * Static asserts for WiFi ssid and credentials len
- Loading branch information
Showing
8 changed files
with
259 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <platform/Tizen/ConnectivityUtils.h> | ||
#include <platform/internal/CHIPDeviceLayerInternal.h> | ||
|
||
// XXX: This is a workaround for a bug in the Tizen SDK header files. It is not | ||
// possible to include both <net/if.h> and <linux/if.h> at the same time. | ||
// This will cause warning that struct ifmap is redefined. On Linux, this | ||
// is not a problem, because in <linux/if.h> the struct is guarded with | ||
// ifdef. To prevent this, we will define _LINUX_IF_H, so the <linux/if.h> | ||
// will not be included. | ||
#define _LINUX_IF_H | ||
|
||
#include <linux/ethtool.h> | ||
#include <linux/sockios.h> | ||
#include <linux/wireless.h> | ||
#include <string.h> | ||
#include <sys/ioctl.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
|
||
using namespace ::chip::app::Clusters::GeneralDiagnostics; | ||
|
||
namespace chip { | ||
namespace DeviceLayer { | ||
namespace Internal { | ||
|
||
InterfaceType ConnectivityUtils::GetInterfaceConnectionType(const char * ifname) | ||
{ | ||
InterfaceType ret = InterfaceType::EMBER_ZCL_INTERFACE_TYPE_UNSPECIFIED; | ||
int sock = -1; | ||
|
||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) | ||
{ | ||
ChipLogError(DeviceLayer, "Failed to open socket"); | ||
return ret; | ||
} | ||
|
||
// Test wireless extensions for CONNECTION_WIFI | ||
struct iwreq pwrq = {}; | ||
strncpy(pwrq.ifr_name, ifname, IFNAMSIZ - 1); | ||
|
||
if (ioctl(sock, SIOCGIWNAME, &pwrq) != -1) | ||
{ | ||
ret = InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI; | ||
} | ||
else if ((strncmp(ifname, "en", 2) == 0) || (strncmp(ifname, "eth", 3) == 0)) | ||
{ | ||
struct ethtool_cmd ecmd = {}; | ||
ecmd.cmd = ETHTOOL_GSET; | ||
struct ifreq ifr = {}; | ||
ifr.ifr_data = reinterpret_cast<char *>(&ecmd); | ||
strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1); | ||
|
||
if (ioctl(sock, SIOCETHTOOL, &ifr) != -1) | ||
ret = InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET; | ||
} | ||
|
||
close(sock); | ||
|
||
return ret; | ||
} | ||
|
||
} // namespace Internal | ||
} // namespace DeviceLayer | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <platform/DiagnosticDataProvider.h> | ||
#include <platform/internal/CHIPDeviceLayerInternal.h> | ||
|
||
namespace chip { | ||
namespace DeviceLayer { | ||
namespace Internal { | ||
|
||
class ConnectivityUtils | ||
{ | ||
public: | ||
static app::Clusters::GeneralDiagnostics::InterfaceType GetInterfaceConnectionType(const char * ifname); | ||
}; | ||
|
||
} // namespace Internal | ||
} // namespace DeviceLayer | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <lib/support/SafePointerCast.h> | ||
#include <platform/CHIPDeviceLayer.h> | ||
#include <platform/Tizen/ConnectivityUtils.h> | ||
#include <platform/Tizen/NetworkCommissioningDriver.h> | ||
|
||
#include <cerrno> | ||
#include <ifaddrs.h> | ||
#include <limits> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace chip::app::Clusters::GeneralDiagnostics; | ||
using namespace chip::DeviceLayer::Internal; | ||
|
||
namespace chip { | ||
namespace DeviceLayer { | ||
namespace NetworkCommissioning { | ||
|
||
TizenEthernetDriver::EthernetNetworkIterator::EthernetNetworkIterator(TizenEthernetDriver * aDriver) : mDriver(aDriver) | ||
{ | ||
struct ifaddrs * ifaddr = nullptr; | ||
VerifyOrReturn(getifaddrs(&ifaddr) == 0, ChipLogError(DeviceLayer, "Failed to get network interfaces: %s", strerror(errno))); | ||
|
||
for (const auto * ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) | ||
{ | ||
if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET) | ||
{ | ||
mInterfaces.push_back(ifa->ifa_name); | ||
if (mInterfaces.size() == mDriver->GetMaxNetworks()) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
freeifaddrs(ifaddr); | ||
} | ||
|
||
bool TizenEthernetDriver::EthernetNetworkIterator::Next(Network & item) | ||
{ | ||
VerifyOrReturnValue(mInterfacesIdx < mInterfaces.size(), false); | ||
|
||
const auto & iface = mInterfaces[mInterfacesIdx++]; | ||
item.networkIDLen = std::min(iface.size(), kMaxNetworkIDLen); | ||
memcpy(item.networkID, iface.c_str(), item.networkIDLen); | ||
item.connected = true; | ||
|
||
mInterfacesIdx++; | ||
return true; | ||
} | ||
|
||
} // namespace NetworkCommissioning | ||
} // namespace DeviceLayer | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters