Skip to content

Commit

Permalink
Fix not sending CDC message when passcode is cancelled on TV app (#34507
Browse files Browse the repository at this point in the history
)

* Fix not sending CDC message when passcode is cancelled

* Update logic

* Restyled by whitespace

* Restyled by clang-format

* Update code

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
lazarkov and restyled-commits authored Aug 6, 2024
1 parent d619f75 commit 62255da
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
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

0 comments on commit 62255da

Please sign in to comment.