Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add length of message to duplicate message detection (addresses #2587) #2589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ ozw_config
gtest-main
cpp/src/command_classes/\.DS_Store
.DS_Store
cpp/build/windows/vs2010/GIT-VS-VERSION-FILE
cpp/build/windows/vs2010/.vs/OpenZWave/v16/.suo
cpp/build/windows/vs2010/.vs/OpenZWave/v16/Browse.VC.db
cpp/build/windows/vs2010/.vs/OpenZWave/v16/Browse.VC.db-shm
cpp/build/windows/vs2010/.vs/OpenZWave/v16/Browse.VC.db-wal
cpp/build/windows/vs2010/.vs/OpenZWave/v16/Browse.VC.opendb
cpp/build/windows/vs2010/.vs/OpenZWave/v16/ipch/AutoPCH/3d8d75d01e4a3926/NODE.ipch
cpp/build/windows/vs2010/OpenZWave.vcxproj.user
14 changes: 9 additions & 5 deletions cpp/src/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ void Driver::ProcessMsg(uint8* _data, uint8 _length)
case FUNC_ID_APPLICATION_COMMAND_HANDLER:
{
Log::Write(LogLevel_Detail, "");
HandleApplicationCommandHandlerRequest(_data, wasencrypted);
HandleApplicationCommandHandlerRequest(_data, _length, wasencrypted);
break;
}
case FUNC_ID_ZW_SEND_DATA:
Expand Down Expand Up @@ -3574,7 +3574,7 @@ void Driver::HandleReplaceFailedNodeRequest(uint8* _data)
// <Driver::HandleApplicationCommandHandlerRequest>
// Process a request from the Z-Wave PC interface
//-----------------------------------------------------------------------------
void Driver::HandleApplicationCommandHandlerRequest(uint8* _data, bool encrypted)
void Driver::HandleApplicationCommandHandlerRequest(uint8* _data, uint8 _length, bool encrypted)
{

uint8 status = _data[2];
Expand All @@ -3594,15 +3594,19 @@ void Driver::HandleApplicationCommandHandlerRequest(uint8* _data, bool encrypted
{
node->m_receivedCnt++;
node->m_errors = 0;
int cmp = memcmp(_data, node->m_lastReceivedMessage, sizeof(node->m_lastReceivedMessage));
if (cmp == 0 && node->m_receivedTS.TimeRemaining() > -500)
if (_length == node->m_lastReceivedMessageLength
&& memcmp(_data, node->m_lastReceivedMessage, _length) == 0
&& node->m_receivedTS.TimeRemaining() > -500)
{
// if the exact same sequence of bytes are received within 500ms
node->m_receivedDups++;
}
else
{
memcpy(node->m_lastReceivedMessage, _data, sizeof(node->m_lastReceivedMessage));
memcpy(node->m_lastReceivedMessage, _data, _length);
if (_length < sizeof(node->m_lastReceivedMessage))
memset(&node->m_lastReceivedMessage[_length], 0x00, sizeof(node->m_lastReceivedMessage) - _length);
node->m_lastReceivedMessageLength = _length;
}
node->m_receivedTS.SetTime();
if (m_expectedReply == FUNC_ID_APPLICATION_COMMAND_HANDLER && m_expectedNodeId == nodeId)
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ namespace OpenZWave
void HandleRemoveFailedNodeRequest(uint8* _data);
void HandleReplaceFailedNodeRequest(uint8* _data);
void HandleRemoveNodeFromNetworkRequest(uint8* _data);
void HandleApplicationCommandHandlerRequest(uint8* _data, bool encrypted);
void HandleApplicationCommandHandlerRequest(uint8* _data, uint8 _length, bool encrypted);
void HandlePromiscuousApplicationCommandHandlerRequest(uint8* _data);
void HandleAssignReturnRouteRequest(uint8* _data);
void HandleDeleteReturnRouteRequest(uint8* _data);
Expand Down
20 changes: 16 additions & 4 deletions cpp/src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,23 @@ static char const* c_queryStageNames[] =
// Constructor
//-----------------------------------------------------------------------------
Node::Node(uint32 const _homeId, uint8 const _nodeId) :
m_queryStage(QueryStage_None), m_queryPending(false), m_queryConfiguration(false), m_queryRetries(0), m_protocolInfoReceived(false), m_basicprotocolInfoReceived(false), m_nodeInfoReceived(false), m_nodePlusInfoReceived(false), m_manufacturerSpecificClassReceived(false), m_nodeInfoSupported(true), m_refreshonNodeInfoFrame(true), m_nodeAlive(true), // assome live node
m_queryStage(QueryStage_None), m_queryPending(false), m_queryConfiguration(false), m_queryRetries(0),
m_protocolInfoReceived(false), m_basicprotocolInfoReceived(false), m_nodeInfoReceived(false),
m_nodePlusInfoReceived(false), m_manufacturerSpecificClassReceived(false), m_nodeInfoSupported(true),
m_refreshonNodeInfoFrame(true), m_nodeAlive(true), // assume live node
m_listening(true), // assume we start out listening
m_frequentListening(false), m_beaming(false), m_routing(false), m_maxBaudRate(0), m_version(0), m_security(false), m_homeId(_homeId), m_nodeId(_nodeId), m_basic(0), m_generic(0), m_specific(0), m_type(""), m_addingNode(false), m_manufacturerName(""), m_productName(""), m_nodeName(""), m_location(""), m_manufacturerId(0), m_productType(0), m_productId(0), m_deviceType(0), m_role(0), m_nodeType(0), m_secured(false), m_nodeCache( NULL), m_Product( NULL), m_fileConfigRevision(0), m_loadedConfigRevision(
0), m_latestConfigRevision(0), m_values(new Internal::VC::ValueStore()), m_sentCnt(0), m_sentFailed(0), m_retries(0), m_receivedCnt(0), m_receivedDups(0), m_receivedUnsolicited(0), m_lastRequestRTT(0), m_lastResponseRTT(0), m_averageRequestRTT(0), m_averageResponseRTT(0), m_quality(0), m_lastReceivedMessage(), m_errors(0), m_txStatusReportSupported(false), m_txTime(0), m_hops(0), m_ackChannel(0), m_lastTxChannel(0), m_routeScheme((TXSTATUS_ROUTING_SCHEME) 0), m_routeUsed
{ }, m_routeSpeed((TXSTATUS_ROUTE_SPEED) 0), m_routeTries(0), m_lastFailedLinkFrom(0), m_lastFailedLinkTo(0), m_lastnonce(0)
m_frequentListening(false), m_beaming(false), m_routing(false), m_maxBaudRate(0), m_version(0), m_security(false),
m_homeId(_homeId), m_nodeId(_nodeId), m_basic(0), m_generic(0), m_specific(0), m_type(""),
m_addingNode(false), m_manufacturerName(""), m_productName(""), m_nodeName(""), m_location(""),
m_manufacturerId(0), m_productType(0), m_productId(0), m_deviceType(0), m_role(0), m_nodeType(0),
m_secured(false), m_nodeCache( NULL), m_Product( NULL), m_fileConfigRevision(0), m_loadedConfigRevision(0),
m_latestConfigRevision(0), m_values(new Internal::VC::ValueStore()), m_sentCnt(0), m_sentFailed(0),
m_retries(0), m_receivedCnt(0), m_receivedDups(0), m_receivedUnsolicited(0), m_lastRequestRTT(0),
m_lastResponseRTT(0), m_averageRequestRTT(0), m_averageResponseRTT(0), m_quality(0), m_lastReceivedMessage(),
m_lastReceivedMessageLength(0), m_errors(0), m_txStatusReportSupported(false), m_txTime(0), m_hops(0),
m_ackChannel(0), m_lastTxChannel(0), m_routeScheme((TXSTATUS_ROUTING_SCHEME) 0), m_routeUsed{ },
m_routeSpeed((TXSTATUS_ROUTE_SPEED) 0), m_routeTries(0), m_lastFailedLinkFrom(0), m_lastFailedLinkTo(0),
m_lastnonce(0)
{
memset(m_neighbors, 0, sizeof(m_neighbors));
memset(m_nonces, 0, sizeof(m_nonces));
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ namespace OpenZWave
uint32 m_averageResponseRTT;
uint8 m_quality; // Node quality measure
uint8 m_lastReceivedMessage[254];
uint8 m_lastReceivedMessageLength;
list<CommandClassData> m_ccData;
bool m_txStatusReportSupported;
uint16 m_txTime;
Expand Down Expand Up @@ -834,6 +835,7 @@ namespace OpenZWave
uint32 m_averageResponseRTT; // Average Response round trip time.
uint8 m_quality; // Node quality measure
uint8 m_lastReceivedMessage[254]; // Place to hold last received message
uint8 m_lastReceivedMessageLength; // Length of the last received message
uint8 m_errors;
bool m_txStatusReportSupported; // if Extended Status Reports are available
uint16 m_txTime; // Time Taken to Transmit the last frame
Expand Down