Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-apple committed Nov 18, 2021
1 parent b2e06ac commit c574fb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ void DeviceController::OnVIDReadResponse(void * context, uint16_t value)
chip::Controller::BasicCluster cluster;
cluster.Associate(device, kBasicClusterEndpoint);

if (cluster.ReadAttribute<chip::app::Clusters::Basic::Attributes::ProductID::TypeInfo>(
context, OnPIDReadResponse, OnVIDPIDReadFailureResponse) != CHIP_NO_ERROR)
if (cluster.ReadAttribute<app::Clusters::Basic::Attributes::ProductID::TypeInfo>(context, OnPIDReadResponse,
OnVIDPIDReadFailureResponse) != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Could not read PID for opening commissioning window");
OnOpenPairingWindowFailureResponse(context, 0);
Expand Down Expand Up @@ -464,7 +464,7 @@ CHIP_ERROR DeviceController::OpenCommissioningWindowWithCallback(NodeId deviceId
return CHIP_ERROR_INVALID_ARGUMENT;
}

if (callback != nullptr && option != 0)
if (callback != nullptr && mCommissioningWindowOption != CommissioningWindowOption::kOriginalSetupCode)
{
OperationalDeviceProxy * device = mCASESessionManager->FindExistingSession(mDeviceWithCommissioningWindowOpen);
VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
Expand All @@ -473,8 +473,8 @@ CHIP_ERROR DeviceController::OpenCommissioningWindowWithCallback(NodeId deviceId
chip::Controller::BasicCluster cluster;
cluster.Associate(device, kBasicClusterEndpoint);

return cluster.ReadAttribute<chip::app::Clusters::Basic::Attributes::VendorID::TypeInfo>(this, OnVIDReadResponse,
OnVIDPIDReadFailureResponse);
return cluster.ReadAttribute<app::Clusters::Basic::Attributes::VendorID::TypeInfo>(this, OnVIDReadResponse,
OnVIDPIDReadFailureResponse);
}

return OpenCommissioningWindowInternal();
Expand All @@ -488,10 +488,6 @@ CHIP_ERROR DeviceController::OpenCommissioningWindowInternal()
OperationalDeviceProxy * device = mCASESessionManager->FindExistingSession(mDeviceWithCommissioningWindowOpen);
VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

std::string QRCode;
std::string manualPairingCode;
ByteSpan salt(Uint8::from_const_char(kSpake2pKeyExchangeSalt), strlen(kSpake2pKeyExchangeSalt));

constexpr EndpointId kAdministratorCommissioningClusterEndpoint = 0;

chip::Controller::AdministratorCommissioningCluster cluster;
Expand All @@ -502,6 +498,7 @@ CHIP_ERROR DeviceController::OpenCommissioningWindowInternal()

if (mCommissioningWindowOption != CommissioningWindowOption::kOriginalSetupCode)
{
ByteSpan salt(Uint8::from_const_char(kSpake2pKeyExchangeSalt), strlen(kSpake2pKeyExchangeSalt));
bool randomSetupPIN = (mCommissioningWindowOption == CommissioningWindowOption::kTokenWithRandomPIN);
PASEVerifier verifier;

Expand All @@ -518,11 +515,15 @@ CHIP_ERROR DeviceController::OpenCommissioningWindowInternal()
successCallback, failureCallback, mCommissioningWindowTimeout, ByteSpan(serializedVerifier, sizeof(serializedVerifier)),
mSetupPayload.discriminator, mCommissioningWindowIteration, salt, mPAKEVerifierID++));

ReturnErrorOnFailure(ManualSetupPayloadGenerator(mSetupPayload).payloadDecimalStringRepresentation(manualPairingCode));
ChipLogProgress(Controller, "Manual pairing code: [%s]", manualPairingCode.c_str());
char payloadBuffer[QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength];

MutableCharSpan manualCode(payloadBuffer);
ReturnErrorOnFailure(ManualSetupPayloadGenerator(mSetupPayload).payloadDecimalStringRepresentation(manualCode));
ChipLogProgress(Controller, "Manual pairing code: [%s]", payloadBuffer);

ReturnErrorOnFailure(QRCodeSetupPayloadGenerator(mSetupPayload).payloadBase38Representation(QRCode));
ChipLogProgress(Controller, "SetupQRCode: [%s]", QRCode.c_str());
MutableCharSpan QRCode(payloadBuffer);
ReturnErrorOnFailure(QRCodeBasicSetupPayloadGenerator(mSetupPayload).payloadBase38Representation(QRCode));
ChipLogProgress(Controller, "SetupQRCode: [%s]", payloadBuffer);
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/setup_payload/QRCodeSetupPayloadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class QRCodeBasicSetupPayloadGenerator
* producing the requested string.
*/
CHIP_ERROR payloadBase38Representation(MutableCharSpan & outBuffer);

// TODO - Find the optimal value for maximum length of QR Code Base38 string
static constexpr uint16_t kMaxQRCodeBase38RepresentationLength = 128;
};

} // namespace chip

0 comments on commit c574fb9

Please sign in to comment.