diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m index 886f46e73b235b..0921d3155d3e9e 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m @@ -727,7 +727,7 @@ - (void)handleRendezVousBLE:(uint16_t)discriminator setupPINCode:(uint32_t)setup { NSError * error; uint64_t deviceID = CHIPGetNextAvailableDeviceID(); - if ([self.chipController pairDevice:deviceID discriminator:discriminator setupPINCode:setupPINCode csrNonce:nil error:&error]) { + if ([self.chipController pairDevice:deviceID discriminator:discriminator setupPINCode:setupPINCode error:&error]) { deviceID++; CHIPSetNextAvailableDeviceID(deviceID); } diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m index dd82722484607c..8b016895154492 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m @@ -207,7 +207,6 @@ - (void)reportFromUserEnteredSettings [cluster subscribeAttributeMeasuredValueWithMinInterval:minIntervalSeconds maxInterval:maxIntervalSeconds - change:deltaInCelsius responseHandler:^(NSError * error, NSDictionary * values) { if (error == nil) return; diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.h b/src/darwin/Framework/CHIP/CHIPDeviceController.h index a80d0c9b2b0e3e..e9848dada27d5c 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.h +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.h @@ -39,7 +39,6 @@ typedef void (^CHIPDeviceConnectionCallback)(CHIPDevice * _Nullable device, NSEr - (BOOL)pairDevice:(uint64_t)deviceID discriminator:(uint16_t)discriminator setupPINCode:(uint32_t)setupPINCode - csrNonce:(nullable NSData *)csrNonce error:(NSError * __autoreleasing *)error; - (BOOL)pairDevice:(uint64_t)deviceID @@ -49,10 +48,7 @@ typedef void (^CHIPDeviceConnectionCallback)(CHIPDevice * _Nullable device, NSEr setupPINCode:(uint32_t)setupPINCode error:(NSError * __autoreleasing *)error; -- (BOOL)pairDevice:(uint64_t)deviceID - onboardingPayload:(NSString *)onboardingPayload - onboardingPayloadType:(CHIPOnboardingPayloadType)onboardingPayloadType - error:(NSError * __autoreleasing *)error; +- (BOOL)pairDevice:(uint64_t)deviceID onboardingPayload:(NSString *)onboardingPayload error:(NSError * __autoreleasing *)error; - (void)setListenPort:(uint16_t)port; - (BOOL)unpairDevice:(uint64_t)deviceID error:(NSError * __autoreleasing *)error; diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.mm b/src/darwin/Framework/CHIP/CHIPDeviceController.mm index 5abb3edee538f4..873d3511b264ac 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.mm +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.mm @@ -37,6 +37,7 @@ #include #include #include +#include static const char * const CHIP_COMMISSIONER_DEVICE_ID_KEY = "com.zigbee.chip.commissioner.device_id"; @@ -51,6 +52,7 @@ static NSString * const kErrorGetPairedDevice = @"Failure while trying to retrieve a paired device"; static NSString * const kErrorNotRunning = @"Controller is not running. Call startup first."; static NSString * const kInfoStackShutdown = @"Shutting down the CHIP Stack"; +static NSString * const kErrorSetupCodeGen = @"Generating Manual Pairing Code failed"; @interface CHIPDeviceController () @@ -267,7 +269,6 @@ - (NSNumber *)_getControllerNodeId - (BOOL)pairDevice:(uint64_t)deviceID discriminator:(uint16_t)discriminator setupPINCode:(uint32_t)setupPINCode - csrNonce:(nullable NSData *)csrNonce error:(NSError * __autoreleasing *)error { __block CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE; @@ -277,16 +278,19 @@ - (BOOL)pairDevice:(uint64_t)deviceID return success; } dispatch_sync(_chipWorkQueue, ^{ - chip::RendezvousParameters params - = chip::RendezvousParameters().SetSetupPINCode(setupPINCode).SetDiscriminator(discriminator); - - if (csrNonce != nil) { - params = params.SetCSRNonce(chip::ByteSpan((const uint8_t *) csrNonce.bytes, csrNonce.length)); + std::string manualPairingCode; + chip::SetupPayload payload; + payload.discriminator = discriminator; + payload.setUpPINCode = setupPINCode; + + errorCode = chip::ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(manualPairingCode); + success = ![self checkForError:errorCode logMsg:kErrorSetupCodeGen error:error]; + if (!success) { + return; } - if ([self isRunning]) { _operationalCredentialsDelegate->SetDeviceID(deviceID); - errorCode = self.cppCommissioner->PairDevice(deviceID, params); + errorCode = self.cppCommissioner->PairDevice(deviceID, manualPairingCode.c_str()); } success = ![self checkForError:errorCode logMsg:kErrorPairDevice error:error]; }); @@ -326,24 +330,22 @@ - (BOOL)pairDevice:(uint64_t)deviceID return success; } -- (BOOL)pairDevice:(uint64_t)deviceID - onboardingPayload:(NSString *)onboardingPayload - onboardingPayloadType:(CHIPOnboardingPayloadType)onboardingPayloadType - error:(NSError * __autoreleasing *)error +- (BOOL)pairDevice:(uint64_t)deviceID onboardingPayload:(NSString *)onboardingPayload error:(NSError * __autoreleasing *)error { - BOOL didSucceed = NO; - CHIPSetupPayload * setupPayload = [CHIPOnboardingPayloadParser setupPayloadForOnboardingPayload:onboardingPayload - ofType:onboardingPayloadType - error:error]; - if (setupPayload) { - uint16_t discriminator = setupPayload.discriminator.unsignedShortValue; - uint32_t setupPINCode = setupPayload.setUpPINCode.unsignedIntValue; - _operationalCredentialsDelegate->SetDeviceID(deviceID); - didSucceed = [self pairDevice:deviceID discriminator:discriminator setupPINCode:setupPINCode csrNonce:nil error:error]; - } else { - CHIP_LOG_ERROR("Failed to create CHIPSetupPayload for pairing with error %@", *error); + __block CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE; + __block BOOL success = NO; + if (![self isRunning]) { + success = ![self checkForError:errorCode logMsg:kErrorNotRunning error:error]; + return success; } - return didSucceed; + dispatch_sync(_chipWorkQueue, ^{ + if ([self isRunning]) { + _operationalCredentialsDelegate->SetDeviceID(deviceID); + errorCode = self.cppCommissioner->PairDevice(deviceID, [onboardingPayload UTF8String]); + } + success = ![self checkForError:errorCode logMsg:kErrorPairDevice error:error]; + }); + return success; } - (BOOL)unpairDevice:(uint64_t)deviceID error:(NSError * __autoreleasing *)error