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..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 @@ -66,8 +66,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, AccountLogin::Id, EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kAccountLoginDeletageTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -88,9 +89,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, AccountLogin::Id, EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 c71282933e3646..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 @@ -67,8 +68,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id, + EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kApplicationBasicDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -89,9 +91,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationBasic::Id, + EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 e3ed24e0ad39ea..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 @@ -74,8 +75,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id, + EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kApplicationLauncherDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -96,9 +98,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id, + EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 81b94192fbb2d7..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 @@ -52,8 +53,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 >= kAudioOutputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -74,8 +76,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 < 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 72c0f59b06a66d..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 @@ -61,8 +62,8 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, Channel::Id, EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kChannelDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -83,9 +84,9 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, Channel::Id, EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + if (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/color-control-server/color-control-server.h b/src/app/clusters/color-control-server/color-control-server.h index e9a87182770fb8..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 #include #include +#include #include #include #include @@ -237,22 +238,25 @@ 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; + static_assert(kColorControlClusterServerMaxEndpointCount <= kEmberInvalidEndpointIndex, "ColorControl endpoint count error"); #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..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 @@ -66,8 +67,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ContentLauncher::Id, + EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kContentLaunchDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -88,9 +90,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ContentLauncher::Id, + EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 ef9101a7807dd7..7e788c7ecbe314 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -3295,8 +3295,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 < 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 05d1d5ee7e56bd..bb2ce23571ba8b 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 #include #include +#include #include #ifndef DOOR_LOCK_SERVER_ENDPOINT @@ -559,7 +560,11 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData); - std::array mEndpointCtx; + 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 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..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 @@ -69,8 +70,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, KeypadInput::Id, EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kKeypadInputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -91,9 +93,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, KeypadInput::Id, EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 66533df0a88e0e..966aa400ef0e83 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 { @@ -194,8 +195,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 >= 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..5881d2e56fc322 100644 --- a/src/app/clusters/low-power-server/low-power-server.cpp +++ b/src/app/clusters/low-power-server/low-power-server.cpp @@ -33,10 +33,12 @@ #include using namespace chip; +using namespace chip::app::Clusters; 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 @@ -49,8 +51,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 >= kLowPowerDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -71,8 +74,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 < 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..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 @@ -52,8 +53,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 >= kMediaInputDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -74,8 +76,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 < 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 979bf49116b34b..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 @@ -69,8 +70,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, MediaPlayback::Id, EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kMediaPlaybackDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -91,9 +93,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, MediaPlayback::Id, EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 0d71e6665006d3..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 @@ -68,8 +69,9 @@ 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); - return ((ep == 0xFFFF || ep >= EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, TargetNavigator::Id, + EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kTargetNavigatorDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -90,9 +92,10 @@ 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 - if (ep != 0xFFFF && ep < EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, TargetNavigator::Id, + EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + 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 78878d0baf7af8..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 @@ -51,8 +52,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 >= kWakeOnLanDelegateTableSize ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -73,8 +74,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 < 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 32515eeff0e8b5..5a08107bed7f35 100644 --- a/src/app/clusters/window-covering-server/window-covering-server.cpp +++ b/src/app/clusters/window-covering-server/window-covering-server.cpp @@ -48,14 +48,15 @@ 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 }; 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]); + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kWindowCoveringDelegateTableSize ? nullptr : gDelegateTable[ep]); } /* @@ -595,10 +596,11 @@ 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 (ep != 0xFFFF && ep < EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT) + // if endpoint is found + if (ep < kWindowCoveringDelegateTableSize) { gDelegateTable[ep] = delegate; }