From 6dc7f5322976d5b786e777311a9f4584d28ac266 Mon Sep 17 00:00:00 2001
From: Boris Zbarsky <bzbarsky@apple.com>
Date: Fri, 17 Feb 2023 11:33:26 -0500
Subject: [PATCH] Remove some no-longer-used ZCL message buffer processing
 code.

---
 src/app/util/af.h        |  28 -----------
 src/app/util/common.h    |   3 --
 src/app/util/message.cpp | 104 ---------------------------------------
 src/app/util/util.cpp    | 104 ---------------------------------------
 src/app/util/util.h      |  79 -----------------------------
 5 files changed, 318 deletions(-)

diff --git a/src/app/util/af.h b/src/app/util/af.h
index 22016cddf77d2e..7a66c75b85faa8 100644
--- a/src/app/util/af.h
+++ b/src/app/util/af.h
@@ -218,38 +218,10 @@ enum
  */
 bool emberAfIsTypeSigned(EmberAfAttributeType dataType);
 
-/**
- * @brief Function that extracts a 64-bit integer from the message buffer
- */
-uint64_t emberAfGetInt64u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen);
-#define emberAfGetInt64s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt64u(message, currentIndex, msgLen))
-
-/**
- * @brief Function that extracts a 32-bit integer from the message buffer
- */
-uint32_t emberAfGetInt32u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen);
-#define emberAfGetInt32s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt32u(message, currentIndex, msgLen))
-
-/**
- * @brief Function that extracts a 24-bit integer from the message buffer
- */
-uint32_t emberAfGetInt24u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen);
-#define emberAfGetInt24s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt24u(message, currentIndex, msgLen))
-
 /**
  * @brief Function that extracts a 16-bit integer from the message buffer
  */
 uint16_t emberAfGetInt16u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen);
-#define emberAfGetInt16s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt16u(message, currentIndex, msgLen))
-
-/**
- * @brief Function that extracts a ZCL string from the message buffer
- */
-uint8_t * emberAfGetString(uint8_t * message, uint16_t currentIndex, uint16_t msgLen);
-/**
- * @brief Function that extracts a ZCL long string from the message buffer
- */
-uint8_t * emberAfGetLongString(uint8_t * message, uint16_t currentIndex, uint16_t msgLen);
 
 /**
  * @brief Macro for consistency, that extracts single byte out of the message
diff --git a/src/app/util/common.h b/src/app/util/common.h
index dc97f18419e5db..dba2b142a01f0b 100644
--- a/src/app/util/common.h
+++ b/src/app/util/common.h
@@ -23,9 +23,6 @@
 #include <app/util/attribute-table.h>
 #include <app/util/util.h>
 
-#include <messaging/ExchangeContext.h>
-
 // the variables used to setup and send responses to cluster messages
 extern uint8_t appResponseData[EMBER_AF_RESPONSE_BUFFER_LEN];
 extern uint16_t appResponseLength;
-extern chip::Messaging::ExchangeContext * emberAfResponseDestination;
diff --git a/src/app/util/message.cpp b/src/app/util/message.cpp
index 220983d78046af..b9756fca151cbc 100644
--- a/src/app/util/message.cpp
+++ b/src/app/util/message.cpp
@@ -31,28 +31,13 @@ using namespace chip;
 // only result in a single call to emberIncomingMsgHandler. If the device
 // receives multiple ZCL messages, the stack will queue these and hand
 // these to the application via emberIncomingMsgHandler one at a time.
-Messaging::ExchangeContext * emberAfResponseDestination;
 uint8_t appResponseData[EMBER_AF_RESPONSE_BUFFER_LEN];
 uint16_t appResponseLength;
 
-// Used for empty string
-static uint16_t zeroLenByte     = 0;
-static uint8_t * zeroLenBytePtr = (uint8_t *) &zeroLenByte;
-
 //------------------------------------------------------------------------------
 // Utilities for adding bytes to the response buffer: appResponseData. These
 // functions take care of incrementing appResponseLength.
 
-void emberAfClearResponseData()
-{
-    emberAfResponseType = ZCL_UTIL_RESP_NORMAL;
-    // To prevent accidentally sending to someone else,
-    // set the destination to ourselves.
-    emberAfResponseDestination = nullptr /* emberAfGetNodeId() */;
-    memset(appResponseData, 0, EMBER_AF_RESPONSE_BUFFER_LEN);
-    appResponseLength = 0;
-}
-
 uint8_t * emberAfPutInt8uInResp(uint8_t value)
 {
     // emberAfDebugPrint("try %x max %x\r\n", appResponseLength, EMBER_AF_RESPONSE_BUFFER_LEN);
@@ -80,35 +65,6 @@ uint16_t * emberAfPutInt16uInResp(uint16_t value)
     return nullptr;
 }
 
