Skip to content

Commit

Permalink
Revert "Add Label to FabricDescriptorStruct and hook up logic with Up…
Browse files Browse the repository at this point in the history
…dateFabricLabel (#6670)" (#7341)

This reverts commit e1cb608 because
that breaks Darwin tests: it changes StorableAdminPairingInfo but
something is setting up admins in kvs without going through
`AdminPairingInfo::StoreIntoKVS` so our code and our stored data end
up out of sync.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 30, 2021
1 parent f5eaa56 commit 1121880
Show file tree
Hide file tree
Showing 23 changed files with 39 additions and 176 deletions.
3 changes: 0 additions & 3 deletions config/nrfconnect/app/enable-gnu-std.cmake

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -434,15 +434,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -866,7 +858,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
1 change: 0 additions & 1 deletion examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ static void OnOperationalCredentialsFabricsListListAttributeResponse(void * cont
ChipLogProgress(chipTool, " FabricId: %" PRIu64 "", entries[i].FabricId);
ChipLogProgress(chipTool, " VendorId: %" PRIu16 "", entries[i].VendorId);
ChipLogProgress(chipTool, " NodeId: %" PRIu64 "", entries[i].NodeId);
ChipLogProgress(Zcl, " Label: %zu", entries[i].Label.size());
}

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
Expand Down
14 changes: 3 additions & 11 deletions examples/lighting-app/lighting-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -140,15 +140,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -342,7 +334,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
2 changes: 0 additions & 2 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-nrfconnect-lighting-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)

target_compile_options(app PRIVATE -Werror)

target_include_directories(app PRIVATE
Expand Down
14 changes: 3 additions & 11 deletions examples/lock-app/lock-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -140,15 +140,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -342,7 +334,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
2 changes: 0 additions & 2 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ target_compile_options(app PRIVATE -Werror)

project(chip-nrfconnect-lock-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)

target_include_directories(app PRIVATE
main/include
${LOCK_COMMON}
Expand Down
2 changes: 0 additions & 2 deletions examples/pigweed-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-nrf52840-pigweed-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)

target_compile_options(app PRIVATE -Werror)

include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
Expand Down
2 changes: 0 additions & 2 deletions examples/pump-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ target_compile_options(app PRIVATE -Werror)

project(chip-nrfconnect-pump-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)

target_include_directories(app PRIVATE
main/include
${PUMP_COMMON}
Expand Down
14 changes: 3 additions & 11 deletions examples/pump-app/pump-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -140,15 +140,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -342,7 +334,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
2 changes: 0 additions & 2 deletions examples/pump-controller-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ target_compile_options(app PRIVATE -Werror)

project(chip-nrfconnect-pump-controller-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)

target_include_directories(app PRIVATE
main/include
${PUMPC_COMMON}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -140,15 +140,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -342,7 +334,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
2 changes: 0 additions & 2 deletions examples/shell/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-nrfconnect-shell-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)

target_compile_options(app PRIVATE -Werror)

target_include_directories(app PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -140,15 +140,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -187,7 +179,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
14 changes: 3 additions & 11 deletions examples/tv-app/tv-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 52;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -338,15 +338,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
chip::ByteSpan * LabelSpan = &entry->Label; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, LabelSpan) : ReadByteSpan(src + entryOffset, 34, LabelSpan)))
{
ChipLogError(Zcl, "Index %l is invalid. Not enough remaining space", index);
return 0;
}
entryOffset = static_cast<uint16_t>(entryOffset + 34);
sizeof(entry->NodeId)); // NODE_ID
break;
}
}
Expand Down Expand Up @@ -682,7 +674,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 52;
entryLength = 18;
break;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
#include <app/server/Server.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/core/PeerId.h>
#include <platform/CHIPDeviceLayer.h>
#include <string.h>
#include <support/CodeUtils.h>
#include <support/ScopedBuffer.h>
#include <support/logging/CHIPLogging.h>
Expand Down Expand Up @@ -79,19 +77,14 @@ EmberAfStatus writeFabricAttribute(uint8_t * buffer, int32_t index = -1)
index + 1);
}

EmberAfStatus writeFabric(FabricId fabricId, NodeId nodeId, uint16_t vendorId, const uint8_t * fabricLabel, int32_t index)
EmberAfStatus writeFabric(FabricId fabricId, NodeId nodeId, uint16_t vendorId, int32_t index)
{
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

EmberAfFabricDescriptor fabricDescriptor;
fabricDescriptor.FabricId = fabricId;
fabricDescriptor.NodeId = nodeId;
fabricDescriptor.VendorId = vendorId;
if (fabricLabel != nullptr)
{
size_t lengthToStore = strnlen(Uint8::to_const_char(fabricLabel), kFabricLabelMaxLengthInBytes);
fabricDescriptor.Label = ByteSpan(fabricLabel, lengthToStore);
}

emberAfPrintln(EMBER_AF_PRINT_DEBUG,
"OpCreds: Writing admin into attribute store at index %d: fabricId 0x" ChipLogFormatX64
Expand All @@ -110,10 +103,9 @@ CHIP_ERROR writeAdminsIntoFabricsListAttribute()
uint32_t fabricIndex = 0;
for (auto & pairing : GetGlobalAdminPairingTable())
{
NodeId nodeId = pairing.GetNodeId();
uint64_t fabricId = pairing.GetFabricId();
uint16_t vendorId = pairing.GetVendorId();
const uint8_t * fabricLabel = pairing.GetFabricLabel();
NodeId nodeId = pairing.GetNodeId();
uint64_t fabricId = pairing.GetFabricId();
uint16_t vendorId = pairing.GetVendorId();

// Skip over uninitialized admins
if (nodeId == kUndefinedNodeId || fabricId == kUndefinedFabricId || vendorId == kUndefinedVendorId)
Expand All @@ -124,7 +116,7 @@ CHIP_ERROR writeAdminsIntoFabricsListAttribute()
ChipLogValueX64(fabricId), ChipLogValueX64(nodeId), vendorId);
continue;
}
else if (writeFabric(fabricId, nodeId, vendorId, fabricLabel, fabricIndex) != EMBER_ZCL_STATUS_SUCCESS)
else if (writeFabric(fabricId, nodeId, vendorId, fabricIndex) != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG,
"OpCreds: Failed to write admin with fabricId 0x" ChipLogFormatX64 " in fabrics list",
Expand Down Expand Up @@ -300,23 +292,7 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(chip::app::Co
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: UpdateFabricLabel");

EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
CHIP_ERROR err;

// Fetch current fabric
AdminPairingInfo * admin = retrieveCurrentAdmin();
VerifyOrExit(admin != nullptr, status = EMBER_ZCL_STATUS_FAILURE);

// Set Label on fabric
err = admin->SetFabricLabel(Label);
VerifyOrExit(err == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);

// Persist updated fabric
err = GetGlobalAdminPairingTable().Store(admin->GetAdminId());
VerifyOrExit(err == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);

exit:
writeAdminsIntoFabricsListAttribute();
EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE;
emberAfSendImmediateDefaultResponse(status);
return true;
}
Expand Down
1 change: 0 additions & 1 deletion src/app/common/gen/af-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ typedef struct _FabricDescriptor
chip::FabricId FabricId;
uint16_t VendorId;
chip::NodeId NodeId;
chip::ByteSpan Label;
} EmberAfFabricDescriptor;

// Struct for GpPairingConfigurationGroupList
Expand Down
Loading

0 comments on commit 1121880

Please sign in to comment.