diff --git a/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.h b/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.h index 2e8283a383e69d..9714fc52831dba 100644 --- a/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.h +++ b/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.h @@ -29,7 +29,7 @@ class OpenCommissioningWindowCommand : public CHIPCommand mOnOpenCommissioningWindowCallback(OnOpenCommissioningWindowResponse, this) { AddArgument("node-id", 0, UINT64_MAX, &mNodeId); - AddArgument("option", 0, UINT8_MAX, &mCommissioningWindowOption); + AddArgument("option", 0, 2, &mCommissioningWindowOption); AddArgument("timeout", 0, UINT16_MAX, &mTimeout); AddArgument("iteration", chip::kPBKDFMinimumIterations, chip::kPBKDFMaximumIterations, &mIteration); AddArgument("discriminator", 0, 4096, &mDiscriminator); @@ -41,7 +41,7 @@ class OpenCommissioningWindowCommand : public CHIPCommand private: NodeId mNodeId; - uint8_t mCommissioningWindowOption; + ChipDeviceController::CommissioningWindowOption mCommissioningWindowOption; uint16_t mTimeout; uint32_t mIteration; uint16_t mDiscriminator; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 291ae58a1c9391..091058452af1fb 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -443,38 +443,34 @@ CHIP_ERROR DeviceController::ComputePASEVerifier(uint32_t iterations, uint32_t s } CHIP_ERROR DeviceController::OpenCommissioningWindowWithCallback(NodeId deviceId, uint16_t timeout, uint32_t iteration, - uint16_t discriminator, uint8_t option, + uint16_t discriminator, CommissioningWindowOption option, chip::Callback::Callback * callback, bool readVIDPIDAttributes) { mSetupPayload = SetupPayload(); - mSetupPayload.version = 0; - mSetupPayload.discriminator = discriminator; - mSetupPayload.rendezvousInformation = RendezvousInformationFlags(RendezvousInformationFlag::kOnNetwork); - - mCommissioningWindowCallback = callback; - mDeviceWithCommissioningWindowOpen = deviceId; - mCommissioningWindowTimeout = timeout; - mCommissioningWindowIteration = iteration; - switch (option) { - case 0: - mCommissioningWindowOption = CommissioningWindowOption::kOriginalSetupCode; - break; - case 1: - mCommissioningWindowOption = CommissioningWindowOption::kTokenWithRandomPIN; + case CommissioningWindowOption::kOriginalSetupCode: + case CommissioningWindowOption::kTokenWithRandomPIN: break; - case 2: - mCommissioningWindowOption = CommissioningWindowOption::kTokenWithProvidedPIN; + case CommissioningWindowOption::kTokenWithProvidedPIN: mSetupPayload.setUpPINCode = mSuggestedSetUpPINCode; break; default: - ChipLogError(Controller, "Invalid Pairing Window option"); return CHIP_ERROR_INVALID_ARGUMENT; } + mSetupPayload.version = 0; + mSetupPayload.discriminator = discriminator; + mSetupPayload.rendezvousInformation = RendezvousInformationFlags(RendezvousInformationFlag::kOnNetwork); + + mCommissioningWindowOption = option; + mCommissioningWindowCallback = callback; + mDeviceWithCommissioningWindowOpen = deviceId; + mCommissioningWindowTimeout = timeout; + mCommissioningWindowIteration = iteration; + if (callback != nullptr && mCommissioningWindowOption != CommissioningWindowOption::kOriginalSetupCode && readVIDPIDAttributes) { OperationalDeviceProxy * device = mCASESessionManager->FindExistingSession(GetPeerIdWithCommissioningWindowOpen()); diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 039a281cdfc65d..9161eb05b37770 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -178,7 +178,7 @@ class DLL_EXPORT DeviceController : public SessionRecoveryDelegate DeviceController(); virtual ~DeviceController() {} - enum class CommissioningWindowOption + enum class CommissioningWindowOption : uint8_t { kOriginalSetupCode = 0, kTokenWithRandomPIN, @@ -271,7 +271,7 @@ class DLL_EXPORT DeviceController : public SessionRecoveryDelegate * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error */ CHIP_ERROR OpenCommissioningWindow(NodeId deviceId, uint16_t timeout, uint32_t iteration, uint16_t discriminator, - uint8_t option, SetupPayload & payload) + CommissioningWindowOption option, SetupPayload & payload) { mSuggestedSetUpPINCode = payload.setUpPINCode; ReturnErrorOnFailure(OpenCommissioningWindowWithCallback(deviceId, timeout, iteration, discriminator, option, nullptr)); @@ -302,7 +302,8 @@ class DLL_EXPORT DeviceController : public SessionRecoveryDelegate * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error */ CHIP_ERROR OpenCommissioningWindowWithCallback(NodeId deviceId, uint16_t timeout, uint32_t iteration, uint16_t discriminator, - uint8_t option, Callback::Callback * callback, + CommissioningWindowOption option, + Callback::Callback * callback, bool readVIDPIDAttributes = false); #if CHIP_DEVICE_CONFIG_ENABLE_DNSSD diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index a8009467e41ab4..564744d794feaf 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -532,8 +532,10 @@ JNI_METHOD(jboolean, openPairingWindow)(JNIEnv * env, jobject self, jlong handle return false; } - AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); - err = wrapper->Controller()->OpenCommissioningWindow(chipDevice->GetDeviceId(), duration, 0, 0, 0, setupPayload); + AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); + DeviceController::CommissioningWindowOption option = DeviceController::CommissioningWindowOption::kOriginalSetupCode; + + err = wrapper->Controller()->OpenCommissioningWindow(chipDevice->GetDeviceId(), duration, 0, 0, option, setupPayload); if (err != CHIP_NO_ERROR) { @@ -560,8 +562,10 @@ JNI_METHOD(jboolean, openPairingWindowWithPIN) return false; } - AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); - err = wrapper->Controller()->OpenCommissioningWindow(chipDevice->GetDeviceId(), duration, iteration, discriminator, 1, + AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); + DeviceController::CommissioningWindowOption option = DeviceController::CommissioningWindowOption::kTokenWithProvidedPIN; + + err = wrapper->Controller()->OpenCommissioningWindow(chipDevice->GetDeviceId(), duration, iteration, discriminator, option, setupPayload); if (err != CHIP_NO_ERROR) diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index d2af20821a5a79..09255f4679d393 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -146,7 +146,7 @@ ChipError::StorageType pychip_DeviceController_PostTaskOnChipThread(ChipThreadTa ChipError::StorageType pychip_DeviceController_OpenCommissioningWindow(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId nodeid, uint16_t timeout, uint32_t iteration, - uint16_t discriminator, uint8_t option); + uint16_t discriminator, uint8_t optionInt); void pychip_DeviceController_PrintDiscoveredDevices(chip::Controller::DeviceCommissioner * devCtrl); bool pychip_DeviceController_GetIPForDiscoveredDevice(chip::Controller::DeviceCommissioner * devCtrl, int idx, char * addrStr, @@ -436,9 +436,11 @@ pychip_DeviceController_DiscoverCommissionableNodesCommissioningEnabled(chip::Co ChipError::StorageType pychip_DeviceController_OpenCommissioningWindow(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId nodeid, uint16_t timeout, uint32_t iteration, - uint16_t discriminator, uint8_t option) + uint16_t discriminator, uint8_t optionInt) { SetupPayload payload; + const auto option = static_cast(optionInt); + return devCtrl->OpenCommissioningWindow(nodeid, timeout, iteration, discriminator, option, payload).AsInteger(); } diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.mm b/src/darwin/Framework/CHIP/CHIPDeviceController.mm index 49c5fde0fb070f..2509084490a119 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.mm +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.mm @@ -511,7 +511,8 @@ - (BOOL)openPairingWindow:(uint64_t)deviceID duration:(NSUInteger)duration error } chip::SetupPayload setupPayload; - err = self.cppCommissioner->OpenCommissioningWindow(deviceID, (uint16_t) duration, 0, 0, 0, setupPayload); + err = self.cppCommissioner->OpenCommissioningWindow(deviceID, (uint16_t) duration, 0, 0, + chip::Controller::DeviceController::CommissioningWindowOption::kOriginalSetupCode, setupPayload); if (err != CHIP_NO_ERROR) { CHIP_LOG_ERROR("Error(%s): Open Pairing Window failed", chip::ErrorStr(err)); @@ -555,8 +556,8 @@ - (NSString *)openPairingWindowWithPIN:(uint64_t)deviceID setupPIN &= ((1 << chip::kSetupPINCodeFieldLengthInBits) - 1); setupPayload.setUpPINCode = (uint32_t) setupPIN; - err = self.cppCommissioner->OpenCommissioningWindow( - deviceID, (uint16_t) duration, 1000, (uint16_t) discriminator, 2, setupPayload); + err = self.cppCommissioner->OpenCommissioningWindow(deviceID, (uint16_t) duration, 1000, (uint16_t) discriminator, + chip::Controller::DeviceController::CommissioningWindowOption::kTokenWithProvidedPIN, setupPayload); if (err != CHIP_NO_ERROR) { CHIP_LOG_ERROR("Error(%s): Open Pairing Window failed", chip::ErrorStr(err));