-uint32_t * emberAfPutInt32uInResp(uint32_t value)
-{
-    uint8_t * a = emberAfPutInt8uInResp(EMBER_BYTE_0(value));
-    uint8_t * b = emberAfPutInt8uInResp(EMBER_BYTE_1(value));
-    uint8_t * c = emberAfPutInt8uInResp(EMBER_BYTE_2(value));
-    uint8_t * d = emberAfPutInt8uInResp(EMBER_BYTE_3(value));
-
-    if (a && b && c && d)
-    {
-        return (uint32_t *) a;
-    }
-
-    return nullptr;
-}
-
-uint32_t * emberAfPutInt24uInResp(uint32_t value)
-{
-    uint8_t * a = emberAfPutInt8uInResp(EMBER_BYTE_0(value));
-    uint8_t * b = emberAfPutInt8uInResp(EMBER_BYTE_1(value));
-    uint8_t * c = emberAfPutInt8uInResp(EMBER_BYTE_2(value));
-
-    if (a && b && c)
-    {
-        return (uint32_t *) a;
-    }
-
-    return nullptr;
-}
-
 uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length)
 {
     if ((appResponseLength + length) < EMBER_AF_RESPONSE_BUFFER_LEN)
@@ -132,11 +88,6 @@ void emberAfPutInt16sInResp(int16_t value)
     emberAfPutInt16uInResp(static_cast<uint16_t>(value));
 }
 
-void emberAfPutStatusInResp(EmberAfStatus value)
-{
-    emberAfPutInt8uInResp(to_underlying(value));
-}
-
 // ------------------------------------
 // Utilities for reading from RAM buffers (reading from incoming message
 // buffer)
@@ -162,66 +113,11 @@ uint64_t emberAfGetInt(const uint8_t * message, uint16_t currentIndex, uint16_t
     return result;
 }
 
-uint64_t emberAfGetInt64u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
-{
-    return emberAfGetInt(message, currentIndex, msgLen, 8);
-}
-
-uint32_t emberAfGetInt32u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
-{
-    return static_cast<uint32_t>(emberAfGetInt(message, currentIndex, msgLen, 4));
-}
-
-uint32_t emberAfGetInt24u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
-{
-    return static_cast<uint32_t>(emberAfGetInt(message, currentIndex, msgLen, 3));
-}
-
 uint16_t emberAfGetInt16u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
 {
     return static_cast<uint16_t>(emberAfGetInt(message, currentIndex, msgLen, 2));
 }
 
