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

Fix not sending CDC message when passcode is cancelled on TV app #34507

Merged
merged 17 commits into from
Aug 6, 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
28 changes: 26 additions & 2 deletions src/controller/CommissionerDiscoveryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,36 @@ void CommissionerDiscoveryController::Cancel()
return;
}
UDCClientState * client = mUdcServer->GetUDCClients().FindUDCClientState(mCurrentInstance);
if (client == nullptr || client->GetUDCClientProcessingState() != UDCClientProcessingState::kPromptingUser)

if (client == nullptr)
{
ChipLogError(AppServer, "UX Cancel: client not found");
return;
}

auto state = client->GetUDCClientProcessingState();

bool isCancelableState =
(state == UDCClientProcessingState::kPromptingUser || state == UDCClientProcessingState::kObtainingOnboardingPayload ||
state == UDCClientProcessingState::kWaitingForCommissionerPasscodeReady);

if (!isCancelableState)
{
ChipLogError(AppServer, "UX Cancel: invalid state for cancel");
ChipLogError(AppServer, "UX Cancel: invalid state for cancel, state: %hhu", static_cast<uint8_t>(state));
return;
}

client->SetUDCClientProcessingState(UDCClientProcessingState::kUserDeclined);

if (state == UDCClientProcessingState::kObtainingOnboardingPayload ||
state == UDCClientProcessingState::kWaitingForCommissionerPasscodeReady)
{
ChipLogDetail(AppServer, "UX Cancel: user cancelled entering PIN code, sending CDC");
CommissionerDeclaration cd;
cd.SetCancelPasscode(true);
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
}

mPendingConsent = false;
ResetState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class DLL_EXPORT IdentificationDeclaration
{
ChipLogDetail(AppServer, "\tpairing hint: %d", mPairingHint);
}

if (mNoPasscode)
{
ChipLogDetail(AppServer, "\tno passcode: true");
Expand Down Expand Up @@ -349,6 +348,9 @@ class DLL_EXPORT CommissionerDeclaration
void SetQRCodeDisplayed(bool newValue) { mQRCodeDisplayed = newValue; };
bool GetQRCodeDisplayed() const { return mQRCodeDisplayed; };

void SetCancelPasscode(bool newValue) { mCancelPasscode = newValue; };
bool GetCancelPasscode() const { return mCancelPasscode; };

/**
* Writes the CommissionerDeclaration message to the given buffer.
*
Expand Down Expand Up @@ -390,6 +392,10 @@ class DLL_EXPORT CommissionerDeclaration
{
ChipLogDetail(AppServer, "\tQR code displayed: true");
}
if (mCancelPasscode)
{
ChipLogDetail(AppServer, "\tPasscode cancelled: true");
}
ChipLogDetail(AppServer, "---- Commissioner Declaration End ----");
}

Expand All @@ -403,6 +409,7 @@ class DLL_EXPORT CommissionerDeclaration
kPasscodeDialogDisplayedTag,
kCommissionerPasscodeTag,
kQRCodeDisplayedTag,
kCancelPasscodeTag,

kMaxNum = UINT8_MAX
};
Expand All @@ -413,6 +420,7 @@ class DLL_EXPORT CommissionerDeclaration
bool mPasscodeDialogDisplayed = false;
bool mCommissionerPasscode = false;
bool mQRCodeDisplayed = false;
bool mCancelPasscode = false;
};

class DLL_EXPORT InstanceNameResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ CHIP_ERROR CommissionerDeclaration::ReadPayload(uint8_t * udcPayload, size_t pay
case kQRCodeDisplayedTag:
err = reader.Get(mQRCodeDisplayed);
break;
case kCancelPasscodeTag:
err = reader.Get(mCancelPasscode);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ uint32_t CommissionerDeclaration::WritePayload(uint8_t * payloadBuffer, size_t p
LogErrorOnFailure(err));
VerifyOrExit(CHIP_NO_ERROR == (err = writer.PutBoolean(chip::TLV::ContextTag(kQRCodeDisplayedTag), mQRCodeDisplayed)),
LogErrorOnFailure(err));
VerifyOrExit(CHIP_NO_ERROR == (err = writer.PutBoolean(chip::TLV::ContextTag(kCancelPasscodeTag), mCancelPasscode)),
LogErrorOnFailure(err));

VerifyOrExit(CHIP_NO_ERROR == (err = writer.EndContainer(outerContainerType)), LogErrorOnFailure(err));
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Finalize()), LogErrorOnFailure(err));
Expand Down
Loading