diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index 83d6abc102701f..ecca799c81d07b 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -87,7 +87,7 @@ class AppCallbacks : public AppDelegate public: void OnCommissioningSessionEstablishmentStarted() {} void OnCommissioningSessionStarted() override { bluetoothLED.Set(true); } - void OnCommissioningSessionStopped(CHIP_ERROR err) override + void OnCommissioningSessionStopped() override { bluetoothLED.Set(false); pairingWindowLED.Set(false); diff --git a/examples/all-clusters-minimal-app/esp32/main/main.cpp b/examples/all-clusters-minimal-app/esp32/main/main.cpp index 43c6faa51a2972..a673a706291a58 100644 --- a/examples/all-clusters-minimal-app/esp32/main/main.cpp +++ b/examples/all-clusters-minimal-app/esp32/main/main.cpp @@ -86,7 +86,7 @@ class AppCallbacks : public AppDelegate public: void OnCommissioningSessionEstablishmentStarted() {} void OnCommissioningSessionStarted() override { bluetoothLED.Set(true); } - void OnCommissioningSessionStopped(CHIP_ERROR err) override + void OnCommissioningSessionStopped() override { bluetoothLED.Set(false); pairingWindowLED.Set(false); diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index cd9fe12a60a0bc..a13e84ca527cad 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -140,7 +140,7 @@ class AppCallbacks : public AppDelegate public: void OnCommissioningSessionEstablishmentStarted() {} void OnCommissioningSessionStarted() override { isComissioningStarted = true; } - void OnCommissioningSessionStopped(CHIP_ERROR err) override { isComissioningStarted = false; } + void OnCommissioningSessionStopped() override { isComissioningStarted = false; } void OnCommissioningWindowClosed() override { if (!isComissioningStarted) diff --git a/src/app/server/AppDelegate.h b/src/app/server/AppDelegate.h index 24dcf2e3a92ec5..78aafd578ecb75 100644 --- a/src/app/server/AppDelegate.h +++ b/src/app/server/AppDelegate.h @@ -29,14 +29,33 @@ class AppDelegate public: virtual ~AppDelegate() {} /** - * This is called on start of session establishment process + * This is called when the PBKDFParamRequest is received and indicates the start of the session establishment process */ virtual void OnCommissioningSessionEstablishmentStarted() {} + + /** + * This is called when the commissioning session has been established + */ virtual void OnCommissioningSessionStarted() {} - virtual void OnCommissioningSessionStopped(CHIP_ERROR err) {} + + /** + * This is called when the PASE establishment failed (such as, when an invalid passcode is provided) or PASE was established + * fine but then the fail-safe expired (including being expired by the commissioner) + * + * @param err CHIP_ERROR indicating the error that occurred during session establishment or the error accompanying the fail-safe + * timeout. + */ + virtual void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) {} + + /** + * This is called when the PASE establishment failed or PASE was established fine but then the fail-safe expired (including + * being expired by the commissioner) AND the commissioning window is closed. The window may be closed because the commissioning + * attempts limit was reached or advertising/listening for PASE failed. + */ + virtual void OnCommissioningSessionStopped() {} /* - * This is called anytime a basic or enhanced commissioning window is opened. + * This is called any time a basic or enhanced commissioning window is opened. * * The type of the window can be retrieved by calling * CommissioningWindowManager::CommissioningWindowStatusForCluster(), but @@ -44,5 +63,9 @@ class AppDelegate * fact open. */ virtual void OnCommissioningWindowOpened() {} + + /* + * This is called any time a basic or enhanced commissioning window is closed. + */ virtual void OnCommissioningWindowClosed() {} }; diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index c6287ab119e67d..a8c6fe1cea462c 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -152,6 +152,8 @@ void CommissioningWindowManager::HandleFailedAttempt(CHIP_ERROR err) #if CONFIG_NETWORK_LAYER_BLE mServer->GetBleLayerObject()->CloseAllBleConnections(); #endif + + CHIP_ERROR prevErr = err; if (mFailedCommissioningAttempts < kMaxFailedCommissioningAttempts) { // If the number of commissioning attempts has not exceeded maximum @@ -159,6 +161,11 @@ void CommissioningWindowManager::HandleFailedAttempt(CHIP_ERROR err) err = AdvertiseAndListenForPASE(); } + if (mAppDelegate != nullptr) + { + mAppDelegate->OnCommissioningSessionEstablishmentError(prevErr); + } + if (err != CHIP_NO_ERROR) { // The commissioning attempts limit was exceeded, or listening for @@ -167,7 +174,7 @@ void CommissioningWindowManager::HandleFailedAttempt(CHIP_ERROR err) if (mAppDelegate != nullptr) { - mAppDelegate->OnCommissioningSessionStopped(err); + mAppDelegate->OnCommissioningSessionStopped(); } } }