Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from project-chip:master #633

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion examples/fabric-sync/admin/PairingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,10 @@ void PairingManager::InitPairingCommand()
mDeviceIsICD = false;
}

CHIP_ERROR PairingManager::PairDeviceWithCode(NodeId nodeId, const char * payload)
CHIP_ERROR PairingManager::PairDeviceWithCode(NodeId nodeId, const char * payload, bool icdRegistration)
{
mICDRegistration.SetValue(icdRegistration);

if (payload == nullptr || strlen(payload) > kMaxManualCodeLength + 1)
{
ChipLogError(NotSpecified, "PairDeviceWithCode failed: Invalid pairing payload");
Expand Down Expand Up @@ -663,4 +665,35 @@ CHIP_ERROR PairingManager::UnpairDevice(NodeId nodeId)
});
}

void PairingManager::ResetForNextCommand()
{
mCommissioningWindowDelegate = nullptr;
mPairingDelegate = nullptr;
mNodeId = chip::kUndefinedNodeId;
mVerifier = chip::ByteSpan();
mSalt = chip::ByteSpan();
mDiscriminator = 0;
mSetupPINCode = 0;
mDeviceIsICD = false;

memset(mRandomGeneratedICDSymmetricKey, 0, sizeof(mRandomGeneratedICDSymmetricKey));
memset(mVerifierBuffer, 0, sizeof(mVerifierBuffer));
memset(mSaltBuffer, 0, sizeof(mSaltBuffer));
memset(mRemoteIpAddr, 0, sizeof(mRemoteIpAddr));
memset(mOnboardingPayload, 0, sizeof(mOnboardingPayload));

mICDRegistration.ClearValue();
mICDCheckInNodeId.ClearValue();
mICDClientType.ClearValue();
mICDSymmetricKey.ClearValue();
mICDMonitoredSubject.ClearValue();
mICDStayActiveDurationMsec.ClearValue();

mWindowOpener.reset();
mOnOpenCommissioningWindowCallback.Cancel();
mOnOpenCommissioningWindowVerifierCallback.Cancel();
mCurrentFabricRemover.reset();
mCurrentFabricRemoveCallback.Cancel();
}

} // namespace admin
9 changes: 8 additions & 1 deletion examples/fabric-sync/admin/PairingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
*
* @param nodeId The target node ID for pairing.
* @param payload The setup code payload, which typically contains device-specific pairing information.
* @param icdRegistration The boolean value to set for mICDRegistration.*
*
* @return CHIP_NO_ERROR on successful initiation of the pairing process, or an appropriate CHIP_ERROR if pairing fails.
*/
CHIP_ERROR PairDeviceWithCode(chip::NodeId nodeId, const char * payload);
CHIP_ERROR PairDeviceWithCode(chip::NodeId nodeId, const char * payload, bool icdRegistration = false);

/**
* Pairs a device using its setup PIN code and remote IP address.
Expand All @@ -132,6 +133,12 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
*/
CHIP_ERROR UnpairDevice(chip::NodeId nodeId);

/**
* Resets the PairingManager's internal state to a baseline, making it ready to handle a new command.
* This method clears all internal states and resets all members to their initial values.
*/
void ResetForNextCommand();

private:
// Constructors
PairingManager();
Expand Down
1 change: 1 addition & 0 deletions examples/fabric-sync/shell/AddBridgeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void AddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
ChipLogValueX64(deviceId), err.Format());
}

admin::PairingManager::Instance().ResetForNextCommand();
CommandRegistry::Instance().ResetActiveCommand();
}

Expand Down
1 change: 1 addition & 0 deletions examples/fabric-sync/shell/AddDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void AddDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
ChipLogValueX64(deviceId), err.Format());
}

admin::PairingManager::Instance().ResetForNextCommand();
CommandRegistry::Instance().ResetActiveCommand();
}

Expand Down
7 changes: 5 additions & 2 deletions examples/fabric-sync/shell/PairDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ using namespace ::chip;

namespace commands {

PairDeviceCommand::PairDeviceCommand(chip::NodeId nodeId, const char * payload) : mNodeId(nodeId), mPayload(payload) {}
PairDeviceCommand::PairDeviceCommand(chip::NodeId nodeId, const char * payload, bool enableICDRegistration) :
mNodeId(nodeId), mPayload(payload), mEnableICDRegistration(enableICDRegistration)
{}

void PairDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
{
Expand Down Expand Up @@ -57,6 +59,7 @@ void PairDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
ChipLogValueX64(deviceId), err.Format());
}

admin::PairingManager::Instance().ResetForNextCommand();
CommandRegistry::Instance().ResetActiveCommand();
}

Expand All @@ -74,7 +77,7 @@ CHIP_ERROR PairDeviceCommand::RunCommand()

