Skip to content

Commit

Permalink
[Tizen] Implement DiagnosticDataProvider interface (#26060)
Browse files Browse the repository at this point in the history
* [Tizen] Implement DiagnosticDataProvider interface

* Restyled by clang-format

* Apply some comments

* Allocate memory for the bssid to WiFiMgr

Signed-off-by: hyunuk.tak <[email protected]>

* Change to MutableByteSpan. But leave it as not implementation now.

* Restyled by clang-format

* Copy into the caller provided buffer

---------

Signed-off-by: hyunuk.tak <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
hyunuktak and restyled-commits authored Apr 21, 2023
1 parent 2eaf956 commit f3f7ecd
Show file tree
Hide file tree
Showing 15 changed files with 1,582 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/platform/Linux/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* for Linux platforms.
*/

#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <app-common/zap-generated/cluster-objects.h>
#include <ifaddrs.h>
#include <lib/core/CHIPVendorIdentifiers.hpp>
Expand Down
26 changes: 24 additions & 2 deletions src/platform/Tizen/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
#include <platform/CHIPDeviceBuildConfig.h>
#include <platform/CHIPDeviceConfig.h>
#include <platform/ConfigurationManager.h>
#include <platform/Tizen/PosixConfig.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#include "PosixConfig.h"
#include "WiFiManager.h"
#include "platform/internal/GenericConfigurationManagerImpl.ipp"

namespace chip {
namespace DeviceLayer {

using namespace ::chip::DeviceLayer::Internal;

ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
{
static ConfigurationManagerImpl sInstance;
Expand Down Expand Up @@ -175,6 +177,26 @@ void ConfigurationManagerImpl::RunConfigUnitTest()
Internal::PosixConfig::RunConfigUnitTest();
}

CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours)
{
return ReadConfigValue(PosixConfig::kCounterKey_TotalOperationalHours, totalOperationalHours);
}

CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
{
return WriteConfigValue(PosixConfig::kCounterKey_TotalOperationalHours, totalOperationalHours);
}

CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason)
{
return ReadConfigValue(PosixConfig::kCounterKey_BootReason, bootReason);
}

CHIP_ERROR ConfigurationManagerImpl::StoreBootReason(uint32_t bootReason)
{
return WriteConfigValue(PosixConfig::kCounterKey_BootReason, bootReason);
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Tizen/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR StoreVendorId(uint16_t vendorId);
CHIP_ERROR StoreProductId(uint16_t productId);

CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;

// This returns an instance of this class.
static ConfigurationManagerImpl & GetDefaultInstance();

Expand Down
82 changes: 82 additions & 0 deletions src/platform/Tizen/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <platform/CHIPDeviceConfig.h>
#include <platform/CHIPDeviceEvent.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/Tizen/ConnectivityUtils.h>

#include <system/SystemClock.h>
#include <system/SystemLayer.h>

Expand All @@ -55,15 +57,32 @@
#include "WiFiManager.h"
#endif

using namespace ::chip::DeviceLayer::Internal;
using namespace ::chip::app::Clusters::WiFiNetworkDiagnostics;

namespace chip {
namespace DeviceLayer {

ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
char ConnectivityManagerImpl::sWiFiIfName[];
#endif

CHIP_ERROR ConnectivityManagerImpl::_Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

if (ConnectivityUtils::GetEthInterfaceName(mEthIfName, IFNAMSIZ) == CHIP_NO_ERROR)
{
ChipLogProgress(DeviceLayer, "Got Ethernet interface: %s", mEthIfName);
}
else
{
ChipLogError(DeviceLayer, "Failed to get Ethernet interface");
mEthIfName[0] = '\0';
}

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
mWiFiStationMode = kWiFiStationMode_Disabled;
mWiFiAPMode = kWiFiAPMode_Disabled;
Expand All @@ -73,6 +92,16 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
mWiFiAPIdleTimeout = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT);

Internal::WiFiMgr().Init();

if (ConnectivityUtils::GetWiFiInterfaceName(sWiFiIfName, IFNAMSIZ) == CHIP_NO_ERROR)
{
ChipLogProgress(DeviceLayer, "Got WiFi interface: %s", sWiFiIfName);
}
else
{
ChipLogError(DeviceLayer, "Failed to get WiFi interface");
sWiFiIfName[0] = '\0';
}
#endif

return err;
Expand Down Expand Up @@ -224,6 +253,59 @@ bool ConnectivityManagerImpl::IsWiFiManagementStarted()
return isActivated;
}

CHIP_ERROR ConnectivityManagerImpl::GetWiFiBssId(MutableByteSpan & value)
{
constexpr size_t bssIdSize = 6;
VerifyOrReturnError(value.size() >= bssIdSize, CHIP_ERROR_BUFFER_TOO_SMALL);

uint8_t * bssId = nullptr;
CHIP_ERROR err = Internal::WiFiMgr().GetBssId(bssId);
ReturnErrorOnFailure(err);

memcpy(value.data(), bssId, bssIdSize);
value.reduce_size(bssIdSize);

return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::GetWiFiSecurityType(SecurityTypeEnum & securityType)
{
wifi_manager_security_type_e secType;
CHIP_ERROR err = Internal::WiFiMgr().GetSecurityType(&secType);
ReturnErrorOnFailure(err);

switch (secType)
{
case WIFI_MANAGER_SECURITY_TYPE_NONE:
securityType = SecurityTypeEnum::kNone;
break;
case WIFI_MANAGER_SECURITY_TYPE_WEP:
securityType = SecurityTypeEnum::kWep;
break;
case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
securityType = SecurityTypeEnum::kWpa;
break;
case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
securityType = SecurityTypeEnum::kWpa2;
break;
case WIFI_MANAGER_SECURITY_TYPE_EAP:
case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK:
case WIFI_MANAGER_SECURITY_TYPE_SAE:
case WIFI_MANAGER_SECURITY_TYPE_OWE:
case WIFI_MANAGER_SECURITY_TYPE_DPP:
default:
securityType = SecurityTypeEnum::kUnspecified;
break;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::GetWiFiVersion(WiFiVersionEnum & wiFiVersion)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

} // namespace DeviceLayer
Expand Down
9 changes: 9 additions & 0 deletions src/platform/Tizen/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
void StartWiFiManagement();
void StopWiFiManagement();
bool IsWiFiManagementStarted();
CHIP_ERROR GetWiFiBssId(MutableByteSpan & value);
CHIP_ERROR GetWiFiSecurityType(app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum & securityType);
CHIP_ERROR GetWiFiVersion(app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum & wiFiVersion);
const char * GetWiFiIfName() { return (sWiFiIfName[0] == '\0') ? nullptr : sWiFiIfName; }
#endif

const char * GetEthernetIfName() { return (mEthIfName[0] == '\0') ? nullptr : mEthIfName; }

private:
// ===== Members that implement the ConnectivityManager abstract interface.

Expand Down Expand Up @@ -127,13 +133,16 @@ class ConnectivityManagerImpl final : public ConnectivityManager,

// ===== Private members reserved for use by this class only.

char mEthIfName[IFNAMSIZ];

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
ConnectivityManager::WiFiStationMode mWiFiStationMode;
ConnectivityManager::WiFiAPMode mWiFiAPMode;
WiFiAPState mWiFiAPState;
System::Clock::Timestamp mLastAPDemandTime;
System::Clock::Timeout mWiFiStationReconnectInterval;
System::Clock::Timeout mWiFiAPIdleTimeout;
static char sWiFiIfName[IFNAMSIZ];
#endif
};

Expand Down
Loading

0 comments on commit f3f7ecd

Please sign in to comment.