-uint8_t * emberAfGetString(uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
-{
-    // Strings must contain at least one byte for the length.
-    if (msgLen <= currentIndex)
-    {
-        emberAfDebugPrintln("GetString: %p", "buffer too short");
-        return zeroLenBytePtr;
-    }
-
-    // Starting from the current index, there must be enough bytes in the message
-    // for the string and the length byte.
-    if (msgLen < currentIndex + emberAfStringLength(&message[currentIndex]) + 1)
-    {
-        emberAfDebugPrintln("GetString: %p", "len byte wrong");
-        return zeroLenBytePtr;
-    }
-
-    return &message[currentIndex];
-}
-
-uint8_t * emberAfGetLongString(uint8_t * message, uint16_t currentIndex, uint16_t msgLen)
-{
-    // Long strings must contain at least two bytes for the length.
-    if (msgLen <= currentIndex + 1)
-    {
-        emberAfDebugPrintln("GetLongString: %p", "buffer too short");
-        return zeroLenBytePtr;
-    }
-
-    // Starting from the current index, there must be enough bytes in the message
-    // for the string and the length bytes.
-    if (msgLen < currentIndex + emberAfLongStringLength(&message[currentIndex]) + 2)
-    {
-        emberAfDebugPrintln("GetLongString: %p", "len bytes wrong");
-        return zeroLenBytePtr;
-    }
-
-    return &message[currentIndex];
-}
-
 uint8_t emberAfStringLength(const uint8_t * buffer)
 {
     // The first byte specifies the length of the string.  A length of 0xFF means
diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp
index fef5b493482841..c42f2b4e153553 100644
--- a/src/app/util/util.cpp
+++ b/src/app/util/util.cpp
@@ -45,19 +45,6 @@ const EmberAfClusterName zclClusterNames[] = {
     { kInvalidClusterId, nullptr }, // terminator
 };
 
-// DEPRECATED.
-uint8_t emberAfIncomingZclSequenceNumber = 0xFF;
-
-// Sequence used for outgoing messages if they are
-// not responses.
-uint8_t emberAfSequenceNumber = 0xFF;
-
-static uint8_t /*enum EmberAfDisableDefaultResponse*/ emAfDisableDefaultResponse          = EMBER_AF_DISABLE_DEFAULT_RESPONSE_NONE;
-static uint8_t /*enum EmberAfDisableDefaultResponse*/ emAfSavedDisableDefaultResponseVale = EMBER_AF_DISABLE_DEFAULT_RESPONSE_NONE;
-
-// Holds the response type
-uint8_t emberAfResponseType = ZCL_UTIL_RESP_NORMAL;
-
 #ifdef EMBER_AF_GENERATED_PLUGIN_TICK_FUNCTION_DECLARATIONS
 EMBER_AF_GENERATED_PLUGIN_TICK_FUNCTION_DECLARATIONS
 #endif
@@ -124,16 +111,6 @@ void emberAfInit()
     emAfCallInits();
 }
 
-void emberAfTick()
-{
-    // Call the AFV2-specific per-endpoint callbacks
-    // Anything that defines callbacks as void *TickCallback(void) is called in
-    // emAfInit(), which is a generated file
-#ifdef EMBER_AF_GENERATED_PLUGIN_TICK_FUNCTION_CALLS
-    EMBER_AF_GENERATED_PLUGIN_TICK_FUNCTION_CALLS
-#endif
-}
-
 // Cluster init functions that don't have a cluster implementation to define
 // them in.
 void MatterBallastConfigurationPluginServerInitCallback() {}
@@ -191,58 +168,6 @@ uint16_t emberAfFindClusterNameIndex(ClusterId cluster)
     return 0xFFFF;
 }
 
