Skip to content

Commit

Permalink
Align WiFi Network Diagnostics with the latest spec
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and woody-apple committed Feb 8, 2022
1 parent d5fffd7 commit 4d54f80
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 15 deletions.
1 change: 1 addition & 0 deletions scripts/idl/generators/java/ChipClustersRead.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <controller/java/AndroidClusterExceptions.h>
#include <controller/java/CHIPDefaultCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>
#include <jni.h>
#include <lib/support/CodeUtils.h>
#include <platform/PlatformManager.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class WiFiDiagosticsAttrAccess : public AttributeAccessInterface
CHIP_ERROR ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder);

CHIP_ERROR ReadWiFiBssId(AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadSecurityType(AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadWiFiVersion(AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadChannelNumber(AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadWiFiRssi(AttributeValueEncoder & aEncoder);
};

template <typename T>
Expand All @@ -73,22 +77,98 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataP

CHIP_ERROR WiFiDiagosticsAttrAccess::ReadWiFiBssId(AttributeValueEncoder & aEncoder)
{
// TODO: Use Nullable<ByteSpan> after we get darwin converted over to the new APIs.
Bssid::TypeInfo::Type bssid;
Attributes::Bssid::TypeInfo::Type bssid;
ByteSpan value;

if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiBssId(bssid) == CHIP_NO_ERROR)
if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiBssId(value) == CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Node is currently connected to Wi-Fi network with BSSID:");
ChipLogByteSpan(Zcl, bssid);
if (!value.empty())
{
bssid.SetNonNull(value);
ChipLogProgress(Zcl, "Node is currently connected to Wi-Fi network with BSSID:");
ChipLogByteSpan(Zcl, value);
}
}
else
{
ChipLogProgress(Zcl, "Node is not currently connected.");
ChipLogProgress(Zcl, "The WiFi interface is not currently connected.");
}

return aEncoder.Encode(bssid);
}

CHIP_ERROR WiFiDiagosticsAttrAccess::ReadSecurityType(AttributeValueEncoder & aEncoder)
{
Attributes::SecurityType::TypeInfo::Type securityType;
uint8_t value = 0;

if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiSecurityType(value) == CHIP_NO_ERROR)
{
securityType.SetNonNull(static_cast<WiFiNetworkDiagnostics::SecurityType>(value));
ChipLogProgress(Zcl, "The current type of Wi-Fi security used: %d", value);
}
else
{
ChipLogProgress(Zcl, "The WiFi interface is not currently configured or operational.");
}

return aEncoder.Encode(securityType);
}

CHIP_ERROR WiFiDiagosticsAttrAccess::ReadWiFiVersion(AttributeValueEncoder & aEncoder)
{
Attributes::WiFiVersion::TypeInfo::Type version;
uint8_t value = 0;

if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiVersion(value) == CHIP_NO_ERROR)
{
version.SetNonNull(static_cast<WiFiNetworkDiagnostics::WiFiVersionType>(value));
ChipLogProgress(Zcl, "The current 802.11 standard version in use by the Node: %d", value);
}
else
{
ChipLogProgress(Zcl, "The current 802.11 standard version in use by the Node is not available");
}

return aEncoder.Encode(version);
}

CHIP_ERROR WiFiDiagosticsAttrAccess::ReadChannelNumber(AttributeValueEncoder & aEncoder)
{
Attributes::ChannelNumber::TypeInfo::Type channelNumber;
uint16_t value = 0;

if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiChannelNumber(value) == CHIP_NO_ERROR)
{
channelNumber.SetNonNull(value);
ChipLogProgress(Zcl, "The channel that Wi-Fi communication is currently operating on is: %d", value);
}
else
{
ChipLogProgress(Zcl, "The WiFi interface is not currently configured or operational.");
}

return aEncoder.Encode(channelNumber);
}

CHIP_ERROR WiFiDiagosticsAttrAccess::ReadWiFiRssi(AttributeValueEncoder & aEncoder)
{
Attributes::Rssi::TypeInfo::Type rssi;
int8_t value = 0;

if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiRssi(value) == CHIP_NO_ERROR)
{
rssi.SetNonNull(value);
ChipLogProgress(Zcl, "The current RSSI of the Node’s Wi-Fi radio in dB: %d", value);
}
else
{
ChipLogProgress(Zcl, "The WiFi interface is not currently configured or operational.");
}

return aEncoder.Encode(rssi);
}

