Skip to content

Commit

Permalink
Align WiFi Network Diagnostics cluster with the latest spec (project-…
Browse files Browse the repository at this point in the history
…chip#14755)

* Align WiFi Network Diagnostics with the latest spec

* Run codegen
  • Loading branch information
yufengwangca authored and fuxingguo16 committed Apr 26, 2022
1 parent 2388f93 commit 8f404a0
Show file tree
Hide file tree
Showing 43 changed files with 1,233 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3423,11 +3423,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/bridge-app/bridge-common/bridge-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1082,11 +1082,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/door-lock-app/door-lock-common/door-lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1474,11 +1474,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1494,11 +1494,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/lighting-app/lighting-common/lighting-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/lock-app/lock-common/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,11 +1079,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1306,11 +1306,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/tv-app/tv-common/tv-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1945,11 +1945,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/tv-casting-app/tv-casting-common/tv-casting-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2797,11 +2797,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
10 changes: 5 additions & 5 deletions examples/window-app/common/window-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,11 @@ server cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
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 @@ -118,6 +118,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 @@ -127,7 +128,16 @@ CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const Nullable<X> & x)
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
#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
10 changes: 5 additions & 5 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3890,11 +3890,11 @@ client cluster WiFiNetworkDiagnostics = 54 {
WiFiConnectionStatus connectionStatus = 0;
}

readonly attribute octet_string<6> bssid = 0;
readonly attribute enum8 securityType = 1;
readonly attribute enum8 wiFiVersion = 2;
readonly attribute int16u channelNumber = 3;
readonly attribute int8s rssi = 4;
readonly attribute nullable octet_string<6> bssid = 0;
readonly attribute nullable SecurityType securityType = 1;
readonly attribute nullable WiFiVersionType wiFiVersion = 2;
readonly attribute nullable int16u channelNumber = 3;
readonly attribute nullable int8s rssi = 4;
readonly attribute int32u beaconLostCount = 5;
readonly attribute int32u beaconRxCount = 6;
readonly attribute int32u packetMulticastRxCount = 7;
Expand Down
Loading

0 comments on commit 8f404a0

Please sign in to comment.