-// the caller to the library can set a flag to say do not respond to the
-// next ZCL message passed in to the library. Passing true means disable
-// the reply for the next ZCL message. Setting to false re-enables the
-// reply (in the case where the app disables it and then doesnt send a
-// message that gets parsed).
-void emberAfSetNoReplyForNextMessage(bool set)
-{
-    if (set)
-    {
-        emberAfResponseType |= ZCL_UTIL_RESP_NONE;
-    }
-    else
-    {
-        emberAfResponseType = static_cast<uint8_t>(emberAfResponseType & ~ZCL_UTIL_RESP_NONE);
-    }
-}
-
-void emberAfSetDisableDefaultResponse(EmberAfDisableDefaultResponse value)
-{
-    emAfDisableDefaultResponse = value;
-    if (value != EMBER_AF_DISABLE_DEFAULT_RESPONSE_ONE_SHOT)
-    {
-        emAfSavedDisableDefaultResponseVale = value;
-    }
-}
-
-EmberAfDisableDefaultResponse emberAfGetDisableDefaultResponse()
-{
-    return (EmberAfDisableDefaultResponse) emAfDisableDefaultResponse;
-}
-
-void emAfApplyDisableDefaultResponse(uint8_t * frame_control)
-{
-    if (frame_control == nullptr)
-    {
-        return;
-    }
-    if (emAfDisableDefaultResponse == EMBER_AF_DISABLE_DEFAULT_RESPONSE_ONE_SHOT)
-    {
-        emAfDisableDefaultResponse = emAfSavedDisableDefaultResponseVale;
-        *frame_control |= ZCL_DISABLE_DEFAULT_RESPONSE_MASK;
-    }
-    else if (emAfDisableDefaultResponse == EMBER_AF_DISABLE_DEFAULT_RESPONSE_PERMANENT)
-    {
-        *frame_control |= ZCL_DISABLE_DEFAULT_RESPONSE_MASK;
-    }
-    else
-    {
-        // MISRA requires ..else if.. to have terminating else.
-    }
-}
-
 void emberAfCopyInt16u(uint8_t * data, uint16_t index, uint16_t x)
 {
     data[index]     = (uint8_t)(((x)) & 0xFF);
@@ -399,35 +324,6 @@ bool emberAfIsTypeSigned(EmberAfAttributeType dataType)
     return (dataType >= ZCL_INT8S_ATTRIBUTE_TYPE && dataType <= ZCL_INT64S_ATTRIBUTE_TYPE);
 }
 
