Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app: Fix clusters delegates table check #26922

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/app/clusters/account-login-server/account-login-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 0xFFFF || ep >= kAccountLoginDeletageTableSize) ? nullptr : gDelegateTable[ep]);
wqx6 marked this conversation as resolved.
Show resolved Hide resolved
}

bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
Expand All @@ -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 != 0xFFFF && ep < kAccountLoginDeletageTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,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 == 0xFFFF || ep >= kApplicationBasicDelegateTableSize) ? nullptr : gDelegateTable[ep]);
}

bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
Expand All @@ -89,9 +90,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 != 0xFFFF && ep < kApplicationBasicDelegateTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,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 == 0xFFFF || ep >= kApplicationLauncherDelegateTableSize) ? nullptr : gDelegateTable[ep]);
}

bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
Expand All @@ -96,9 +97,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 != 0xFFFF && ep < kApplicationLauncherDelegateTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
10 changes: 6 additions & 4 deletions src/app/clusters/audio-output-server/audio-output-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/clusters/channel-server/channel-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,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 == 0xFFFF || ep >= kChannelDelegateTableSize) ? nullptr : gDelegateTable[ep]);
}

bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
Expand All @@ -83,9 +83,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 != 0xFFFF && ep < kChannelDelegateTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
18 changes: 12 additions & 6 deletions src/app/clusters/color-control-server/color-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 8 additions & 6 deletions src/app/clusters/color-control-server/color-control-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

/**********************************************************
Expand Down
12 changes: 7 additions & 5 deletions src/app/clusters/content-launch-server/content-launch-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,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 == 0xFFFF || ep >= kContentLaunchDelegateTableSize) ? nullptr : gDelegateTable[ep]);
}

bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
Expand All @@ -88,9 +89,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 != 0xFFFF && ep < kContentLaunchDelegateTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down
12 changes: 7 additions & 5 deletions src/app/clusters/keypad-input-server/keypad-input-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,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 == 0xFFFF || ep >= kKeypadInputDelegateTableSize) ? nullptr : gDelegateTable[ep]);
}

bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
Expand All @@ -91,9 +92,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 != 0xFFFF && ep < kKeypadInputDelegateTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions src/app/clusters/low-power-server/low-power-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions src/app/clusters/media-input-server/media-input-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
Loading