admin::PairingManager::Instance().SetPairingDelegate(this);

return admin::PairingManager::Instance().PairDeviceWithCode(mNodeId, mPayload);
return admin::PairingManager::Instance().PairDeviceWithCode(mNodeId, mPayload, mEnableICDRegistration);
}

} // namespace commands
3 changes: 2 additions & 1 deletion examples/fabric-sync/shell/PairDeviceCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ namespace commands {
class PairDeviceCommand : public Command, public admin::PairingDelegate
{
public:
PairDeviceCommand(chip::NodeId nodeId, const char * payload);
PairDeviceCommand(chip::NodeId nodeId, const char * payload, bool enableICDRegistration);
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err) override;
CHIP_ERROR RunCommand() override;

private:
chip::NodeId mNodeId;
const char * mPayload;
bool mEnableICDRegistration;
};

} // namespace commands
1 change: 1 addition & 0 deletions examples/fabric-sync/shell/RemoveBridgeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void RemoveBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)
ChipLogValueX64(deviceId), err.Format());
}

admin::PairingManager::Instance().ResetForNextCommand();
CommandRegistry::Instance().ResetActiveCommand();
}

Expand Down
1 change: 1 addition & 0 deletions examples/fabric-sync/shell/RemoveDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void RemoveDeviceCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)
ChipLogValueX64(deviceId), err.Format());
}

admin::PairingManager::Instance().ResetForNextCommand();
CommandRegistry::Instance().ResetActiveCommand();
}

Expand Down
21 changes: 16 additions & 5 deletions examples/fabric-sync/shell/ShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ static CHIP_ERROR PrintAllCommands()
streamer_printf(sout,
" add-device Pair a device to local fabric. Usage: app add-device node-id setup-pin-code "
"device-remote-ip device-remote-port\r\n");
streamer_printf(sout, " pair-device Pair a device to local fabric. Usage: app pair-device node-id code\r\n");
streamer_printf(
sout,
" pair-device Pair a device to local fabric. Usage: app pair-device node-id code [--enable-icd-registration]\r\n");
streamer_printf(sout, " remove-device Remove a device from the local fabric. Usage: app remove-device node-id\r\n");
streamer_printf(sout, " sync-device Sync a device from other ecosystem. Usage: app sync-device endpointid\r\n");
streamer_printf(sout, "\r\n");
Expand Down Expand Up @@ -149,9 +151,11 @@ static CHIP_ERROR HandleAddDeviceCommand(int argc, char ** argv)

static CHIP_ERROR HandlePairDeviceCommand(int argc, char ** argv)
{
if (argc != 3)
bool enableICDRegistration = false;

if (argc < 3 || argc > 4) // Adjusted to allow 3 or 4 arguments
{
fprintf(stderr, "Invalid arguments. Usage: app pair-device node-id code\n");
fprintf(stderr, "Invalid arguments. Usage: app pair-device node-id code [--enable-icd-registration]\n");
return CHIP_ERROR_INVALID_ARGUMENT;
}

Expand All @@ -162,11 +166,18 @@ static CHIP_ERROR HandlePairDeviceCommand(int argc, char ** argv)
return CHIP_ERROR_BUSY;
}

// Parse arguments
// Parse mandatory arguments
chip::NodeId nodeId = static_cast<chip::NodeId>(strtoull(argv[1], nullptr, 10));
const char * setUpCode = argv[2];

auto command = std::make_unique<commands::PairDeviceCommand>(nodeId, setUpCode);
// Parse optional arguments
if (argc == 4 && strcmp(argv[3], "--enable-icd-registration") == 0)
{
enableICDRegistration = true;
}

// Create the command object, passing the new parameter
auto command = std::make_unique<commands::PairDeviceCommand>(nodeId, setUpCode, enableICDRegistration);

CHIP_ERROR result = command->RunCommand();
if (result == CHIP_NO_ERROR)
Expand Down
1 change: 1 addition & 0 deletions examples/fabric-sync/shell/SyncDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void SyncDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
ChipLogValueX64(deviceId), err.Format());
}

admin::PairingManager::Instance().ResetForNextCommand();
CommandRegistry::Instance().ResetActiveCommand();
}

