From 4fcfcfa74c4ba8cd9e668f927a2dad8bde119fe4 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 30 Jan 2022 09:22:38 -0500 Subject: [PATCH] Remove a bunch of just-about-dead Ember message send code. (#14571) sendToClient in ias-zone-server is the only place all this machinery could be reached from in practice. And since at that one callsite the machinery is not going to do anything useful, there's no point in pretending like it works and keeping it. --- examples/all-clusters-app/mbed/CMakeLists.txt | 2 - examples/lighting-app/telink/CMakeLists.txt | 2 - src/app/BUILD.gn | 1 - src/app/chip-zcl-zpro-codec.h | 35 - src/app/chip_data_model.cmake | 2 - src/app/chip_data_model.gni | 3 - .../ias-zone-server/ias-zone-server.cpp | 5 + src/app/encoder-common.cpp | 68 -- src/app/util/af-main-common.cpp | 653 ------------------ src/app/util/af-main.h | 156 ----- src/app/util/af.h | 213 ------ src/app/util/attribute-table.cpp | 1 - src/app/util/chip-message-send.cpp | 140 ---- src/app/util/chip-message-send.h | 59 -- src/app/util/client-api.cpp | 105 --- src/app/util/client-api.h | 57 -- .../util/ember-compatibility-functions.cpp | 2 +- src/app/util/util.cpp | 203 +----- src/app/util/util.h | 2 - .../java/CHIPDeviceController-JNI.cpp | 1 - .../Framework/CHIP.xcodeproj/project.pbxproj | 8 - src/protocols/Protocols.h | 1 - src/protocols/temp_zcl/TempZCL.h | 58 -- 23 files changed, 13 insertions(+), 1764 deletions(-) delete mode 100644 src/app/encoder-common.cpp delete mode 100644 src/app/util/af-main-common.cpp delete mode 100644 src/app/util/af-main.h delete mode 100644 src/app/util/chip-message-send.cpp delete mode 100644 src/app/util/chip-message-send.h delete mode 100644 src/protocols/temp_zcl/TempZCL.h diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index afb2c76413fd53..7d18414b2fb274 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -71,12 +71,10 @@ target_sources(${APP_TARGET} PRIVATE ${APP_UTIL}/DataModelHandler.cpp ${APP_UTIL}/af-event.cpp - ${APP_UTIL}/af-main-common.cpp ${APP_UTIL}/attribute-storage.cpp ${APP_UTIL}/attribute-table.cpp ${APP_UTIL}/attribute-size-util.cpp ${APP_UTIL}/binding-table.cpp - ${APP_UTIL}/chip-message-send.cpp ${APP_UTIL}/client-api.cpp ${APP_UTIL}/ember-print.cpp ${APP_UTIL}/ember-compatibility-functions.cpp diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index 680a49431a77f9..e7da5dc0d8225d 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -54,12 +54,10 @@ target_sources(app PRIVATE ${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp ${CHIP_ROOT}/src/app/util/DataModelHandler.cpp ${CHIP_ROOT}/src/app/util/af-event.cpp - ${CHIP_ROOT}/src/app/util/af-main-common.cpp ${CHIP_ROOT}/src/app/util/attribute-size-util.cpp ${CHIP_ROOT}/src/app/util/attribute-storage.cpp ${CHIP_ROOT}/src/app/util/attribute-table.cpp ${CHIP_ROOT}/src/app/util/binding-table.cpp - ${CHIP_ROOT}/src/app/util/chip-message-send.cpp ${CHIP_ROOT}/src/app/util/client-api.cpp ${CHIP_ROOT}/src/app/util/ember-compatibility-functions.cpp ${CHIP_ROOT}/src/app/util/ember-print.cpp diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 56a9d0af129fd1..26ba877e790c62 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -145,7 +145,6 @@ static_library("app") { "TimedRequest.h", "WriteClient.cpp", "WriteHandler.cpp", - "encoder-common.cpp", "reporting/Engine.cpp", "reporting/Engine.h", ] diff --git a/src/app/chip-zcl-zpro-codec.h b/src/app/chip-zcl-zpro-codec.h index 9c25a339aff810..facda21c5a518b 100644 --- a/src/app/chip-zcl-zpro-codec.h +++ b/src/app/chip-zcl-zpro-codec.h @@ -41,38 +41,3 @@ typedef struct uint8_t sequence; uint8_t radius; } EmberApsFrame; - -/** - * @brief Encode an APS frame into the given buffer. Returns the number of - * bytes of buffer used by the encoding or 0 if the given buffer is not big - * enough. If buffer is null, no encoding will happen; the function will - * instead return the number of bytes that would be needed to encode the APS - * frame. - * - * @param[in] buffer The buffer to write to. If null, the call is in "count the - * bytes" mode, and no writing will happen. - * @parem[in] buf_length The size of the buffer. Ignored if buffer is null. - * @param[in] apsFrame The frame to encode. - * - * @return - * - If buffer is null, the number of bytes needed to encode. If this number - * does not fit in a uint16_t, 0 will be returned. - * - If buffer is non-null but buf_length is not enough to hold the - * EmberApsFrame, 0. - * - If buffer is non-null and buf_length is large enough, the number of bytes - * placed in buffer. - */ -uint16_t encodeApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * apsFrame); - -/** - * @brief Encode the given informations into the given BufferWriter. - * Returns the number of bytes of buffer used by the encoding or 0 if - * the given buffer is not big enough. - * - * @return - * - If the buffer length is not enough to hold the EmberApsFrame, 0. - * - If the buffer length is large enough, the number of bytes placed in buffer. - */ -uint16_t doEncodeApsFrame(chip::Encoding::LittleEndian::BufferWriter & buf, chip::ClusterId clusterId, - chip::EndpointId sourceEndpoint, chip::EndpointId destinationEndpoint, EmberApsOption options, - chip::GroupId groupId, uint8_t sequence, uint8_t radius, bool isMeasuring); diff --git a/src/app/chip_data_model.cmake b/src/app/chip_data_model.cmake index 9c6a71f6f5c716..91f1c77268c45f 100644 --- a/src/app/chip_data_model.cmake +++ b/src/app/chip_data_model.cmake @@ -81,12 +81,10 @@ function(chip_configure_data_model APP_TARGET) ${CHIP_APP_BASE_DIR}/../../zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp ${CHIP_APP_BASE_DIR}/../../zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp ${CHIP_APP_BASE_DIR}/util/af-event.cpp - ${CHIP_APP_BASE_DIR}/util/af-main-common.cpp ${CHIP_APP_BASE_DIR}/util/attribute-size-util.cpp ${CHIP_APP_BASE_DIR}/util/attribute-storage.cpp ${CHIP_APP_BASE_DIR}/util/attribute-table.cpp ${CHIP_APP_BASE_DIR}/util/binding-table.cpp - ${CHIP_APP_BASE_DIR}/util/chip-message-send.cpp ${CHIP_APP_BASE_DIR}/util/client-api.cpp ${CHIP_APP_BASE_DIR}/util/DataModelHandler.cpp ${CHIP_APP_BASE_DIR}/util/ember-compatibility-functions.cpp diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 50204cc7b6db25..78ff3e3474a6d7 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -95,16 +95,13 @@ template("chip_data_model") { "${_app_root}/clusters/zll-level-control-server/zll-level-control-server.h", "${_app_root}/clusters/zll-on-off-server/zll-on-off-server.h", "${_app_root}/clusters/zll-scenes-server/zll-scenes-server.h", - "${_app_root}/encoder-common.cpp", "${_app_root}/reporting/reporting.h", "${_app_root}/util/DataModelHandler.cpp", "${_app_root}/util/af-event.cpp", - "${_app_root}/util/af-main-common.cpp", "${_app_root}/util/attribute-size-util.cpp", "${_app_root}/util/attribute-storage.cpp", "${_app_root}/util/attribute-table.cpp", "${_app_root}/util/binding-table.cpp", - "${_app_root}/util/chip-message-send.cpp", "${_app_root}/util/client-api.cpp", "${_app_root}/util/ember-compatibility-functions.cpp", "${_app_root}/util/ember-print.cpp", diff --git a/src/app/clusters/ias-zone-server/ias-zone-server.cpp b/src/app/clusters/ias-zone-server/ias-zone-server.cpp index 77cbb555976f19..f6eae8be3d712f 100644 --- a/src/app/clusters/ias-zone-server/ias-zone-server.cpp +++ b/src/app/clusters/ias-zone-server/ias-zone-server.cpp @@ -184,10 +184,15 @@ static EmberStatus sendToClient(EndpointId endpoint) // emberAfSendCommandUnicastToBindings() emberAfSetCommandEndpoints(endpoint, 0); + // TODO: Figure out how this sending should actually work in Matter. +#if 0 // A binding table entry is created on Zone Enrollment for each endpoint, so // a simple call to SendCommandUnicastToBinding will handle determining the // destination endpoint, address, etc for us. status = emberAfSendCommandUnicastToBindings(); +#else + status = EMBER_ERR_FATAL; +#endif if (EMBER_SUCCESS != status) { diff --git a/src/app/encoder-common.cpp b/src/app/encoder-common.cpp deleted file mode 100644 index 031149975683e6..00000000000000 --- a/src/app/encoder-common.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * Copyright (c) 2021 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. - */ - -#include "chip-zcl-zpro-codec.h" -#include -#include - -using namespace chip::Encoding::LittleEndian; - -uint16_t doEncodeApsFrame(BufferWriter & buf, chip::ClusterId clusterId, chip::EndpointId sourceEndpoint, - chip::EndpointId destinationEndpoint, EmberApsOption options, chip::GroupId groupId, uint8_t sequence, - uint8_t radius, bool isMeasuring) -{ - - uint8_t control_byte = 0; - buf.Put(control_byte) // Put in a control byte - .Put32(clusterId) - .Put16(sourceEndpoint) - .Put16(destinationEndpoint) - .EndianPut(options, sizeof(EmberApsOption)) - .Put16(groupId) - .Put8(sequence) - .Put8(radius); - - size_t result = buf.Needed(); - if (isMeasuring) - { - ChipLogDetail(Zcl, "Measured APS frame size %zu", result); - } - else if (buf.Fit()) - { - ChipLogDetail(Zcl, "Successfully encoded %zu bytes", result); - } - else - { - ChipLogError(Zcl, "Error encoding APS Frame: Buffer too small"); - result = 0; - } - - if (!chip::CanCastTo(result)) - { - ChipLogError(Zcl, "Can't fit our measured size in uint16_t"); - result = 0; - } - - return static_cast(result); -} - -uint16_t encodeApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * apsFrame) -{ - BufferWriter buf(buffer, buf_length); - return doEncodeApsFrame(buf, apsFrame->clusterId, apsFrame->sourceEndpoint, apsFrame->destinationEndpoint, apsFrame->options, - apsFrame->groupId, apsFrame->sequence, apsFrame->radius, !buffer); -} diff --git a/src/app/util/af-main-common.cpp b/src/app/util/af-main-common.cpp deleted file mode 100644 index 67801a695fe4da..00000000000000 --- a/src/app/util/af-main-common.cpp +++ /dev/null @@ -1,653 +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 Code common to both the Host and SOC (system - *on a chip) versions of the Application Framework. - ******************************************************************************* - ******************************************************************************/ - -//#include PLATFORM_HEADER // Micro and compiler specific typedefs and macros - -#if defined EZSP_HOST -#include "stack/include/ember-types.h" -#include "stack/include/error.h" -#include "stack/include/library.h" -#else -// Ember stack and related utilities -//#include "stack/include/cbke-crypto-engine.h" -//#include "stack/include/ember.h" // Main stack definitions -#endif - -// HAL - hardware abstraction layer -//#include "hal/hal.h" -//#include "plugin/serial/serial.h" // Serial utility APIs - -// CLI - command line interface -//#include "app/util/serial/command-interpreter2.h" - -#if defined EZSP_HOST -// EZSP - ember serial host protocol -#include "app/util/ezsp/ezsp-protocol.h" -#include "app/util/ezsp/ezsp-utils.h" -#include "app/util/ezsp/ezsp.h" -#include "app/util/ezsp/serial-interface.h" -#endif - -// Sub-GHz client, for a last-minute chance to block sending ZCL messgaes within the suspend period -#ifdef EMBER_AF_PLUGIN_SUB_GHZ_CLIENT -#include "app/framework/plugin/sub-ghz-client/sub-ghz-client.h" -#endif - -// Sub-GHz server, for an automatic reply if a client attempt to communicate within the suspend period -#ifdef EMBER_AF_PLUGIN_SUB_GHZ_SERVER -#include "app/framework/plugin/sub-ghz-server/sub-ghz-server.h" -#endif - -// Fragmentation. -#ifdef EMBER_AF_PLUGIN_FRAGMENTATION -#include "app/framework/plugin/fragmentation/fragmentation.h" -#endif - -#ifdef EMBER_AF_PLUGIN_CRITICAL_MESSAGE_QUEUE -#include "app/framework/plugin/critical-message-queue/critical-message-queue.h" -#endif // EMBER_AF_PLUGIN_CRITICAL_MESSAGE_QUEUE - -// Service discovery library -//#include "service-discovery.h" - -// determines the number of in-clusters and out-clusters based on defines -// in config.h -#include - -//#include "app/framework/security/af-security.h" -//#include "app/framework/security/crypto-state.h" -#include "app/util/common.h" -#include -#include -#include -#include -//#include "print.h" -#include -#include -#include - -using namespace chip; - -// Querying the Ember Stack for what libraries are present. -//#include "app/util/common/library.h" - -// ZDO - ZigBee Device Object -//#include "app/util/zigbee-framework/zigbee-device-common.h" - -//#include "app/framework/plugin/ota-storage-common/ota-storage.h" -//#include "app/framework/plugin/partner-link-key-exchange/partner-link-key-exchange.h" - -//------------------------------------------------------------------------------ - -#define INVALID_MESSAGE_TAG 0xFF - -#if defined(EMBER_AF_HAS_COORDINATOR_NETWORK) -#if !defined(EMBER_AF_PLUGIN_CONCENTRATOR) -#error "A Coordinator device (Trust Center) MUST enable the concentrator plugin to function correctly." -#endif -#endif - -#ifdef EMBER_AF_GENERATED_PLUGIN_STACK_STATUS_FUNCTION_DECLARATIONS -EMBER_AF_GENERATED_PLUGIN_STACK_STATUS_FUNCTION_DECLARATIONS -#endif - -#ifdef EMBER_AF_GENERATED_PLUGIN_MESSAGE_SENT_FUNCTION_DECLARATIONS -EMBER_AF_GENERATED_PLUGIN_MESSAGE_SENT_FUNCTION_DECLARATIONS -#endif - -#ifdef EMBER_AF_GENERATED_PLUGIN_ZDO_MESSAGE_RECEIVED_FUNCTION_DECLARATIONS -EMBER_AF_GENERATED_PLUGIN_ZDO_MESSAGE_RECEIVED_FUNCTION_DECLARATIONS -#endif - -static CallbackTableEntry messageSentCallbacks[EMBER_AF_MESSAGE_SENT_CALLBACK_TABLE_SIZE]; - -// We declare this variable 'const' but NOT const. Those functions that we may use -// this variable would also have to declare it const in order to function -// correctly, which is not the case (e.g. emberFindKeyTableEntry()). -const EmberEUI64 emberAfNullEui64 = { 0, 0, 0, 0, 0, 0, 0, 0 }; - -//------------------------------------------------------------------------------ -// Forward declarations -static uint8_t getMessageSentCallbackIndex(void); -static void invalidateMessageSentCallbackEntry(uint8_t messageTag); -static EmberAfMessageSentFunction getMessageSentCallback(uint8_t tag); - -static uint8_t getMessageSentCallbackIndex(void) -{ - uint8_t i; - for (i = 0; i < EMBER_AF_MESSAGE_SENT_CALLBACK_TABLE_SIZE; i++) - { - if (messageSentCallbacks[i].tag == INVALID_MESSAGE_TAG) - { - return i; - } - } - - return INVALID_MESSAGE_TAG; -} - -static void invalidateMessageSentCallbackEntry(uint8_t tag) -{ - uint8_t i; - for (i = 0; i < EMBER_AF_MESSAGE_SENT_CALLBACK_TABLE_SIZE; i++) - { - if (messageSentCallbacks[i].tag == tag) - { - messageSentCallbacks[i].tag = INVALID_MESSAGE_TAG; - messageSentCallbacks[i].callback = NULL; - return; - } - } -} - -static EmberAfMessageSentFunction getMessageSentCallback(uint8_t tag) -{ - uint8_t i; - for (i = 0; i < EMBER_AF_MESSAGE_SENT_CALLBACK_TABLE_SIZE; i++) - { - if (messageSentCallbacks[i].tag == tag) - { - return messageSentCallbacks[i].callback; - } - } - - return NULL; -} - -void emAfInitializeMessageSentCallbackArray(void) -{ - uint8_t i; - for (i = 0; i < EMBER_AF_MESSAGE_SENT_CALLBACK_TABLE_SIZE; i++) - { - messageSentCallbacks[i].tag = INVALID_MESSAGE_TAG; - messageSentCallbacks[i].callback = NULL; - } -} - -static EmberStatus send(const MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, bool broadcast, EmberNodeId alias, uint8_t sequence, EmberAfMessageSentFunction callback) -{ - EmberStatus status; - uint16_t index; - uint8_t messageSentIndex; - uint8_t messageTag = INVALID_MESSAGE_TAG; - - // The send APIs only deal with ZCL messages, so they must at least contain - // the ZCL header. - if (messageLength < EMBER_AF_ZCL_OVERHEAD) - { - return EMBER_ERR_FATAL; - } - else if ((message[0] & ZCL_MANUFACTURER_SPECIFIC_MASK) != 0U) - { - if (messageLength < EMBER_AF_ZCL_MANUFACTURER_SPECIFIC_OVERHEAD) - { - return EMBER_ERR_FATAL; - } - } - - messageSentIndex = getMessageSentCallbackIndex(); - if (callback != NULL && messageSentIndex == INVALID_MESSAGE_TAG) - { - return EMBER_TABLE_FULL; - } - - // The source endpoint in the APS frame MUST be valid at this point. We use - // it to set the appropriate outgoing network in the APS frame. - EmberAfEndpointInfoStruct endpointInfo; - uint8_t networkIndex = 0; - if (emberAfGetEndpointInfoCallback(apsFrame->sourceEndpoint, &networkIndex, &endpointInfo)) - { - // status = emberAfPushNetworkIndex(networkIndex); - // if (status != EMBER_SUCCESS) - // { - // return status; - // } - } - else - { - index = emberAfIndexFromEndpoint(apsFrame->sourceEndpoint); - if (index == 0xFFFF) - { - return EMBER_INVALID_ENDPOINT; - } - // status = emberAfPushEndpointNetworkIndex(apsFrame->sourceEndpoint); - // if (status != EMBER_SUCCESS) - // { - // return status; - // } - } - -#ifdef EMBER_AF_PLUGIN_SUB_GHZ_CLIENT - // If the Sub-GHz client is present and currently in the "suspended" state, - // block any outgoing message unless it comes from the Sub-GHz client itself. - if (emberAfPluginSubGhzClientIsSendingZclMessagesSuspended() && apsFrame->clusterId != ZCL_SUB_GHZ_CLUSTER_ID) - { - return EMBER_TRANSMISSION_SUSPENDED; - } -#endif - - { - EmberAfMessageStruct messageStruct = { - callback, apsFrame, message, destination, messageLength, broadcast, - }; - // Called prior to fragmentation in case the mesasge does not go out over the - // Zigbee radio, and instead goes to some other transport that does not require - // low level ZigBee fragmentation. - if (emberAfPreMessageSendCallback(&messageStruct, &status)) - { - return status; - } - } - - // SE 1.4 requires an option to disable APS ACK and Default Response - emAfApplyDisableDefaultResponse(&message[0]); - emAfApplyRetryOverride(&apsFrame->options); - - if (messageLength <= EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH) - { - status = emAfSend(destination, apsFrame, messageLength, message, &messageTag, alias, sequence); - } - else - { - status = EMBER_MESSAGE_TOO_LONG; - } - -#ifdef EMBER_AF_PLUGIN_CRITICAL_MESSAGE_QUEUE - // If this was a critical message queue entry, fire the callback - if ((status != EMBER_SUCCESS) && - (callback == emberAfPluginCriticalMessageQueueEnqueueCallback || callback == emAfPluginCriticalMessageQueueRetryCallback)) - { - callback(destination, apsFrame, messageLength, message, status); - } -#endif // EMBER_AF_PLUGIN_CRITICAL_MESSAGE_QUEUE - - if (callback != NULL && status == EMBER_SUCCESS && messageTag != INVALID_MESSAGE_TAG && - messageSentIndex < EMBER_AF_MESSAGE_SENT_CALLBACK_TABLE_SIZE) - { - messageSentCallbacks[messageSentIndex].tag = messageTag; - messageSentCallbacks[messageSentIndex].callback = callback; - } - - if (status == EMBER_OPERATION_IN_PROGRESS && apsFrame->options & EMBER_APS_OPTION_DSA_SIGN) - { - // We consider "in progress" signed messages as being sent successfully. - // The stack will send the message after signing. - status = EMBER_SUCCESS; - // TODO: Can we actually hit this case in CHIP, or can this whole block - // go away? - // emAfSetCryptoOperationInProgress(); - } - - if (status == EMBER_SUCCESS) - { - emberAfAddToCurrentAppTasks(EMBER_AF_WAITING_FOR_DATA_ACK | EMBER_AF_WAITING_FOR_ZCL_RESPONSE); - } - - // emberAfPopNetworkIndex(); - return status; -} - -EmberStatus emberAfSendMulticastWithAliasWithCallback(GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, EmberNodeId alias, uint8_t sequence, - EmberAfMessageSentFunction callback) -{ - apsFrame->groupId = multicastId; - const auto destination = MessageSendDestination::MulticastWithAlias(multicastId); - return send(destination, apsFrame, messageLength, message, - true, // broadcast - alias, sequence, callback); -} - -EmberStatus emberAfSendMulticastWithCallback(GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, EmberAfMessageSentFunction callback) -{ - apsFrame->groupId = multicastId; - const auto destination = MessageSendDestination::Multicast(multicastId); - return send(destination, apsFrame, messageLength, message, - true, // broadcast? - 0, // alias - 0, // sequence - callback); -} - -EmberStatus emberAfSendMulticast(GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) -{ - return emberAfSendMulticastWithCallback(multicastId, apsFrame, messageLength, message, NULL); -} - -EmberStatus emberAfSendMulticastToBindings(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) -{ - EmberStatus status = EMBER_INVALID_BINDING_INDEX; - uint8_t i; - EmberBindingTableEntry binding; - GroupId groupDest; - - if ((NULL == apsFrame) || (0 == messageLength) || (NULL == message)) - { - return EMBER_BAD_ARGUMENT; - } - - for (i = 0; i < EMBER_BINDING_TABLE_SIZE; i++) - { - status = emberGetBinding(i, &binding); - if (status != EMBER_SUCCESS) - { - return status; - } - - if (binding.type == EMBER_MULTICAST_BINDING && binding.local == apsFrame->sourceEndpoint && - binding.clusterId == apsFrame->clusterId) - { - groupDest = binding.groupId; - apsFrame->groupId = groupDest; - apsFrame->destinationEndpoint = binding.remote; - - status = emberAfSendMulticast(groupDest, // multicast ID - apsFrame, messageLength, message); - - if (status != EMBER_SUCCESS) - { - return status; - } - } - } - - return status; -} - -// TODO: Figure out whether we need emberAfSendBroadcastWithCallback at all. -// EmberStatus emberAfSendBroadcastWithCallback(EmberNodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, -// uint8_t * message, EmberAfMessageSentFunction callback) -//{ -// return send(EMBER_OUTGOING_BROADCAST, destination, apsFrame, messageLength, message, -// true, // broadcast? -// 0, // alias -// 0, // sequence -// callback); -//} - -// TODO: Figure out whether we need emberAfSendBroadcastWithAliasWithCallback at all. -// EmberStatus emberAfSendBroadcastWithAliasWithCallback(EmberNodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, -// uint8_t * message, EmberNodeId alias, uint8_t sequence, -// EmberAfMessageSentFunction callback) -//{ -// return send(EMBER_OUTGOING_BROADCAST_WITH_ALIAS, destination, apsFrame, messageLength, message, -// true, // broadcast? -// alias, // alias -// sequence, // sequence -// callback); -//} - -// TODO: Figure out whether we need emberAfSendBroadcast at all. -// EmberStatus emberAfSendBroadcast(EmberNodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) -//{ -// return emberAfSendBroadcastWithCallback(destination, apsFrame, messageLength, message, NULL); -//} - -EmberStatus emberAfSendUnicastWithCallback(const MessageSendDestination & destination, EmberApsFrame * apsFrame, - uint16_t messageLength, uint8_t * message, EmberAfMessageSentFunction callback) -{ - // The source endpoint in the APS frame MAY NOT be valid at this point if the - // outgoing type is "via binding." - if (destination.IsViaBinding()) - { - // If using binding, set the endpoints based on those in the binding. The - // cluster in the binding is not used because bindings can be used to send - // messages with any cluster id, not just the one set in the binding. - EmberBindingTableEntry binding; - // TODO: This cast should go away once - // https://github.com/project-chip/connectedhomeip/issues/3584 is fixed. - EmberStatus status = emberGetBinding(destination.GetBindingIndex(), &binding); - if (status != EMBER_SUCCESS) - { - return status; - } - apsFrame->sourceEndpoint = binding.local; - apsFrame->destinationEndpoint = binding.remote; - } - return send(destination, apsFrame, messageLength, message, - false, // broadcast? - 0, // alias - 0, // sequence - callback); -} - -EmberStatus emberAfSendUnicast(const MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message) -{ - return emberAfSendUnicastWithCallback(destination, apsFrame, messageLength, message, NULL); -} - -EmberStatus emberAfSendUnicastToBindingsWithCallback(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message, - EmberAfMessageSentFunction callback) -{ - EmberStatus status = EMBER_INVALID_BINDING_INDEX; - uint8_t i; - - for (i = 0; i < EMBER_BINDING_TABLE_SIZE; i++) - { - EmberBindingTableEntry binding; - status = emberGetBinding(i, &binding); - if (status != EMBER_SUCCESS) - { - return status; - } - if (binding.type == EMBER_UNICAST_BINDING && binding.local == apsFrame->sourceEndpoint && - binding.clusterId == apsFrame->clusterId) - { - apsFrame->destinationEndpoint = binding.remote; - const MessageSendDestination destination = MessageSendDestination::ViaBinding(i); - status = send(destination, apsFrame, messageLength, message, - false, // broadcast? - 0, // alias - 0, // sequence - callback); - if (status != EMBER_SUCCESS) - { - return status; - } - } - } - - return status; -} - -EmberStatus emberAfSendUnicastToBindings(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) -{ - return emberAfSendUnicastToBindingsWithCallback(apsFrame, messageLength, message, NULL); -} - -EmberStatus emberAfSendInterPan(EmberPanId panId, const EmberEUI64 destinationLongId, EmberNodeId destinationShortId, - GroupId multicastId, ClusterId clusterId, uint16_t messageLength, uint8_t * messageBytes) -{ - EmberAfInterpanHeader header; - memset(&header, 0, sizeof(EmberAfInterpanHeader)); - header.panId = panId; - header.shortAddress = destinationShortId; - if (destinationLongId != NULL) - { - memmove(header.longAddress, destinationLongId, EUI64_SIZE); - header.options |= EMBER_AF_INTERPAN_OPTION_MAC_HAS_LONG_ADDRESS; - header.messageType = EMBER_AF_INTER_PAN_UNICAST; - } - else if (multicastId != 0) - { - header.groupId = multicastId; - header.messageType = EMBER_AF_INTER_PAN_MULTICAST; - } - else - { - header.messageType = - (destinationShortId < EMBER_BROADCAST_ADDRESS ? EMBER_AF_INTER_PAN_UNICAST : EMBER_AF_INTER_PAN_BROADCAST); - } - header.clusterId = clusterId; - return emberAfInterpanSendMessageCallback(&header, messageLength, messageBytes); -} - -void emberAfPrintMessageData(uint8_t * data, uint16_t length) -{ -#if defined EMBER_AF_PRINT_APP - emberAfAppPrint(" payload (len %2x) [", length); - emberAfAppPrintBuffer(data, length, true); - emberAfAppPrintln("]"); -#endif -} - -void emAfPrintStatus(const char * task, EmberStatus status) -{ - if (status == EMBER_SUCCESS) - { - emberAfPrint(emberAfPrintActiveArea, "%p: %p", "Success", task); - } - else - { - emberAfPrint(emberAfPrintActiveArea, "%p: %p: 0x%x", "Error", task, status); - } -} - -// ****************************************************************** -// Functions called by the Serial Command Line Interface (CLI) -// ****************************************************************** - -static void printMessage(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * messageContents) -{ - emberAfAppPrint("Cluster: " ChipLogFormatMEI ", %d bytes,", ChipLogValueMEI(apsFrame->clusterId), messageLength); - if (messageLength >= 3) - { - emberAfAppPrint(" ZCL %p Cmd ID: %d", (messageContents[0] & ZCL_CLUSTER_SPECIFIC_COMMAND ? "Cluster" : "Global"), - messageContents[2]); - } - emberAfAppPrintln("%s", ""); -} - -void emAfMessageSentHandler(const MessageSendDestination & destination, EmberApsFrame * apsFrame, EmberStatus status, - uint16_t messageLength, uint8_t * messageContents, uint8_t messageTag) -{ - EmberAfMessageSentFunction callback; - if (status != EMBER_SUCCESS) - { - emberAfAppPrint("%ptx %x, ", "ERROR: ", status); - printMessage(apsFrame, messageLength, messageContents); - } - - callback = getMessageSentCallback(messageTag); - invalidateMessageSentCallbackEntry(messageTag); - - emberAfRemoveFromCurrentAppTasks(EMBER_AF_WAITING_FOR_DATA_ACK); - - if (messageContents != NULL && messageContents[0] & ZCL_CLUSTER_SPECIFIC_COMMAND) - { - emberAfClusterMessageSentCallback(destination, apsFrame, messageLength, messageContents, status); - } - - if (callback != NULL) - { - (*callback)(destination, apsFrame, messageLength, messageContents, status); - } - -#ifdef EMBER_AF_GENERATED_PLUGIN_MESSAGE_SENT_FUNCTION_CALLS - EMBER_AF_GENERATED_PLUGIN_MESSAGE_SENT_FUNCTION_CALLS -#endif - - emberAfMessageSentCallback(destination, apsFrame, messageLength, messageContents, status); -} - -#ifdef EMBER_AF_PLUGIN_FRAGMENTATION -void emAfFragmentationMessageSentHandler(const MessageSendDestination & destination, EmberApsFrame * apsFrame, uint8_t * buffer, - uint16_t bufLen, EmberStatus status, uint8_t messageTag) -{ - // the fragmented message is no longer in process - emberAfDebugPrintln("%pend.", "Fragmentation:"); - emAfMessageSentHandler(destination, apsFrame, status, bufLen, buffer, messageTag); - - // EMZIGBEE-4437: setting back the buffers to the original in case someone set - // that to something else. - emberAfSetExternalBuffer(appResponseData, EMBER_AF_RESPONSE_BUFFER_LEN, &appResponseLength, &emberAfResponseApsFrame); -} -#endif // EMBER_AF_PLUGIN_FRAGMENTATION - -EmberStatus emAfSend(const MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, uint8_t * messageTag, EmberNodeId alias, uint8_t sequence) -{ - // TODO: There's an impedance mismatch here in a few ways: - // 1) The caller expects to get a messageTag out that will identify this - // message somewhat uniquely. Right now we just ignore that and claim an - // invalid tag, which means message-sent callbacks don't get called. - // - // 2) The caller expects us to call emAfMessageSentHandler when we get an - // ack or time out, and pass it the original contents of the message, so it - // can invoke message-sent callbacks as needed. But we may not have the - // contents of the message if we've done in-place encryption since then. - // Need to figure out whether any of this matters. - // - // https://github.com/project-chip/connectedhomeip/issues/2435 sort of - // tracks this. - *messageTag = INVALID_MESSAGE_TAG; - EmberStatus status = EMBER_SUCCESS; - if (destination.IsViaBinding()) - { - EmberBindingTableEntry binding; - status = emberGetBinding(destination.GetBindingIndex(), &binding); - if (status != EMBER_SUCCESS) - { - return status; - } - if (binding.type != EMBER_UNICAST_BINDING) - { - return EMBER_INVALID_BINDING_INDEX; - } - return chipSendUnicast(binding.nodeId, apsFrame, messageLength, message); - } - else if (destination.IsDirect()) - { - return chipSendUnicast(destination.GetDirectNodeId(), apsFrame, messageLength, message); - } - else if (destination.IsViaExchange()) - { - return chipSendUnicast(destination.GetExchangeContext(), apsFrame, messageLength, message); - } - else - { - // No implementation yet. - return EMBER_ERR_FATAL; - } -} diff --git a/src/app/util/af-main.h b/src/app/util/af-main.h deleted file mode 100644 index 3ab846b5d517d2..00000000000000 --- a/src/app/util/af-main.h +++ /dev/null @@ -1,156 +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 - ******************************************************************************* - ******************************************************************************/ - -#pragma once - -#include - -//#include CONFIGURATION_HEADER -//#include PLATFORM_HEADER // Micro and compiler specific typedefs and macros -//#include "stack/include/ember-types.h" - -#define MFG_STRING_MAX_LENGTH 16 - -typedef struct -{ - EmberAfMessageSentFunction callback; - uint8_t tag; -} CallbackTableEntry; - -#if defined(EZSP_HOST) -bool emberAfMemoryByteCompare(const uint8_t * pointer, uint8_t count, uint8_t byteValue); -#else -bool emMemoryByteCompare(const uint8_t * bytes, uint8_t count, uint8_t target); - -#define emberAfMemoryByteCompare(pointer, count, byteValue) emMemoryByteCompare((pointer), (count), (byteValue)) -#endif - -// returnData must be MFG_STRING_MAX_LENGTH in length and -// is NOT expected to be NULL terminated (could be though) -void emberAfGetMfgString(uint8_t * returnData); - -// Functions common to both SOC and Host versions of the application. -void emAfInitializeMessageSentCallbackArray(void); - -#if defined(EZSP_HOST) -void emAfClearNetworkCache(uint8_t networkIndex); -#else -#define emAfClearNetworkCache(index) -uint8_t emAfCopyMessageIntoRamBuffer(EmberMessageBuffer message, uint8_t * buffer, uint16_t bufLen); -#endif - -#if defined EZSP_HOST -// utility for setting an EZSP config value and printing the result -EzspStatus emberAfSetEzspConfigValue(EzspConfigId configId, uint16_t value, const char * configIdName); - -// utility for setting an EZSP policy and printing the result -EzspStatus emberAfSetEzspPolicy(EzspPolicyId policyId, EzspDecisionId decisionId, const char * policyName, - const char * decisionName); - -// utility for setting an EZSP value and printing the result -EzspStatus emberAfSetEzspValue(EzspValueId valueId, uint8_t valueLength, uint8_t * value, const char * valueName); - -bool emberAfNcpNeedsReset(void); - -#endif // EZSP_HOST - -void emAfPrintStatus(const char * task, EmberStatus status); - -uint8_t emberAfGetKeyTableSize(void); -uint8_t emberAfGetBindingTableSize(void); -uint8_t emberAfGetAddressTableSize(void); -uint8_t emberAfGetChildTableSize(void); -uint8_t emberAfGetRouteTableSize(void); -uint8_t emberAfGetNeighborTableSize(void); -uint8_t emberAfGetStackProfile(void); -uint8_t emberAfGetSleepyMulticastConfig(void); - -uint8_t emAfGetPacketBufferFreeCount(void); -uint8_t emAfGetPacketBufferTotalCount(void); - -EmberStatus emberAfGetSourceRouteTableEntry(uint8_t index, EmberNodeId * destination, uint8_t * closerIndex); - -uint8_t emberAfGetSourceRouteTableTotalSize(void); -uint8_t emberAfGetSourceRouteTableFilledSize(void); - -EmberStatus emberAfGetChildData(uint8_t index, EmberChildData * childData); - -void emAfCliVersionCommand(void); - -EmberStatus emAfPermitJoin(uint8_t duration, bool broadcastMgmtPermitJoin); -void emAfStopSmartEnergyStartup(void); - -bool emAfProcessZdo(EmberNodeId sender, EmberApsFrame * apsFrame, uint8_t * message, uint16_t length); - -void emAfIncomingMessageHandler(EmberIncomingMessageType type, EmberApsFrame * apsFrame, uint8_t lastHopLqi, int8_t lastHopRssi, - uint16_t messageLength, uint8_t * messageContents); -EmberStatus emAfSend(const chip::MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, uint8_t * messageTag, EmberNodeId alias, uint8_t sequence); -void emAfMessageSentHandler(const chip::MessageSendDestination & destination, EmberApsFrame * apsFrame, EmberStatus status, - uint16_t messageLength, uint8_t * messageContents, uint8_t messageTag); - -void emAfStackStatusHandler(EmberStatus status); -void emAfNetworkInit(void); - -// For testing purposes only, we suppress the normal call to emberNetworkInit() -// at reboot. This allows us to call it manually later and prevent the node -// from immediately coming back up on the network after reboot. -#ifdef EMBER_AF_TC_SWAP_OUT_TEST -#define EM_AF_NETWORK_INIT() -#else -#define EM_AF_NETWORK_INIT() emAfNetworkInit() -#endif - -#define emberAfCopyBigEndianEui64Argument emberCopyBigEndianEui64Argument -void emAfScheduleFindAndRejoinEvent(void); - -extern const EmberEUI64 emberAfNullEui64; - -void emberAfFormatMfgString(uint8_t * mfgString); - -extern bool emberAfPrintReceivedMessages; - -void emAfParseAndPrintVersion(EmberVersion versionStruct); -void emAfPrintEzspEndpointFlags(chip::EndpointId endpoint); - -// Old names -#define emberAfMoveInProgress() emberAfMoveInProgressCallback() -#define emberAfStartMove() emberAfStartMoveCallback() -#define emberAfStopMove() emberAfStopMoveCallback() diff --git a/src/app/util/af.h b/src/app/util/af.h index efd1c17901be49..ee860739dce335 100644 --- a/src/app/util/af.h +++ b/src/app/util/af.h @@ -1047,213 +1047,11 @@ uint32_t emberAfMsToNextEventExtended(uint32_t maxMs, uint8_t * returnIndex); /** @name Messaging */ // @{ -/** - * @brief This function sends a ZCL response, based on the information - * that is currently in the outgoing buffer. It is expected that a complete - * ZCL message is present, including header. The application may use - * this method directly from within the message handling function - * and associated callbacks. However this will result in the - * response being sent before the APS Ack is sent which is not - * ideal. - * - * NOTE: This will overwrite the ZCL sequence number of the message - * to use the LAST received sequence number. - */ -EmberStatus emberAfSendResponse(void); - -/** - * @brief Send ZCL response with attached message sent callback - */ -EmberStatus emberAfSendResponseWithCallback(EmberAfMessageSentFunction callback); - -/** - * @brief Sends multicast. - */ -EmberStatus emberAfSendMulticast(chip::GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message); - -/** - * @brief Multicasts the message to the group in the binding table that - * matches the cluster and source endpoint in the APS frame. Note: if the - * binding table contains many matching entries, calling this API cause a - * significant amount of network traffic. Care should be taken when considering - * the effects of broadcasts in a network. - */ -EmberStatus emberAfSendMulticastToBindings(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message); - -/** - * @brief Sends Multicast with alias with attached message sent callback - */ -EmberStatus emberAfSendMulticastWithAliasWithCallback(chip::GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, EmberNodeId alias, uint8_t sequence, - EmberAfMessageSentFunction callback); - -/** - * @brief Sends multicast with attached message sent callback. - */ -EmberStatus emberAfSendMulticastWithCallback(chip::GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, EmberAfMessageSentFunction callback); - -/** - * @brief Sends broadcast. - */ -// EmberStatus emberAfSendBroadcast(EmberNodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message); - -/** - * @brief Sends broadcast with attached message sent callback. - */ -// EmberStatus emberAfSendBroadcastWithCallback(EmberNodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, -// uint8_t * message, EmberAfMessageSentFunction callback); - -/** - * @brief Sends broadcast with alias with attached message sent callback. - */ -// EmberStatus emberAfSendBroadcastWithAliasWithCallback(EmberNodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, -// uint8_t * message, EmberNodeId alias, uint8_t sequence, -// EmberAfMessageSentFunction callback); - -/** - * @brief Sends unicast. - */ -EmberStatus emberAfSendUnicast(const chip::MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message); - -/** - * @brief Sends unicast with attached message sent callback. - */ -EmberStatus emberAfSendUnicastWithCallback(const chip::MessageSendDestination & destination, EmberApsFrame * apsFrame, - uint16_t messageLength, uint8_t * message, EmberAfMessageSentFunction callback); - -/** - * @brief Unicasts the message to each remote node in the binding table that - * matches the cluster and source endpoint in the APS frame. Note: if the - * binding table contains many matching entries, calling this API cause a - * significant amount of network traffic. - */ -EmberStatus emberAfSendUnicastToBindings(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message); - -/** - * @brief emberAfSendUnicastToBindings with attached message sent callback. - */ -EmberStatus emberAfSendUnicastToBindingsWithCallback(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message, - EmberAfMessageSentFunction callback); - -/** - * @brief Sends interpan message. - */ -EmberStatus emberAfSendInterPan(EmberPanId panId, const EmberEUI64 destinationLongId, EmberNodeId destinationShortId, - chip::GroupId multicastId, chip::ClusterId clusterId, uint16_t messageLength, - uint8_t * messageBytes); - /** * @brief Sends end device binding request. */ EmberStatus emberAfSendEndDeviceBind(chip::EndpointId endpoint); -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. It - * will be sent as unicast to each remote node in the binding table that - * matches the cluster and source endpoint in the APS frame. Note: if the - * binding table contains many matching entries, calling this API cause a - * significant amount of network traffic. - */ -EmberStatus emberAfSendCommandUnicastToBindings(void); - -/** - * @brief emberAfSendCommandUnicastToBindings with attached message sent callback. - */ -EmberStatus emberAfSendCommandUnicastToBindingsWithCallback(EmberAfMessageSentFunction callback); - -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. It - * will be sent as multicast. - */ -EmberStatus emberAfSendCommandMulticast(chip::GroupId multicastId); - -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. It - * will be sent as multicast. - */ -EmberStatus emberAfSendCommandMulticastWithAlias(chip::GroupId multicastId, EmberNodeId alias, uint8_t sequence); - -/** - * @brief emberAfSendCommandMulticast with attached message sent callback. - */ -EmberStatus emberAfSendCommandMulticastWithCallback(chip::GroupId multicastId, EmberAfMessageSentFunction callback); - -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. It - * will be sent as multicast to the group specified in the binding table that - * matches the cluster and source endpoint in the APS frame. Note: if the - * binding table contains many matching entries, calling this API cause a - * significant amount of network traffic. - */ -EmberStatus emberAfSendCommandMulticastToBindings(void); -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. - * It will be sent as unicast. - */ -EmberStatus emberAfSendCommandUnicast(const chip::MessageSendDestination & destination); - -/** - * @brief emberAfSendCommandUnicast with attached message sent callback. - */ -EmberStatus emberAfSendCommandUnicastWithCallback(const chip::MessageSendDestination & destination, - EmberAfMessageSentFunction callback); - -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. - */ -EmberStatus emberAfSendCommandBroadcast(EmberNodeId destination); - -/** - * @brief emberAfSendCommandBroadcast with attached message sent callback. - */ -EmberStatus emberAfSendCommandBroadcastWithCallback(EmberNodeId destination, EmberAfMessageSentFunction callback); - -/** - * @brief emberAfSendCommandBroadcast from alias with attached message sent callback. - */ -EmberStatus emberAfSendCommandBroadcastWithAliasWithCallback(EmberNodeId destination, EmberNodeId alias, uint8_t sequence, - EmberAfMessageSentFunction callback); - -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. - */ -EmberStatus emberAfSendCommandBroadcastWithAlias(EmberNodeId destination, EmberNodeId alias, uint8_t sequence); -/** - * @brief Sends the command prepared with emberAfFill.... macro. - * - * This function is used to send a command that was previously prepared - * using the emberAfFill... macros from the client command API. - * It will be sent via inter-PAN. If destinationLongId is not NULL, the message - * will be sent to that long address using long addressing mode; otherwise, the - * message will be sent to destinationShortId using short address mode. IF - * multicastId is not zero, the message will be sent using multicast mode. - */ -EmberStatus emberAfSendCommandInterPan(EmberPanId panId, const EmberEUI64 destinationLongId, EmberNodeId destinationShortId, - chip::GroupId multicastId); - /** * @brief Sends a default response to a cluster command. * @@ -1267,12 +1065,6 @@ EmberStatus emberAfSendCommandInterPan(EmberPanId panId, const EmberEUI64 destin */ EmberStatus emberAfSendDefaultResponse(const EmberAfClusterCommand * cmd, EmberAfStatus status); -/** - * @brief emberAfSendDefaultResponse with attached message sent callback. - */ -EmberStatus emberAfSendDefaultResponseWithCallback(const EmberAfClusterCommand * cmd, EmberAfStatus status, - EmberAfMessageSentFunction callback); - /** * @brief Sends a default response to a cluster command using the * current command. @@ -1286,11 +1078,6 @@ EmberStatus emberAfSendDefaultResponseWithCallback(const EmberAfClusterCommand * */ EmberStatus emberAfSendImmediateDefaultResponse(EmberAfStatus status); -/** - * @brief emberAfSendImmediateDefaultResponse with attached message sent callback. - */ -EmberStatus emberAfSendImmediateDefaultResponseWithCallback(EmberAfStatus status, EmberAfMessageSentFunction callback); - /** * @brief Access to client API APS frame. */ diff --git a/src/app/util/attribute-table.cpp b/src/app/util/attribute-table.cpp index 84b042f62f8576..617e02b8fbb2e4 100644 --- a/src/app/util/attribute-table.cpp +++ b/src/app/util/attribute-table.cpp @@ -48,7 +48,6 @@ // for pulling in defines dealing with EITHER server or client #include "app/util/common.h" #include -#include #include #include diff --git a/src/app/util/chip-message-send.cpp b/src/app/util/chip-message-send.cpp deleted file mode 100644 index 3c37e1dcd58fb1..00000000000000 --- a/src/app/util/chip-message-send.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 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, softwarEchoe - * 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 - * This file provides an implementation of functions for sending messages. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace chip; - -// TODO: This is not ideal, but we're still sorting out how secure session -// managers end up working and whether they're singletons. In the long term, -// there will be some sane API that lets us send a message to a given node id. -// -// https://github.com/project-chip/connectedhomeip/issues/2566 tracks that API. -namespace chip { -// TODO: This is a placeholder delegate for exchange context created in Device::SendMessage() -// Delete this class when Device::SendMessage() is obsoleted. -class DeviceExchangeDelegate : public Messaging::ExchangeDelegate -{ - CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader, - System::PacketBufferHandle && payload) override - { - return CHIP_NO_ERROR; - } - void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} -}; - -extern Messaging::ExchangeManager * ExchangeManager(); -} // namespace chip - -EmberStatus chipSendUnicast(Messaging::ExchangeContext * exchange, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, Messaging::SendFlags sendFlags) -{ - uint16_t frameSize = encodeApsFrame(nullptr, 0, apsFrame); - uint32_t dataLengthUnchecked = uint32_t(frameSize) + uint32_t(messageLength); - if (dataLengthUnchecked > UINT16_MAX) - { - // Definitely too long for a packet! - return EMBER_MESSAGE_TOO_LONG; - } - uint16_t dataLength = static_cast(dataLengthUnchecked); - - if (frameSize == 0) - { - ChipLogError(Zcl, "Error encoding APS frame"); - return EMBER_ERR_FATAL; - } - - System::PacketBufferHandle buffer = MessagePacketBuffer::New(dataLength); - if (buffer.IsNull()) - { - // FIXME: Not quite right... what's the right way to indicate "out of - // heap"? - return EMBER_MESSAGE_TOO_LONG; - } - - if (encodeApsFrame(buffer->Start(), dataLength, apsFrame) != frameSize) - { - // Something is very wrong here; our first call lied to us! - ChipLogError(Zcl, "Something wrong happened trying to encode aps frame to respond with"); - return EMBER_ERR_FATAL; - } - - memcpy(buffer->Start() + frameSize, message, messageLength); - buffer->SetDataLength(dataLength); - - CHIP_ERROR err = exchange->SendMessage(Protocols::TempZCL::MsgType::TempZCLResponse, std::move(buffer), sendFlags); - - if (err != CHIP_NO_ERROR) - { - // FIXME: Figure out better translations between our error types? - return EMBER_DELIVERY_FAILED; - } - - return EMBER_SUCCESS; -} - -EmberStatus chipSendUnicast(NodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) -{ - // TODO: temporary create a handle from node id, will be fix in PR 3602 - Messaging::ExchangeManager * exchangeMgr = ExchangeManager(); - if (exchangeMgr == nullptr) - { - return EMBER_DELIVERY_FAILED; - } - - Messaging::ExchangeContext * exchange = - exchangeMgr->NewContext(exchangeMgr->GetSessionManager()->FindSecureSessionForNode(destination), nullptr); - if (exchange == nullptr) - { - return EMBER_DELIVERY_FAILED; - } - - // TODO(#5675): This code is temporary, and must be updated to use the IM API. Currently, we use a temporary Protocol - // TempZCL to carry over legacy ZCL messages, use an ephemeral exchange to send message and use its unsolicited message - // handler to receive messages. We need to set flag kNoAutoRequestAck since there is no persistent exchange to - // receive the ack message. This logic needs to be deleted after we convert all legacy ZCL messages to IM messages. - DeviceExchangeDelegate delegate; - exchange->SetDelegate(&delegate); - - Messaging::SendFlags sendFlags; - - sendFlags.Set(Messaging::SendMessageFlags::kNoAutoRequestAck); - - EmberStatus err = chipSendUnicast(exchange, apsFrame, messageLength, message, sendFlags); - - // Make sure we always close the temporary exchange we just created, unless - // we sent a message successfully. - if (err != EMBER_SUCCESS) - { - exchange->Close(); - } - - return err; -} diff --git a/src/app/util/chip-message-send.h b/src/app/util/chip-message-send.h deleted file mode 100644 index ca429785eb360b..00000000000000 --- a/src/app/util/chip-message-send.h +++ /dev/null @@ -1,59 +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, softwarEchoe - * 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 - * This file declares a function that can be called to send a unicast message - * (in the form of a buffer and length) to a given response destination node - * id. - */ - -#pragma once - -#include // For EmberApsFrame, EmberStatus, node ids. -#include -#include - -/** - * @brief - * Called to send a unicast message on the given exchange. The message is - * constructed by serializing the given APS frame followed by the actual - * message buffer passed in. - * - * @param[in] exchange The exchange to send the message on. - * @param[in] apsFrame The APS frame to use for the message. - * @param[in] messageLength The length of the message to send after the APS - * frame. - * @param[in] message The message to send after the APS frame. - * @param[in] sendFlags The SendFlags needed, if any. - */ -EmberStatus chipSendUnicast(chip::Messaging::ExchangeContext * exchange, EmberApsFrame * apsFrame, uint16_t messageLength, - uint8_t * message, chip::Messaging::SendFlags sendFlags = chip::Messaging::SendFlags()); - -/** - * @brief - * Called to send a unicast message. The message is constructed - * by serializing the given APS frame followed by the actual message - * buffer passed in. - * - * @param[in] destination The destination node id to send the message to. - * @param[in] apsFrame The APS frame to use for the message. - * @param[in] messageLength The length of the message to send after the APS - * frame. - * @param[in] message The message to send after the APS frame. - */ -EmberStatus chipSendUnicast(chip::NodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message); diff --git a/src/app/util/client-api.cpp b/src/app/util/client-api.cpp index 53250ea3f7b5db..cb2d25038a3e8d 100644 --- a/src/app/util/client-api.cpp +++ b/src/app/util/client-api.cpp @@ -254,21 +254,6 @@ void emberAfSetExternalBuffer(uint8_t * buffer, uint16_t bufferLen, uint16_t * l emAfCommandApsFrame = apsFrame; } -uint16_t emberAfFillExternalManufacturerSpecificBuffer(uint8_t frameControl, ClusterId clusterId, uint16_t manufacturerCode, - CommandId commandId, const char * format, ...) -{ - uint16_t returnValue; - va_list argPointer; - - va_start(argPointer, format); - returnValue = vFillBuffer(emAfZclBuffer, emAfZclBufferLen, frameControl, manufacturerCode, commandId, format, argPointer); - va_end(argPointer); - *emAfResponseLengthPtr = returnValue; - emAfCommandApsFrame->clusterId = clusterId; - emAfCommandApsFrame->options = EMBER_AF_DEFAULT_APS_OPTIONS; - return returnValue; -} - uint16_t emberAfFillExternalBuffer(uint8_t frameControl, ClusterId clusterId, CommandId commandId, const char * format, ...) { uint16_t returnValue; @@ -284,96 +269,6 @@ uint16_t emberAfFillExternalBuffer(uint8_t frameControl, ClusterId clusterId, Co return returnValue; } -uint16_t emberAfFillBuffer(uint8_t * buffer, uint16_t bufferLen, uint8_t frameControl, CommandId commandId, const char * format, - ...) -{ - uint16_t returnValue; - va_list argPointer; - va_start(argPointer, format); - returnValue = vFillBuffer(buffer, bufferLen, frameControl, EMBER_AF_NULL_MANUFACTURER_CODE, commandId, format, argPointer); - va_end(argPointer); - return returnValue; -} - -EmberStatus emberAfSendCommandUnicastToBindingsWithCallback(EmberAfMessageSentFunction callback) -{ - return emberAfSendUnicastToBindingsWithCallback(emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer, callback); -} - -EmberStatus emberAfSendCommandUnicastToBindings(void) -{ - return emberAfSendCommandUnicastToBindingsWithCallback(NULL); -} - -// EmberStatus emberAfSendCommandMulticastWithCallback(GroupId multicastId, EmberAfMessageSentFunction callback) -// { -// return emberAfSendMulticastWithCallback(multicastId, emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer, callback); -// } - -// EmberStatus emberAfSendCommandMulticastWithAliasWithCallback(GroupId multicastId, EmberNodeId alias, uint8_t sequence, -// EmberAfMessageSentFunction callback) -// { -// return emberAfSendMulticastWithAliasWithCallback(multicastId, emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer, -// alias, -// sequence, callback); -// } - -// EmberStatus emberAfSendCommandMulticast(GroupId multicastId) -// { -// return emberAfSendCommandMulticastWithCallback(multicastId, NULL); -// } - -// EmberStatus emberAfSendCommandMulticastWithAlias(GroupId multicastId, EmberNodeId alias, uint8_t sequence) -// { -// return emberAfSendCommandMulticastWithAliasWithCallback(multicastId, alias, sequence, NULL); -// } - -EmberStatus emberAfSendCommandMulticastToBindings(void) -{ - return emberAfSendMulticastToBindings(emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer); -} - -// EmberStatus emberAfSendCommandUnicastWithCallback(const chip::MessageSendDestination & destination, EmberAfMessageSentFunction -// callback) -// { -// return emberAfSendUnicastWithCallback(destination, emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer, callback); -// } - -// EmberStatus emberAfSendCommandUnicast(const chip::MessageSendDestination & destination) -// { -// return emberAfSendCommandUnicastWithCallback(destination, NULL); -// } - -// EmberStatus emberAfSendCommandBroadcastWithCallback(EmberNodeId destination, EmberAfMessageSentFunction callback) -// { -// return emberAfSendBroadcastWithCallback(destination, emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer, callback); -// } - -// EmberStatus emberAfSendCommandBroadcastWithAliasWithCallback(EmberNodeId destination, EmberNodeId alias, uint8_t sequence, -// EmberAfMessageSentFunction callback) -// { -// return emberAfSendBroadcastWithAliasWithCallback(destination, emAfCommandApsFrame, *emAfResponseLengthPtr, emAfZclBuffer, -// alias, -// sequence, callback); -// } - -// EmberStatus emberAfSendCommandBroadcastWithAlias(EmberNodeId destination, EmberNodeId alias, uint8_t sequence) -// { -// return emberAfSendCommandBroadcastWithAliasWithCallback(destination, alias, sequence, NULL); -// } - -// EmberStatus emberAfSendCommandBroadcast(EmberNodeId destination) -// { -// return emberAfSendCommandBroadcastWithCallback(destination, NULL); -// } - -// EmberStatus emberAfSendCommandInterPan(EmberPanId panId, const EmberEUI64 destinationLongId, EmberNodeId destinationShortId, -// GroupId multicastId) -// { -// return emberAfSendInterPan(panId, destinationLongId, destinationShortId, multicastId, emAfCommandApsFrame->clusterId, -// *emAfResponseLengthPtr, emAfZclBuffer); -// } - EmberApsFrame * emberAfGetCommandApsFrame(void) { return emAfCommandApsFrame; diff --git a/src/app/util/client-api.h b/src/app/util/client-api.h index 648dbb0c93c78f..9488eca4399a4b 100644 --- a/src/app/util/client-api.h +++ b/src/app/util/client-api.h @@ -94,53 +94,6 @@ uint16_t emberAfFillExternalBuffer(uint8_t frameControl, chip::ClusterId clusterId, chip::CommandId commandId, const char * format, ...); -/** - * @brief Function that fills in the buffer with manufacturer-specific command. - * - * Fills the outgoing ZCL buffer and returns the number - * of bytes used in a buffer. Uses the buffers that - * were previously set with emberAfSetExternalBuffer. - * - * @param frameControl Byte used for frame control. - * @param clusterId Cluster ID of message. - * @param manufacturerCode Manufacturer code of message. - * @param commandId Command ID of message. - * @param format String format for further arguments to the function. - * Format values are: - * - '0' -- '9' and 'A' -- 'G': Pointer to a buffer containing 0--16 raw - * bytes. The data is copied as is to the destination buffer. - * - 'u': uint8_t. - * - 'v': uint16_t. The bytes are copied in little-endian format to the - * destination buffer. - * - 'x': int24u. The bytes are copied in little-endian format to the - * destination buffer. - * - 'w': uint32_t. The bytes are copied in little-endian format to the - * destination buffer. - * - 'y': uint64_t. The bytes are copied in little-endian format to the - * destination buffer. - * - 'l': Pointer to a buffer containing a ZigBee long string, with the - * first two bytes of the buffer specifying the length of the string - * data in little-endian format. The length bytes and the string - * itself are both included as is in the destination buffer. - * - 's': Pointer to a buffer containing a ZigBee string, with the first - * byte of the buffer specifying the length of the string data. The - * length byte and the string itself are both included as is in the - * destination buffer. - * - 'L': Pointer to a buffer containing a long string followed by an - * uint16_t specifying the length of the string data. The length - * bytes in little-endian format will precede the string itself in - * the destination buffer. - * - 'S': Pointer to a buffer containing a string followed by an uint8_t - * specifying the length of the string data. The length byte will - * precede the string itself in the destination buffer. - * - 'b': Pointer to a buffer containing a sequence of raw bytes followed - * by an uint16_t specifying the length of the data. The data is - * copied as is to the destination buffer. The length is not - * included. - */ -uint16_t emberAfFillExternalManufacturerSpecificBuffer(uint8_t frameControl, chip::ClusterId clusterId, uint16_t manufacturerCode, - chip::CommandId commandId, const char * format, ...); - /** * @brief Function that registers the buffer to use with the fill function. * Registers the buffer for use with the emberAfFillExternalBuffer function. @@ -152,16 +105,6 @@ uint16_t emberAfFillExternalManufacturerSpecificBuffer(uint8_t frameControl, chi */ void emberAfSetExternalBuffer(uint8_t * buffer, uint16_t bufferLen, uint16_t * responseLengthPtr, EmberApsFrame * apsFramePtr); -/** - * @brief Stateless function that fills the passed buffer with command data. - * - * Stateless method, that fill the passed buffer. - * Used internally by emberAfFillExternalBuffer, but can be used - * for generic buffer filling. - */ -uint16_t emberAfFillBuffer(uint8_t * buffer, uint16_t bufferLen, uint8_t frameControl, chip::CommandId commandId, - const char * format, ...); - #if !defined(DOXYGEN_SHOULD_SKIP_THIS) // The buffer used for filling ZCL Messages. extern uint8_t * emAfZclBuffer; diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index 106bd9b58a102c..2e3dc4d2092329 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -204,7 +204,7 @@ bool IMEmberAfSendDefaultResponseWithCallback(EmberAfStatus status) { if (currentCommandObject == nullptr) { - // If this command is not handled by IM, then let ember send response. + // We have no idea what we're supposed to respond to. return false; } diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index bdf61764c17a99..d0bfa582928ccb 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -48,8 +48,8 @@ #include #include #include -#include #include +#include #include #ifdef EMBER_AF_PLUGIN_GROUPS_SERVER @@ -58,19 +58,6 @@ using namespace chip; -// Function for Compatibility -namespace chip { -namespace app { -namespace Compatibility { -bool IMEmberAfSendDefaultResponseWithCallback(EmberAfStatus status); -bool __attribute__((weak)) IMEmberAfSendDefaultResponseWithCallback(EmberAfStatus status) -{ - return false; -} -} // namespace Compatibility -} // namespace app -} // namespace chip - //------------------------------------------------------------------------------ // Forward Declarations @@ -113,12 +100,6 @@ static uint8_t /*enum EmberAfDisableDefaultResponse*/ emAfSavedDisableDefaultRes // Holds the response type uint8_t emberAfResponseType = ZCL_UTIL_RESP_NORMAL; -static EmberAfInterpanHeader interpanResponseHeader; - -uint8_t emAfExtendedPanId[EXTENDED_PAN_ID_SIZE] = { - 0, 0, 0, 0, 0, 0, 0, 0, -}; - #ifdef EMBER_AF_GENERATED_PLUGIN_TICK_FUNCTION_DECLARATIONS EMBER_AF_GENERATED_PLUGIN_TICK_FUNCTION_DECLARATIONS #endif @@ -207,38 +188,6 @@ EmberAfDifferenceType emberAfGetDifference(uint8_t * pData, EmberAfDifferenceTyp return diff; } -// -------------------------------------------------- - -static void prepareForResponse(const EmberAfClusterCommand * cmd) -{ - emberAfResponseApsFrame.clusterId = cmd->apsFrame->clusterId; - emberAfResponseApsFrame.sourceEndpoint = cmd->apsFrame->destinationEndpoint; - emberAfResponseApsFrame.destinationEndpoint = cmd->apsFrame->sourceEndpoint; - - // Use the default APS options for the response, but also use encryption and - // retries if the incoming message used them. The rationale is that the - // sender of the request cares about some aspects of the delivery, so we as - // the receiver should make equal effort for the response. - emberAfResponseApsFrame.options = EMBER_AF_DEFAULT_APS_OPTIONS; - if ((cmd->apsFrame->options & EMBER_APS_OPTION_RETRY) != 0U) - { - emberAfResponseApsFrame.options |= EMBER_APS_OPTION_RETRY; - } - - if (cmd->interPanHeader == NULL) - { - emberAfResponseDestination = cmd->source; - emberAfResponseType = static_cast(emberAfResponseType & ~ZCL_UTIL_RESP_INTERPAN); - } - else - { - emberAfResponseType |= ZCL_UTIL_RESP_INTERPAN; - memmove(&interpanResponseHeader, cmd->interPanHeader, sizeof(EmberAfInterpanHeader)); - // Always send responses as unicast - interpanResponseHeader.messageType = EMBER_AF_INTER_PAN_UNICAST; - } -} - // **************************************** // Initialize Clusters // **************************************** @@ -465,164 +414,26 @@ void emAfApplyDisableDefaultResponse(uint8_t * frame_control) } } -static bool isBroadcastDestination(Messaging::ExchangeContext * responseDestination) -{ - // TODO: Will need to actually figure out how to test for this! - return false; -} - -EmberStatus emberAfSendResponseWithCallback(EmberAfMessageSentFunction callback) -{ - EmberStatus status; - uint8_t label; - - // If the no-response flag is set, don't send anything. - if ((emberAfResponseType & ZCL_UTIL_RESP_NONE) != 0U) - { - emberAfDebugPrintln("ZCL Util: no response at user request"); - return EMBER_SUCCESS; - } - - // Make sure we are respecting the request APS options - // there are seemingly some calls to emberAfSendResponse - // that occur outside of the emberAfProcessMessage context, - // which leads to a bad memory reference - AHilton - if (emberAfCurrentCommand() != NULL) - { - if ((emberAfCurrentCommand()->apsFrame->options & EMBER_APS_OPTION_RETRY) != 0U) - { - emberAfResponseApsFrame.options |= EMBER_APS_OPTION_RETRY; - } - } - - // Fill commands may increase the sequence. For responses, we want to make - // sure the sequence is reset to that of the request. - if ((appResponseData[0] & ZCL_MANUFACTURER_SPECIFIC_MASK) != 0U) - { - appResponseData[3] = emberAfIncomingZclSequenceNumber; - } - else - { - appResponseData[1] = emberAfIncomingZclSequenceNumber; - } - - // The manner in which the message is sent depends on the response flags and - // the destination of the message. - if ((emberAfResponseType & ZCL_UTIL_RESP_INTERPAN) != 0U) - { - label = 'I'; - status = emberAfInterpanSendMessageCallback(&interpanResponseHeader, appResponseLength, appResponseData); - emberAfResponseType = static_cast(emberAfResponseType & ~ZCL_UTIL_RESP_INTERPAN); - } - else if (!isBroadcastDestination(emberAfResponseDestination)) - { - label = 'U'; - status = emberAfSendUnicastWithCallback(MessageSendDestination::ViaExchange(emberAfResponseDestination), - &emberAfResponseApsFrame, appResponseLength, appResponseData, callback); - } - else - { - label = 'B'; -#if 0 - status = emberAfSendBroadcastWithCallback(emberAfResponseDestination, - &emberAfResponseApsFrame, - appResponseLength, - appResponseData, - callback); -#else - status = EMBER_SUCCESS; -#endif - } - UNUSED_VAR(label); - emberAfDebugPrintln("T%4x:TX (%p) %ccast 0x%x%p", 0, "resp", label, status, ""); - emberAfDebugPrint("TX buffer: ["); - emberAfDebugFlush(); - emberAfDebugPrintBuffer(appResponseData, appResponseLength, true); - emberAfDebugPrintln("]"); - emberAfDebugFlush(); - -#ifdef EMBER_AF_ENABLE_STATISTICS - if (status == EMBER_SUCCESS) - { - afNumPktsSent++; - } -#endif - - return status; -} - -EmberStatus emberAfSendResponse(void) -{ - return emberAfSendResponseWithCallback(NULL); -} - -EmberStatus emberAfSendImmediateDefaultResponseWithCallback(EmberAfStatus status, EmberAfMessageSentFunction callback) -{ - return emberAfSendDefaultResponseWithCallback(emberAfCurrentCommand(), status, callback); -} - EmberStatus emberAfSendImmediateDefaultResponse(EmberAfStatus status) { - return emberAfSendImmediateDefaultResponseWithCallback(status, NULL); + return emberAfSendDefaultResponse(emberAfCurrentCommand(), status); } -EmberStatus emberAfSendDefaultResponseWithCallback(const EmberAfClusterCommand * cmd, EmberAfStatus status, - EmberAfMessageSentFunction callback) +EmberStatus emberAfSendDefaultResponse(const EmberAfClusterCommand * cmd, EmberAfStatus status) { - uint8_t frameControl; - // Default Response commands are only sent in response to unicast commands. if (cmd->type != EMBER_INCOMING_UNICAST && cmd->type != EMBER_INCOMING_UNICAST_REPLY) { return EMBER_SUCCESS; } - if (chip::app::Compatibility::IMEmberAfSendDefaultResponseWithCallback(status)) - { - // If the compatibility can handle this response - return EMBER_SUCCESS; - } - - // If the Disable Default Response sub-field is set, Default Response commands - // are only sent if there was an error. - if ((cmd->buffer[0] & ZCL_DISABLE_DEFAULT_RESPONSE_MASK) && status == EMBER_ZCL_STATUS_SUCCESS) - { - return EMBER_SUCCESS; - } - - // Default Response commands are never sent in response to other Default - // Response commands. - if (!cmd->clusterSpecific && cmd->commandId == ZCL_DEFAULT_RESPONSE_COMMAND_ID) - { - return EMBER_SUCCESS; - } - - appResponseLength = 0; - frameControl = static_cast(ZCL_GLOBAL_COMMAND | - (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER ? ZCL_FRAME_CONTROL_SERVER_TO_CLIENT - : ZCL_FRAME_CONTROL_CLIENT_TO_SERVER)); - - if (!cmd->mfgSpecific) - { - emberAfPutInt8uInResp(frameControl & (uint8_t) ~ZCL_MANUFACTURER_SPECIFIC_MASK); - } - else + if (!chip::app::Compatibility::IMEmberAfSendDefaultResponseWithCallback(status)) { - emberAfPutInt8uInResp(frameControl | ZCL_MANUFACTURER_SPECIFIC_MASK); - emberAfPutInt16uInResp(cmd->mfgCode); + // Caller is not responding to anything! + return EMBER_ERR_FATAL; } - emberAfPutInt8uInResp(cmd->seqNum); - emberAfPutInt32uInResp(ZCL_DEFAULT_RESPONSE_COMMAND_ID); - emberAfPutInt32uInResp(cmd->commandId); - emberAfPutStatusInResp(status); - prepareForResponse(cmd); - return emberAfSendResponseWithCallback(callback); -} - -EmberStatus emberAfSendDefaultResponse(const EmberAfClusterCommand * cmd, EmberAfStatus status) -{ - return emberAfSendDefaultResponseWithCallback(cmd, status, NULL); + return EMBER_SUCCESS; } void emberAfCopyInt16u(uint8_t * data, uint16_t index, uint16_t x) diff --git a/src/app/util/util.h b/src/app/util/util.h index f85a272740ab6e..7a8552e8a8d4b0 100644 --- a/src/app/util/util.h +++ b/src/app/util/util.h @@ -223,8 +223,6 @@ uint16_t emberAfStrnlen(const uint8_t * string, uint16_t maxLength); uint8_t emberAfAppendCharacters(uint8_t * zclString, uint8_t zclStringMaxLen, const uint8_t * appendingChars, uint8_t appendingCharsLen); -extern uint8_t emAfExtendedPanId[]; - EmberStatus emAfValidateChannelPages(uint8_t page, uint8_t channel); /* @brief A Silicon Labs assert function diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 7b2969fbee23b4..6ddafa5993cb1a 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include diff --git a/src/darwin/Framework/CHIP.xcodeproj/project.pbxproj b/src/darwin/Framework/CHIP.xcodeproj/project.pbxproj index f22942df72f47f..5cc83020846a17 100644 --- a/src/darwin/Framework/CHIP.xcodeproj/project.pbxproj +++ b/src/darwin/Framework/CHIP.xcodeproj/project.pbxproj @@ -20,12 +20,10 @@ 1E85732826551A490050A4D9 /* attribute-table.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731826551A490050A4D9 /* attribute-table.cpp */; }; 1E85732926551A490050A4D9 /* af-event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731926551A490050A4D9 /* af-event.cpp */; }; 1E85732A26551A490050A4D9 /* ember-compatibility-functions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731A26551A490050A4D9 /* ember-compatibility-functions.cpp */; }; - 1E85732B26551A490050A4D9 /* af-main-common.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731B26551A490050A4D9 /* af-main-common.cpp */; }; 1E85732C26551A490050A4D9 /* DataModelHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731C26551A490050A4D9 /* DataModelHandler.cpp */; }; 1E85732D26551A490050A4D9 /* util.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731D26551A490050A4D9 /* util.cpp */; }; 1E85732E26551A490050A4D9 /* ember-print.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731E26551A490050A4D9 /* ember-print.cpp */; }; 1E85732F26551A490050A4D9 /* attribute-size-util.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85731F26551A490050A4D9 /* attribute-size-util.cpp */; }; - 1E85733126551A490050A4D9 /* chip-message-send.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E85732126551A490050A4D9 /* chip-message-send.cpp */; }; 1EB41B7B263C4CC60048E4C1 /* CHIPClustersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EB41B7A263C4CC60048E4C1 /* CHIPClustersTests.m */; }; 1EC3238D271999E2002A8BF0 /* cluster-objects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1EC3238C271999E2002A8BF0 /* cluster-objects.cpp */; }; 1EC4CE5D25CC26E900D7304F /* CHIPClustersObjc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1EC4CE5925CC26E900D7304F /* CHIPClustersObjc.mm */; }; @@ -110,12 +108,10 @@ 1E85731826551A490050A4D9 /* attribute-table.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "attribute-table.cpp"; path = "../../../app/util/attribute-table.cpp"; sourceTree = ""; }; 1E85731926551A490050A4D9 /* af-event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "af-event.cpp"; path = "../../../app/util/af-event.cpp"; sourceTree = ""; }; 1E85731A26551A490050A4D9 /* ember-compatibility-functions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "ember-compatibility-functions.cpp"; path = "../../../app/util/ember-compatibility-functions.cpp"; sourceTree = ""; }; - 1E85731B26551A490050A4D9 /* af-main-common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "af-main-common.cpp"; path = "../../../app/util/af-main-common.cpp"; sourceTree = ""; }; 1E85731C26551A490050A4D9 /* DataModelHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DataModelHandler.cpp; path = ../../../app/util/DataModelHandler.cpp; sourceTree = ""; }; 1E85731D26551A490050A4D9 /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = util.cpp; path = ../../../app/util/util.cpp; sourceTree = ""; }; 1E85731E26551A490050A4D9 /* ember-print.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "ember-print.cpp"; path = "../../../app/util/ember-print.cpp"; sourceTree = ""; }; 1E85731F26551A490050A4D9 /* attribute-size-util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "attribute-size-util.cpp"; path = "../../../app/util/attribute-size-util.cpp"; sourceTree = ""; }; - 1E85732126551A490050A4D9 /* chip-message-send.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "chip-message-send.cpp"; path = "../../../app/util/chip-message-send.cpp"; sourceTree = ""; }; 1EB41B7A263C4CC60048E4C1 /* CHIPClustersTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHIPClustersTests.m; sourceTree = ""; }; 1EC3238C271999E2002A8BF0 /* cluster-objects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "cluster-objects.cpp"; path = "../../../../zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp"; sourceTree = ""; }; 1EC4CE5925CC26E900D7304F /* CHIPClustersObjc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CHIPClustersObjc.mm; path = "zap-generated/CHIPClustersObjc.mm"; sourceTree = ""; }; @@ -207,12 +203,10 @@ 2F79A67626CE6672006377B0 /* im-client-callbacks.cpp */, 2FD775542695557E00FF4B12 /* error-mapping.cpp */, 1E85731926551A490050A4D9 /* af-event.cpp */, - 1E85731B26551A490050A4D9 /* af-main-common.cpp */, 1E85731F26551A490050A4D9 /* attribute-size-util.cpp */, 1E85731626551A490050A4D9 /* attribute-storage.cpp */, 1E85731826551A490050A4D9 /* attribute-table.cpp */, 1E85731226551A490050A4D9 /* binding-table.cpp */, - 1E85732126551A490050A4D9 /* chip-message-send.cpp */, 1E85731726551A490050A4D9 /* client-api.cpp */, 1E85731C26551A490050A4D9 /* DataModelHandler.cpp */, 1E85731A26551A490050A4D9 /* ember-compatibility-functions.cpp */, @@ -522,7 +516,6 @@ 1ED276E026C57CF000547A89 /* CHIPCallbackBridge.mm in Sources */, 1E85732D26551A490050A4D9 /* util.cpp in Sources */, 513DDB8A2761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm in Sources */, - 1E85732B26551A490050A4D9 /* af-main-common.cpp in Sources */, 2FD775552695557E00FF4B12 /* error-mapping.cpp in Sources */, 1E85732A26551A490050A4D9 /* ember-compatibility-functions.cpp in Sources */, B289D4222639C0D300D4E314 /* CHIPOnboardingPayloadParser.m in Sources */, @@ -534,7 +527,6 @@ 1E85732826551A490050A4D9 /* attribute-table.cpp in Sources */, 1E85732626551A490050A4D9 /* attribute-storage.cpp in Sources */, 1E85732C26551A490050A4D9 /* DataModelHandler.cpp in Sources */, - 1E85733126551A490050A4D9 /* chip-message-send.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/protocols/Protocols.h b/src/protocols/Protocols.h index fc661b1d6de848..7f87ce0aea59d1 100644 --- a/src/protocols/Protocols.h +++ b/src/protocols/Protocols.h @@ -78,7 +78,6 @@ CHIP_STANDARD_PROTOCOL(InteractionModel, 0x0001) // Interaction Model P CHIP_STANDARD_PROTOCOL(BDX, 0x0002) // Bulk Data Exchange Protocol CHIP_STANDARD_PROTOCOL(UserDirectedCommissioning, 0x0003) // User Directed Commissioning Protocol CHIP_STANDARD_PROTOCOL(Echo, 0x0004) // Echo Protocol. To be removed or standardized. -CHIP_STANDARD_PROTOCOL(TempZCL, 0x0009) // For carrying ZCL-compatible messages, to be removed when we no longer use them #undef CHIP_STANDARD_PROTOCOL diff --git a/src/protocols/temp_zcl/TempZCL.h b/src/protocols/temp_zcl/TempZCL.h deleted file mode 100644 index 42673abde38be4..00000000000000 --- a/src/protocols/temp_zcl/TempZCL.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * All rights reserved. - * - * 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 - * This file defines message types for TempZCL protocol. - * - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace chip { -namespace Protocols { -namespace TempZCL { - -/** - * TempZCL Protocol Message Types - */ -enum class MsgType : uint8_t -{ - TempZCLRequest = 0x01, - TempZCLResponse = 0x02 -}; - -} // namespace TempZCL - -template <> -struct MessageTypeTraits -{ - static constexpr const Protocols::Id & ProtocolId() { return TempZCL::Id; } -}; - -} // namespace Protocols -} // namespace chip