-uint8_t emberAfAppendCharacters(uint8_t * zclString, uint8_t zclStringMaxLen, const uint8_t * appendingChars,
-                                uint8_t appendingCharsLen)
-{
-    uint8_t freeChars;
-    uint8_t curLen;
-    uint8_t charsToWrite;
-
-    if ((zclString == nullptr) || (zclStringMaxLen == 0) || (appendingChars == nullptr) || (appendingCharsLen == 0))
-    {
-        return 0;
-    }
-
-    curLen = emberAfStringLength(zclString);
-
-    if ((zclString[0] == 0xFF) || (curLen >= zclStringMaxLen))
-    {
-        return 0;
-    }
-
-    freeChars    = static_cast<uint8_t>(zclStringMaxLen - curLen);
-    charsToWrite = (freeChars > appendingCharsLen) ? appendingCharsLen : freeChars;
-
-    memcpy(&zclString[1 + curLen], // 1 is to account for zcl's length byte
-           appendingChars, charsToWrite);
-    // Cast is safe, because the sum can't be bigger than zclStringMaxLen.
-    zclString[0] = static_cast<uint8_t>(curLen + charsToWrite);
-    return charsToWrite;
-}
-
 bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId)
 {
     return (emberAfGetServerAttributeIndexByAttributeId(endpoint, clusterId, attributeId) != UINT16_MAX);
diff --git a/src/app/util/util.h b/src/app/util/util.h
index 48fac334cdfeb4..271219c21f97b1 100644
--- a/src/app/util/util.h
+++ b/src/app/util/util.h
@@ -19,17 +19,6 @@
 
 #include <inttypes.h>
 
-// User asserts can override SLAB_ASSERT and should be defined as follows:
-// void userAssert (int file, int line);                   // declaration
-// #define USER_ASSERT(file, line) userAssert(file, line)  // definition
-
-// This controls the type of response. Normally The library sends an automatic
-// response (if appropriate) on the same PAN. The reply can be disabled by
-// calling emberAfSetNoReplyForNextMessage.
-#define ZCL_UTIL_RESP_NORMAL 0
-#define ZCL_UTIL_RESP_NONE 1
-#define ZCL_UTIL_RESP_INTERPAN 2
-
 // Cluster name structure
 typedef struct
 {
@@ -41,33 +30,10 @@ extern const EmberAfClusterName zclClusterNames[];
 
 #include <app/util/af.h>
 
-// Override Disable Default Response flag in the ZCL Frame Control
-typedef enum
-{
-    EMBER_AF_DISABLE_DEFAULT_RESPONSE_NONE      = 0, // no override
-    EMBER_AF_DISABLE_DEFAULT_RESPONSE_ONE_SHOT  = 1, // next message only
-    EMBER_AF_DISABLE_DEFAULT_RESPONSE_PERMANENT = 2  // until cancelled
-} EmberAfDisableDefaultResponse;
-
-// The default value for the Disable Default Response flag in ZCL Frame Control
-// is 0 (i.e. default responses are generated). The app can disable default
-// reponses either for the next message only or for all messages until another
-// call to this function.
-void emberAfSetDisableDefaultResponse(EmberAfDisableDefaultResponse value);
-
-// Return the current status
-EmberAfDisableDefaultResponse emberAfGetDisableDefaultResponse(void);
-
-// This function applies the curent override value to the ZCL Frame Control.
-// It is called internally by the framework in the final stages of filling the
-// message buffer.
-void emAfApplyDisableDefaultResponse(uint8_t * frame_control);
-
 // EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH is defined in config.h
 #define EMBER_AF_RESPONSE_BUFFER_LEN EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH
 
 void emberAfInit();
-void emberAfTick(void);
 uint16_t emberAfFindClusterNameIndex(chip::ClusterId cluster);
 void emberAfStackDown(void);
 
@@ -93,56 +59,11 @@ EmberAfDifferenceType emberAfGetDifference(uint8_t * pData, EmberAfDifferenceTyp
  */
 uint64_t emberAfGetInt(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen, uint8_t bytes);
 
-void emberAfClearResponseData(void);
 uint8_t * emberAfPutInt8uInResp(uint8_t value);
 uint16_t * emberAfPutInt16uInResp(uint16_t value);
-uint32_t * emberAfPutInt32uInResp(uint32_t value);
-uint32_t * emberAfPutInt24uInResp(uint32_t value);
 uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length);
 uint8_t * emberAfPutStringInResp(const uint8_t * buffer);
 void emberAfPutInt16sInResp(int16_t value);
-void emberAfPutStatusInResp(EmberAfStatus value);
-
-bool emberAfIsThisMyEui64(EmberEUI64 eui64);
-
-#ifdef EZSP_HOST
-// the EM260 host application is expected to provide these functions if using
-// a cluster that needs it.
-EmberNodeId emberGetSender(void);
-EmberStatus emberGetSenderEui64(EmberEUI64 senderEui64);
-#endif // EZSP_HOST
-
-// DEPRECATED.
-extern uint8_t emberAfIncomingZclSequenceNumber;
-
-// the caller to the library can set a flag to say do not respond to the
-// next ZCL message passed in to the library. Passing true means disable
-// the reply for the next ZCL message. Setting to false re-enables the
-// reply (in the case where the app disables it and then doesnt send a
-// message that gets parsed).
-void emberAfSetNoReplyForNextMessage(bool set);
-
-#define isThisDataTypeSentLittleEndianOTA(dataType) (!(emberAfIsThisDataTypeAStringType(dataType)))
-
-extern uint8_t emberAfResponseType;
-
-uint16_t emberAfStrnlen(const uint8_t * string, uint16_t maxLength);
-
-/* @brief Append characters to a ZCL string.
- *
- * Appending characters to an existing ZCL string. If it is an invalid string
- * (length byte equals 0xFF), no characters will be appended.
- *
- * @param zclString - pointer to the zcl string
- * @param zclStringMaxLen - length of zcl string (does not include zcl length byte)
- * @param src - pointer to plain text characters
- * @param srcLen - length of plain text characters
- *
- * @return number of characters appended
- *
- */
-uint8_t emberAfAppendCharacters(uint8_t * zclString, uint8_t zclStringMaxLen, const uint8_t * appendingChars,
-                                uint8_t appendingCharsLen);
 
 bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId);