21
21
#include < controller/AutoCommissioner.h>
22
22
#include < controller/CHIPDeviceController.h>
23
23
#include < controller/CommissionerDiscoveryController.h>
24
+ #include < controller/CurrentFabricRemover.h>
24
25
#include < controller/ExampleOperationalCredentialsIssuer.h>
25
26
#include < controller/OperationalCredentialsDelegate.h>
26
27
#include < credentials/DeviceAttestationCredsProvider.h>
@@ -46,6 +47,44 @@ namespace esp_matter {
46
47
namespace controller {
47
48
48
49
#ifndef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
50
+ typedef void (*remove_fabric_callback)(chip::NodeId remoteNodeId, CHIP_ERROR status);
51
+
52
+ class auto_fabric_remover : private chip ::Controller::CurrentFabricRemover
53
+ {
54
+ public:
55
+ static esp_err_t remove_fabric (chip::Controller::DeviceController *controller, chip::NodeId remote_node,
56
+ remove_fabric_callback callback)
57
+ {
58
+ auto * remover = chip::Platform::New<auto_fabric_remover>(controller, callback);
59
+ if (remover == nullptr ) {
60
+ return ESP_ERR_NO_MEM;
61
+ }
62
+ CHIP_ERROR err = remover->CurrentFabricRemover ::RemoveCurrentFabric (remote_node, &remover->m_matter_callback );
63
+ if (err != CHIP_NO_ERROR)
64
+ {
65
+ // If failing to call RemoveCurrentFabric(), delete the remover here. Otherwise the remover will be deleted
66
+ // in on_remove_current_fabric().
67
+ chip::Platform::Delete (remover);
68
+ }
69
+ return err == CHIP_NO_ERROR ? ESP_OK : ESP_FAIL;
70
+ }
71
+
72
+ auto_fabric_remover (chip::Controller::DeviceController *controller, remove_fabric_callback callback) :
73
+ chip::Controller::CurrentFabricRemover (controller), m_matter_callback(on_remove_current_fabric, this ),
74
+ m_remove_fabric_callback (callback) {}
75
+ private:
76
+ static void on_remove_current_fabric (void * context, chip::NodeId remote_node, CHIP_ERROR status)
77
+ {
78
+ auto *self = static_cast <auto_fabric_remover *>(context);
79
+ if (self && self->m_remove_fabric_callback ) {
80
+ self->m_remove_fabric_callback (remote_node, status);
81
+ }
82
+ chip::Platform::Delete (self);
83
+ }
84
+ chip::Callback::Callback<chip::Controller::OnCurrentFabricRemove> m_matter_callback;
85
+ remove_fabric_callback m_remove_fabric_callback;
86
+ };
87
+
49
88
class matter_controller_client {
50
89
public:
51
90
class controller_storage_delegate : public chip ::PersistentStorageDelegate {
@@ -94,6 +133,10 @@ class matter_controller_client {
94
133
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
95
134
esp_err_t setup_commissioner ();
96
135
MatterDeviceCommissioner *get_commissioner () { return &m_device_commissioner; }
136
+ esp_err_t unpair (NodeId remote_node, remove_fabric_callback callback = nullptr )
137
+ {
138
+ return auto_fabric_remover::remove_fabric (&m_device_commissioner, remote_node, callback);
139
+ }
97
140
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY
98
141
CommissionerDiscoveryController *get_discovery_controller () { return &m_commissioner_discovery_controller; }
99
142
#endif
0 commit comments