From 60027211435e6013334c58274ca6d882f883c17b Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 21 Oct 2020 13:49:21 -0400 Subject: [PATCH] Make IAS Zone server compile (#3364) --- .../wifi-echo/server/esp32/main/component.mk | 2 +- .../esp32/main/gen/clusters-callback-stubs.c | 24 - .../ias-zone-server/ias-zone-server-cli.c | 246 --------- .../ias-zone-server/ias-zone-server-test.c | 513 ------------------ .../ias-zone-server/ias-zone-server.c | 34 +- .../ias-zone-server/ias-zone-server.h | 2 + src/app/util/af-event.cpp | 5 - 7 files changed, 25 insertions(+), 801 deletions(-) delete mode 100644 src/app/clusters/ias-zone-server/ias-zone-server-cli.c delete mode 100644 src/app/clusters/ias-zone-server/ias-zone-server-test.c diff --git a/examples/wifi-echo/server/esp32/main/component.mk b/examples/wifi-echo/server/esp32/main/component.mk index 17c86d612989ee..8eea98627c1229 100644 --- a/examples/wifi-echo/server/esp32/main/component.mk +++ b/examples/wifi-echo/server/esp32/main/component.mk @@ -38,8 +38,8 @@ COMPONENT_SRCDIRS := ../third_party/connectedhomeip/src/app/clusters/basic \ ../third_party/connectedhomeip/src/app/reporting \ ../third_party/connectedhomeip/src/app/clusters/door-lock-server \ + ../third_party/connectedhomeip/src/app/clusters/ias-zone-server \ # ../third_party/connectedhomeip/src/app/clusters/ias-zone-client \ -# ../third_party/connectedhomeip/src/app/clusters/ias-zone-server \ COMPONENT_EXTRA_INCLUDES := $(PROJECT_PATH)/third_party/connectedhomeip/src/app/util \ diff --git a/examples/wifi-echo/server/esp32/main/gen/clusters-callback-stubs.c b/examples/wifi-echo/server/esp32/main/gen/clusters-callback-stubs.c index 67331ef6610f2e..276f7dc8a76042 100644 --- a/examples/wifi-echo/server/esp32/main/gen/clusters-callback-stubs.c +++ b/examples/wifi-echo/server/esp32/main/gen/clusters-callback-stubs.c @@ -56,18 +56,6 @@ bool emberAfIasZoneClusterZoneEnrollRequestCallback(uint16_t zoneType, uint16_t return false; } -/** @brief IAS Zone Cluster Zone Enroll Response - * - * - * - * @param enrollResponseCode Ver.: always - * @param zoneId Ver.: always - */ -bool emberAfIasZoneClusterZoneEnrollResponseCallback(uint8_t enrollResponseCode, uint8_t zoneId) -{ - return false; -} - /** @brief IAS Zone Cluster Zone Status Change Notification * * @@ -86,18 +74,6 @@ bool emberAfIasZoneClusterZoneStatusChangeNotificationCallback(uint16_t zoneStat // endpoint_config.h callbacks, grep'd from SDK, comment these out as clusters come in void emberAfIasZoneClusterClientInitCallback(uint8_t endpoint) {} -void emberAfIasZoneClusterServerInitCallback(uint8_t endpoint) {} -void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, - EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, - EmberStatus status) -{} - -EmberAfStatus emberAfIasZoneClusterServerPreAttributeChangedCallback(uint8_t endpoint, EmberAfAttributeId attributeId, - EmberAfAttributeType attributeType, uint8_t size, - uint8_t * value) -{ - return EMBER_ZCL_STATUS_SUCCESS; -} void emberAfPollControlClusterServerAttributeChangedCallback(uint8_t endpoint, EmberAfAttributeId attributeId) {} void emberAfPollControlClusterServerInitCallback(uint8_t endpoint) {} diff --git a/src/app/clusters/ias-zone-server/ias-zone-server-cli.c b/src/app/clusters/ias-zone-server/ias-zone-server-cli.c deleted file mode 100644 index 61671e217440c0..00000000000000 --- a/src/app/clusters/ias-zone-server/ias-zone-server-cli.c +++ /dev/null @@ -1,246 +0,0 @@ -/** - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * - * Copyright (c) 2020 Silicon Labs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/**************************************************************************** - * @file - * @brief This is the source for the command line - *interface used for the ias zone server plugin. - ******************************************************************************* - ******************************************************************************/ - -#include "af.h" -#include "ias-zone-server.h" - -//----------------------------------------------------------------------------- -// Globals - -#define RESERVED_END 0x7FFF -#define MANUFACTURER_SPECIFIC_START 0x8000 -#define MANUFACTURER_SPECIFIC_END 0xFFFE - -void emberAfPluginIasZoneServerInfoCommand(void); -void emberAfPluginIasZoneServerChangeStatusCommand(void); -void emberAfPluginIasZoneServerSetEnrollmentMethodCommand(void); - -static const char * infoArguments[] = { - "endpoint", - NULL, -}; - -static const char * changeStatusArguments[] = { - "new-status", - "time-since-occurred-seconds", - "endpoint", - NULL, -}; - -static const char * setEnrollmentModeArguments[] = { - "endpoint", - "enrollmentMode", - NULL, -}; - -EmberCommandEntry emberAfPluginIasZoneServerCommands[] = { - emberCommandEntryActionWithDetails("info", emberAfPluginIasZoneServerInfoCommand, "", "Print IAS Zone information", - infoArguments), - emberCommandEntryActionWithDetails("change-status", emberAfPluginIasZoneServerChangeStatusCommand, "vu", - "Change the current Zone Status", changeStatusArguments), - emberCommandEntryActionWithDetails("set-enrollment-mode", emberAfPluginIasZoneServerSetEnrollmentMethodCommand, "uu", - "Change the current enrollment method", setEnrollmentModeArguments), - emberCommandEntryTerminator(), -}; - -typedef struct -{ - uint16_t zoneType; - const char * zoneTypeString; -} ZoneTypeToStringMap; - -// These functions and variables are only used to generate strings used with -// emberAfIasZoneClusterPrintln calls, so if EMBER_AF_PRINT_IAS_ZONE_CLUSTER is -// not defined and they are compiled in, these declarations generate "function -// declared but never referenced" warnings -#if defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_IAS_ZONE_CLUSTER) -static ZoneTypeToStringMap zoneTypeToStringMap[] = { - { 0x0000, "Standard CIE" }, - { 0x000d, "Motion Sensor" }, - { 0x0015, "Contact Switch" }, - { 0x0028, "Fire Sensor" }, - { 0x002a, "Water Sensor" }, - { 0x002b, "Gas Sensor" }, - { 0x002c, "Peersonal Emergency Device" }, - { 0x002d, "Vibration / Movement Sensor" }, - { 0x010f, "Remote Control" }, - { 0x0115, "Key Fob" }, - { 0x021d, "Keypad" }, - { 0x0225, "Standard Warning Device" }, - { 0xFFFF, NULL } // terminator -}; - -static const char manufacturerSpecificString[] = "Manufacturer Specific"; -static const char invalidZoneTypeString[] = "Invalid"; -static const char reservedString[] = "Reserved"; - -static const char notEnrolledString[] = "NOT Enrolled"; -static const char enrolledString[] = "Enrolled"; -static const char unknownZoneStateString[] = "Unknown"; - -//----------------------------------------------------------------------------- -// Functions - -static const char * getZoneTypeString(uint16_t type) -{ - uint16_t i = 0; - while (zoneTypeToStringMap[i].zoneTypeString != NULL) - { - if (zoneTypeToStringMap[i].zoneType == type) - { - return zoneTypeToStringMap[i].zoneTypeString; - } - i++; - } - - if (type <= RESERVED_END) - { - return reservedString; - } - - if (type >= MANUFACTURER_SPECIFIC_START && type <= MANUFACTURER_SPECIFIC_END) - { - return manufacturerSpecificString; - } - - return invalidZoneTypeString; -} - -static const char * getZoneStateString(uint8_t zoneState) -{ - switch (zoneState) - { - case EMBER_ZCL_IAS_ZONE_STATE_ENROLLED: - return enrolledString; - case EMBER_ZCL_IAS_ZONE_STATE_NOT_ENROLLED: - return notEnrolledString; - } - return unknownZoneStateString; -} -#endif // defined(EMBER_AF_PRINT_ENABLE) -//&& defined(EMBER_AF_PRINT_IAS_ZONE_CLUSTER) - -static void getAttributes(uint8_t * returnCieAddress, uint16_t * returnZoneStatus, uint16_t * returnZoneType, - uint8_t * returnZoneState, uint8_t endpoint) -{ - EMBER_TEST_ASSERT(endpoint != EM_AF_UNKNOWN_ENDPOINT); - - emberAfReadServerAttribute(endpoint, ZCL_IAS_ZONE_CLUSTER_ID, ZCL_IAS_CIE_ADDRESS_ATTRIBUTE_ID, returnCieAddress, EUI64_SIZE); - - emberAfReadServerAttribute(endpoint, ZCL_IAS_ZONE_CLUSTER_ID, ZCL_ZONE_STATUS_ATTRIBUTE_ID, (uint8_t *) returnZoneStatus, - 2); // uint16_t size - - emberAfReadServerAttribute(endpoint, ZCL_IAS_ZONE_CLUSTER_ID, ZCL_ZONE_TYPE_ATTRIBUTE_ID, (uint8_t *) returnZoneType, - 2); // uint16_t size - - emberAfReadServerAttribute(endpoint, ZCL_IAS_ZONE_CLUSTER_ID, ZCL_ZONE_STATE_ATTRIBUTE_ID, (uint8_t *) returnZoneState, - 1); // uint8_t size -} - -void emberAfPluginIasZoneServerInfoCommand(void) -{ - uint8_t cieAddress[EUI64_SIZE]; - uint16_t zoneStatus; - uint16_t zoneType; - uint8_t zoneState; - uint8_t endpoint = (uint8_t) emberUnsignedCommandArgument(0); - - getAttributes(cieAddress, &zoneStatus, &zoneType, &zoneState, endpoint); - emberAfIasZoneClusterPrint("CIE Address: "); - emberAfPrintBigEndianEui64(cieAddress); - emberAfIasZoneClusterPrintln(""); - emberAfIasZoneClusterPrintln("Zone Type: 0x%2X (%p)", zoneType, getZoneTypeString(zoneType)); - emberAfIasZoneClusterPrintln("Zone State: 0x%X (%p)", zoneState, getZoneStateString(zoneState)); - emberAfIasZoneClusterPrintln("Zone Status: 0x%2X", zoneStatus); - emberAfIasZoneClusterPrintln("Zone ID: 0x%2X", emberAfPluginIasZoneServerGetZoneId(endpoint)); -} - -void emberAfPluginIasZoneServerChangeStatusCommand(void) -{ - uint16_t newStatus = (uint16_t) emberUnsignedCommandArgument(0); - uint8_t timeSinceOccurredSeconds = (uint8_t) emberUnsignedCommandArgument(1); - uint8_t endpoint = (uint8_t) emberUnsignedCommandArgument(2); - emberAfPluginIasZoneServerUpdateZoneStatus(endpoint, newStatus, timeSinceOccurredSeconds << 2); -} - -void emberAfPluginIasZoneServerSetEnrollmentMethodCommand(void) -{ - uint8_t endpoint = (uint8_t) emberUnsignedCommandArgument(0); - uint8_t enrollmentMode = (uint8_t) emberUnsignedCommandArgument(1); - emberAfPluginIasZoneClusterSetEnrollmentMethod(endpoint, enrollmentMode); -} - -void emberAfPluginIasZoneServerChangeBackoffConfiguration(void) -{ -#if defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ENABLE_QUEUE) - IasZoneStatusQueueRetryConfig retryConfig = { (uint8_t) emberUnsignedCommandArgument(0), - (uint8_t) emberUnsignedCommandArgument(1), - (uint32_t) emberUnsignedCommandArgument(2), - (bool) emberUnsignedCommandArgument(3), - (uint16_t) emberUnsignedCommandArgument(4) }; - - if (EMBER_BAD_ARGUMENT == emberAfIasZoneServerConfigStatusQueueRetryParams(&retryConfig)) - { - emberAfIasZoneClusterPrintln("Parameter error! Valid parameters: %s, %s, %s %d, %s.", "0 < firstBackoff", "0 < commonRatio", - "firstBackoff < maxBackoff <", IAS_ZONE_STATUS_QUEUE_RETRY_ABS_MAX_BACKOFF_TIME_SEC, - "0 < maxRetryAttempts"); - } -#else - emberAfIasZoneClusterPrintln("Command error! IAS Zone Server status queue is not enabled"); -#endif -} - -void emberAfPluginIasZoneServerCliPrintQueue(void) -{ -#if defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ENABLE_QUEUE) - emberAfPluginIasZoneServerPrintQueue(); -#else - emberAfIasZoneClusterPrintln("Command error! IAS Zone Server status queue is not enabled"); -#endif -} - -void emberAfPluginIasZoneServerCliPrintQueueConfig(void) -{ -#if defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ENABLE_QUEUE) - emberAfPluginIasZoneServerPrintQueueConfig(); -#else - emberAfIasZoneClusterPrintln("Command error! IAS Zone Server status queue is not enabled"); -#endif -} diff --git a/src/app/clusters/ias-zone-server/ias-zone-server-test.c b/src/app/clusters/ias-zone-server/ias-zone-server-test.c deleted file mode 100644 index 657a21c825063a..00000000000000 --- a/src/app/clusters/ias-zone-server/ias-zone-server-test.c +++ /dev/null @@ -1,513 +0,0 @@ -/** - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * - * Copyright (c) 2020 Silicon Labs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/**************************************************************************** - * @file - * @brief Unit tests for ias zone server plugin - ******************************************************************************* - ******************************************************************************/ - -#include "app/framework/include/af.h" -#include "ias-zone-server.h" - -#include "app/framework/plugin/ias-zone-server/ias-zone-server-test.h" -#include "app/framework/test/test-framework.h" - -#define NUM_ENDPOINTS 3 -#define UNDEFINED_ZONE_ID 0xFF - -// These are non-public in ias-zone-server.c, so make a copy here. -#define IAS_ZONE_SERVER_PAYLOAD_COMMAND_IDX 0x02 -#define ZCL_FRAME_CONTROL_IDX 0x00 -#define RETRY_TEST_QUEUE_ENTRIES (3) -#define RETRY_TEST_MAKE_IT_UNLIMITED (10) - -// This is non-public in ias-zone-server.c, so make a copy here. -typedef struct -{ - uint8_t endpoint; - uint16_t status; - uint32_t eventTimeMs; -} IasZoneStatusQueueEntry; - -// This is non-public in ias-zone-server.c, so make a copy here. -typedef struct -{ - uint8_t entriesInQueue; - uint8_t startIdx; - uint8_t lastIdx; - IasZoneStatusQueueEntry buffer[EMBER_AF_PLUGIN_IAS_ZONE_SERVER_QUEUE_DEPTH]; -} IasZoneStatusQueue; - -void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status); - -// State variables used to stub out framework functionality -uint8_t currentEndpoint = 0; -EmberBindingTableEntry dummyBind; -EmberApsFrame frame; -EmberAfClusterCommand command; -EmberAfClusterCommand * emAfCurrentCommand = &command; -EmberAfDefinedEndpoint emAfEndpoints[NUM_ENDPOINTS]; - -// State variables used for later expect statements -bool attributeWritten; -bool bindSet = false; -uint8_t CurrentCieAddress[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -uint8_t zoneIdClearedCount = 0; -uint8_t cieAddressClearedCount = 0; -uint8_t zoneTypeClearedCount = 0; -uint8_t lastEndpointWritten = 0; - -extern IasZoneStatusQueue messageQueue; -extern EmberEventControl emberAfPluginIasZoneServerManageQueueEventControl; - -// ----------------------------------------------------------------------------- -// stubbed out functions: In general, we don't care about these functions; they -// just need to compile and always return success when called at runtime -// ----------------------------------------------------------------------------- - -bool emberAfStartMoveCallback(void) -{ - return true; -} - -bool emberAfContainsServer(uint8_t endpoint, EmberAfClusterId clusterId) -{ - return true; -} - -EmberStatus emberLeaveNetwork(void) -{ - return EMBER_SUCCESS; -} - -EmberAfAttributeMetadata * emberAfLocateAttributeMetadata(uint8_t endpoint, EmberAfClusterId clusterId, - EmberAfAttributeId attributeId, uint8_t mask, uint16_t manufacturerCode) -{ - return NULL; -} - -void halInternalGetTokenData(void * data, uint16_t token, uint8_t index, uint8_t len) -{ - return; -} - -void halInternalSetTokenData(uint16_t token, uint8_t index, void * data, uint8_t len) {} - -uint32_t halCommonGetInt32uMillisecondTick(void) -{ - return 0; -} - -// ----------------------------------------------------------------------------- -// test implemented functions: These functions need to be more representative of -// how the system will work -// ----------------------------------------------------------------------------- - -static const uint8_t attributeSizes[] = { -#include "attribute-size.h" -}; - -uint8_t emberAfGetDataSize(uint8_t dataType) -{ - uint8_t i; - for (i = 0; (i + 1) < sizeof(attributeSizes); i += 2) - { - if (attributeSizes[i] == dataType) - { - return attributeSizes[i + 1]; - } - } - - return 0; -} - -EmberStatus emberGetBinding(uint8_t idx, EmberBindingTableEntry * entry) -{ - entry->type = EMBER_UNUSED_BINDING; - bindSet = true; - - return EMBER_SUCCESS; -} - -EmberAfStatus emberAfReadServerAttribute(uint8_t endpoint, EmberAfClusterId cluster, EmberAfAttributeId attributeID, - uint8_t * dataPtr, uint8_t readLength) -{ - uint8_t i; - - if (attributeID != ZCL_IAS_CIE_ADDRESS_ATTRIBUTE_ID) - { - return -1; - } - - for (i = 0; i < 8; i++) - { - dataPtr[i] = CurrentCieAddress[i]; - } - - return EMBER_SUCCESS; -} - -uint8_t emberAfEndpointCount() -{ - return NUM_ENDPOINTS; -} - -uint8_t emberAfEndpointFromIndex(uint8_t idx) -{ - currentEndpoint = idx + 1; - return currentEndpoint; -} - -EmberAfStatus emberAfWriteServerAttribute(uint8_t endpoint, EmberAfClusterId cluster, EmberAfAttributeId attributeID, - uint8_t * dataPtr, uint8_t emberSetBindingataType) -{ - uint8_t zoneId; - uint16_t zoneType; - uint8_t i; - bool zeroAddress = true; - - lastEndpointWritten = endpoint; - - if (attributeID == ZCL_ZONE_ID_ATTRIBUTE_ID) - { - zoneId = *dataPtr; - if (zoneId == UNDEFINED_ZONE_ID) - { - zoneIdClearedCount++; - return EMBER_SUCCESS; - } - } - else if (attributeID == ZCL_ZONE_TYPE_ATTRIBUTE_ID) - { - zoneType = *(uint16_t *) dataPtr; - if (zoneType == EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ZONE_TYPE) - { - zoneTypeClearedCount++; - } - } - else if (attributeID == ZCL_IAS_CIE_ADDRESS_ATTRIBUTE_ID) - { - for (i = 0; i < 8; i++) - { - if (dataPtr[i] != 0) - { - zeroAddress = false; - } - } - if (zeroAddress) - { - cieAddressClearedCount++; - } - } - attributeWritten = true; - return 0; -} - -EmberStatus emberSetBinding(uint8_t index, EmberBindingTableEntry * value) -{ - bindSet = true; - return 0; -} - -// ----------------------------------------------------------------------------- -// Test cases: These are the test cases called by the test framework when unit -// tests are run. -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// Test case: enrollTest -// ----------------------------------------------------------------------------- -// Verify that binding table entries are created when a new CIE address is -// written to the device -static void enrollTest(void) -{ - uint8_t endpoint = 1; - EmberAfAttributeId attributeIdCie = ZCL_IAS_CIE_ADDRESS_ATTRIBUTE_ID; - EmberAfAttributeType attributeType = 0; - uint8_t size = EUI64_SIZE; - uint8_t newCieAddress[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - uint8_t i; - - // bind is created - - // Verify that no extra action happens when we send an attribute other than - // the CIE_ADDRESS_ATTRIBUTE - emAfCurrentCommand->apsFrame = &frame; - emAfCurrentCommand->apsFrame->sourceEndpoint = 1; - - for (i = 0; i < 8; i++) - { - CurrentCieAddress[i] = 0; - } - bindSet = false; - - emberAfIasZoneClusterServerPreAttributeChangedCallback(endpoint, attributeIdCie, attributeType, size, newCieAddress); - - expectComparisonDecimal(true, bindSet, "expected binding entry state", "observed binding entry state"); -} - -// ----------------------------------------------------------------------------- -// Test case: leaveTest -// ----------------------------------------------------------------------------- -// Verify that on network leave, attributes are reset to default values -static void leaveTest(void) -{ - currentEndpoint = 0; - zoneIdClearedCount = 0; - cieAddressClearedCount = 0; - zoneTypeClearedCount = 0; - - // EMAPPFWKV2-1530: if we are told that are network is down, but we are - // rejoining, then we should not unenroll. - testFrameworkNetworkState = EMBER_JOINED_NETWORK_NO_PARENT; - emberAfPluginIasZoneServerStackStatusCallback(EMBER_NETWORK_DOWN); - expectComparisonDecimal(0, zoneTypeClearedCount, "expected number of zone Type cleared", - "observed number of zone Type cleared"); - expectComparisonDecimal(0, cieAddressClearedCount, "expected number of CieAddr cleared", "observed number of CieAddr cleared"); - expectComparisonDecimal(0, zoneIdClearedCount, "expected number of zone ID cleared", "observed number of zone ID cleared"); - - // If we are told that are network is really down, then we do unenroll. - testFrameworkNetworkState = EMBER_NO_NETWORK; - emberAfPluginIasZoneServerStackStatusCallback(EMBER_NETWORK_DOWN); - expectComparisonDecimal(NUM_ENDPOINTS, zoneTypeClearedCount, "expected number of zone Type cleared", - "observed number of zone Type cleared"); - expectComparisonDecimal(NUM_ENDPOINTS, cieAddressClearedCount, "expected number of CieAddr cleared", - "observed number of CieAddr cleared"); - expectComparisonDecimal(NUM_ENDPOINTS, zoneIdClearedCount, "expected number of zone ID cleared", - "observed number of zone ID cleared"); -} - -// ----------------------------------------------------------------------------- -// Test case: updateTest -// ----------------------------------------------------------------------------- -// Verify that updates are sent to the correct endpoint when updateStatus -// function is called -static void updateTest(void) -{ - uint8_t testEndpoint = 0; - - for (testEndpoint = 0; testEndpoint < NUM_ENDPOINTS; testEndpoint++) - { - emberAfPluginIasZoneServerUpdateZoneStatus(testEndpoint, 0, 0); - expectComparisonDecimal(testEndpoint, lastEndpointWritten, "expected attribute write to endpoint", - "observed attribute write to endpoint"); - } -} - -// ----------------------------------------------------------------------------- -// Test case: status queue retry tests -// ----------------------------------------------------------------------------- - -#define testConfigStatusQueueRetryParamsBadArgument() \ - do \ - { \ - EmberStatus status = emberAfIasZoneServerConfigStatusQueueRetryParams(&retryConfig); \ - expectComparisonDecimal(EMBER_BAD_ARGUMENT, status, "expected return status", "observed return status"); \ - } while (0) - -// Verify that status queue configuration parameter check is operating per the current -// requirements. Both parameter limits and the input parameters are tested. -void statusQueueParameterTest(uint8_t firstBackoffTimeSec, uint8_t backoffSeqCommonRatio, uint32_t maxBackoffTimeSec, - bool unlimitedRetries, uint8_t maxRetryAttempts) -{ - // Filling up retryConfig with the input parameters of this function - // and changing each parameters to an invalid value one by one so that - // parameter check is tested. - IasZoneStatusQueueRetryConfig retryConfig = { firstBackoffTimeSec, backoffSeqCommonRatio, maxBackoffTimeSec, unlimitedRetries, - maxRetryAttempts }; - - retryConfig.firstBackoffTimeSec = 0; - testConfigStatusQueueRetryParamsBadArgument(); - retryConfig.firstBackoffTimeSec = firstBackoffTimeSec; - - retryConfig.backoffSeqCommonRatio = 0; - testConfigStatusQueueRetryParamsBadArgument(); - retryConfig.backoffSeqCommonRatio = backoffSeqCommonRatio; - - retryConfig.maxRetryAttempts = 0; - testConfigStatusQueueRetryParamsBadArgument(); - retryConfig.maxRetryAttempts = maxRetryAttempts; - - retryConfig.maxBackoffTimeSec = 0; - testConfigStatusQueueRetryParamsBadArgument(); - retryConfig.maxBackoffTimeSec = IAS_ZONE_STATUS_QUEUE_RETRY_ABS_MAX_BACKOFF_TIME_SEC + 1; - testConfigStatusQueueRetryParamsBadArgument(); - retryConfig.maxBackoffTimeSec = maxBackoffTimeSec; -} - -// Helper function to test status queue retry functionality with different configuration values. -uint32_t retryTestRunner(uint8_t firstBackoffTimeSec, uint8_t backoffSeqCommonRatio, uint32_t maxBackoffTimeSec, - bool unlimitedRetries, uint16_t maxTestRetryAttempts) -{ - uint32_t retryCount; - uint32_t expectedBackoffTimeSec = 0; - uint8_t message[3]; - uint8_t maxRetryAttempts; - uint8_t maxBackoffTestCount = 3; - - // Unlimited retry is configured by setting the max retry attempts to 0xFFFF. - if (unlimitedRetries) - { - maxRetryAttempts = 0xFF; - } - else - { - maxRetryAttempts = maxTestRetryAttempts - 1; - } - - // Setup specific message parameters that are checked in - // emberAfIasZoneClusterServerMessageSentCallback(). - // Note: these are independent of this actual test. - message[ZCL_FRAME_CONTROL_IDX] = ZCL_CLUSTER_SPECIFIC_COMMAND | ZCL_FRAME_CONTROL_SERVER_TO_CLIENT; - message[IAS_ZONE_SERVER_PAYLOAD_COMMAND_IDX] = ZCL_ZONE_STATUS_CHANGE_NOTIFICATION_COMMAND_ID; - - IasZoneStatusQueueRetryConfig retryConfig = { firstBackoffTimeSec, backoffSeqCommonRatio, maxBackoffTimeSec, unlimitedRetries, - maxRetryAttempts }; - - // Setting up retry parameters - emberAfIasZoneServerConfigStatusQueueRetryParams(&retryConfig); - - // Calling message sent callback of the plugin with status parameter set to failure, - // so that retry functionality is tested. - expectedBackoffTimeSec = firstBackoffTimeSec; - for (retryCount = 0; retryCount < maxTestRetryAttempts; retryCount++) - { - emberAfIasZoneClusterServerMessageSentCallback(0, 0, NULL, IAS_ZONE_SERVER_PAYLOAD_COMMAND_IDX, message, - EMBER_DELIVERY_FAILED); - - // No need to test max backoff if already reached and tested for a few times. - // This makes the test run shorter and prints less garbage (ie. unnecessary dots) - // on the screen. - if (maxBackoffTestCount) - { - // Testing that the backoff time is increased according to current backoff configuration. - expectComparisonDecimal(expectedBackoffTimeSec * MILLISECOND_TICKS_PER_SECOND, - emberAfPluginIasZoneServerManageQueueEventControl.timeToExecute, "expected back-off time in ms", - "observed back-off time in ms"); - } - - // Max retry attempts is reached, break here. - if (emberAfPluginIasZoneServerManageQueueEventControl.status == EMBER_EVENT_ZERO_DELAY) - { - break; - } - - // Increase expected backoff time until it reaches max backoff time. - // Make sure that the current backoff time is still tested for a few - // times after max backoff time is reached. - if (expectedBackoffTimeSec * backoffSeqCommonRatio <= maxBackoffTimeSec) - { - expectedBackoffTimeSec = expectedBackoffTimeSec * backoffSeqCommonRatio; - } - else if (maxBackoffTestCount) - { - maxBackoffTestCount--; - } - } - - return retryCount; -} - -// Verify that the status queue retry funcionality works as expected with -// different backoff parameters. Also test unlimited and limited retries. -static void retryTest(void) -{ - uint8_t firstBackoffTimeSec, backoffSeqCommonRatio; - uint32_t retryCount, maxBackoffTimeSec, maxTestRetryAttempts; - - // "Loading" the status queue with some elements. - messageQueue.entriesInQueue = RETRY_TEST_QUEUE_ENTRIES; - messageQueue.startIdx = 0; - messageQueue.lastIdx = RETRY_TEST_QUEUE_ENTRIES - 1; - - // -------------------------------------------------------------------- - // Test 1: test with minimal settings (small max retry attempts). - // -------------------------------------------------------------------- - firstBackoffTimeSec = 2; - backoffSeqCommonRatio = 3; - maxBackoffTimeSec = 500; - maxTestRetryAttempts = 11; - - statusQueueParameterTest(firstBackoffTimeSec, backoffSeqCommonRatio, maxBackoffTimeSec, false, maxTestRetryAttempts); - - retryCount = retryTestRunner(firstBackoffTimeSec, backoffSeqCommonRatio, maxBackoffTimeSec, false, maxTestRetryAttempts); - - // Testing if the number of retry attempts is what is expected. - expectComparisonDecimal(retryCount, maxTestRetryAttempts - 1, "number of retry attempts at end of test", - "expected max retry attempts"); - - // Testing if queue element is removed after reaching max retry attempts. - expectComparisonDecimal(messageQueue.entriesInQueue, RETRY_TEST_QUEUE_ENTRIES - 1, "current number of element in message queue", - "expected number of element in message queue"); - - // ----------------------------------------------------------- - // Test 2: test with default (legacy) settings of this plugin. - // ----------------------------------------------------------- - firstBackoffTimeSec = 3; - backoffSeqCommonRatio = 2; - maxBackoffTimeSec = 12; - // 0xFF is unlimited attempts per the requirements. Making the retry attempts - // in this test way higher than this limit so unlimited retires can be tested. - maxTestRetryAttempts = 3 * 0xFF; - - statusQueueParameterTest(firstBackoffTimeSec, backoffSeqCommonRatio, maxBackoffTimeSec, true, maxTestRetryAttempts); - - retryCount = retryTestRunner(firstBackoffTimeSec, backoffSeqCommonRatio, maxBackoffTimeSec, true, maxTestRetryAttempts); - - // Testing if the number of retry attempts equals to what is expected. - expectComparisonDecimal(retryCount, maxTestRetryAttempts, "number of retry attempts at end of test", - "expected retry attempts (ie. unlimited)"); - - // Testing if queue element was not cleared (ie. same as after the previous test), - // since this is an unlimited retry test. - expectComparisonDecimal(messageQueue.entriesInQueue, RETRY_TEST_QUEUE_ENTRIES - 1, "current number of element in message queue", - "expected number of element in message queue"); -} - -int main(int argc, char * argv[]) -{ - const TestCase tests[] = { - { "attribute-response", enrollTest }, - { "leave-test", leaveTest }, - { "update-test", updateTest }, - { "retry-test", retryTest }, - { NULL }, - }; - - // This test only runs correctly with network 0. - // Ideally we should look into this. - emberSetCurrentNetwork(0); - - return parseCommandLineAndExecuteTest(argc, argv, "IAS Zone Server", tests); -} diff --git a/src/app/clusters/ias-zone-server/ias-zone-server.c b/src/app/clusters/ias-zone-server/ias-zone-server.c index 134f1935ea4c69..a583d766d71ed6 100644 --- a/src/app/clusters/ias-zone-server/ias-zone-server.c +++ b/src/app/clusters/ias-zone-server/ias-zone-server.c @@ -51,12 +51,9 @@ // ***************************************************************************** #include "ias-zone-server.h" -#include "app/framework/include/af.h" -#include "hal/micro/token.h" - -#ifdef EMBER_SCRIPTED_TEST -#include "app/framework/plugin/ias-zone-server/ias-zone-server-test.h" -#endif +#include +#include +#include #define UNDEFINED_ZONE_ID 0xFF #define DELAY_TIMER_MS (1 * MILLISECOND_TICKS_PER_SECOND) @@ -75,6 +72,11 @@ #define DEFAULT_ENROLLMENT_METHOD EMBER_ZCL_IAS_ZONE_ENROLLMENT_MODE_REQUEST +// TODO: Need to figure out what needs to happen wrt HAL tokens here, but for +// now define ESZP_HOST to disable it. See +// https://github.com/project-chip/connectedhomeip/issues/3275 +#define EZSP_HOST + typedef struct { uint8_t endpoint; @@ -143,6 +145,13 @@ static int16_t copyToBuffer(IasZoneStatusQueue * ring, const IasZoneStatusQueueE static int16_t popFromBuffer(IasZoneStatusQueue * ring, IasZoneStatusQueueEntry * entry); #endif +// TODO: https://github.com/project-chip/connectedhomeip/issues/3276 needs to be +// fixed to implement this for real. +EmberNetworkStatus emberAfNetworkState(void) +{ + return EMBER_JOINED_NETWORK; +} + //----------------------------------------------------------------------------- // Functions @@ -196,7 +205,7 @@ EmberAfStatus emberAfIasZoneClusterServerPreAttributeChangedCallback(uint8_t end bool zeroAddress; EmberBindingTableEntry bindingEntry; EmberBindingTableEntry currentBind; - EmberEUI64 destEUI; + ChipNodeId destNodeId; uint8_t ieeeAddress[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; // If this is not a CIE Address write, the CIE address has already been @@ -206,7 +215,7 @@ EmberAfStatus emberAfIasZoneClusterServerPreAttributeChangedCallback(uint8_t end return EMBER_ZCL_STATUS_SUCCESS; } - MEMCOPY(destEUI, value, EUI64_SIZE); + memcpy(&destNodeId, value, sizeof(ChipNodeId)); // Create the binding table entry @@ -219,7 +228,7 @@ EmberAfStatus emberAfIasZoneClusterServerPreAttributeChangedCallback(uint8_t end bindingEntry.local = endpoint; bindingEntry.clusterId = ZCL_IAS_ZONE_CLUSTER_ID; bindingEntry.remote = emberAfCurrentCommand()->apsFrame->sourceEndpoint; - MEMCOPY(bindingEntry.identifier, destEUI, EUI64_SIZE); + bindingEntry.nodeId = destNodeId; // Cycle through the binding table until we find a valid entry that is not // being used, then use the created entry to make the bind. @@ -634,7 +643,7 @@ void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status) { endpoint = emberAfEndpointFromIndex(i); networkIndex = emberAfNetworkIndexFromEndpointIndex(i); - if (networkIndex == emberGetCurrentNetwork() && emberAfContainsServer(endpoint, ZCL_IAS_ZONE_CLUSTER_ID)) + if (networkIndex == 0 /* emberGetCurrentNetwork() */ && emberAfContainsServer(endpoint, ZCL_IAS_ZONE_CLUSTER_ID)) { unenrollSecurityDevice(endpoint); } @@ -740,8 +749,9 @@ void emberAfPluginIasZoneServerPrintQueueConfig(void) // destination when the destination is the only router the node is joined to. // In that case, the command will never have been sent, as the device will have // had no router by which to send the command. -void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, int16u indexOrDestination, - EmberApsFrame * apsFrame, int16u msgLen, int8u * message, EmberStatus status) +void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, + EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, + EmberStatus status) { #if defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ENABLE_QUEUE) uint8_t frameControl; diff --git a/src/app/clusters/ias-zone-server/ias-zone-server.h b/src/app/clusters/ias-zone-server/ias-zone-server.h index 03af14a26d70b7..9ebe59788a195a 100644 --- a/src/app/clusters/ias-zone-server/ias-zone-server.h +++ b/src/app/clusters/ias-zone-server/ias-zone-server.h @@ -46,6 +46,8 @@ #ifndef SILABS_IAS_ZONE_SERVER_H #define SILABS_IAS_ZONE_SERVER_H +#include + #define EM_AF_UNKNOWN_ENDPOINT 0 // Absolute max backoff time, at least one retry a day // (ie. 24 hours * 60 minutes * 60 seconds). diff --git a/src/app/util/af-event.cpp b/src/app/util/af-event.cpp index 01609cf9a75e6a..6e1cb5b45bcaa7 100644 --- a/src/app/util/af-event.cpp +++ b/src/app/util/af-event.cpp @@ -69,11 +69,6 @@ extern "C" { EmberEventControl emberAfPluginIasZoneClientStateMachineEventControl; void emberAfPluginIasZoneClientStateMachineEventHandler(void){}; -// Stubs for IAS Zone Server Cluster issue #2058 -EmberEventControl emberAfPluginIasZoneServerManageQueueEventControl; -void emberAfPluginIasZoneServerManageQueueEventHandler(void){}; -void emberAfIasZoneClusterServerTickCallback(uint8_t endpoint){}; - EMBER_AF_GENERATED_EVENT_CODE } #endif // EMBER_AF_GENERATED_EVENT_CODE