Skip to content

Commit

Permalink
Remove some no-longer-used ZCL message buffer processing code. (#25166)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 23, 2023
1 parent 31db3ce commit 90b3efd
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 318 deletions.
28 changes: 0 additions & 28 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/app/util/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
104 changes: 0 additions & 104 deletions src/app/util/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
104 changes: 0 additions & 104 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,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
Expand Down Expand Up @@ -123,16 +110,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() {}
Expand Down Expand Up @@ -190,58 +167,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);
Expand Down Expand Up @@ -398,35 +323,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);
Expand Down
Loading

0 comments on commit 90b3efd

Please sign in to comment.