diff --git a/src/app/clusters/ethernet_network_diagnostics_server/ethernet_network_diagnostics_server.cpp b/src/app/clusters/ethernet_network_diagnostics_server/ethernet_network_diagnostics_server.cpp index ee14423d255080..d22005ba58cbe6 100644 --- a/src/app/clusters/ethernet_network_diagnostics_server/ethernet_network_diagnostics_server.cpp +++ b/src/app/clusters/ethernet_network_diagnostics_server/ethernet_network_diagnostics_server.cpp @@ -25,14 +25,14 @@ #include #include #include -#include +#include using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::EthernetNetworkDiagnostics; using namespace chip::app::Clusters::EthernetNetworkDiagnostics::Attributes; -using chip::DeviceLayer::ConnectivityManager; +using chip::DeviceLayer::DiagnosticDataProvider; namespace { @@ -46,15 +46,15 @@ class EthernetDiagosticsAttrAccess : public AttributeAccessInterface private: template - CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &), AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder); }; template -CHIP_ERROR EthernetDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &), +CHIP_ERROR EthernetDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder) { T data; - CHIP_ERROR err = (DeviceLayer::ConnectivityMgr().*getter)(data); + CHIP_ERROR err = (DeviceLayer::GetDiagnosticDataProvider().*getter)(data); if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) { data = 0; @@ -80,31 +80,31 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & switch (aPath.mAttributeId) { case PHYRate::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthPHYRate, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthPHYRate, aEncoder); } case FullDuplex::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthFullDuplex, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthFullDuplex, aEncoder); } case CarrierDetect::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthCarrierDetect, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthCarrierDetect, aEncoder); } case TimeSinceReset::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthTimeSinceReset, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthTimeSinceReset, aEncoder); } case PacketRxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthPacketRxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthPacketRxCount, aEncoder); } case PacketTxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthPacketTxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthPacketTxCount, aEncoder); } case TxErrCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthTxErrCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthTxErrCount, aEncoder); } case CollisionCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthCollisionCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthCollisionCount, aEncoder); } case OverrunCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetEthOverrunCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetEthOverrunCount, aEncoder); } default: { break; @@ -121,7 +121,7 @@ bool emberAfEthernetNetworkDiagnosticsClusterResetCountsCallback(app::CommandHan EndpointId endpoint = commandPath.mEndpointId; EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - VerifyOrExit(DeviceLayer::ConnectivityMgr().ResetEthNetworkDiagnosticsCounts() == CHIP_NO_ERROR, + VerifyOrExit(DeviceLayer::GetDiagnosticDataProvider().ResetEthNetworkDiagnosticsCounts() == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE); status = EthernetNetworkDiagnostics::Attributes::PacketRxCount::Set(endpoint, 0); diff --git a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp index daa3b6b90b98eb..75aef817892d89 100644 --- a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp +++ b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp @@ -103,7 +103,7 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEnco CHIP_ERROR err = CHIP_NO_ERROR; DeviceLayer::NetworkInterface * netifs; - if (ConnectivityMgr().GetNetworkInterfaces(&netifs) == CHIP_NO_ERROR) + if (DeviceLayer::GetDiagnosticDataProvider().GetNetworkInterfaces(&netifs) == CHIP_NO_ERROR) { err = aEncoder.EncodeList([&netifs](const TagBoundEncoder & encoder) -> CHIP_ERROR { for (DeviceLayer::NetworkInterface * ifp = netifs; ifp != nullptr; ifp = ifp->Next) @@ -114,7 +114,7 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEnco return CHIP_NO_ERROR; }); - ConnectivityMgr().ReleaseNetworkInterfaces(netifs); + DeviceLayer::GetDiagnosticDataProvider().ReleaseNetworkInterfaces(netifs); } else { diff --git a/src/app/clusters/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp b/src/app/clusters/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp index b83768c332c05d..0e0bbc1f88025a 100644 --- a/src/app/clusters/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp +++ b/src/app/clusters/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp @@ -25,15 +25,14 @@ #include #include #include -#include +#include using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::WiFiNetworkDiagnostics; using namespace chip::app::Clusters::WiFiNetworkDiagnostics::Attributes; -using chip::DeviceLayer::ConnectivityManager; -using chip::DeviceLayer::ConnectivityMgr; +using chip::DeviceLayer::DiagnosticDataProvider; namespace { @@ -47,17 +46,17 @@ class WiFiDiagosticsAttrAccess : public AttributeAccessInterface private: template - CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &), AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder); CHIP_ERROR ReadWiFiBssId(AttributeValueEncoder & aEncoder); }; template -CHIP_ERROR WiFiDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &), +CHIP_ERROR WiFiDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder) { T data; - CHIP_ERROR err = (DeviceLayer::ConnectivityMgr().*getter)(data); + CHIP_ERROR err = (DeviceLayer::GetDiagnosticDataProvider().*getter)(data); if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) { data = 0; @@ -75,7 +74,7 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::ReadWiFiBssId(AttributeValueEncoder & aEnco // TODO: Use Nullable after we get darwin converted over to the new APIs. Bssid::TypeInfo::Type bssid; - if (ConnectivityMgr().GetWiFiBssId(bssid) == CHIP_NO_ERROR) + if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiBssId(bssid) == CHIP_NO_ERROR) { ChipLogProgress(Zcl, "Node is currently connected to Wi-Fi network with BSSID:"); ChipLogByteSpan(Zcl, bssid); @@ -104,40 +103,40 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPat return ReadWiFiBssId(aEncoder); } case Attributes::SecurityType::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiSecurityType, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiSecurityType, aEncoder); } case WiFiVersion::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiVersion, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiVersion, aEncoder); } case ChannelNumber::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiChannelNumber, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiChannelNumber, aEncoder); } case Rssi::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiRssi, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiRssi, aEncoder); } case BeaconLostCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiBeaconLostCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiBeaconLostCount, aEncoder); } case BeaconRxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiBeaconRxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiBeaconRxCount, aEncoder); } case PacketMulticastRxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiPacketMulticastRxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketMulticastRxCount, aEncoder); } case PacketMulticastTxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiPacketMulticastTxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketMulticastTxCount, aEncoder); } case PacketUnicastRxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiPacketUnicastRxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketUnicastRxCount, aEncoder); } case PacketUnicastTxCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiPacketUnicastTxCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketUnicastTxCount, aEncoder); } case CurrentMaxRate::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiCurrentMaxRate, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiCurrentMaxRate, aEncoder); } case OverrunCount::Id: { - return ReadIfSupported(&ConnectivityManager::GetWiFiOverrunCount, aEncoder); + return ReadIfSupported(&DiagnosticDataProvider::GetWiFiOverrunCount, aEncoder); } default: { break; @@ -154,7 +153,7 @@ bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler EndpointId endpoint = commandPath.mEndpointId; EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - VerifyOrExit(DeviceLayer::ConnectivityMgr().ResetWiFiNetworkDiagnosticsCounts() == CHIP_NO_ERROR, + VerifyOrExit(DeviceLayer::GetDiagnosticDataProvider().ResetWiFiNetworkDiagnosticsCounts() == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE); status = WiFiNetworkDiagnostics::Attributes::BeaconLostCount::Set(endpoint, 0); diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index 1a999ed72054f8..26056f71dc1589 100644 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -51,16 +51,6 @@ template class GenericPlatformManagerImpl_POSIX; } // namespace Internal -// 48-bit IEEE MAC Address or a 64-bit IEEE MAC Address (e.g. EUI-64). -constexpr size_t kMaxHardwareAddrSize = 8; - -struct NetworkInterface : public app::Clusters::GeneralDiagnostics::Structs::NetworkInterfaceType::Type -{ - char Name[Inet::InterfaceId::kMaxIfNameLength]; - uint8_t MacAddress[kMaxHardwareAddrSize]; - NetworkInterface * Next; /* Pointer to the next structure. */ -}; - class ConnectivityManager; class ConnectivityManagerImpl; @@ -203,16 +193,6 @@ class ConnectivityManager void ResetThreadNetworkDiagnosticsCounts(); CHIP_ERROR WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder); - // General diagnostics methods - - /* - * Get the linked list of network interfaces of the current plaform. After usage, each caller of GetNetworkInterfaces - * needs to release the network interface list it gets via ReleaseNetworkInterfaces. - * - */ - CHIP_ERROR GetNetworkInterfaces(NetworkInterface ** netifpp); - void ReleaseNetworkInterfaces(NetworkInterface * netifp); - // Sleepy end device methods #if CHIP_DEVICE_CONFIG_ENABLE_SED CHIP_ERROR GetSEDPollingConfig(SEDPollingConfig & pollingConfig); @@ -235,34 +215,6 @@ class ConnectivityManager CHIP_ERROR RequestSEDFastPollingMode(bool onOff); #endif - // Ethernet network diagnostics methods - CHIP_ERROR GetEthPHYRate(uint8_t & pHYRate); - CHIP_ERROR GetEthFullDuplex(bool & fullDuplex); - CHIP_ERROR GetEthCarrierDetect(bool & carrierDetect); - CHIP_ERROR GetEthTimeSinceReset(uint64_t & timeSinceReset); - CHIP_ERROR GetEthPacketRxCount(uint64_t & packetRxCount); - CHIP_ERROR GetEthPacketTxCount(uint64_t & packetTxCount); - CHIP_ERROR GetEthTxErrCount(uint64_t & txErrCount); - CHIP_ERROR GetEthCollisionCount(uint64_t & collisionCount); - CHIP_ERROR GetEthOverrunCount(uint64_t & overrunCount); - CHIP_ERROR ResetEthNetworkDiagnosticsCounts(); - - // WiFi network diagnostics methods - CHIP_ERROR GetWiFiBssId(ByteSpan & value); - CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType); - CHIP_ERROR GetWiFiVersion(uint8_t & wiFiVersion); - CHIP_ERROR GetWiFiChannelNumber(uint16_t & channelNumber); - CHIP_ERROR GetWiFiRssi(int8_t & rssi); - CHIP_ERROR GetWiFiBeaconLostCount(uint32_t & beaconLostCount); - CHIP_ERROR GetWiFiBeaconRxCount(uint32_t & beaconRxCount); - CHIP_ERROR GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); - CHIP_ERROR GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); - CHIP_ERROR GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); - CHIP_ERROR GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); - CHIP_ERROR GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); - CHIP_ERROR GetWiFiOverrunCount(uint64_t & overrunCount); - CHIP_ERROR ResetWiFiNetworkDiagnosticsCounts(); - // CHIPoBLE service methods Ble::BleLayer * GetBleLayer(); CHIPoBLEServiceMode GetCHIPoBLEServiceMode(); @@ -461,136 +413,6 @@ inline CHIP_ERROR ConnectivityManager::GetAndLogWifiStatsCounters() return static_cast(this)->_GetAndLogWifiStatsCounters(); } -inline CHIP_ERROR ConnectivityManager::GetNetworkInterfaces(NetworkInterface ** netifpp) -{ - return static_cast(this)->_GetNetworkInterfaces(netifpp); -} - -inline void ConnectivityManager::ReleaseNetworkInterfaces(NetworkInterface * netifp) -{ - return static_cast(this)->_ReleaseNetworkInterfaces(netifp); -} - -inline CHIP_ERROR ConnectivityManager::GetEthPHYRate(uint8_t & pHYRate) -{ - return static_cast(this)->_GetEthPHYRate(pHYRate); -} - -inline CHIP_ERROR ConnectivityManager::GetEthFullDuplex(bool & fullDuplex) -{ - return static_cast(this)->_GetEthFullDuplex(fullDuplex); -} - -inline CHIP_ERROR ConnectivityManager::GetEthCarrierDetect(bool & carrierDetect) -{ - return static_cast(this)->_GetEthCarrierDetect(carrierDetect); -} - -inline CHIP_ERROR ConnectivityManager::GetEthTimeSinceReset(uint64_t & timeSinceReset) -{ - return static_cast(this)->_GetEthTimeSinceReset(timeSinceReset); -} - -inline CHIP_ERROR ConnectivityManager::GetEthPacketRxCount(uint64_t & packetRxCount) -{ - return static_cast(this)->_GetEthPacketRxCount(packetRxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetEthPacketTxCount(uint64_t & packetTxCount) -{ - return static_cast(this)->_GetEthPacketTxCount(packetTxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetEthTxErrCount(uint64_t & txErrCount) -{ - return static_cast(this)->_GetEthTxErrCount(txErrCount); -} - -inline CHIP_ERROR ConnectivityManager::GetEthCollisionCount(uint64_t & collisionCount) -{ - return static_cast(this)->_GetEthCollisionCount(collisionCount); -} - -inline CHIP_ERROR ConnectivityManager::GetEthOverrunCount(uint64_t & overrunCount) -{ - return static_cast(this)->_GetEthOverrunCount(overrunCount); -} - -inline CHIP_ERROR ConnectivityManager::ResetEthNetworkDiagnosticsCounts() -{ - return static_cast(this)->_ResetEthNetworkDiagnosticsCounts(); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiBssId(ByteSpan & value) -{ - return static_cast(this)->_GetWiFiBssId(value); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiSecurityType(uint8_t & securityType) -{ - return static_cast(this)->_GetWiFiSecurityType(securityType); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiVersion(uint8_t & wiFiVersion) -{ - return static_cast(this)->_GetWiFiVersion(wiFiVersion); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiChannelNumber(uint16_t & channelNumber) -{ - return static_cast(this)->_GetWiFiChannelNumber(channelNumber); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiRssi(int8_t & rssi) -{ - return static_cast(this)->_GetWiFiRssi(rssi); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiBeaconLostCount(uint32_t & beaconLostCount) -{ - return static_cast(this)->_GetWiFiBeaconLostCount(beaconLostCount); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiBeaconRxCount(uint32_t & beaconRxCount) -{ - return static_cast(this)->_GetWiFiBeaconRxCount(beaconRxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) -{ - return static_cast(this)->_GetWiFiPacketMulticastRxCount(packetMulticastRxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) -{ - return static_cast(this)->_GetWiFiPacketMulticastTxCount(packetMulticastTxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) -{ - return static_cast(this)->_GetWiFiPacketUnicastRxCount(packetUnicastRxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) -{ - return static_cast(this)->_GetWiFiPacketUnicastTxCount(packetUnicastTxCount); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) -{ - return static_cast(this)->_GetWiFiCurrentMaxRate(currentMaxRate); -} - -inline CHIP_ERROR ConnectivityManager::GetWiFiOverrunCount(uint64_t & overrunCount) -{ - return static_cast(this)->_GetWiFiOverrunCount(overrunCount); -} - -inline CHIP_ERROR ConnectivityManager::ResetWiFiNetworkDiagnosticsCounts() -{ - return static_cast(this)->_ResetWiFiNetworkDiagnosticsCounts(); -} - inline ConnectivityManager::ThreadMode ConnectivityManager::GetThreadMode() { return static_cast(this)->_GetThreadMode(); diff --git a/src/include/platform/DiagnosticDataProvider.h b/src/include/platform/DiagnosticDataProvider.h index e83f8f05f1088e..25a67bfc21dfa1 100644 --- a/src/include/platform/DiagnosticDataProvider.h +++ b/src/include/platform/DiagnosticDataProvider.h @@ -33,12 +33,22 @@ namespace DeviceLayer { // static for the duration of the thread. static constexpr size_t kMaxThreadNameLength = 32; +// 48-bit IEEE MAC Address or a 64-bit IEEE MAC Address (e.g. EUI-64). +constexpr size_t kMaxHardwareAddrSize = 8; + struct ThreadMetrics : public app::Clusters::SoftwareDiagnostics::Structs::ThreadMetrics::Type { char NameBuf[kMaxThreadNameLength + 1]; ThreadMetrics * Next; /* Pointer to the next structure. */ }; +struct NetworkInterface : public app::Clusters::GeneralDiagnostics::Structs::NetworkInterfaceType::Type +{ + char Name[Inet::InterfaceId::kMaxIfNameLength]; + uint8_t MacAddress[kMaxHardwareAddrSize]; + NetworkInterface * Next; /* Pointer to the next structure. */ +}; + /** * Defines the delegate class of Platform Manager to notify platform updates. */ @@ -92,6 +102,14 @@ class DiagnosticDataProvider virtual CHIP_ERROR GetActiveRadioFaults(GeneralFaults & radioFaults); virtual CHIP_ERROR GetActiveNetworkFaults(GeneralFaults & networkFaults); + /* + * Get the linked list of network interfaces of the current plaform. After usage, each caller of GetNetworkInterfaces + * needs to release the network interface list it gets via ReleaseNetworkInterfaces. + * + */ + virtual CHIP_ERROR GetNetworkInterfaces(NetworkInterface ** netifpp); + virtual void ReleaseNetworkInterfaces(NetworkInterface * netifp); + /** * Software Diagnostics methods. */ @@ -107,6 +125,38 @@ class DiagnosticDataProvider virtual CHIP_ERROR GetThreadMetrics(ThreadMetrics ** threadMetricsOut); virtual void ReleaseThreadMetrics(ThreadMetrics * threadMetrics); + /** + * Ethernet network diagnostics methods + */ + virtual CHIP_ERROR GetEthPHYRate(uint8_t & pHYRate); + virtual CHIP_ERROR GetEthFullDuplex(bool & fullDuplex); + virtual CHIP_ERROR GetEthCarrierDetect(bool & carrierDetect); + virtual CHIP_ERROR GetEthTimeSinceReset(uint64_t & timeSinceReset); + virtual CHIP_ERROR GetEthPacketRxCount(uint64_t & packetRxCount); + virtual CHIP_ERROR GetEthPacketTxCount(uint64_t & packetTxCount); + virtual CHIP_ERROR GetEthTxErrCount(uint64_t & txErrCount); + virtual CHIP_ERROR GetEthCollisionCount(uint64_t & collisionCount); + virtual CHIP_ERROR GetEthOverrunCount(uint64_t & overrunCount); + virtual CHIP_ERROR ResetEthNetworkDiagnosticsCounts(); + + /** + * WiFi network diagnostics methods + */ + virtual CHIP_ERROR GetWiFiBssId(ByteSpan & value); + virtual CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType); + virtual CHIP_ERROR GetWiFiVersion(uint8_t & wiFiVersion); + virtual CHIP_ERROR GetWiFiChannelNumber(uint16_t & channelNumber); + virtual CHIP_ERROR GetWiFiRssi(int8_t & rssi); + virtual CHIP_ERROR GetWiFiBeaconLostCount(uint32_t & beaconLostCount); + virtual CHIP_ERROR GetWiFiBeaconRxCount(uint32_t & beaconRxCount); + virtual CHIP_ERROR GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); + virtual CHIP_ERROR GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); + virtual CHIP_ERROR GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); + virtual CHIP_ERROR GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); + virtual CHIP_ERROR GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); + virtual CHIP_ERROR GetWiFiOverrunCount(uint64_t & overrunCount); + virtual CHIP_ERROR ResetWiFiNetworkDiagnosticsCounts(); + protected: // Construction/destruction limited to subclasses. DiagnosticDataProvider() = default; @@ -193,5 +243,132 @@ inline CHIP_ERROR DiagnosticDataProvider::GetActiveNetworkFaults(GeneralFaults(this); } }; @@ -84,76 +71,6 @@ template inline void GenericConnectivityManagerImpl::_SetUserSelectedModeTimeout(uint16_t val) {} -template -inline void GenericConnectivityManagerImpl::_ReleaseNetworkInterfaces(NetworkInterface * netifp) -{} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetNetworkInterfaces(NetworkInterface ** netifpp) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthPHYRate(uint8_t & pHYRate) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthFullDuplex(bool & fullDuplex) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthCarrierDetect(bool & carrierDetect) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthTimeSinceReset(uint64_t & timeSinceReset) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthPacketRxCount(uint64_t & packetRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthPacketTxCount(uint64_t & packetTxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthTxErrCount(uint64_t & txErrCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthCollisionCount(uint64_t & collisionCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_GetEthOverrunCount(uint64_t & overrunCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl::_ResetEthNetworkDiagnosticsCounts() -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h b/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h index 9bb5dca21a33a0..8d62822e69bf41 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h @@ -71,20 +71,6 @@ class GenericConnectivityManagerImpl_NoWiFi System::Clock::Timeout _GetWiFiAPIdleTimeout(void); void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); CHIP_ERROR _GetAndLogWifiStatsCounters(void); - CHIP_ERROR _GetWiFiBssId(ByteSpan & value); - CHIP_ERROR _GetWiFiSecurityType(uint8_t & securityType); - CHIP_ERROR _GetWiFiVersion(uint8_t & wiFiVersion); - CHIP_ERROR _GetWiFiChannelNumber(uint16_t & channelNumber); - CHIP_ERROR _GetWiFiRssi(int8_t & rssi); - CHIP_ERROR _GetWiFiBeaconLostCount(uint32_t & beaconLostCount); - CHIP_ERROR _GetWiFiBeaconRxCount(uint32_t & beaconRxCount); - CHIP_ERROR _GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); - CHIP_ERROR _GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); - CHIP_ERROR _GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); - CHIP_ERROR _GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); - CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); - CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount); - CHIP_ERROR _ResetWiFiNetworkDiagnosticsCounts(); bool _CanStartWiFiScan(); void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); @@ -235,92 +221,6 @@ inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiAPSta return NULL; } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiBssId(ByteSpan & value) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiSecurityType(uint8_t & securityType) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiVersion(uint8_t & wiFiVersion) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiChannelNumber(uint16_t & channelNumber) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiRssi(int8_t & rssi) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiBeaconLostCount(uint32_t & beaconLostCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiBeaconRxCount(uint32_t & beaconRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR -GenericConnectivityManagerImpl_NoWiFi::_GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR -GenericConnectivityManagerImpl_NoWiFi::_GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetWiFiOverrunCount(uint64_t & overrunCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_ResetWiFiNetworkDiagnosticsCounts() -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h b/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h index 74fb0de64259d6..cb352445a0c7bd 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h @@ -73,20 +73,6 @@ class GenericConnectivityManagerImpl_WiFi System::Clock::Timeout _GetWiFiAPIdleTimeout(); void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); CHIP_ERROR _GetAndLogWifiStatsCounters(); - CHIP_ERROR _GetWiFiBssId(ByteSpan & value); - CHIP_ERROR _GetWiFiSecurityType(uint8_t & securityType); - CHIP_ERROR _GetWiFiVersion(uint8_t & wiFiVersion); - CHIP_ERROR _GetWiFiChannelNumber(uint16_t & channelNumber); - CHIP_ERROR _GetWiFiRssi(int8_t & rssi); - CHIP_ERROR _GetWiFiBeaconLostCount(uint32_t & beaconLostCount); - CHIP_ERROR _GetWiFiBeaconRxCount(uint32_t & beaconRxCount); - CHIP_ERROR _GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); - CHIP_ERROR _GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); - CHIP_ERROR _GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); - CHIP_ERROR _GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); - CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); - CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount); - CHIP_ERROR _ResetWiFiNetworkDiagnosticsCounts(); bool _CanStartWiFiScan(); void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); @@ -195,90 +181,6 @@ template inline void GenericConnectivityManagerImpl_WiFi::_OnWiFiStationProvisionChange() {} -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiBssId(ByteSpan & value) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiSecurityType(uint8_t & securityType) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiVersion(uint8_t & wiFiVersion) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiChannelNumber(uint16_t & channelNumber) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiRssi(int8_t & rssi) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiBeaconLostCount(uint32_t & beaconLostCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiBeaconRxCount(uint32_t & beaconRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetWiFiOverrunCount(uint64_t & overrunCount) -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -template -inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_ResetWiFiNetworkDiagnosticsCounts() -{ - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Ameba/ConnectivityManagerImpl.cpp b/src/platform/Ameba/ConnectivityManagerImpl.cpp index 579122441349a3..4a96a893a0ad65 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -798,65 +798,6 @@ void ConnectivityManagerImpl::DHCPProcess(void) xTaskCreate(DHCPProcessThread, "DHCPProcess", 4096 / sizeof(StackType_t), this, 1, NULL); } -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) -{ - securityType = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumber) -{ - channelNumber = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiRssi(int8_t & rssi) -{ - rssi = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiBeaconLostCount(uint32_t & beaconLostCount) -{ - beaconLostCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) -{ - currentMaxRate = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) -{ - packetMulticastRxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) -{ - packetMulticastTxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) -{ - packetUnicastRxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) -{ - packetUnicastTxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiOverrunCount(uint64_t & overrunCount) -{ - overrunCount = 0; - return CHIP_NO_ERROR; -} #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI } // namespace DeviceLayer diff --git a/src/platform/Ameba/ConnectivityManagerImpl.h b/src/platform/Ameba/ConnectivityManagerImpl.h index 253c4744797d9d..e4ed47d430cdd4 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.h +++ b/src/platform/Ameba/ConnectivityManagerImpl.h @@ -106,17 +106,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); - CHIP_ERROR _GetWiFiSecurityType(uint8_t & securityType); - CHIP_ERROR _GetWiFiChannelNumber(uint16_t & channelNumber); - CHIP_ERROR _GetWiFiRssi(int8_t & rssi); - CHIP_ERROR _GetWiFiBeaconLostCount(uint32_t & beaconLostCount); - CHIP_ERROR _GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); - CHIP_ERROR _GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); - CHIP_ERROR _GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); - CHIP_ERROR _GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); - CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); - CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount); - // ===== Private members reserved for use by this class only. System::Clock::Timestamp mLastStationConnectFailTime; diff --git a/src/platform/Ameba/DiagnosticDataProviderImpl.cpp b/src/platform/Ameba/DiagnosticDataProviderImpl.cpp index 7b983efc097a49..e447b56d7ca175 100644 --- a/src/platform/Ameba/DiagnosticDataProviderImpl.cpp +++ b/src/platform/Ameba/DiagnosticDataProviderImpl.cpp @@ -116,5 +116,67 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(uint8_t & bootReason) return err; } +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(uint8_t & securityType) +{ + securityType = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber) +{ + channelNumber = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) +{ + rssi = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconLostCount) +{ + beaconLostCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) +{ + currentMaxRate = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) +{ + packetMulticastRxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) +{ + packetMulticastTxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) +{ + packetUnicastRxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) +{ + packetUnicastTxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiOverrunCount(uint64_t & overrunCount) +{ + overrunCount = 0; + return CHIP_NO_ERROR; +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Ameba/DiagnosticDataProviderImpl.h b/src/platform/Ameba/DiagnosticDataProviderImpl.h index d96dbbb826538a..047d55bdac9b3f 100644 --- a/src/platform/Ameba/DiagnosticDataProviderImpl.h +++ b/src/platform/Ameba/DiagnosticDataProviderImpl.h @@ -45,6 +45,19 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider CHIP_ERROR GetUpTime(uint64_t & upTime) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; CHIP_ERROR GetBootReason(uint8_t & bootReason) override; + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType) override; + CHIP_ERROR GetWiFiChannelNumber(uint16_t & channelNumber) override; + CHIP_ERROR GetWiFiRssi(int8_t & rssi) override; + CHIP_ERROR GetWiFiBeaconLostCount(uint32_t & beaconLostCount) override; + CHIP_ERROR GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) override; + CHIP_ERROR GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) override; + CHIP_ERROR GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) override; + CHIP_ERROR GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) override; + CHIP_ERROR GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) override; + CHIP_ERROR GetWiFiOverrunCount(uint64_t & overrunCount) override; +#endif }; } // namespace DeviceLayer diff --git a/src/platform/ESP32/ConnectivityManagerImpl.cpp b/src/platform/ESP32/ConnectivityManagerImpl.cpp index 6c8e8ee3aeacc5..db167c9ec7e7ca 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl.cpp @@ -71,62 +71,5 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) #endif } -static InterfaceType GetInterfaceType(const char * if_desc) -{ - if (strncmp(if_desc, "ap", strnlen(if_desc, 2)) == 0 || strncmp(if_desc, "sta", strnlen(if_desc, 3)) == 0) - return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI; - if (strncmp(if_desc, "openthread", strnlen(if_desc, 10)) == 0) - return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_THREAD; - if (strncmp(if_desc, "eth", strnlen(if_desc, 3)) == 0) - return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET; - return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_UNSPECIFIED; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetNetworkInterfaces(NetworkInterface ** netifpp) -{ - esp_netif_t * netif = esp_netif_next(NULL); - NetworkInterface * head = NULL; - if (netif == NULL) - { - ChipLogError(DeviceLayer, "Failed to get network interfaces"); - } - else - { - for (esp_netif_t * ifa = netif; ifa != NULL; ifa = esp_netif_next(ifa)) - { - NetworkInterface * ifp = new NetworkInterface(); - strncpy(ifp->Name, esp_netif_get_ifkey(ifa), Inet::InterfaceId::kMaxIfNameLength); - ifp->Name[Inet::InterfaceId::kMaxIfNameLength - 1] = '\0'; - ifp->name = CharSpan(ifp->Name, strlen(ifp->Name)); - ifp->fabricConnected = true; - ifp->type = GetInterfaceType(esp_netif_get_desc(ifa)); - ifp->offPremiseServicesReachableIPv4 = false; - ifp->offPremiseServicesReachableIPv6 = false; - if (esp_netif_get_mac(ifa, ifp->MacAddress) != ESP_OK) - { - ChipLogError(DeviceLayer, "Failed to get network hardware address"); - } - else - { - ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6); - } - ifp->Next = head; - head = ifp; - } - } - *netifpp = head; - return CHIP_NO_ERROR; -} - -void ConnectivityManagerImpl::_ReleaseNetworkInterfaces(NetworkInterface * netifp) -{ - while (netifp) - { - NetworkInterface * del = netifp; - netifp = netifp->Next; - delete del; - } -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/ESP32/ConnectivityManagerImpl.h b/src/platform/ESP32/ConnectivityManagerImpl.h index ed31629427dc67..96163cc9ca3dd2 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl.h +++ b/src/platform/ESP32/ConnectivityManagerImpl.h @@ -86,8 +86,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, CHIP_ERROR _Init(void); void _OnPlatformEvent(const ChipDeviceEvent * event); - CHIP_ERROR _GetNetworkInterfaces(NetworkInterface ** netifpp); - void _ReleaseNetworkInterfaces(NetworkInterface * netifp); #if CHIP_DEVICE_CONFIG_ENABLE_WIFI using Flags = GenericConnectivityManagerImpl_WiFi::ConnectivityFlags; // ===== Members that implement the ConnectivityManager abstract interface. @@ -115,20 +113,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); - CHIP_ERROR _GetWiFiBssId(ByteSpan & BssId); - CHIP_ERROR _GetWiFiSecurityType(uint8_t & securityType); - CHIP_ERROR _GetWiFiVersion(uint8_t & wifiVersion); - CHIP_ERROR _GetWiFiChannelNumber(uint16_t & channelNumber); - CHIP_ERROR _GetWiFiRssi(int8_t & rssi); - CHIP_ERROR _GetWiFiBeaconLostCount(uint32_t & beaconLostCount); - CHIP_ERROR _GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); - CHIP_ERROR _GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); - CHIP_ERROR _GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); - CHIP_ERROR _GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); - CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); - CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount); - CHIP_ERROR _ResetWiFiNetworkDiagnosticsCounts(); - // ===== Private members reserved for use by this class only. System::Clock::Timestamp mLastStationConnectFailTime; @@ -139,7 +123,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, WiFiAPState mWiFiAPState; System::Clock::Timeout mWiFiStationReconnectInterval; System::Clock::Timeout mWiFiAPIdleTimeout; - uint8_t mWiFiMacAddress[kMaxHardwareAddrSize]; BitFlags mFlags; CHIP_ERROR InitWiFi(void); diff --git a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp index 6e976369a2289a..aa484a1b33ea80 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp @@ -994,154 +994,6 @@ void ConnectivityManagerImpl::OnIPv6AddressAvailable(const ip_event_got_ip6_t & PlatformMgr().PostEventOrDie(&event); } -uint8_t MapAuthModeToSecurityType(wifi_auth_mode_t authmode) -{ - switch (authmode) - { - case WIFI_AUTH_OPEN: - return 1; - case WIFI_AUTH_WEP: - return 2; - case WIFI_AUTH_WPA_PSK: - return 3; - case WIFI_AUTH_WPA2_PSK: - return 4; - case WIFI_AUTH_WPA3_PSK: - return 5; - default: - return 0; - } -} - -uint8_t GetWiFiVersionFromAPRecord(wifi_ap_record_t ap_info) -{ - if (ap_info.phy_11n) - return 3; - else if (ap_info.phy_11g) - return 2; - else if (ap_info.phy_11b) - return 1; - else - return 0; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiBssId(ByteSpan & BssId) -{ - wifi_ap_record_t ap_info; - esp_err_t err; - - err = esp_wifi_sta_get_ap_info(&ap_info); - if (err == ESP_OK) - { - memcpy(mWiFiMacAddress, ap_info.bssid, 6); - } - BssId = ByteSpan(mWiFiMacAddress, 6); - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) -{ - securityType = 0; - wifi_ap_record_t ap_info; - esp_err_t err; - - err = esp_wifi_sta_get_ap_info(&ap_info); - if (err == ESP_OK) - { - securityType = MapAuthModeToSecurityType(ap_info.authmode); - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiVersion(uint8_t & wifiVersion) -{ - wifiVersion = 0; - wifi_ap_record_t ap_info; - esp_err_t err; - err = esp_wifi_sta_get_ap_info(&ap_info); - if (err == ESP_OK) - { - wifiVersion = GetWiFiVersionFromAPRecord(ap_info); - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumber) -{ - channelNumber = 0; - wifi_ap_record_t ap_info; - esp_err_t err; - - err = esp_wifi_sta_get_ap_info(&ap_info); - if (err == ESP_OK) - { - channelNumber = ap_info.primary; - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiRssi(int8_t & rssi) -{ - rssi = 0; - wifi_ap_record_t ap_info; - esp_err_t err; - - err = esp_wifi_sta_get_ap_info(&ap_info); - - if (err == ESP_OK) - { - rssi = ap_info.rssi; - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiBeaconLostCount(uint32_t & beaconLostCount) -{ - beaconLostCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) -{ - currentMaxRate = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) -{ - packetMulticastRxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) -{ - packetMulticastTxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) -{ - packetUnicastRxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) -{ - packetUnicastTxCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiOverrunCount(uint64_t & overrunCount) -{ - overrunCount = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_ResetWiFiNetworkDiagnosticsCounts() -{ - return CHIP_NO_ERROR; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/ESP32/DiagnosticDataProviderImpl.cpp b/src/platform/ESP32/DiagnosticDataProviderImpl.cpp index dd64d9b606d817..f97e2a6459c005 100644 --- a/src/platform/ESP32/DiagnosticDataProviderImpl.cpp +++ b/src/platform/ESP32/DiagnosticDataProviderImpl.cpp @@ -37,6 +37,60 @@ #include "esp_system.h" #include "esp_wifi.h" +using namespace ::chip; +using namespace ::chip::TLV; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceLayer::Internal; +using namespace ::chip::app::Clusters::GeneralDiagnostics; + +namespace { + +InterfaceType GetInterfaceType(const char * if_desc) +{ + if (strncmp(if_desc, "ap", strnlen(if_desc, 2)) == 0 || strncmp(if_desc, "sta", strnlen(if_desc, 3)) == 0) + return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI; + if (strncmp(if_desc, "openthread", strnlen(if_desc, 10)) == 0) + return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_THREAD; + if (strncmp(if_desc, "eth", strnlen(if_desc, 3)) == 0) + return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET; + return InterfaceType::EMBER_ZCL_INTERFACE_TYPE_UNSPECIFIED; +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +uint8_t MapAuthModeToSecurityType(wifi_auth_mode_t authmode) +{ + switch (authmode) + { + case WIFI_AUTH_OPEN: + return 1; + case WIFI_AUTH_WEP: + return 2; + case WIFI_AUTH_WPA_PSK: + return 3; + case WIFI_AUTH_WPA2_PSK: + return 4; + case WIFI_AUTH_WPA3_PSK: + return 5; + default: + return 0; + } +} + +uint8_t GetWiFiVersionFromAPRecord(wifi_ap_record_t ap_info) +{ + if (ap_info.phy_11n) + return 3; + else if (ap_info.phy_11g) + return 2; + else if (ap_info.phy_11b) + return 1; + else + return 0; +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + +} // namespace + namespace chip { namespace DeviceLayer { @@ -140,5 +194,171 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(uint8_t & bootReason) return CHIP_NO_ERROR; } +CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) +{ + esp_netif_t * netif = esp_netif_next(NULL); + NetworkInterface * head = NULL; + if (netif == NULL) + { + ChipLogError(DeviceLayer, "Failed to get network interfaces"); + } + else + { + for (esp_netif_t * ifa = netif; ifa != NULL; ifa = esp_netif_next(ifa)) + { + NetworkInterface * ifp = new NetworkInterface(); + strncpy(ifp->Name, esp_netif_get_ifkey(ifa), Inet::InterfaceId::kMaxIfNameLength); + ifp->Name[Inet::InterfaceId::kMaxIfNameLength - 1] = '\0'; + ifp->name = CharSpan(ifp->Name, strlen(ifp->Name)); + ifp->fabricConnected = true; + ifp->type = GetInterfaceType(esp_netif_get_desc(ifa)); + ifp->offPremiseServicesReachableIPv4 = false; + ifp->offPremiseServicesReachableIPv6 = false; + if (esp_netif_get_mac(ifa, ifp->MacAddress) != ESP_OK) + { + ChipLogError(DeviceLayer, "Failed to get network hardware address"); + } + else + { + ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6); + } + ifp->Next = head; + head = ifp; + } + } + *netifpp = head; + return CHIP_NO_ERROR; +} + +void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * netifp) +{ + while (netifp) + { + NetworkInterface * del = netifp; + netifp = netifp->Next; + delete del; + } +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & BssId) +{ + wifi_ap_record_t ap_info; + esp_err_t err; + uint8_t macAddress[kMaxHardwareAddrSize]; + + err = esp_wifi_sta_get_ap_info(&ap_info); + if (err == ESP_OK) + { + memcpy(macAddress, ap_info.bssid, 6); + } + BssId = ByteSpan(macAddress, 6); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(uint8_t & securityType) +{ + securityType = 0; + wifi_ap_record_t ap_info; + esp_err_t err; + + err = esp_wifi_sta_get_ap_info(&ap_info); + if (err == ESP_OK) + { + securityType = MapAuthModeToSecurityType(ap_info.authmode); + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(uint8_t & wifiVersion) +{ + wifiVersion = 0; + wifi_ap_record_t ap_info; + esp_err_t err; + err = esp_wifi_sta_get_ap_info(&ap_info); + if (err == ESP_OK) + { + wifiVersion = GetWiFiVersionFromAPRecord(ap_info); + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber) +{ + channelNumber = 0; + wifi_ap_record_t ap_info; + esp_err_t err; + + err = esp_wifi_sta_get_ap_info(&ap_info); + if (err == ESP_OK) + { + channelNumber = ap_info.primary; + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) +{ + rssi = 0; + wifi_ap_record_t ap_info; + esp_err_t err; + + err = esp_wifi_sta_get_ap_info(&ap_info); + + if (err == ESP_OK) + { + rssi = ap_info.rssi; + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconLostCount) +{ + beaconLostCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) +{ + currentMaxRate = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) +{ + packetMulticastRxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) +{ + packetMulticastTxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) +{ + packetUnicastRxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) +{ + packetUnicastTxCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiOverrunCount(uint64_t & overrunCount) +{ + overrunCount = 0; + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts() +{ + return CHIP_NO_ERROR; +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/ESP32/DiagnosticDataProviderImpl.h b/src/platform/ESP32/DiagnosticDataProviderImpl.h index cd33af8885df15..158cf96eae8be7 100644 --- a/src/platform/ESP32/DiagnosticDataProviderImpl.h +++ b/src/platform/ESP32/DiagnosticDataProviderImpl.h @@ -47,6 +47,25 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider CHIP_ERROR GetUpTime(uint64_t & upTime) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; CHIP_ERROR GetBootReason(uint8_t & bootReason) override; + + CHIP_ERROR GetNetworkInterfaces(NetworkInterface ** netifpp) override; + void ReleaseNetworkInterfaces(NetworkInterface * netifp) override; + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + CHIP_ERROR GetWiFiBssId(ByteSpan & BssId) override; + CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType) override; + CHIP_ERROR GetWiFiVersion(uint8_t & wifiVersion) override; + CHIP_ERROR GetWiFiChannelNumber(uint16_t & channelNumber) override; + CHIP_ERROR GetWiFiRssi(int8_t & rssi) override; + CHIP_ERROR GetWiFiBeaconLostCount(uint32_t & beaconLostCount) override; + CHIP_ERROR GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) override; + CHIP_ERROR GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) override; + CHIP_ERROR GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) override; + CHIP_ERROR GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) override; + CHIP_ERROR GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) override; + CHIP_ERROR GetWiFiOverrunCount(uint64_t & overrunCount) override; + CHIP_ERROR ResetWiFiNetworkDiagnosticsCounts() override; +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI }; } // namespace DeviceLayer diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index 2268e4ce19872b..80cde727bf86dd 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -21,14 +21,13 @@ #include #include #include +#include #include #include #include #include -#include -#include #include #include #include @@ -59,161 +58,6 @@ using namespace ::chip::DeviceLayer; using namespace ::chip::DeviceLayer::Internal; using namespace ::chip::app::Clusters::GeneralDiagnostics; -namespace { - -enum class EthernetStatsCountType -{ - kEthPacketRxCount, - kEthPacketTxCount, - kEthTxErrCount, - kEthCollisionCount, - kEthOverrunCount -}; - -enum class WiFiStatsCountType -{ - kWiFiUnicastPacketRxCount, - kWiFiUnicastPacketTxCount, - kWiFiMulticastPacketRxCount, - kWiFiMulticastPacketTxCount, - kWiFiOverrunCount -}; - -CHIP_ERROR GetEthernetStatsCount(EthernetStatsCountType type, uint64_t & count) -{ - CHIP_ERROR err = CHIP_ERROR_READ_FAILED; - struct ifaddrs * ifaddr = nullptr; - - if (getifaddrs(&ifaddr) == -1) - { - ChipLogError(DeviceLayer, "Failed to get network interfaces"); - } - else - { - struct ifaddrs * ifa = nullptr; - - // Walk through linked list, maintaining head pointer so we can free list later. - for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) - { - if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET) - { - ChipLogProgress(DeviceLayer, "Found the primary Ethernet interface:%s", ifa->ifa_name); - break; - } - } - - if (ifa != nullptr) - { - if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) - { - struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; - switch (type) - { - case EthernetStatsCountType::kEthPacketRxCount: - count = stats->rx_packets; - err = CHIP_NO_ERROR; - break; - case EthernetStatsCountType::kEthPacketTxCount: - count = stats->tx_packets; - err = CHIP_NO_ERROR; - break; - case EthernetStatsCountType::kEthTxErrCount: - count = stats->tx_errors; - err = CHIP_NO_ERROR; - break; - case EthernetStatsCountType::kEthCollisionCount: - count = stats->collisions; - err = CHIP_NO_ERROR; - break; - case EthernetStatsCountType::kEthOverrunCount: - count = stats->rx_over_errors; - err = CHIP_NO_ERROR; - break; - default: - ChipLogError(DeviceLayer, "Unknown Ethernet statistic metric type"); - break; - } - } - } - - freeifaddrs(ifaddr); - } - - return err; -} - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI -CHIP_ERROR GetWiFiStatsCount(WiFiStatsCountType type, uint64_t & count) -{ - CHIP_ERROR err = CHIP_ERROR_READ_FAILED; - struct ifaddrs * ifaddr = nullptr; - - if (getifaddrs(&ifaddr) == -1) - { - ChipLogError(DeviceLayer, "Failed to get network interfaces"); - } - else - { - struct ifaddrs * ifa = nullptr; - - // Walk through linked list, maintaining head pointer so we can free list later. - for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) - { - if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI) - { - ChipLogProgress(DeviceLayer, "Found the primary WiFi interface:%s", ifa->ifa_name); - break; - } - } - - if (ifa != nullptr) - { - if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) - { - // The usecase of this function is embedded devices,on which we can interact with the WiFi - // driver to get the accurate number of muticast and unicast packets accurately. - // On Linux simulation, we can only get the total packets received, the total bytes transmitted, - // the multicast packets received and receiver ring buff overflow. - - struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; - switch (type) - { - case WiFiStatsCountType::kWiFiUnicastPacketRxCount: - count = stats->rx_packets; - err = CHIP_NO_ERROR; - break; - case WiFiStatsCountType::kWiFiUnicastPacketTxCount: - count = stats->tx_packets; - err = CHIP_NO_ERROR; - break; - case WiFiStatsCountType::kWiFiMulticastPacketRxCount: - count = stats->multicast; - err = CHIP_NO_ERROR; - break; - case WiFiStatsCountType::kWiFiMulticastPacketTxCount: - count = 0; - err = CHIP_NO_ERROR; - break; - case WiFiStatsCountType::kWiFiOverrunCount: - count = stats->rx_over_errors; - err = CHIP_NO_ERROR; - break; - default: - ChipLogError(DeviceLayer, "Unknown WiFi statistic metric type"); - break; - } - } - } - - freeifaddrs(ifaddr); - } - - return err; -} -#endif // #if CHIP_DEVICE_CONFIG_ENABLE_WIFI - -} // namespace - namespace chip { namespace DeviceLayer { @@ -240,7 +84,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() mEthIfName[0] = '\0'; } - if (ResetEthernetStatsCount() != CHIP_NO_ERROR) + if (GetDiagnosticDataProvider().ResetEthNetworkDiagnosticsCounts() != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "Failed to reset Ethernet statistic counts"); } @@ -261,7 +105,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() sWiFiIfName[0] = '\0'; } - if (ResetWiFiStatsCount() != CHIP_NO_ERROR) + if (GetDiagnosticDataProvider().ResetWiFiNetworkDiagnosticsCounts() != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "Failed to reset WiFi statistic counts"); } @@ -432,104 +276,6 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val) return err; } -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiBssId(ByteSpan & value) -{ - CHIP_ERROR err = CHIP_ERROR_READ_FAILED; - struct ifaddrs * ifaddr = nullptr; - - // On Linux simulation, we don't have the DBus API to get the BSSID of connected AP. Use mac address - // of local WiFi network card instead. - if (getifaddrs(&ifaddr) == -1) - { - ChipLogError(DeviceLayer, "Failed to get network interfaces"); - } - else - { - // Walk through linked list, maintaining head pointer so we can free list later. - for (struct ifaddrs * ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) - { - if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI) - { - if (ConnectivityUtils::GetInterfaceHardwareAddrs(ifa->ifa_name, mWiFiMacAddress, kMaxHardwareAddrSize) != - CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "Failed to get WiFi network hardware address"); - } - else - { - // Set 48-bit IEEE MAC Address - value = ByteSpan(mWiFiMacAddress, 6); - err = CHIP_NO_ERROR; - break; - } - } - } - - freeifaddrs(ifaddr); - } - - return err; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) -{ - const gchar * mode = nullptr; - - std::lock_guard lock(mWpaSupplicantMutex); - - if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED) - { - ChipLogError(DeviceLayer, "wpa_supplicant: _GetWiFiSecurityType: interface proxy not connected"); - return CHIP_ERROR_INCORRECT_STATE; - } - - mode = wpa_fi_w1_wpa_supplicant1_interface_get_current_auth_mode(mWpaSupplicant.iface); - ChipLogProgress(DeviceLayer, "wpa_supplicant: current Wi-Fi security type: %s", mode); - - if (strncmp(mode, "WPA-PSK", 7) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_WPA; - } - else if (strncmp(mode, "WPA2-PSK", 8) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_WPA2; - } - else if (strncmp(mode, "WPA2-EAP", 8) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_WPA2; - } - else if (strncmp(mode, "WPA3-PSK", 8) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_WPA3; - } - else if (strncmp(mode, "WEP", 3) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_WEP; - } - else if (strncmp(mode, "NONE", 4) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_NONE; - } - else if (strncmp(mode, "WPA-NONE", 8) == 0) - { - securityType = EMBER_ZCL_SECURITY_TYPE_NONE; - } - else - { - securityType = EMBER_ZCL_SECURITY_TYPE_UNSPECIFIED; - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiVersion(uint8_t & wiFiVersion) -{ - // We don't have driect API to get the WiFi version yet, retrun 802.11n on Linux simulation. - wiFiVersion = EMBER_ZCL_WI_FI_VERSION_TYPE_802__11N; - - return CHIP_NO_ERROR; -} - void ConnectivityManagerImpl::_DemandStartWiFiAP() { if (mWiFiAPMode == kWiFiAPMode_OnDemand || mWiFiAPMode == kWiFiAPMode_OnDemand_NoStationProvision) @@ -1177,378 +923,107 @@ CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, cons return ret; } -#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA - -void ConnectivityManagerImpl::_ReleaseNetworkInterfaces(NetworkInterface * netifp) -{ - while (netifp) - { - NetworkInterface * del = netifp; - netifp = netifp->Next; - delete del; - } -} -CHIP_ERROR ConnectivityManagerImpl::_GetNetworkInterfaces(NetworkInterface ** netifpp) +CHIP_ERROR ConnectivityManagerImpl::GetWiFiBssId(ByteSpan & value) { CHIP_ERROR err = CHIP_ERROR_READ_FAILED; struct ifaddrs * ifaddr = nullptr; + // On Linux simulation, we don't have the DBus API to get the BSSID of connected AP. Use mac address + // of local WiFi network card instead. if (getifaddrs(&ifaddr) == -1) { ChipLogError(DeviceLayer, "Failed to get network interfaces"); } else { - NetworkInterface * head = nullptr; + uint8_t macAddress[kMaxHardwareAddrSize]; // Walk through linked list, maintaining head pointer so we can free list later. for (struct ifaddrs * ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) + if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI) { - NetworkInterface * ifp = new NetworkInterface(); - - strncpy(ifp->Name, ifa->ifa_name, Inet::InterfaceId::kMaxIfNameLength); - ifp->Name[Inet::InterfaceId::kMaxIfNameLength - 1] = '\0'; - - ifp->name = CharSpan(ifp->Name, strlen(ifp->Name)); - ifp->fabricConnected = ifa->ifa_flags & IFF_RUNNING; - ifp->type = ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name); - ifp->offPremiseServicesReachableIPv4 = false; - ifp->offPremiseServicesReachableIPv6 = false; - - if (ConnectivityUtils::GetInterfaceHardwareAddrs(ifa->ifa_name, ifp->MacAddress, kMaxHardwareAddrSize) != - CHIP_NO_ERROR) + if (ConnectivityUtils::GetInterfaceHardwareAddrs(ifa->ifa_name, macAddress, kMaxHardwareAddrSize) != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "Failed to get network hardware address"); + ChipLogError(DeviceLayer, "Failed to get WiFi network hardware address"); } else { // Set 48-bit IEEE MAC Address - ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6); + value = ByteSpan(macAddress, 6); + err = CHIP_NO_ERROR; + break; } - - ifp->Next = head; - head = ifp; } } - *netifpp = head; - err = CHIP_NO_ERROR; - freeifaddrs(ifaddr); } return err; } -CHIP_ERROR ConnectivityManagerImpl::_GetEthPHYRate(uint8_t & pHYRate) +CHIP_ERROR ConnectivityManagerImpl::GetWiFiSecurityType(uint8_t & securityType) { - if (mEthIfName[0] == '\0') - { - return CHIP_ERROR_READ_FAILED; - } + const gchar * mode = nullptr; - return ConnectivityUtils::GetEthPHYRate(mEthIfName, pHYRate); -} + std::lock_guard lock(mWpaSupplicantMutex); -CHIP_ERROR ConnectivityManagerImpl::_GetEthFullDuplex(bool & fullDuplex) -{ - if (mEthIfName[0] == '\0') + if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED) { - return CHIP_ERROR_READ_FAILED; + ChipLogError(DeviceLayer, "wpa_supplicant: _GetWiFiSecurityType: interface proxy not connected"); + return CHIP_ERROR_INCORRECT_STATE; } - return ConnectivityUtils::GetEthFullDuplex(mEthIfName, fullDuplex); -} - -CHIP_ERROR ConnectivityManagerImpl::_GetEthTimeSinceReset(uint64_t & timeSinceReset) -{ - return GetDiagnosticDataProvider().GetUpTime(timeSinceReset); -} - -CHIP_ERROR ConnectivityManagerImpl::_GetEthPacketRxCount(uint64_t & packetRxCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthPacketRxCount, count)); - VerifyOrReturnError(count >= mEthPacketRxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - packetRxCount = count - mEthPacketRxCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetEthPacketTxCount(uint64_t & packetTxCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthPacketTxCount, count)); - VerifyOrReturnError(count >= mEthPacketTxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - packetTxCount = count - mEthPacketTxCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetEthTxErrCount(uint64_t & txErrCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthTxErrCount, count)); - VerifyOrReturnError(count >= mEthTxErrCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - txErrCount = count - mEthTxErrCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetEthCollisionCount(uint64_t & collisionCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthCollisionCount, count)); - VerifyOrReturnError(count >= mEthCollisionCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - collisionCount = count - mEthCollisionCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetEthOverrunCount(uint64_t & overrunCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthOverrunCount, count)); - VerifyOrReturnError(count >= mEthOverrunCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - overrunCount = count - mEthOverrunCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_ResetEthNetworkDiagnosticsCounts() -{ - return ResetEthernetStatsCount(); -} - -CHIP_ERROR ConnectivityManagerImpl::ResetEthernetStatsCount() -{ - CHIP_ERROR err = CHIP_ERROR_READ_FAILED; - struct ifaddrs * ifaddr = nullptr; + mode = wpa_fi_w1_wpa_supplicant1_interface_get_current_auth_mode(mWpaSupplicant.iface); + ChipLogProgress(DeviceLayer, "wpa_supplicant: current Wi-Fi security type: %s", mode); - if (getifaddrs(&ifaddr) == -1) + if (strncmp(mode, "WPA-PSK", 7) == 0) { - ChipLogError(DeviceLayer, "Failed to get network interfaces"); + securityType = EMBER_ZCL_SECURITY_TYPE_WPA; } - else + else if (strncmp(mode, "WPA2-PSK", 8) == 0) { - struct ifaddrs * ifa = nullptr; - - // Walk through linked list, maintaining head pointer so we can free list later. - for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) - { - if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET) - { - ChipLogProgress(DeviceLayer, "Found the primary Ethernet interface:%s", ifa->ifa_name); - break; - } - } - - if (ifa != nullptr) - { - if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) - { - struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; - - mEthPacketRxCount = stats->rx_packets; - mEthPacketTxCount = stats->tx_packets; - mEthTxErrCount = stats->tx_errors; - mEthCollisionCount = stats->collisions; - mEthOverrunCount = stats->rx_over_errors; - err = CHIP_NO_ERROR; - } - } - - freeifaddrs(ifaddr); + securityType = EMBER_ZCL_SECURITY_TYPE_WPA2; } - - return err; -} - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumber) -{ - if (sWiFiIfName[0] == '\0') + else if (strncmp(mode, "WPA2-EAP", 8) == 0) { - return CHIP_ERROR_READ_FAILED; + securityType = EMBER_ZCL_SECURITY_TYPE_WPA2; } - - return ConnectivityUtils::GetWiFiChannelNumber(sWiFiIfName, channelNumber); -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiRssi(int8_t & rssi) -{ - if (sWiFiIfName[0] == '\0') + else if (strncmp(mode, "WPA3-PSK", 8) == 0) { - return CHIP_ERROR_READ_FAILED; + securityType = EMBER_ZCL_SECURITY_TYPE_WPA3; } - - return ConnectivityUtils::GetWiFiRssi(sWiFiIfName, rssi); -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiBeaconLostCount(uint32_t & beaconLostCount) -{ - uint32_t count; - - if (sWiFiIfName[0] == '\0') + else if (strncmp(mode, "WEP", 3) == 0) { - return CHIP_ERROR_READ_FAILED; + securityType = EMBER_ZCL_SECURITY_TYPE_WEP; } - - ReturnErrorOnFailure(ConnectivityUtils::GetWiFiBeaconLostCount(sWiFiIfName, count)); - VerifyOrReturnError(count >= mBeaconLostCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - beaconLostCount = count - mBeaconLostCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) -{ - if (sWiFiIfName[0] == '\0') + else if (strncmp(mode, "NONE", 4) == 0) { - return CHIP_ERROR_READ_FAILED; + securityType = EMBER_ZCL_SECURITY_TYPE_NONE; } - - return ConnectivityUtils::GetWiFiCurrentMaxRate(sWiFiIfName, currentMaxRate); -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiMulticastPacketRxCount, count)); - VerifyOrReturnError(count >= mPacketMulticastRxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - count -= mPacketMulticastRxCount; - VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); - - packetMulticastRxCount = static_cast(count); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiMulticastPacketTxCount, count)); - VerifyOrReturnError(count >= mPacketMulticastTxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - count -= mPacketMulticastTxCount; - VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); - - packetMulticastTxCount = static_cast(count); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiUnicastPacketRxCount, count)); - VerifyOrReturnError(count >= mPacketUnicastRxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - count -= mPacketUnicastRxCount; - VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); - - packetUnicastRxCount = static_cast(count); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiUnicastPacketTxCount, count)); - VerifyOrReturnError(count >= mPacketUnicastTxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - count -= mPacketUnicastTxCount; - VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); - - packetUnicastTxCount = static_cast(count); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_GetWiFiOverrunCount(uint64_t & overrunCount) -{ - uint64_t count; - - ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiOverrunCount, count)); - VerifyOrReturnError(count >= mOverrunCount, CHIP_ERROR_INVALID_INTEGER_VALUE); - - overrunCount = count - mOverrunCount; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_ResetWiFiNetworkDiagnosticsCounts() -{ - return ResetWiFiStatsCount(); -} - -CHIP_ERROR ConnectivityManagerImpl::ResetWiFiStatsCount() -{ - CHIP_ERROR err = CHIP_ERROR_READ_FAILED; - struct ifaddrs * ifaddr = nullptr; - - ReturnErrorOnFailure(_GetWiFiBeaconLostCount(mBeaconLostCount)); - - if (getifaddrs(&ifaddr) == -1) + else if (strncmp(mode, "WPA-NONE", 8) == 0) { - ChipLogError(DeviceLayer, "Failed to get network interfaces"); + securityType = EMBER_ZCL_SECURITY_TYPE_NONE; } else { - struct ifaddrs * ifa = nullptr; - - // Walk through linked list, maintaining head pointer so we can free list later. - for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) - { - if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI) - { - ChipLogProgress(DeviceLayer, "Found the primary WiFi interface:%s", ifa->ifa_name); - break; - } - } - - if (ifa != nullptr) - { - if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) - { - struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; - - mPacketMulticastRxCount = stats->multicast; - mPacketMulticastTxCount = 0; - mPacketUnicastRxCount = stats->rx_packets; - mPacketUnicastTxCount = stats->tx_packets; - mOverrunCount = stats->rx_over_errors; + securityType = EMBER_ZCL_SECURITY_TYPE_UNSPECIFIED; + } - err = CHIP_NO_ERROR; - } - } + return CHIP_NO_ERROR; +} - freeifaddrs(ifaddr); - } +CHIP_ERROR ConnectivityManagerImpl::GetWiFiVersion(uint8_t & wiFiVersion) +{ + // We don't have driect API to get the WiFi version yet, retrun 802.11n on Linux simulation. + wiFiVersion = EMBER_ZCL_WI_FI_VERSION_TYPE_802__11N; - return err; + return CHIP_NO_ERROR; } -#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI +#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Linux/ConnectivityManagerImpl.h b/src/platform/Linux/ConnectivityManagerImpl.h index 2f26ece65ff5bd..cbaeb242c9a430 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.h +++ b/src/platform/Linux/ConnectivityManagerImpl.h @@ -110,10 +110,15 @@ class ConnectivityManagerImpl final : public ConnectivityManager, CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); void StartWiFiManagement(); bool IsWiFiManagementStarted(); + CHIP_ERROR GetWiFiBssId(ByteSpan & value); + CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType); + CHIP_ERROR GetWiFiVersion(uint8_t & wiFiVersion); #endif + const char * GetEthernetIfName() { return (mEthIfName[0] == '\0') ? nullptr : mEthIfName; } + #if CHIP_DEVICE_CONFIG_ENABLE_WIFI - static const char * GetWiFiIfName() { return sWiFiIfName; } + static const char * GetWiFiIfName() { return (sWiFiIfName[0] == '\0') ? nullptr : sWiFiIfName; } #endif private: @@ -136,9 +141,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, WiFiAPMode _GetWiFiAPMode(); CHIP_ERROR _SetWiFiAPMode(WiFiAPMode val); - CHIP_ERROR _GetWiFiBssId(ByteSpan & value); - CHIP_ERROR _GetWiFiSecurityType(uint8_t & securityType); - CHIP_ERROR _GetWiFiVersion(uint8_t & wiFiVersion); bool _IsWiFiAPActive(); bool _IsWiFiAPApplicationControlled(); void _DemandStartWiFiAP(); @@ -160,39 +162,8 @@ class ConnectivityManagerImpl final : public ConnectivityManager, static std::mutex mWpaSupplicantMutex; #endif - void _ReleaseNetworkInterfaces(NetworkInterface * netifp); - CHIP_ERROR _GetNetworkInterfaces(NetworkInterface ** netifpp); - CHIP_ERROR _GetEthPHYRate(uint8_t & pHYRate); - CHIP_ERROR _GetEthFullDuplex(bool & fullDuplex); - CHIP_ERROR _GetEthTimeSinceReset(uint64_t & timeSinceReset); - CHIP_ERROR _GetEthPacketRxCount(uint64_t & packetRxCount); - CHIP_ERROR _GetEthPacketTxCount(uint64_t & packetTxCount); - CHIP_ERROR _GetEthTxErrCount(uint64_t & txErrCount); - CHIP_ERROR _GetEthCollisionCount(uint64_t & collisionCount); - CHIP_ERROR _GetEthOverrunCount(uint64_t & overrunCount); - CHIP_ERROR _ResetEthNetworkDiagnosticsCounts(); - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI - CHIP_ERROR _GetWiFiChannelNumber(uint16_t & channelNumber); - CHIP_ERROR _GetWiFiRssi(int8_t & rssi); - CHIP_ERROR _GetWiFiBeaconLostCount(uint32_t & beaconLostCount); - CHIP_ERROR _GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount); - CHIP_ERROR _GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount); - CHIP_ERROR _GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount); - CHIP_ERROR _GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount); - CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate); - CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount); - CHIP_ERROR _ResetWiFiNetworkDiagnosticsCounts(); -#endif - // ==================== ConnectivityManager Private Methods ==================== - CHIP_ERROR ResetEthernetStatsCount(); - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI - CHIP_ERROR ResetWiFiStatsCount(); -#endif - #if CHIP_DEVICE_CONFIG_ENABLE_WPA void DriveAPState(); CHIP_ERROR ConfigureWiFiAP(); @@ -209,11 +180,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, // ===== Private members reserved for use by this class only. - uint64_t mEthPacketRxCount = 0; - uint64_t mEthPacketTxCount = 0; - uint64_t mEthTxErrCount = 0; - uint64_t mEthCollisionCount = 0; - uint64_t mEthOverrunCount = 0; char mEthIfName[IFNAMSIZ]; #if CHIP_DEVICE_CONFIG_ENABLE_WPA @@ -223,16 +189,9 @@ class ConnectivityManagerImpl final : public ConnectivityManager, System::Clock::Timestamp mLastAPDemandTime; System::Clock::Timeout mWiFiStationReconnectInterval; System::Clock::Timeout mWiFiAPIdleTimeout; - uint8_t mWiFiMacAddress[kMaxHardwareAddrSize]; #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI - uint32_t mBeaconLostCount = 0; - uint32_t mPacketMulticastRxCount = 0; - uint32_t mPacketMulticastTxCount = 0; - uint32_t mPacketUnicastRxCount = 0; - uint32_t mPacketUnicastTxCount = 0; - uint64_t mOverrunCount = 0; static char sWiFiIfName[IFNAMSIZ]; #endif }; diff --git a/src/platform/Linux/DiagnosticDataProviderImpl.cpp b/src/platform/Linux/DiagnosticDataProviderImpl.cpp index 5d6e173bb3d0e4..c40818ceb5ad22 100644 --- a/src/platform/Linux/DiagnosticDataProviderImpl.cpp +++ b/src/platform/Linux/DiagnosticDataProviderImpl.cpp @@ -27,17 +27,186 @@ #include #include #include +#include #include #include #include +#include +#include +#include #include #include #include #include #include +#include +#include +#include +#include #include +using namespace ::chip; +using namespace ::chip::TLV; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceLayer::Internal; +using namespace ::chip::app::Clusters::GeneralDiagnostics; + +namespace { + +enum class EthernetStatsCountType +{ + kEthPacketRxCount, + kEthPacketTxCount, + kEthTxErrCount, + kEthCollisionCount, + kEthOverrunCount +}; + +enum class WiFiStatsCountType +{ + kWiFiUnicastPacketRxCount, + kWiFiUnicastPacketTxCount, + kWiFiMulticastPacketRxCount, + kWiFiMulticastPacketTxCount, + kWiFiOverrunCount +}; + +CHIP_ERROR GetEthernetStatsCount(EthernetStatsCountType type, uint64_t & count) +{ + CHIP_ERROR err = CHIP_ERROR_READ_FAILED; + struct ifaddrs * ifaddr = nullptr; + + if (getifaddrs(&ifaddr) == -1) + { + ChipLogError(DeviceLayer, "Failed to get network interfaces"); + } + else + { + struct ifaddrs * ifa = nullptr; + + // Walk through linked list, maintaining head pointer so we can free list later. + for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) + { + if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET) + { + ChipLogProgress(DeviceLayer, "Found the primary Ethernet interface:%s", ifa->ifa_name); + break; + } + } + + if (ifa != nullptr) + { + if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) + { + struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; + switch (type) + { + case EthernetStatsCountType::kEthPacketRxCount: + count = stats->rx_packets; + err = CHIP_NO_ERROR; + break; + case EthernetStatsCountType::kEthPacketTxCount: + count = stats->tx_packets; + err = CHIP_NO_ERROR; + break; + case EthernetStatsCountType::kEthTxErrCount: + count = stats->tx_errors; + err = CHIP_NO_ERROR; + break; + case EthernetStatsCountType::kEthCollisionCount: + count = stats->collisions; + err = CHIP_NO_ERROR; + break; + case EthernetStatsCountType::kEthOverrunCount: + count = stats->rx_over_errors; + err = CHIP_NO_ERROR; + break; + default: + ChipLogError(DeviceLayer, "Unknown Ethernet statistic metric type"); + break; + } + } + } + + freeifaddrs(ifaddr); + } + + return err; +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +CHIP_ERROR GetWiFiStatsCount(WiFiStatsCountType type, uint64_t & count) +{ + CHIP_ERROR err = CHIP_ERROR_READ_FAILED; + struct ifaddrs * ifaddr = nullptr; + + if (getifaddrs(&ifaddr) == -1) + { + ChipLogError(DeviceLayer, "Failed to get network interfaces"); + } + else + { + struct ifaddrs * ifa = nullptr; + + // Walk through linked list, maintaining head pointer so we can free list later. + for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) + { + if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI) + { + ChipLogProgress(DeviceLayer, "Found the primary WiFi interface:%s", ifa->ifa_name); + break; + } + } + + if (ifa != nullptr) + { + if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) + { + // The usecase of this function is embedded devices,on which we can interact with the WiFi + // driver to get the accurate number of muticast and unicast packets accurately. + // On Linux simulation, we can only get the total packets received, the total bytes transmitted, + // the multicast packets received and receiver ring buff overflow. + + struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; + switch (type) + { + case WiFiStatsCountType::kWiFiUnicastPacketRxCount: + count = stats->rx_packets; + err = CHIP_NO_ERROR; + break; + case WiFiStatsCountType::kWiFiUnicastPacketTxCount: + count = stats->tx_packets; + err = CHIP_NO_ERROR; + break; + case WiFiStatsCountType::kWiFiMulticastPacketRxCount: + count = stats->multicast; + err = CHIP_NO_ERROR; + break; + case WiFiStatsCountType::kWiFiMulticastPacketTxCount: + count = 0; + err = CHIP_NO_ERROR; + break; + case WiFiStatsCountType::kWiFiOverrunCount: + count = stats->rx_over_errors; + err = CHIP_NO_ERROR; + break; + default: + ChipLogError(DeviceLayer, "Unknown WiFi statistic metric type"); + break; + } + } + } + + freeifaddrs(ifaddr); + } + + return err; +} +#endif // #if CHIP_DEVICE_CONFIG_ENABLE_WIFI + +} // namespace + namespace chip { namespace DeviceLayer { @@ -239,5 +408,382 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetActiveNetworkFaults(GeneralFaultsifa_next) + { + if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) + { + NetworkInterface * ifp = new NetworkInterface(); + + strncpy(ifp->Name, ifa->ifa_name, Inet::InterfaceId::kMaxIfNameLength); + ifp->Name[Inet::InterfaceId::kMaxIfNameLength - 1] = '\0'; + + ifp->name = CharSpan(ifp->Name, strlen(ifp->Name)); + ifp->fabricConnected = ifa->ifa_flags & IFF_RUNNING; + ifp->type = ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name); + ifp->offPremiseServicesReachableIPv4 = false; + ifp->offPremiseServicesReachableIPv6 = false; + + if (ConnectivityUtils::GetInterfaceHardwareAddrs(ifa->ifa_name, ifp->MacAddress, kMaxHardwareAddrSize) != + CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to get network hardware address"); + } + else + { + // Set 48-bit IEEE MAC Address + ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6); + } + + ifp->Next = head; + head = ifp; + } + } + + *netifpp = head; + err = CHIP_NO_ERROR; + + freeifaddrs(ifaddr); + } + + return err; +} + +void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * netifp) +{ + while (netifp) + { + NetworkInterface * del = netifp; + netifp = netifp->Next; + delete del; + } +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthPHYRate(uint8_t & pHYRate) +{ + if (ConnectivityMgrImpl().GetEthernetIfName() == nullptr) + { + return CHIP_ERROR_READ_FAILED; + } + + return ConnectivityUtils::GetEthPHYRate(ConnectivityMgrImpl().GetEthernetIfName(), pHYRate); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthFullDuplex(bool & fullDuplex) +{ + if (ConnectivityMgrImpl().GetEthernetIfName() == nullptr) + { + return CHIP_ERROR_READ_FAILED; + } + + return ConnectivityUtils::GetEthFullDuplex(ConnectivityMgrImpl().GetEthernetIfName(), fullDuplex); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthTimeSinceReset(uint64_t & timeSinceReset) +{ + return GetDiagnosticDataProvider().GetUpTime(timeSinceReset); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthPacketRxCount(uint64_t & packetRxCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthPacketRxCount, count)); + VerifyOrReturnError(count >= mEthPacketRxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + packetRxCount = count - mEthPacketRxCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthPacketTxCount(uint64_t & packetTxCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthPacketTxCount, count)); + VerifyOrReturnError(count >= mEthPacketTxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + packetTxCount = count - mEthPacketTxCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthTxErrCount(uint64_t & txErrCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthTxErrCount, count)); + VerifyOrReturnError(count >= mEthTxErrCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + txErrCount = count - mEthTxErrCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthCollisionCount(uint64_t & collisionCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthCollisionCount, count)); + VerifyOrReturnError(count >= mEthCollisionCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + collisionCount = count - mEthCollisionCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetEthOverrunCount(uint64_t & overrunCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetEthernetStatsCount(EthernetStatsCountType::kEthOverrunCount, count)); + VerifyOrReturnError(count >= mEthOverrunCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + overrunCount = count - mEthOverrunCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::ResetEthNetworkDiagnosticsCounts() +{ + CHIP_ERROR err = CHIP_ERROR_READ_FAILED; + struct ifaddrs * ifaddr = nullptr; + + if (getifaddrs(&ifaddr) == -1) + { + ChipLogError(DeviceLayer, "Failed to get network interfaces"); + } + else + { + struct ifaddrs * ifa = nullptr; + + // Walk through linked list, maintaining head pointer so we can free list later. + for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) + { + if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_ETHERNET) + { + ChipLogProgress(DeviceLayer, "Found the primary Ethernet interface:%s", ifa->ifa_name); + break; + } + } + + if (ifa != nullptr) + { + if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) + { + struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; + + mEthPacketRxCount = stats->rx_packets; + mEthPacketTxCount = stats->tx_packets; + mEthTxErrCount = stats->tx_errors; + mEthCollisionCount = stats->collisions; + mEthOverrunCount = stats->rx_over_errors; + err = CHIP_NO_ERROR; + } + } + + freeifaddrs(ifaddr); + } + + return err; +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiChannelNumber(uint16_t & channelNumber) +{ + if (ConnectivityMgrImpl().GetWiFiIfName() == nullptr) + { + return CHIP_ERROR_READ_FAILED; + } + + return ConnectivityUtils::GetWiFiChannelNumber(ConnectivityMgrImpl().GetWiFiIfName(), channelNumber); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiRssi(int8_t & rssi) +{ + if (ConnectivityMgrImpl().GetWiFiIfName() == nullptr) + { + return CHIP_ERROR_READ_FAILED; + } + + return ConnectivityUtils::GetWiFiRssi(ConnectivityMgrImpl().GetWiFiIfName(), rssi); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconLostCount) +{ + uint32_t count; + + if (ConnectivityMgrImpl().GetWiFiIfName() == nullptr) + { + return CHIP_ERROR_READ_FAILED; + } + + ReturnErrorOnFailure(ConnectivityUtils::GetWiFiBeaconLostCount(ConnectivityMgrImpl().GetWiFiIfName(), count)); + VerifyOrReturnError(count >= mBeaconLostCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + beaconLostCount = count - mBeaconLostCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) +{ + if (ConnectivityMgrImpl().GetWiFiIfName() == nullptr) + { + return CHIP_ERROR_READ_FAILED; + } + + return ConnectivityUtils::GetWiFiCurrentMaxRate(ConnectivityMgrImpl().GetWiFiIfName(), currentMaxRate); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiMulticastPacketRxCount, count)); + VerifyOrReturnError(count >= mPacketMulticastRxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + count -= mPacketMulticastRxCount; + VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); + + packetMulticastRxCount = static_cast(count); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiMulticastPacketTxCount, count)); + VerifyOrReturnError(count >= mPacketMulticastTxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + count -= mPacketMulticastTxCount; + VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); + + packetMulticastTxCount = static_cast(count); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiUnicastPacketRxCount, count)); + VerifyOrReturnError(count >= mPacketUnicastRxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + count -= mPacketUnicastRxCount; + VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); + + packetUnicastRxCount = static_cast(count); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiUnicastPacketTxCount, count)); + VerifyOrReturnError(count >= mPacketUnicastTxCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + count -= mPacketUnicastTxCount; + VerifyOrReturnError(count <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); + + packetUnicastTxCount = static_cast(count); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiOverrunCount(uint64_t & overrunCount) +{ + uint64_t count; + + ReturnErrorOnFailure(GetWiFiStatsCount(WiFiStatsCountType::kWiFiOverrunCount, count)); + VerifyOrReturnError(count >= mOverrunCount, CHIP_ERROR_INVALID_INTEGER_VALUE); + + overrunCount = count - mOverrunCount; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts() +{ + CHIP_ERROR err = CHIP_ERROR_READ_FAILED; + struct ifaddrs * ifaddr = nullptr; + + ReturnErrorOnFailure(GetWiFiBeaconLostCount(mBeaconLostCount)); + + if (getifaddrs(&ifaddr) == -1) + { + ChipLogError(DeviceLayer, "Failed to get network interfaces"); + } + else + { + struct ifaddrs * ifa = nullptr; + + // Walk through linked list, maintaining head pointer so we can free list later. + for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) + { + if (ConnectivityUtils::GetInterfaceConnectionType(ifa->ifa_name) == InterfaceType::EMBER_ZCL_INTERFACE_TYPE_WI_FI) + { + ChipLogProgress(DeviceLayer, "Found the primary WiFi interface:%s", ifa->ifa_name); + break; + } + } + + if (ifa != nullptr) + { + if (ifa->ifa_addr->sa_family == AF_PACKET && ifa->ifa_data != nullptr) + { + struct rtnl_link_stats * stats = (struct rtnl_link_stats *) ifa->ifa_data; + + mPacketMulticastRxCount = stats->multicast; + mPacketMulticastTxCount = 0; + mPacketUnicastRxCount = stats->rx_packets; + mPacketUnicastTxCount = stats->tx_packets; + mOverrunCount = stats->rx_over_errors; + + err = CHIP_NO_ERROR; + } + } + + freeifaddrs(ifaddr); + } + + return err; +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiVersion(uint8_t & wiFiVersion) +{ + return ConnectivityMgrImpl().GetWiFiVersion(wiFiVersion); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & value) +{ + return ConnectivityMgrImpl().GetWiFiBssId(value); +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(uint8_t & securityType) +{ + return ConnectivityMgrImpl().GetWiFiSecurityType(securityType); +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Linux/DiagnosticDataProviderImpl.h b/src/platform/Linux/DiagnosticDataProviderImpl.h index f58c6d712d81cf..db547518824948 100644 --- a/src/platform/Linux/DiagnosticDataProviderImpl.h +++ b/src/platform/Linux/DiagnosticDataProviderImpl.h @@ -53,6 +53,54 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider CHIP_ERROR GetActiveHardwareFaults(GeneralFaults & hardwareFaults) override; CHIP_ERROR GetActiveRadioFaults(GeneralFaults & radioFaults) override; CHIP_ERROR GetActiveNetworkFaults(GeneralFaults & networkFaults) override; + + CHIP_ERROR GetNetworkInterfaces(NetworkInterface ** netifpp) override; + void ReleaseNetworkInterfaces(NetworkInterface * netifp) override; + + CHIP_ERROR GetEthPHYRate(uint8_t & pHYRate) override; + CHIP_ERROR GetEthFullDuplex(bool & fullDuplex) override; + CHIP_ERROR GetEthTimeSinceReset(uint64_t & timeSinceReset) override; + CHIP_ERROR GetEthPacketRxCount(uint64_t & packetRxCount) override; + CHIP_ERROR GetEthPacketTxCount(uint64_t & packetTxCount) override; + CHIP_ERROR GetEthTxErrCount(uint64_t & txErrCount) override; + CHIP_ERROR GetEthCollisionCount(uint64_t & collisionCount) override; + CHIP_ERROR GetEthOverrunCount(uint64_t & overrunCount) override; + CHIP_ERROR ResetEthNetworkDiagnosticsCounts() override; + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + CHIP_ERROR GetWiFiChannelNumber(uint16_t & channelNumber) override; + CHIP_ERROR GetWiFiRssi(int8_t & rssi) override; + CHIP_ERROR GetWiFiBeaconLostCount(uint32_t & beaconLostCount) override; + CHIP_ERROR GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) override; + CHIP_ERROR GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount) override; + CHIP_ERROR GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount) override; + CHIP_ERROR GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount) override; + CHIP_ERROR GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) override; + CHIP_ERROR GetWiFiOverrunCount(uint64_t & overrunCount) override; + CHIP_ERROR ResetWiFiNetworkDiagnosticsCounts() override; +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + CHIP_ERROR GetWiFiVersion(uint8_t & wiFiVersion) override; + CHIP_ERROR GetWiFiBssId(ByteSpan & value) override; + CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType) override; +#endif + +private: + uint64_t mEthPacketRxCount = 0; + uint64_t mEthPacketTxCount = 0; + uint64_t mEthTxErrCount = 0; + uint64_t mEthCollisionCount = 0; + uint64_t mEthOverrunCount = 0; + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + uint32_t mBeaconLostCount = 0; + uint32_t mPacketMulticastRxCount = 0; + uint32_t mPacketMulticastTxCount = 0; + uint32_t mPacketUnicastRxCount = 0; + uint32_t mPacketUnicastTxCount = 0; + uint64_t mOverrunCount = 0; +#endif }; } // namespace DeviceLayer diff --git a/src/platform/tests/TestConnectivityMgr.cpp b/src/platform/tests/TestConnectivityMgr.cpp index dfcc9c02ff370b..932be3dcfc5b1a 100644 --- a/src/platform/tests/TestConnectivityMgr.cpp +++ b/src/platform/tests/TestConnectivityMgr.cpp @@ -34,6 +34,7 @@ #include #include +#include using namespace chip; using namespace chip::Logging; @@ -57,11 +58,11 @@ static void TestConnectivityMgr_GetNetworkInterfaces(nlTestSuite * inSuite, void NetworkInterface * netifs = nullptr; - err = ConnectivityMgr().GetNetworkInterfaces(&netifs); + err = GetDiagnosticDataProvider().GetNetworkInterfaces(&netifs); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, netifs != nullptr); - ConnectivityMgr().ReleaseNetworkInterfaces(netifs); + GetDiagnosticDataProvider().ReleaseNetworkInterfaces(netifs); } /**