Expand Down
9 changes: 6 additions & 3 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ - (void)_ensureSubscriptionForExistingDelegates:(NSString *)reason
if ([self _deviceUsesThread]) {
MTR_LOG(" => %@ - device is a thread device, scheduling in pool", self);
mtr_weakify(self);
NSString * description = [NSString stringWithFormat:@"MTRDevice setDelegate first subscription / controller resume (%p)", self];
[self _scheduleSubscriptionPoolWork:^{
mtr_strongify(self);
VerifyOrReturn(self);
Expand All @@ -827,7 +828,7 @@ - (void)_ensureSubscriptionForExistingDelegates:(NSString *)reason
std::lock_guard lock(self->_lock);
[self _clearSubscriptionPoolWork];
}];
} inNanoseconds:0 description:@"MTRDevice setDelegate first subscription"];
} inNanoseconds:0 description:description];
} else {
[_deviceController asyncDispatchToMatterQueue:^{
std::lock_guard lock(self->_lock);
Expand Down Expand Up @@ -1350,7 +1351,8 @@ - (void)_handleResubscriptionNeededWithDelayOnDeviceQueue:(NSNumber *)resubscrip
if (deviceUsesThread) {
std::lock_guard lock(_lock);
// For Thread-enabled devices, schedule the _triggerResubscribeWithReason call to run in the subscription pool
[self _scheduleSubscriptionPoolWork:resubscriptionBlock inNanoseconds:resubscriptionDelayNs description:@"ReadClient resubscription"];
NSString * description = [NSString stringWithFormat:@"ReadClient resubscription (%p)", self];
[self _scheduleSubscriptionPoolWork:resubscriptionBlock inNanoseconds:resubscriptionDelayNs description:description];
} else {
// For non-Thread-enabled devices, just call the resubscription block after the specified time
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, resubscriptionDelayNs), self.queue, resubscriptionBlock);
Expand Down Expand Up @@ -1467,7 +1469,8 @@ - (void)_doHandleSubscriptionReset:(NSNumber * _Nullable)retryDelay
int64_t resubscriptionDelayNs = static_cast<int64_t>(secondsToWait * NSEC_PER_SEC);
if ([self _deviceUsesThread]) {
// For Thread-enabled devices, schedule the _reattemptSubscriptionNowIfNeededWithReason call to run in the subscription pool
[self _scheduleSubscriptionPoolWork:resubscriptionBlock inNanoseconds:resubscriptionDelayNs description:@"MTRDevice resubscription"];
NSString * description = [NSString stringWithFormat:@"MTRDevice resubscription (%p)", self];
[self _scheduleSubscriptionPoolWork:resubscriptionBlock inNanoseconds:resubscriptionDelayNs description:description];
} else {
// For non-Thread-enabled devices, just call the resubscription block after the specified time
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, resubscriptionDelayNs), self.queue, resubscriptionBlock);
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/MTRFrameworkDiagnostics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

#import "MTRLogging_Internal.h"

#ifndef GIT_COMMIT_SHA
#define GIT_COMMIT_SHA "unknown-sha"
#endif

void MTRFrameworkInitDiagnosticLog()
{
MTR_LOG("Matter Framework Init (git: %s)", GIT_COMMIT_SHA);
Expand Down
2 changes: 1 addition & 1 deletion src/python_testing/TC_MCORE_FS_1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def test_TC_MCORE_FS_1_2(self):
nodeid=self.dut_node_id,
attributes=subscription_contents,
reportInterval=(min_report_interval_sec, max_report_interval_sec),
keepSubscriptions=False
keepSubscriptions=True
)

parts_list_queue = queue.Queue()
Expand Down
7 changes: 4 additions & 3 deletions src/python_testing/TC_MCORE_FS_1_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def test_TC_MCORE_FS_1_5(self):
nodeid=self.dut_node_id,
attributes=parts_list_subscription_contents,
reportInterval=(min_report_interval_sec, max_report_interval_sec),
keepSubscriptions=False
keepSubscriptions=True
)

parts_list_queue = queue.Queue()
Expand Down Expand Up @@ -249,14 +249,15 @@ async def test_TC_MCORE_FS_1_5(self):
await self.default_controller.CommissionOnNetwork(nodeId=self.th_server_local_nodeid, setupPinCode=passcode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator)

self.step(6)
max_report_interval_sec = 10
cadmin_subscription_contents = [
(newly_added_endpoint, Clusters.AdministratorCommissioning)
]
self._cadmin_subscription = await self.default_controller.ReadAttribute(
nodeid=self.dut_node_id,
attributes=cadmin_subscription_contents,
reportInterval=(min_report_interval_sec, max_report_interval_sec),
keepSubscriptions=False
keepSubscriptions=True
)

cadmin_queue = queue.Queue()
Expand All @@ -282,7 +283,7 @@ async def test_TC_MCORE_FS_1_5(self):
current_fabric_index, "AdminFabricIndex is unexpected")

self.step(10)
report_waiting_timeout_delay_sec = 10
report_waiting_timeout_delay_sec = max_report_interval_sec + 1
logging.info("Waiting for update to AdministratorCommissioning attributes.")
start_time = time.time()
elapsed = 0
Expand Down
Loading