Skip to content

Commit

Permalink
Remove unused emberAfPreCommandReceived callback and some discovery r…
Browse files Browse the repository at this point in the history
…elated code (#10765)

* Remove unused emberAfPreCommandReceived callback

* Remove some DiscoverAttributes related code

* Update generated code
  • Loading branch information
vivien-apple authored and pull[bot] committed Dec 9, 2021
1 parent f82724a commit 3261467
Show file tree
Hide file tree
Showing 51 changed files with 0 additions and 4,678 deletions.
115 changes: 0 additions & 115 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ const EmberAfAttributeMinMaxValue minMaxDefaults[] = GENERATED_MIN_MAX_DEFAULTS;
GENERATED_FUNCTION_ARRAYS
#endif

#ifdef EMBER_AF_SUPPORT_COMMAND_DISCOVERY
const EmberAfCommandMetadata generatedCommands[] = GENERATED_COMMANDS;
const EmberAfManufacturerCodeEntry commandManufacturerCodes[] = GENERATED_COMMAND_MANUFACTURER_CODES;
const uint16_t commandManufacturerCodeCount = GENERATED_COMMAND_MANUFACTURER_CODE_COUNT;
#endif

const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES;
const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS;
const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES;
Expand Down Expand Up @@ -1329,115 +1323,6 @@ EmberAfGenericClusterFunction emberAfFindClusterFunction(EmberAfCluster * cluste
return cluster->functions[functionIndex];
}

#ifdef EMBER_AF_SUPPORT_COMMAND_DISCOVERY

uint16_t emAfGetManufacturerCodeForCommand(EmberAfCommandMetadata * command)
{
return getManufacturerCode((EmberAfManufacturerCodeEntry *) commandManufacturerCodes, commandManufacturerCodeCount,
static_cast<uint16_t>(command - generatedCommands));
}

/**
* This function populates command IDs into a given buffer.
*
* It returns true if commands are complete, meaning there are NO MORE
* commands that would be returned after the last command.
* It returns false, if there were more commands, but were not populated
* because of maxIdCount limitation.
*/
bool emberAfExtractCommandIds(bool outgoing, EmberAfClusterCommand * cmd, ClusterId clusterId, uint8_t * buffer,
uint16_t bufferLength, uint16_t * bufferIndex, uint8_t startId, uint8_t maxIdCount)
{
uint16_t i, count = 0;
bool returnValue = true;
uint8_t cmdDirMask = 0;

// determine the appropriate mask to match the request
// discover commands generated, client is asking server what commands do you generate?
if (outgoing && (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER))
{
cmdDirMask = COMMAND_MASK_OUTGOING_SERVER;
// discover commands generated server is asking client what commands do you generate?
}
else if (outgoing && (cmd->direction == ZCL_DIRECTION_SERVER_TO_CLIENT))
{
cmdDirMask = COMMAND_MASK_OUTGOING_CLIENT;
// discover commands received client is asking server what commands do you receive?
}
else if (!outgoing && (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER))
{
cmdDirMask = COMMAND_MASK_INCOMING_SERVER;
// discover commands received server is asking client what commands do you receive?
}
else
{
cmdDirMask = COMMAND_MASK_INCOMING_CLIENT;
}

for (i = 0; i < EMBER_AF_GENERATED_COMMAND_COUNT; i++)
{
if (generatedCommands[i].clusterId != clusterId)
{
continue;
}

if ((generatedCommands[i].mask & cmdDirMask) == 0)
{
continue;
}

// Only start from the passed command id
if (generatedCommands[i].commandId < startId)
{
continue;
}

// According to spec: if cmd->mfgSpecific is set, then we ONLY return the
// mfg specific commands. If it's not, then we ONLY return non-mfg specific.
if (generatedCommands[i].mask & COMMAND_MASK_MANUFACTURER_SPECIFIC)
{
// Command is Mfg specific
if (!cmd->mfgSpecific)
{
continue; // ignore if asking for not mfg specific
}
if (cmd->mfgCode != emAfGetManufacturerCodeForCommand((EmberAfCommandMetadata *) &(generatedCommands[i])))
{
continue; // Ignore if mfg code doesn't match the commands
}
}
else
{
// Command is not mfg specific.
if (cmd->mfgSpecific)
{
continue; // Ignore if asking for mfg specific
}
}

// The one we are about to put in, is beyond the maxIdCount,
// so instead of populating it in, we set the return flag to
// false and get out of here.
if (maxIdCount == count || count >= bufferLength)
{
returnValue = false;
break;
}
buffer[count] = generatedCommands[i].commandId;
(*bufferIndex)++;
count++;
}
return returnValue;
}
#else
// We just need an empty stub if we don't support it
bool emberAfExtractCommandIds(bool outgoing, EmberAfClusterCommand * cmd, ClusterId clusterId, uint8_t * buffer,
uint16_t bufferLength, uint16_t * bufferIndex, uint8_t startId, uint8_t maxIdCount)
{
return true;
}
#endif

bool registerAttributeAccessOverride(app::AttributeAccessInterface * attrOverride)
{
for (auto * cur = gAttributeAccessOverrides; cur; cur = cur->GetNext())
Expand Down
2 changes: 0 additions & 2 deletions src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ void emAfCallInits(void);

// Initial configuration
void emberAfEndpointConfigure(void);
bool emberAfExtractCommandIds(bool outgoing, EmberAfClusterCommand * cmd, chip::ClusterId clusterId, uint8_t * buffer,
uint16_t bufferLength, uint16_t * bufferIndex, uint8_t startId, uint8_t maxIdCount);

EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord, EmberAfAttributeMetadata ** metadata,
uint8_t * buffer, uint16_t readLength, bool write, int32_t index = -1);
Expand Down
1 change: 0 additions & 1 deletion src/app/util/debug-printing-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
#define EMBER_AF_PRINT_APP 0x0D80
#define EMBER_AF_PRINT_SECURITY 0x0E01
#define EMBER_AF_PRINT_ATTRIBUTES 0x0E02
#define EMBER_AF_PRINT_SERVICE_DISCOVERY 0x0E08
#define EMBER_AF_PRINT_REGISTRATION 0x0E10
#define EMBER_AF_PRINT_ZDO 0x0E20
#define EMBER_AF_PRINT_CUSTOM1 0x0E40
Expand Down
24 changes: 0 additions & 24 deletions src/app/util/debug-printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -2772,30 +2772,6 @@
#define emberAfAttributesPrintString(buffer)
#endif // defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_ATTRIBUTES)

// Printing macros for Service discovery
// Prints messages related to service discovery
#if defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_SERVICE_DISCOVERY)
#define emberAfServiceDiscoveryPrint(...) emberAfPrint(EMBER_AF_PRINT_SERVICE_DISCOVERY, __VA_ARGS__)
#define emberAfServiceDiscoveryPrintln(...) emberAfPrintln(EMBER_AF_PRINT_SERVICE_DISCOVERY, __VA_ARGS__)
// Blocking IO is enabled for all serial ports, therefore flush calls are unnecessary.
#define emberAfServiceDiscoveryFlush()
#define emberAfServiceDiscoveryDebugExec(x) \
if (emberAfPrintEnabled(EMBER_AF_PRINT_SERVICE_DISCOVERY)) \
{ \
x; \
}
#define emberAfServiceDiscoveryPrintBuffer(buffer, len, withSpace) \
emberAfPrintBuffer(EMBER_AF_PRINT_SERVICE_DISCOVERY, (buffer), (len), (withSpace))
#define emberAfServiceDiscoveryPrintString(buffer) emberAfPrintString(EMBER_AF_PRINT_SERVICE_DISCOVERY, (buffer))
#else
#define emberAfServiceDiscoveryPrint(...)
#define emberAfServiceDiscoveryPrintln(...)
#define emberAfServiceDiscoveryFlush()
#define emberAfServiceDiscoveryDebugExec(x)
#define emberAfServiceDiscoveryPrintBuffer(buffer, len, withSpace)
#define emberAfServiceDiscoveryPrintString(buffer)
#endif // defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_SERVICE_DISCOVERY)

// Printing macros for Registration
// Prints messages related to registration
#if defined(EMBER_AF_PRINT_ENABLE) && defined(EMBER_AF_PRINT_REGISTRATION)
Expand Down
176 changes: 0 additions & 176 deletions src/app/util/process-global-message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <app-common/zap-generated/callback.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/command-id.h>
#include <app/clusters/ias-zone-client/ias-zone-client.h>
#include <app/reporting/reporting.h>
#include <app/util/common.h>

Expand All @@ -58,45 +57,6 @@

using namespace chip;

// flag to keep track of the fact that we just sent a read attr for time and
// we should set our time to the result of the read attr response.
bool emAfSyncingTime = false;

#ifdef EMBER_AF_GBCS_COMPATIBLE
// Some GBCS use cases (e.g. GCS15e, GCS21f) require that ReadAttributesResponse
// should be send back with Disable Default Response flag set. The only pattern
// is that the decision is based on the cluster and attribute IDs requested.
// To reduce the possibility of false positives, we disable default response
// only for responses containing at least the specified minimum of attributes.
#define MIN_MATCHING_ATTR_IDS_TO_DISABLE_DEFAULT_RESPONSE 3
#endif

#define DISC_ATTR_RSP_MAX_ATTRIBUTES \
(((EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH - EMBER_AF_ZCL_MANUFACTURER_SPECIFIC_OVERHEAD /* max ZCL header size */ \
- 1) /* discovery is complete boolean */ \
/ 5) /* size of one discover attributes response entry */ \
% UINT8_MAX) /* make count fit in an 8 bit integer */
#define DISC_ATTR_EXT_RSP_MAX_ATTRIBUTES \
(((EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH - EMBER_AF_ZCL_MANUFACTURER_SPECIFIC_OVERHEAD /* max ZCL header size */ \
- 1) /* discovery is complete boolean */ \
/ 5) /* size of one discover attributes extended response entry */ \
% UINT8_MAX) /* make count fit in an 8 bit integer */

#if defined(EMBER_AF_SUPPORT_COMMAND_DISCOVERY)
static void printDiscoverCommandsResponse(bool generated, ClusterId clusterId, bool discoveryComplete, uint8_t * buffer,
uint16_t length)
{
uint16_t i;
emberAfServiceDiscoveryPrint("Discover Commands response (complete: %c), %p IDs: ", (discoveryComplete ? 'y' : 'n'),
(generated ? "Generated" : "Received"));
for (i = 0; i < length; i++)
{
emberAfServiceDiscoveryPrint("0x%X ", buffer[i]);
}
emberAfServiceDiscoveryPrintln("");
}
#endif

bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd)
{
uint8_t frameControl;
Expand Down Expand Up @@ -156,56 +116,6 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd)

