diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.h b/src/darwin/Framework/CHIP/MTRDeviceController.h index 3ad0c37ea025bb..9d3623bbde1549 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController.h @@ -34,6 +34,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS @class MTRCommissioningParameters; @class MTRCommissionableBrowserResult; @class MTRSetupPayload; +@class MTRDevice; @protocol MTRDevicePairingDelegate; @protocol MTRDeviceControllerDelegate; @@ -269,6 +270,11 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) */ - (void)removeServerEndpoint:(MTRServerEndpoint *)endpoint MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6)); +/** + * Delete a device from a device controller, also purge storage for the device. + */ +- (void)deleteDevice:(MTRDevice *)device MTR_NEWLY_AVAILABLE; + /** * Compute a PASE verifier for the desired setup passcode. * diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 3b222a1e3eccfc..0377905bbc188a 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -387,6 +387,11 @@ - (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID return [self _deviceForNodeID:nodeID createIfNeeded:YES]; } +- (void)deleteDevice:(MTRDevice *)device +{ + [self removeDevice:device]; +} + - (void)removeDevice:(MTRDevice *)device { std::lock_guard lock(*self.deviceMapLock); diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm index 99398867ccfa68..507cbb65f17352 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm @@ -1314,6 +1314,12 @@ - (void)removeServerEndpointOnMatterQueue:(MTRServerEndpoint *)endpoint [_factory removeServerEndpoint:endpoint]; } +- (void)deleteDevice:(MTRDevice *)device +{ + // TODO NEED TO CLEAN UP DB HERE + MTR_LOG("%@: Delete device: %@", self, device); +} + - (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg { if (condition) { diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm b/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm index 827dad526025d0..ed9c3dec6b1c77 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm @@ -59,6 +59,9 @@ @implementation MTRDeviceController_XPC MTR_DEVICECONTROLLER_SIMPLE_REMOTE_XPC_COMMAND(updateControllerConfiguration : (NSDictionary *) controllerState, updateControllerConfiguration : (NSDictionary *) controllerState) +MTR_DEVICECONTROLLER_SIMPLE_REMOTE_XPC_COMMAND(deleteNodeID + : (NSNumber *) nodeID, deleteNodeID + : (NSNumber *) nodeID) - (void)_updateRegistrationInfo { @@ -95,6 +98,15 @@ - (void)removeDevice:(MTRDevice *)device [self _updateRegistrationInfo]; } +- (void)deleteDevice:(MTRDevice *)device +{ + MTR_LOG("%@: Delete device: %@", self, device); + if (device.nodeID) { + [self deleteNodeID:device.nodeID]; + } + [super deleteDevice:device]; +} + #pragma mark - XPC @synthesize controllerNodeID = _controllerNodeID; @synthesize compressedFabricID = _compressedFabricID; diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.h b/src/darwin/Framework/CHIP/MTRSetupPayload.h index d1cd5550bcf800..1de482641da233 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.h +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.h @@ -218,6 +218,8 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6)) @interface MTRSetupPayload () + ++ (BOOL)isValidSetupPIN:(NSUInteger)setupPIN MTR_NEWLY_AVAILABLE; @end @interface MTROptionalQRCodeInfo (Deprecated) diff --git a/src/darwin/Framework/CHIP/MTRSetupPayload.mm b/src/darwin/Framework/CHIP/MTRSetupPayload.mm index c4694884ea829d..aae4ba5f744f5b 100644 --- a/src/darwin/Framework/CHIP/MTRSetupPayload.mm +++ b/src/darwin/Framework/CHIP/MTRSetupPayload.mm @@ -206,6 +206,11 @@ @implementation MTRSetupPayload { NSNumber * _Nullable _shadowDiscriminator; } ++ (BOOL)isValidSetupPIN:(NSUInteger)setupPIN +{ + return [[MTRSetupPayload alloc] initWithPayload:[NSString stringWithFormat:@"%lu", static_cast(setupPIN)]] != nil; +} + + (void)initialize { // Some aspects of working with chip::SetupPayload use Platform memory primitives. diff --git a/src/darwin/Framework/CHIP/XPC Protocol/MTRXPCServerProtocol.h b/src/darwin/Framework/CHIP/XPC Protocol/MTRXPCServerProtocol.h index 45d19185d9184e..b060298e89fe3e 100644 --- a/src/darwin/Framework/CHIP/XPC Protocol/MTRXPCServerProtocol.h +++ b/src/darwin/Framework/CHIP/XPC Protocol/MTRXPCServerProtocol.h @@ -70,6 +70,7 @@ MTR_AVAILABLE(ios(18.2), macos(15.2), watchos(11.2), tvos(18.2)) // - (oneway void)deviceController:(NSUUID *)controller addServerEndpoint:(MTRServerEndpoint *)endpoint withReply:(void (^)(BOOL success))reply; // - (oneway void)deviceController:(NSUUID *)controller removeServerEndpoint:(MTRServerEndpoint *)endpoint; +- (oneway void)deviceController:(NSUUID *)controller deleteNodeID:(NSNumber *)nodeID; - (oneway void)deviceController:(NSUUID *)controller registerNodeID:(NSNumber *)nodeID; - (oneway void)deviceController:(NSUUID *)controller unregisterNodeID:(NSNumber *)nodeID;