From 3cfd9e55bb27e58a2418c0d1c082e396a88c64db Mon Sep 17 00:00:00 2001 From: WanqQixiang <wangqixiang@espressif.com> Date: Mon, 29 May 2023 18:57:18 +0800 Subject: [PATCH 1/3] app: Fix clusters delegates table check --- .../account-login-server/account-login-server.cpp | 4 ++-- .../application-basic-server.cpp | 4 ++-- .../application-launcher-server.cpp | 4 ++-- src/app/clusters/channel-server/channel-server.cpp | 4 ++-- .../color-control-server/color-control-server.h | 14 ++++++++------ .../content-launch-server.cpp | 4 ++-- .../clusters/door-lock-server/door-lock-server.h | 6 +++++- .../keypad-input-server/keypad-input-server.cpp | 4 ++-- .../media-playback-server.cpp | 4 ++-- .../target-navigator-server.cpp | 4 ++-- .../window-covering-server.cpp | 5 ++--- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/app/clusters/account-login-server/account-login-server.cpp b/src/app/clusters/account-login-server/account-login-server.cpp index da1cafacbd51ad..c3bd3093f92073 100644 --- a/src/app/clusters/account-login-server/account-login-server.cpp +++ b/src/app/clusters/account-login-server/account-login-server.cpp @@ -67,7 +67,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "AccountLogin NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, AccountLogin::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kAccountLoginDeletageTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -90,7 +90,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, AccountLogin::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kAccountLoginDeletageTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/application-basic-server/application-basic-server.cpp b/src/app/clusters/application-basic-server/application-basic-server.cpp index c71282933e3646..d00d028a583527 100644 --- a/src/app/clusters/application-basic-server/application-basic-server.cpp +++ b/src/app/clusters/application-basic-server/application-basic-server.cpp @@ -68,7 +68,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "ApplicationBasic NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kApplicationBasicDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -91,7 +91,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationBasic::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kApplicationBasicDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.cpp b/src/app/clusters/application-launcher-server/application-launcher-server.cpp index e3ed24e0ad39ea..bea77f5dd087cd 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.cpp +++ b/src/app/clusters/application-launcher-server/application-launcher-server.cpp @@ -75,7 +75,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "ApplicationLauncher NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kApplicationLauncherDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -98,7 +98,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kApplicationLauncherDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/channel-server/channel-server.cpp b/src/app/clusters/channel-server/channel-server.cpp index 72c0f59b06a66d..9aa79272cafd8e 100644 --- a/src/app/clusters/channel-server/channel-server.cpp +++ b/src/app/clusters/channel-server/channel-server.cpp @@ -62,7 +62,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "Channel NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, Channel::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kChannelDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -85,7 +85,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, Channel::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kChannelDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/color-control-server/color-control-server.h b/src/app/clusters/color-control-server/color-control-server.h index e9a87182770fb8..3de1cd22418c00 100644 --- a/src/app/clusters/color-control-server/color-control-server.h +++ b/src/app/clusters/color-control-server/color-control-server.h @@ -237,22 +237,24 @@ class ColorControlServer * Attributes Declaration *********************************************************/ static ColorControlServer instance; + static constexpr size_t kColorControlClusterServerMaxEndpointCount = + EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV - ColorHueTransitionState colorHueTransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; - Color16uTransitionState colorSatTransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + ColorHueTransitionState colorHueTransitionStates[kColorControlClusterServerMaxEndpointCount]; + Color16uTransitionState colorSatTransitionStates[kColorControlClusterServerMaxEndpointCount]; #endif #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_XY - Color16uTransitionState colorXtransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; - Color16uTransitionState colorYtransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + Color16uTransitionState colorXtransitionStates[kColorControlClusterServerMaxEndpointCount]; + Color16uTransitionState colorYtransitionStates[kColorControlClusterServerMaxEndpointCount]; #endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_XY #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP - Color16uTransitionState colorTempTransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + Color16uTransitionState colorTempTransitionStates[kColorControlClusterServerMaxEndpointCount]; #endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP - EmberEventControl eventControls[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + EmberEventControl eventControls[kColorControlClusterServerMaxEndpointCount]; }; /********************************************************** diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index f5a700ff8a972d..d9b4eab150d4a4 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -67,7 +67,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "Content Launcher NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ContentLauncher::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kContentLaunchDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -90,7 +90,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ContentLauncher::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kContentLaunchDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index 5728a4a891c559..2ea033bcfc7617 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -29,6 +29,7 @@ #include <app/ConcreteCommandPath.h> #include <app/util/af.h> #include <app/util/config.h> +#include <platform/CHIPDeviceConfig.h> #include <protocols/interaction_model/StatusCode.h> #ifndef DOOR_LOCK_SERVER_ENDPOINT @@ -553,7 +554,10 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData); - std::array<EmberAfDoorLockEndpointContext, EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT> mEndpointCtx; + static constexpr size_t kDoorLockClusterServerMaxEndpointCount = + EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + + std::array<EmberAfDoorLockEndpointContext, kDoorLockClusterServerMaxEndpointCount> mEndpointCtx; static DoorLockServer instance; }; diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.cpp b/src/app/clusters/keypad-input-server/keypad-input-server.cpp index 9790e2f5a6b6ab..b7e90d32e03ce2 100644 --- a/src/app/clusters/keypad-input-server/keypad-input-server.cpp +++ b/src/app/clusters/keypad-input-server/keypad-input-server.cpp @@ -70,7 +70,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "KeypadInput NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, KeypadInput::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kKeypadInputDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -93,7 +93,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, KeypadInput::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kKeypadInputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/media-playback-server/media-playback-server.cpp b/src/app/clusters/media-playback-server/media-playback-server.cpp index 979bf49116b34b..a158b72154f613 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.cpp +++ b/src/app/clusters/media-playback-server/media-playback-server.cpp @@ -70,7 +70,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogError(Zcl, "MediaPlayback NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, MediaPlayback::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kMediaPlaybackDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -93,7 +93,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, MediaPlayback::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kMediaPlaybackDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.cpp b/src/app/clusters/target-navigator-server/target-navigator-server.cpp index 0d71e6665006d3..b4083e69e41a15 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.cpp +++ b/src/app/clusters/target-navigator-server/target-navigator-server.cpp @@ -69,7 +69,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "TargetNavigator NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, TargetNavigator::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kTargetNavigatorDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -92,7 +92,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, TargetNavigator::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kTargetNavigatorDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/window-covering-server/window-covering-server.cpp b/src/app/clusters/window-covering-server/window-covering-server.cpp index d01f2fac668746..d008adcf4983fb 100644 --- a/src/app/clusters/window-covering-server/window-covering-server.cpp +++ b/src/app/clusters/window-covering-server/window-covering-server.cpp @@ -54,8 +54,7 @@ Delegate * gDelegateTable[kWindowCoveringDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, WindowCovering::Id); - return ((ep == kInvalidEndpointId || ep >= EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr - : gDelegateTable[ep]); + return ((ep == kInvalidEndpointId || ep >= kWindowCoveringDelegateTableSize) ? nullptr : gDelegateTable[ep]); } /* @@ -598,7 +597,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, WindowCovering::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kWindowCoveringDelegateTableSize) { gDelegateTable[ep] = delegate; } From cccb6ffe6596bf3b71df115dfaa394ebbf3e4abc Mon Sep 17 00:00:00 2001 From: WanqQixiang <wangqixiang@espressif.com> Date: Wed, 31 May 2023 15:45:49 +0800 Subject: [PATCH 2/3] replace emberAfFindClusterServerEndpointIndex with emberAfGetClusterServerEndpointIndex --- .../account-login-server.cpp | 8 +++++--- .../application-basic-server.cpp | 8 +++++--- .../application-launcher-server.cpp | 8 +++++--- .../audio-output-server.cpp | 10 ++++++---- .../clusters/channel-server/channel-server.cpp | 6 +++--- .../color-control-server.cpp | 18 ++++++++++++------ .../content-launch-server.cpp | 8 +++++--- .../door-lock-server/door-lock-server.cpp | 4 ++-- .../keypad-input-server.cpp | 8 +++++--- .../clusters/level-control/level-control.cpp | 5 +++-- .../low-power-server/low-power-server.cpp | 11 +++++++---- .../media-input-server/media-input-server.cpp | 10 ++++++---- .../media-playback-server.cpp | 8 +++++--- .../target-navigator-server.cpp | 8 +++++--- .../wake-on-lan-server/wake-on-lan-server.cpp | 8 ++++---- .../window-covering-server.cpp | 8 +++++--- 16 files changed, 83 insertions(+), 53 deletions(-) diff --git a/src/app/clusters/account-login-server/account-login-server.cpp b/src/app/clusters/account-login-server/account-login-server.cpp index c3bd3093f92073..85729448443537 100644 --- a/src/app/clusters/account-login-server/account-login-server.cpp +++ b/src/app/clusters/account-login-server/account-login-server.cpp @@ -66,7 +66,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "AccountLogin NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, AccountLogin::Id); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, AccountLogin::Id, EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kAccountLoginDeletageTableSize) ? nullptr : gDelegateTable[ep]); } @@ -88,8 +89,9 @@ namespace AccountLogin { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, AccountLogin::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, AccountLogin::Id, EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kAccountLoginDeletageTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/application-basic-server/application-basic-server.cpp b/src/app/clusters/application-basic-server/application-basic-server.cpp index d00d028a583527..e7f8c648d2ae8d 100644 --- a/src/app/clusters/application-basic-server/application-basic-server.cpp +++ b/src/app/clusters/application-basic-server/application-basic-server.cpp @@ -67,7 +67,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "ApplicationBasic NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id, + EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kApplicationBasicDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -89,8 +90,9 @@ namespace ApplicationBasic { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationBasic::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationBasic::Id, + EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kApplicationBasicDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.cpp b/src/app/clusters/application-launcher-server/application-launcher-server.cpp index bea77f5dd087cd..ee2e4c107fefc6 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.cpp +++ b/src/app/clusters/application-launcher-server/application-launcher-server.cpp @@ -74,7 +74,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "ApplicationLauncher NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id, + EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kApplicationLauncherDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -96,8 +97,9 @@ namespace ApplicationLauncher { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id, + EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kApplicationLauncherDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/audio-output-server/audio-output-server.cpp b/src/app/clusters/audio-output-server/audio-output-server.cpp index 81b94192fbb2d7..c0d67a5846c2b6 100644 --- a/src/app/clusters/audio-output-server/audio-output-server.cpp +++ b/src/app/clusters/audio-output-server/audio-output-server.cpp @@ -52,8 +52,9 @@ Delegate * gDelegateTable[kAudioOutputDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id); - return (ep == 0xFFFF ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id, + EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep == 0xFFFF || ep >= kAudioOutputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -74,8 +75,9 @@ namespace AudioOutput { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id); - if (ep != 0xFFFF) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id, + EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + if (ep != 0xFFFF && ep < kAudioOutputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/channel-server/channel-server.cpp b/src/app/clusters/channel-server/channel-server.cpp index 9aa79272cafd8e..e3eca0c8618ec4 100644 --- a/src/app/clusters/channel-server/channel-server.cpp +++ b/src/app/clusters/channel-server/channel-server.cpp @@ -61,7 +61,7 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "Channel NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, Channel::Id); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, Channel::Id, EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kChannelDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -83,8 +83,8 @@ namespace Channel { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, Channel::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, Channel::Id, EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kChannelDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index e80e87b0ea9440..707e1ba73a328b 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -301,7 +301,8 @@ uint16_t ColorControlServer::computeTransitionTimeFromStateAndRate(ColorControlS */ EmberEventControl * ColorControlServer::getEventControl(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, ColorControl::Id, EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); EmberEventControl * event = nullptr; if (index < ArraySize(eventControls)) @@ -424,7 +425,8 @@ bool ColorControlServer::computeNewColor16uValue(ColorControlServer::Color16uTra */ ColorControlServer::ColorHueTransitionState * ColorControlServer::getColorHueTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, ColorControl::Id, EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); ColorHueTransitionState * state = nullptr; if (index < ArraySize(colorHueTransitionStates)) @@ -442,7 +444,8 @@ ColorControlServer::ColorHueTransitionState * ColorControlServer::getColorHueTra */ ColorControlServer::Color16uTransitionState * ColorControlServer::getSaturationTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, ColorControl::Id, EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); Color16uTransitionState * state = nullptr; if (index < ArraySize(colorSatTransitionStates)) @@ -1680,7 +1683,8 @@ void ColorControlServer::updateHueSatCommand(EndpointId endpoint) */ ColorControlServer::Color16uTransitionState * ColorControlServer::getXTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, ColorControl::Id, EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); Color16uTransitionState * state = nullptr; if (index < ArraySize(colorXtransitionStates)) @@ -1699,7 +1703,8 @@ ColorControlServer::Color16uTransitionState * ColorControlServer::getXTransition */ ColorControlServer::Color16uTransitionState * ColorControlServer::getYTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, ColorControl::Id, EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); Color16uTransitionState * state = nullptr; if (index < ArraySize(colorYtransitionStates)) @@ -2026,7 +2031,8 @@ void ColorControlServer::updateXYCommand(EndpointId endpoint) */ ColorControlServer::Color16uTransitionState * ColorControlServer::getTempTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + uint16_t index = + emberAfGetClusterServerEndpointIndex(endpoint, ColorControl::Id, EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); Color16uTransitionState * state = nullptr; if (index < ArraySize(colorTempTransitionStates)) diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index d9b4eab150d4a4..409600055728d6 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -66,7 +66,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "Content Launcher NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ContentLauncher::Id); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ContentLauncher::Id, + EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kContentLaunchDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -88,8 +89,9 @@ namespace ContentLauncher { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ContentLauncher::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ContentLauncher::Id, + EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kContentLaunchDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index f63248d022676b..b9baf23c9f8c4f 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -3284,8 +3284,8 @@ CHIP_ERROR DoorLockServer::sendClusterResponse(chip::app::CommandHandler * comma EmberAfDoorLockEndpointContext * DoorLockServer::getContext(chip::EndpointId endpointId) { - auto index = emberAfFindClusterServerEndpointIndex(endpointId, ::Id); - if (index != 0xFFFF) + auto index = emberAfGetClusterServerEndpointIndex(endpointId, ::Id, EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT); + if (index != 0xFFFF && index < kDoorLockClusterServerMaxEndpointCount) { return &mEndpointCtx[index]; } diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.cpp b/src/app/clusters/keypad-input-server/keypad-input-server.cpp index b7e90d32e03ce2..3fe239b8fa29d8 100644 --- a/src/app/clusters/keypad-input-server/keypad-input-server.cpp +++ b/src/app/clusters/keypad-input-server/keypad-input-server.cpp @@ -69,7 +69,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "KeypadInput NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, KeypadInput::Id); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, KeypadInput::Id, EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kKeypadInputDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -91,8 +92,9 @@ namespace KeypadInput { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, KeypadInput::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, KeypadInput::Id, EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kKeypadInputDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/level-control/level-control.cpp b/src/app/clusters/level-control/level-control.cpp index 5a732074dd0851..19a63c879c5c51 100644 --- a/src/app/clusters/level-control/level-control.cpp +++ b/src/app/clusters/level-control/level-control.cpp @@ -194,8 +194,9 @@ static void cancelEndpointTimerCallback(EndpointId endpoint) static EmberAfLevelControlState * getState(EndpointId endpoint) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, LevelControl::Id); - return (ep == 0xFFFF ? nullptr : &stateTable[ep]); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, LevelControl::Id, EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep == 0xFFFF || ep >= kLevelControlStateTableSize ? nullptr : &stateTable[ep]); } #if !defined(IGNORE_LEVEL_CONTROL_CLUSTER_OPTIONS) && defined(EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP) diff --git a/src/app/clusters/low-power-server/low-power-server.cpp b/src/app/clusters/low-power-server/low-power-server.cpp index 66b618c6b50636..5a60e429362af0 100644 --- a/src/app/clusters/low-power-server/low-power-server.cpp +++ b/src/app/clusters/low-power-server/low-power-server.cpp @@ -33,6 +33,7 @@ #include <protocols/interaction_model/StatusCode.h> using namespace chip; +using namespace chip::app::Clusters; using namespace chip::app::Clusters::LowPower; static constexpr size_t kLowPowerDelegateTableSize = @@ -49,8 +50,9 @@ Delegate * gDelegateTable[kLowPowerDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id); - return (ep == 0xFFFF ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id, + EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep == 0xFFFF || ep >= kLowPowerDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -71,8 +73,9 @@ namespace LowPower { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id); - if (ep != 0xFFFF) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id, + EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT); + if (ep != 0xFFFF && ep < kLowPowerDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/media-input-server/media-input-server.cpp b/src/app/clusters/media-input-server/media-input-server.cpp index 7c19ec264f12a7..f3d6468fe9746d 100644 --- a/src/app/clusters/media-input-server/media-input-server.cpp +++ b/src/app/clusters/media-input-server/media-input-server.cpp @@ -52,8 +52,9 @@ Delegate * gDelegateTable[kMediaInputDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::MediaInput::Id); - return (ep == 0xFFFF ? nullptr : gDelegateTable[ep]); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, MediaInput::Id, EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep == 0xFFFF || ep >= kMediaInputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -74,8 +75,9 @@ namespace MediaInput { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::MediaInput::Id); - if (ep != 0xFFFF) + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, MediaInput::Id, EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + if (ep != 0xFFFF && ep < kMediaInputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/media-playback-server/media-playback-server.cpp b/src/app/clusters/media-playback-server/media-playback-server.cpp index a158b72154f613..a0a6752ccf869b 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.cpp +++ b/src/app/clusters/media-playback-server/media-playback-server.cpp @@ -69,7 +69,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogError(Zcl, "MediaPlayback NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, MediaPlayback::Id); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, MediaPlayback::Id, EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kMediaPlaybackDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -91,8 +92,9 @@ namespace MediaPlayback { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, MediaPlayback::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, MediaPlayback::Id, EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kMediaPlaybackDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.cpp b/src/app/clusters/target-navigator-server/target-navigator-server.cpp index b4083e69e41a15..5a169bd5f574ca 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.cpp +++ b/src/app/clusters/target-navigator-server/target-navigator-server.cpp @@ -68,7 +68,8 @@ Delegate * GetDelegate(EndpointId endpoint) #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED ChipLogProgress(Zcl, "TargetNavigator NOT returning ContentApp delegate for endpoint:%u", endpoint); - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, TargetNavigator::Id); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, TargetNavigator::Id, + EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == 0xFFFF || ep >= kTargetNavigatorDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -90,8 +91,9 @@ namespace TargetNavigator { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, TargetNavigator::Id); - // if endpoint is found and is not a dynamic endpoint + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, TargetNavigator::Id, + EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found if (ep != 0xFFFF && ep < kTargetNavigatorDelegateTableSize) { gDelegateTable[ep] = delegate; diff --git a/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp index 78878d0baf7af8..1273ec20a92478 100644 --- a/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp +++ b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp @@ -51,8 +51,8 @@ Delegate * gDelegateTable[kWakeOnLanDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::WakeOnLan::Id); - return (ep == 0xFFFF ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, WakeOnLan::Id, EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep == 0xFFFF || ep >= kWakeOnLanDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -73,8 +73,8 @@ namespace WakeOnLan { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::WakeOnLan::Id); - if (ep != 0xFFFF) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, WakeOnLan::Id, EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT); + if (ep != 0xFFFF && ep < kWakeOnLanDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/window-covering-server/window-covering-server.cpp b/src/app/clusters/window-covering-server/window-covering-server.cpp index d008adcf4983fb..84699ff197be1b 100644 --- a/src/app/clusters/window-covering-server/window-covering-server.cpp +++ b/src/app/clusters/window-covering-server/window-covering-server.cpp @@ -53,7 +53,8 @@ Delegate * gDelegateTable[kWindowCoveringDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, WindowCovering::Id); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT); return ((ep == kInvalidEndpointId || ep >= kWindowCoveringDelegateTableSize) ? nullptr : gDelegateTable[ep]); } @@ -594,9 +595,10 @@ Status GetMotionLockStatus(chip::EndpointId endpoint) void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, WindowCovering::Id); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT); - // if endpoint is found and is not a dynamic endpoint + // if endpoint is found if (ep != 0xFFFF && ep < kWindowCoveringDelegateTableSize) { gDelegateTable[ep] = delegate; From 4158c78efb73093b7648c0fd278241c56c6e6373 Mon Sep 17 00:00:00 2001 From: WanqQixiang <wangqixiang@espressif.com> Date: Thu, 1 Jun 2023 11:06:47 +0800 Subject: [PATCH 3/3] remove InvalidEndpointIndex check --- .../clusters/account-login-server/account-login-server.cpp | 6 +++--- .../application-basic-server/application-basic-server.cpp | 5 +++-- .../application-launcher-server.cpp | 5 +++-- .../clusters/audio-output-server/audio-output-server.cpp | 5 +++-- src/app/clusters/channel-server/channel-server.cpp | 5 +++-- .../clusters/color-control-server/color-control-server.h | 2 ++ .../content-launch-server/content-launch-server.cpp | 5 +++-- src/app/clusters/door-lock-server/door-lock-server.cpp | 2 +- src/app/clusters/door-lock-server/door-lock-server.h | 1 + .../clusters/keypad-input-server/keypad-input-server.cpp | 5 +++-- src/app/clusters/level-control/level-control.cpp | 3 ++- src/app/clusters/low-power-server/low-power-server.cpp | 5 +++-- src/app/clusters/media-input-server/media-input-server.cpp | 5 +++-- .../media-playback-server/media-playback-server.cpp | 5 +++-- .../target-navigator-server/target-navigator-server.cpp | 5 +++-- src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp | 5 +++-- .../window-covering-server/window-covering-server.cpp | 5 +++-- 17 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/app/clusters/account-login-server/account-login-server.cpp b/src/app/clusters/account-login-server/account-login-server.cpp index 85729448443537..b9a05b8bc65cc8 100644 --- a/src/app/clusters/account-login-server/account-login-server.cpp +++ b/src/app/clusters/account-login-server/account-login-server.cpp @@ -46,7 +46,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kAccountLoginDeletageTableSize = EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; - +static_assert(kAccountLoginDeletageTableSize <= kEmberInvalidEndpointIndex, "AccountLogin Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -68,7 +68,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, AccountLogin::Id, EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kAccountLoginDeletageTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kAccountLoginDeletageTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -92,7 +92,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, AccountLogin::Id, EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kAccountLoginDeletageTableSize) + if (ep < kAccountLoginDeletageTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/application-basic-server/application-basic-server.cpp b/src/app/clusters/application-basic-server/application-basic-server.cpp index e7f8c648d2ae8d..e2bf100aea2358 100644 --- a/src/app/clusters/application-basic-server/application-basic-server.cpp +++ b/src/app/clusters/application-basic-server/application-basic-server.cpp @@ -45,6 +45,7 @@ using namespace chip::AppPlatform; static constexpr size_t kApplicationBasicDelegateTableSize = EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kApplicationBasicDelegateTableSize <= kEmberInvalidEndpointIndex, "ApplicationBasic Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -69,7 +70,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id, EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kApplicationBasicDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kApplicationBasicDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -93,7 +94,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationBasic::Id, EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kApplicationBasicDelegateTableSize) + if (ep < kApplicationBasicDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.cpp b/src/app/clusters/application-launcher-server/application-launcher-server.cpp index ee2e4c107fefc6..982f1e8249548b 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.cpp +++ b/src/app/clusters/application-launcher-server/application-launcher-server.cpp @@ -49,6 +49,7 @@ using namespace chip::Uint8; static constexpr size_t kApplicationLauncherDelegateTableSize = EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kApplicationLauncherDelegateTableSize <= kEmberInvalidEndpointIndex, "ApplicationLauncher Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -76,7 +77,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id, EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kApplicationLauncherDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kApplicationLauncherDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -100,7 +101,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id, EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kApplicationLauncherDelegateTableSize) + if (ep < kApplicationLauncherDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/audio-output-server/audio-output-server.cpp b/src/app/clusters/audio-output-server/audio-output-server.cpp index c0d67a5846c2b6..d73f340547ce47 100644 --- a/src/app/clusters/audio-output-server/audio-output-server.cpp +++ b/src/app/clusters/audio-output-server/audio-output-server.cpp @@ -40,6 +40,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kAudioOutputDelegateTableSize = EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kAudioOutputDelegateTableSize <= kEmberInvalidEndpointIndex, "AudioOutput Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -54,7 +55,7 @@ Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id, EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT); - return (ep == 0xFFFF || ep >= kAudioOutputDelegateTableSize ? nullptr : gDelegateTable[ep]); + return (ep >= kAudioOutputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -77,7 +78,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id, EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT); - if (ep != 0xFFFF && ep < kAudioOutputDelegateTableSize) + if (ep < kAudioOutputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/channel-server/channel-server.cpp b/src/app/clusters/channel-server/channel-server.cpp index e3eca0c8618ec4..eaf4958270b2a0 100644 --- a/src/app/clusters/channel-server/channel-server.cpp +++ b/src/app/clusters/channel-server/channel-server.cpp @@ -39,6 +39,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kChannelDelegateTableSize = EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kChannelDelegateTableSize <= kEmberInvalidEndpointIndex, "Channel Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -62,7 +63,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "Channel NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, Channel::Id, EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kChannelDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kChannelDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -85,7 +86,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, Channel::Id, EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kChannelDelegateTableSize) + if (ep < kChannelDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/color-control-server/color-control-server.h b/src/app/clusters/color-control-server/color-control-server.h index 3de1cd22418c00..5f73e6a37475e3 100644 --- a/src/app/clusters/color-control-server/color-control-server.h +++ b/src/app/clusters/color-control-server/color-control-server.h @@ -21,6 +21,7 @@ #include <app/CommandHandler.h> #include <app/ConcreteCommandPath.h> #include <app/util/af-types.h> +#include <app/util/af.h> #include <app/util/basic-types.h> #include <app/util/config.h> #include <platform/CHIPDeviceConfig.h> @@ -239,6 +240,7 @@ class ColorControlServer static ColorControlServer instance; static constexpr size_t kColorControlClusterServerMaxEndpointCount = EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + static_assert(kColorControlClusterServerMaxEndpointCount <= kEmberInvalidEndpointIndex, "ColorControl endpoint count error"); #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV ColorHueTransitionState colorHueTransitionStates[kColorControlClusterServerMaxEndpointCount]; diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index 409600055728d6..fc0321ecb296f9 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -44,6 +44,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kContentLaunchDelegateTableSize = EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kContentLaunchDelegateTableSize < kEmberInvalidEndpointIndex, "ContentLaunch Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -68,7 +69,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ContentLauncher::Id, EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kContentLaunchDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kContentLaunchDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -92,7 +93,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ContentLauncher::Id, EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kContentLaunchDelegateTableSize) + if (ep < kContentLaunchDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index b9baf23c9f8c4f..f122398b9ed03f 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -3285,7 +3285,7 @@ CHIP_ERROR DoorLockServer::sendClusterResponse(chip::app::CommandHandler * comma EmberAfDoorLockEndpointContext * DoorLockServer::getContext(chip::EndpointId endpointId) { auto index = emberAfGetClusterServerEndpointIndex(endpointId, ::Id, EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT); - if (index != 0xFFFF && index < kDoorLockClusterServerMaxEndpointCount) + if (index < kDoorLockClusterServerMaxEndpointCount) { return &mEndpointCtx[index]; } diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index 2ea033bcfc7617..ec601c0645cbe1 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -556,6 +556,7 @@ class DoorLockServer static constexpr size_t kDoorLockClusterServerMaxEndpointCount = EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + static_assert(kDoorLockClusterServerMaxEndpointCount <= kEmberInvalidEndpointIndex, "DoorLock Endpoint count error"); std::array<EmberAfDoorLockEndpointContext, kDoorLockClusterServerMaxEndpointCount> mEndpointCtx; diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.cpp b/src/app/clusters/keypad-input-server/keypad-input-server.cpp index 3fe239b8fa29d8..9bcbfee6baae39 100644 --- a/src/app/clusters/keypad-input-server/keypad-input-server.cpp +++ b/src/app/clusters/keypad-input-server/keypad-input-server.cpp @@ -47,6 +47,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kKeypadInputDelegateTableSize = EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kKeypadInputDelegateTableSize < kEmberInvalidEndpointIndex, "KeypadInput Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -71,7 +72,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, KeypadInput::Id, EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kKeypadInputDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kKeypadInputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -95,7 +96,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, KeypadInput::Id, EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kKeypadInputDelegateTableSize) + if (ep < kKeypadInputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/level-control/level-control.cpp b/src/app/clusters/level-control/level-control.cpp index 19a63c879c5c51..35ebf4f415f98d 100644 --- a/src/app/clusters/level-control/level-control.cpp +++ b/src/app/clusters/level-control/level-control.cpp @@ -73,6 +73,7 @@ static bool areStartUpLevelControlServerAttributesNonVolatile(EndpointId endpoin static constexpr size_t kLevelControlStateTableSize = EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kLevelControlStateTableSize <= kEmberInvalidEndpointIndex, "LevelControl state table size error"); struct CallbackScheduleState { @@ -196,7 +197,7 @@ static EmberAfLevelControlState * getState(EndpointId endpoint) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LevelControl::Id, EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); - return (ep == 0xFFFF || ep >= kLevelControlStateTableSize ? nullptr : &stateTable[ep]); + return (ep >= kLevelControlStateTableSize ? nullptr : &stateTable[ep]); } #if !defined(IGNORE_LEVEL_CONTROL_CLUSTER_OPTIONS) && defined(EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP) diff --git a/src/app/clusters/low-power-server/low-power-server.cpp b/src/app/clusters/low-power-server/low-power-server.cpp index 5a60e429362af0..5881d2e56fc322 100644 --- a/src/app/clusters/low-power-server/low-power-server.cpp +++ b/src/app/clusters/low-power-server/low-power-server.cpp @@ -38,6 +38,7 @@ using namespace chip::app::Clusters::LowPower; static constexpr size_t kLowPowerDelegateTableSize = EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kLowPowerDelegateTableSize <= kEmberInvalidEndpointIndex, "LowPower Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -52,7 +53,7 @@ Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id, EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT); - return (ep == 0xFFFF || ep >= kLowPowerDelegateTableSize ? nullptr : gDelegateTable[ep]); + return (ep >= kLowPowerDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -75,7 +76,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id, EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT); - if (ep != 0xFFFF && ep < kLowPowerDelegateTableSize) + if (ep < kLowPowerDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/media-input-server/media-input-server.cpp b/src/app/clusters/media-input-server/media-input-server.cpp index f3d6468fe9746d..71e6223b5ce2aa 100644 --- a/src/app/clusters/media-input-server/media-input-server.cpp +++ b/src/app/clusters/media-input-server/media-input-server.cpp @@ -40,6 +40,7 @@ using Protocols::InteractionModel::Status; static constexpr size_t kMediaInputDelegateTableSize = EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kMediaInputDelegateTableSize <= kEmberInvalidEndpointIndex, "MediaInput Delegate tablle size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -54,7 +55,7 @@ Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, MediaInput::Id, EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); - return (ep == 0xFFFF || ep >= kMediaInputDelegateTableSize ? nullptr : gDelegateTable[ep]); + return (ep >= kMediaInputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -77,7 +78,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, MediaInput::Id, EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); - if (ep != 0xFFFF && ep < kMediaInputDelegateTableSize) + if (ep < kMediaInputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/media-playback-server/media-playback-server.cpp b/src/app/clusters/media-playback-server/media-playback-server.cpp index a0a6752ccf869b..443880cc12e40b 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.cpp +++ b/src/app/clusters/media-playback-server/media-playback-server.cpp @@ -47,6 +47,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kMediaPlaybackDelegateTableSize = EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kMediaPlaybackDelegateTableSize <= kEmberInvalidEndpointIndex, "kMediaPlayback Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -71,7 +72,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, MediaPlayback::Id, EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kMediaPlaybackDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kMediaPlaybackDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -95,7 +96,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, MediaPlayback::Id, EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kMediaPlaybackDelegateTableSize) + if (ep < kMediaPlaybackDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.cpp b/src/app/clusters/target-navigator-server/target-navigator-server.cpp index 5a169bd5f574ca..d1146d9e3bd209 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.cpp +++ b/src/app/clusters/target-navigator-server/target-navigator-server.cpp @@ -46,6 +46,7 @@ using chip::Protocols::InteractionModel::Status; static constexpr size_t kTargetNavigatorDelegateTableSize = EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kTargetNavigatorDelegateTableSize <= kEmberInvalidEndpointIndex, "TargetNavigator Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -70,7 +71,7 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, TargetNavigator::Id, EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == 0xFFFF || ep >= kTargetNavigatorDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kTargetNavigatorDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -94,7 +95,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, TargetNavigator::Id, EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kTargetNavigatorDelegateTableSize) + if (ep < kTargetNavigatorDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp index 1273ec20a92478..15b514c9e3f247 100644 --- a/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp +++ b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp @@ -39,6 +39,7 @@ using namespace chip::app::Clusters::WakeOnLan; static constexpr size_t kWakeOnLanDelegateTableSize = EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kWakeOnLanDelegateTableSize <= kEmberInvalidEndpointIndex, "WakeOnLan Delegate table size error"); // ----------------------------------------------------------------------------- // Delegate Implementation @@ -52,7 +53,7 @@ Delegate * gDelegateTable[kWakeOnLanDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, WakeOnLan::Id, EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT); - return (ep == 0xFFFF || ep >= kWakeOnLanDelegateTableSize ? nullptr : gDelegateTable[ep]); + return (ep >= kWakeOnLanDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -74,7 +75,7 @@ namespace WakeOnLan { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, WakeOnLan::Id, EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT); - if (ep != 0xFFFF && ep < kWakeOnLanDelegateTableSize) + if (ep < kWakeOnLanDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/window-covering-server/window-covering-server.cpp b/src/app/clusters/window-covering-server/window-covering-server.cpp index 84699ff197be1b..15aa001c7f5b3c 100644 --- a/src/app/clusters/window-covering-server/window-covering-server.cpp +++ b/src/app/clusters/window-covering-server/window-covering-server.cpp @@ -48,6 +48,7 @@ namespace { constexpr size_t kWindowCoveringDelegateTableSize = EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; +static_assert(kWindowCoveringDelegateTableSize <= kEmberInvalidEndpointIndex, "WindowCovering Delegate table size error"); Delegate * gDelegateTable[kWindowCoveringDelegateTableSize] = { nullptr }; @@ -55,7 +56,7 @@ Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT); - return ((ep == kInvalidEndpointId || ep >= kWindowCoveringDelegateTableSize) ? nullptr : gDelegateTable[ep]); + return (ep >= kWindowCoveringDelegateTableSize ? nullptr : gDelegateTable[ep]); } /* @@ -599,7 +600,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found - if (ep != 0xFFFF && ep < kWindowCoveringDelegateTableSize) + if (ep < kWindowCoveringDelegateTableSize) { gDelegateTable[ep] = delegate; }