switch (zclCmd)
{
// the format of discover is: [start attr ID:2] [max attr IDs:1]
// the format of the response is: [done:1] ([attrID:2] [type:1]) * N
case ZCL_DISCOVER_ATTRIBUTES_COMMAND_ID:
case ZCL_DISCOVER_ATTRIBUTES_EXTENDED_COMMAND_ID: {
AttributeId startingAttributeId;
uint8_t numberAttributes;
uint8_t * complete;

emberAfAttributesPrintln("%p%p: clus " ChipLogFormatMEI, "DISC_ATTR",
(zclCmd == ZCL_DISCOVER_ATTRIBUTES_EXTENDED_COMMAND_ID ? "_EXT" : ""), ChipLogValueMEI(clusterId));

// set the cmd byte - this is byte 3 index 2, but since we have
// already incremented past the 3 byte ZCL header (our index is at 3),
// this gets written to "-1" since 3 - 1 = 2.
emberAfPutInt32uInResp((zclCmd == ZCL_DISCOVER_ATTRIBUTES_COMMAND_ID
? ZCL_DISCOVER_ATTRIBUTES_RESPONSE_COMMAND_ID
: ZCL_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE_COMMAND_ID));

// get the attrId to start on and the max count
startingAttributeId = emberAfGetInt32u(message, msgIndex, msgLen);
numberAttributes = emberAfGetInt8u(message, msgIndex + 4, msgLen);

// BUGZID: EMAPPFWKV2-828, EMAPPFWKV2-1401
if (zclCmd == ZCL_DISCOVER_ATTRIBUTES_COMMAND_ID && numberAttributes > DISC_ATTR_RSP_MAX_ATTRIBUTES)
{
numberAttributes = DISC_ATTR_RSP_MAX_ATTRIBUTES;
}
else if (zclCmd == ZCL_DISCOVER_ATTRIBUTES_EXTENDED_COMMAND_ID && numberAttributes > DISC_ATTR_EXT_RSP_MAX_ATTRIBUTES)
{
numberAttributes = DISC_ATTR_EXT_RSP_MAX_ATTRIBUTES;
}
else
{
// MISRA requires ..else if.. to have terminating else.
}

// The response has a one-byte field indicating whether discovery is
// complete. We can't populate that field until we've finished going
// through all the attributes, so save a placeholder, write a temporary
// value for now (so that the offset moves forward), and write the real
// value when we're done.
complete = &(appResponseData[appResponseLength]);
emberAfPutInt8uInResp(false);
*complete = emberAfReadSequentialAttributesAddToResponse(cmd->apsFrame->destinationEndpoint, clusterId, startingAttributeId,
clientServerMask, cmd->mfgCode, numberAttributes,
(zclCmd == ZCL_DISCOVER_ATTRIBUTES_EXTENDED_COMMAND_ID));
emberAfSendResponse();
return true;
}

// [command id:4] [status:1]
case ZCL_DEFAULT_RESPONSE_COMMAND_ID: {
EmberAfStatus status;
Expand All @@ -219,92 +129,6 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd)
return true;
}

