diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.h b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.h index 77d143c2c5a2bb..85a2f1f133f2f5 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.h +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.h @@ -21,6 +21,6 @@ #import @interface QRCodeViewController - : UIViewController + : UIViewController @end diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m index 2105bec3b20545..66c2883964932d 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m @@ -408,7 +408,7 @@ - (void)viewDidLoad dispatch_queue_t callbackQueue = dispatch_queue_create("com.csa.matter.qrcodevc.callback", DISPATCH_QUEUE_SERIAL); self.chipController = InitializeMTR(); - [self.chipController setPairingDelegate:self queue:callbackQueue]; + [self.chipController setDeviceControllerDelegate:self queue:callbackQueue]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; [self.view addGestureRecognizer:tap]; @@ -478,8 +478,8 @@ - (void)setVendorIDOnAccessory } } -// MARK: MTRDevicePairingDelegate -- (void)onPairingComplete:(NSError * _Nullable)error +// MARK: MTRDeviceControllerDelegate +- (void)controller:(MTRDeviceController *)controller commissioningSessionEstablishmentDone:(NSError * _Nullable)error { if (error != nil) { NSLog(@"Got pairing error back %@", error); @@ -672,18 +672,26 @@ - (void)commissionWithSSID:(NSString *)ssid password:(NSString *)password } } -- (void)onCommissioningComplete:(NSError * _Nullable)error +// MARK: MTRDeviceControllerDelegate +- (void)controller:(MTRDeviceController *)controller + commissioningComplete:(NSError * _Nullable)error + nodeID:(NSNumber * _Nullable)nodeID { if (error != nil) { NSLog(@"Error retrieving device informations over Mdns: %@", error); return; } // track this device - uint64_t deviceId = MTRGetNextAvailableDeviceID() - 1; - MTRSetDevicePaired(deviceId, YES); + MTRSetDevicePaired([nodeID unsignedLongLongValue], YES); [self setVendorIDOnAccessory]; } +// MARK: MTRDeviceControllerDelegate +- (void)controller:(MTRDeviceController *)controller readCommissioningInfo:(MTRProductIdentity *)info +{ + NSLog(@"readCommissioningInfo, vendorID:%@, productID:%@", info.vendorID, info.productID); +} + - (void)updateUIFields:(MTRSetupPayload *)payload rawPayload:(nullable NSString *)rawPayload isManualCode:(BOOL)isManualCode { if (isManualCode) { @@ -789,7 +797,7 @@ - (void)_restartMatterStack { self.chipController = MTRRestartController(self.chipController); dispatch_queue_t callbackQueue = dispatch_queue_create("com.csa.matter.qrcodevc.callback", DISPATCH_QUEUE_SERIAL); - [self.chipController setPairingDelegate:self queue:callbackQueue]; + [self.chipController setDeviceControllerDelegate:self queue:callbackQueue]; } - (void)handleRendezVousDefault:(NSString *)payload diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h index 5245b980de5fbf..37c2f691307d02 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h @@ -28,6 +28,19 @@ typedef NS_ENUM(NSInteger, MTRCommissioningStatus) { = 3, } API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)); +/** + * A representation of a (vendor, product) pair that identifies a specific product. + */ +MTR_NEWLY_AVAILABLE +@interface MTRProductIdentity : NSObject + +@property (nonatomic, copy, readonly) NSNumber * vendorID; + +@property (nonatomic, copy, readonly) NSNumber * productID; + +- (instancetype)initWithVendorID:(NSNumber *)vendorID productID:(NSNumber *)productID; +@end + @class MTRDeviceController; /** @@ -52,8 +65,28 @@ API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) /** * Notify the delegate when commissioning is completed. */ -- (void)controller:(MTRDeviceController *)controller commissioningComplete:(NSError * _Nullable)error; +- (void)controller:(MTRDeviceController *)controller + commissioningComplete:(NSError * _Nullable)error MTR_NEWLY_DEPRECATED("Please use controller:commissioningComplete:nodeID:"); + +/** + * Notify the delegate when commissioning is completed. + * + * Exactly one of error and nodeID will be nil. + * + * If nodeID is not nil, then it represents the node id the node was assigned, as encoded in its operational certificate. + */ +- (void)controller:(MTRDeviceController *)controller + commissioningComplete:(NSError * _Nullable)error + nodeID:(NSNumber * _Nullable)nodeID MTR_NEWLY_AVAILABLE; +/** + * Notify the delegate when commissioning infomation has been read from the Basic + * Information cluster of the commissionee. + * + * At the point when this notification happens, device attestation has not been performed yet, + * so the information delivered by this notification should not be trusted. + */ +- (void)controller:(MTRDeviceController *)controller readCommissioningInfo:(MTRProductIdentity *)info MTR_NEWLY_AVAILABLE; @end typedef NS_ENUM(NSUInteger, MTRPairingStatus) { diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h index 464f0c91093d8d..d13331f46bd2ac 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.h @@ -18,6 +18,7 @@ #import "MTRDeviceControllerDelegate.h" #include +#include #include NS_ASSUME_NONNULL_BEGIN @@ -37,6 +38,8 @@ class MTRDeviceControllerDelegateBridge : public chip::Controller::DevicePairing void OnPairingDeleted(CHIP_ERROR error) override; + void OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info) override; + void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override; private: diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm index 59d18882e536c4..71ca534e67ddff 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm @@ -94,6 +94,25 @@ // This is never actually called; just do nothing. } +void MTRDeviceControllerDelegateBridge::OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info) +{ + chip::VendorId vendorId = info.basic.vendorId; + uint16_t productId = info.basic.productId; + + MTR_LOG_DEFAULT("DeviceControllerDelegate Read Commissioning Info. VendorId %u ProductId %u", vendorId, productId); + + id strongDelegate = mDelegate; + MTRDeviceController * strongController = mController; + if (strongDelegate && mQueue && strongController) { + if ([strongDelegate respondsToSelector:@selector(controller:readCommissioningInfo:)]) { + dispatch_async(mQueue, ^{ + auto * info = [[MTRProductIdentity alloc] initWithVendorID:@(vendorId) productID:@(productId)]; + [strongDelegate controller:strongController readCommissioningInfo:info]; + }); + } + } +} + void MTRDeviceControllerDelegateBridge::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR error) { MTR_LOG_DEFAULT("DeviceControllerDelegate Commissioning complete. NodeId %llu Status %s", nodeId, chip::ErrorStr(error)); @@ -101,6 +120,18 @@ id strongDelegate = mDelegate; MTRDeviceController * strongController = mController; if (strongDelegate && mQueue && strongController) { + if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:nodeID:)]) { + dispatch_async(mQueue, ^{ + NSError * nsError = [MTRError errorForCHIPErrorCode:error]; + NSNumber * nodeID = nil; + if (error == CHIP_NO_ERROR) { + nodeID = @(nodeId); + } + [strongDelegate controller:strongController commissioningComplete:nsError nodeID:nodeID]; + }); + return; + } + // If only the DEPRECATED function is defined if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:)]) { dispatch_async(mQueue, ^{ NSError * nsError = [MTRError errorForCHIPErrorCode:error]; @@ -109,3 +140,16 @@ } } } + +@implementation MTRProductIdentity + +- (instancetype)initWithVendorID:(NSNumber *)vendorID productID:(NSNumber *)productID +{ + if (self = [super init]) { + _vendorID = vendorID; + _productID = productID; + } + return self; +} + +@end