WiFiDiagosticsAttrAccess gAttrAccess;

CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
Expand All @@ -105,16 +185,16 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPat
return ReadWiFiBssId(aEncoder);
}
case Attributes::SecurityType::Id: {
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiSecurityType, aEncoder);
return ReadSecurityType(aEncoder);
}
case WiFiVersion::Id: {
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiVersion, aEncoder);
return ReadWiFiVersion(aEncoder);
}
case ChannelNumber::Id: {
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiChannelNumber, aEncoder);
return ReadChannelNumber(aEncoder);
}
case Rssi::Id: {
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiRssi, aEncoder);
return ReadWiFiRssi(aEncoder);
}
case BeaconLostCount::Id: {
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiBeaconLostCount, aEncoder);
Expand Down
10 changes: 10 additions & 0 deletions src/app/data-model/Encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const Nullable<X> & x)
{
return writer.PutNull(tag);
}

// Allow sending invalid values for nullables when
// CONFIG_IM_BUILD_FOR_UNIT_TEST is true, so we can test how the other side
// responds.
Expand All @@ -126,7 +127,16 @@ CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const Nullable<X> & x)
return CHIP_ERROR_IM_CONSTRAINT_ERROR;
}
#endif // !CONFIG_IM_BUILD_FOR_UNIT_TEST

// The -Wmaybe-uninitialized warning gets confused about the fact
// that x.mValue is always initialized if x.IsNull() is not
// true, so suppress it for our access to x.Value().
#pragma GCC diagnostic push
#if !defined(__clang__)
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // !defined(__clang__)
return Encode(writer, tag, x.Value());
#pragma GCC diagnostic pop
}

} // namespace DataModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ limitations under the License.
<code>0x0036</code>
<define>WIFI_NETWORK_DIAGNOSTICS_CLUSTER</define>
<description>The Wi-Fi Network Diagnostics Cluster provides a means to acquire standardized diagnostics metrics that MAY be used by a Node to assist a user or Administrative Node in diagnosing potential problems.</description>
<attribute side="server" code="0x00" define="BSSID" type="OCTET_STRING" length="6" writable="false" optional="false">bssid</attribute>
<attribute side="server" code="0x01" define="SECURITY_TYPE" type="ENUM8" writable="false" optional="false">SecurityType</attribute>
<attribute side="server" code="0x02" define="WIFI_VERSION" type="ENUM8" writable="false" optional="false">WiFiVersion</attribute>
<attribute side="server" code="0x03" define="CHANNEL_NUMBER" type="INT16U" min="0x0000" max="0xFFFF" writable="false" default="0x0000" optional="false">ChannelNumber</attribute>
<attribute side="server" code="0x04" define="RSSI" type="INT8S" min="-120" max="0" writable="false" default="0x00" optional="false">Rssi</attribute>
<attribute side="server" code="0x00" define="BSSID" type="OCTET_STRING" length="6" writable="false" isNullable="true" optional="false">bssid</attribute>
<attribute side="server" code="0x01" define="SECURITY_TYPE" type="SecurityType" writable="false" isNullable="true" optional="false">SecurityType</attribute>
<attribute side="server" code="0x02" define="WIFI_VERSION" type="WiFiVersionType" writable="false" isNullable="true" optional="false">WiFiVersion</attribute>
<attribute side="server" code="0x03" define="CHANNEL_NUMBER" type="INT16U" min="0x0000" max="0xFFFF" writable="false" default="0x0000" isNullable="true" optional="false">ChannelNumber</attribute>
<attribute side="server" code="0x04" define="RSSI" type="INT8S" min="-120" max="0" writable="false" isNullable="true" optional="false">Rssi</attribute>
<attribute side="server" code="0x05" define="BEACON_LOST_COUNT" type="INT32U" min="0x00000000" max="0xFFFFFFFF" writable="false" default="0x00000000" optional="true">BeaconLostCount</attribute>
<attribute side="server" code="0x06" define="BEACON_RX_COUNT" type="INT32U" min="0x00000000" max="0xFFFFFFFF" writable="false" default="0x00000000" optional="true">BeaconRxCount</attribute>
<attribute side="server" code="0x07" define="PACKET_MULTICAST_RX_COUNT" type="INT32U" min="0x00000000" max="0xFFFFFFFF" writable="false" default="0x00000000" optional="true">PacketMulticastRxCount</attribute>
Expand Down

0 comments on commit 4d54f80

Please sign in to comment.