// [discovery complete:1] ([attribute id:4] [type:1])*
case ZCL_DISCOVER_ATTRIBUTES_RESPONSE_COMMAND_ID:
case ZCL_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE_COMMAND_ID: {
bool discoveryComplete = emberAfGetInt8u(message, msgIndex, msgLen);
msgIndex++;
if (!emberAfDiscoverAttributesResponseCallback(clusterId, discoveryComplete, message + msgIndex,
static_cast<uint16_t>(msgLen - msgIndex),
(zclCmd == ZCL_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE_COMMAND_ID)))
{
emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS);
}
return true;
}

#ifdef EMBER_AF_SUPPORT_COMMAND_DISCOVERY
// Command discovery takes a bit of flash because we need to add structs
// for commands into the generated hader. Hence it's all configurable.
case ZCL_DISCOVER_COMMANDS_RECEIVED_COMMAND_ID:
case ZCL_DISCOVER_COMMANDS_GENERATED_COMMAND_ID: {
uint8_t startCommandIdentifier = emberAfGetInt8u(message, msgIndex, msgLen);
uint8_t maximumCommandIdentifiers = emberAfGetInt8u(message, msgIndex + 1, msgLen);
uint16_t savedIndex;
bool flag;

// Ok. This is the command that matters.
if (zclCmd == ZCL_DISCOVER_COMMANDS_RECEIVED_COMMAND_ID)
{
emberAfPutInt32uInResp(ZCL_DISCOVER_COMMANDS_RECEIVED_RESPONSE_COMMAND_ID);
flag = false;
}
else
{
emberAfPutInt32uInResp(ZCL_DISCOVER_COMMANDS_GENERATED_RESPONSE_COMMAND_ID);
flag = true;
}
savedIndex = appResponseLength;
flag = emberAfExtractCommandIds(flag, cmd, clusterId, appResponseData + appResponseLength + 1,
static_cast<uint16_t>(EMBER_AF_RESPONSE_BUFFER_LEN - appResponseLength - 1),
&appResponseLength, startCommandIdentifier, maximumCommandIdentifiers);
appResponseData[savedIndex] = (flag ? 1 : 0);
appResponseLength++;
emberAfSendResponse();
return true;
}
case ZCL_DISCOVER_COMMANDS_RECEIVED_RESPONSE_COMMAND_ID: {
bool discoveryComplete = emberAfGetInt8u(message, msgIndex, msgLen);
msgIndex++;
if (msgIndex <= msgLen)
{
printDiscoverCommandsResponse(false, // is ZCL command generated?
clusterId, discoveryComplete, message + msgIndex,
static_cast<uint16_t>(msgLen - msgIndex));
if (!emberAfDiscoverCommandsReceivedResponseCallback(clusterId, cmd->mfgCode, discoveryComplete, message + msgIndex,
static_cast<uint16_t>(msgLen - msgIndex)))
{
emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS);
}
return true;
}
else
{
return false;
}
}
case ZCL_DISCOVER_COMMANDS_GENERATED_RESPONSE_COMMAND_ID: {
bool discoveryComplete = emberAfGetInt8u(message, msgIndex, msgLen);
msgIndex++;
if (msgIndex <= msgLen)
{
printDiscoverCommandsResponse(true, // is ZCL command generated?
clusterId, discoveryComplete, message + msgIndex,
static_cast<uint16_t>(msgLen - msgIndex));
if (!emberAfDiscoverCommandsGeneratedResponseCallback(clusterId, cmd->mfgCode, discoveryComplete, message + msgIndex,
static_cast<uint16_t>(msgLen - msgIndex)))
{
emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS);
}
return true;
}
else
{
return false;
}
}

#endif
default:
// MISRA requires default case.
break;
Expand Down
6 changes: 0 additions & 6 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,6 @@ bool emberAfProcessMessage(EmberApsFrame * apsFrame, EmberIncomingMessageType ty
printIncomingZclMessage(&curCmd);
prepareForResponse(&curCmd);

if (emberAfPreCommandReceivedCallback(&curCmd))
{
msgHandled = true;
goto kickout;
}

if (interPanHeader != NULL && !(interPanHeader->options & EMBER_AF_INTERPAN_OPTION_MAC_HAS_LONG_ADDRESS))
{
// For safety, dump all interpan messages that don't have a long
Expand Down
Loading

0 comments on commit 3261467

Please sign in to comment.