Skip to content

Commit

Permalink
Work on Issue #1639 - Querying a Endpoint for Secured CommandClasses.…
Browse files Browse the repository at this point in the history
… Not working for me, but I may have a buggy device
  • Loading branch information
Fishwaldo committed Jan 23, 2019
1 parent ef1e9b7 commit 5445f18
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/options.xml
Expand Up @@ -8,7 +8,7 @@
<Option name="SaveConfiguration" value="true" />
<!-- <Option name="RetryTimeout" value="40000" /> -->
<!-- If you are using any Security Devices, you MUST set a network Key -->
<!-- <Option name="NetworkKey" value="0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10" /> -->
<Option name="NetworkKey" value="0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10" />

<!-- Some Devices have a big UserCode Table, that can mean startup times
when refreshing Session Variables is very long (Especialy on Security
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Driver.cpp
Expand Up @@ -1044,7 +1044,7 @@ void Driver::SendMsg
if( Node* node = GetNode(_msg->GetTargetNodeId()) )
{
/* if the node Supports the Security Class - check if this message is meant to be encapsulated */
if ( node->GetCommandClass(Security::StaticGetCommandClassId() ) )
if ( node->GetCommandClass(Security::StaticGetCommandClassId()) )
{
CommandClass *cc = node->GetCommandClass(_msg->GetSendingCommandClass());
if ( (cc) && (cc->IsSecured()) )
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/Msg.cpp
Expand Up @@ -327,16 +327,19 @@ Driver* Msg::GetDriver
}


uint8* Msg::GetBuffer() {
uint8* Msg::GetBuffer
(
)
{
Log::Write(LogLevel_Info, m_targetNodeId, "Encrypted Flag is %d", m_encrypted);
if (m_encrypted == false)
return m_buffer;
else
if (EncyrptBuffer(m_buffer, m_length, GetDriver(), GetDriver()->GetControllerNodeId(), m_targetNodeId, m_nonce, e_buffer)) {
return e_buffer;
} else {
Log::Write(LogLevel_Warning, m_targetNodeId, "Failed to Encyrpt Packet");
Log::Write(LogLevel_Warning, m_targetNodeId, "Failed to Encrypt Packet");
return NULL;
}
}


2 changes: 0 additions & 2 deletions cpp/src/Msg.h
Expand Up @@ -143,9 +143,7 @@ namespace OpenZWave
return m_buffer[6];
}
return 0;

}

bool isEncrypted() {
return m_encrypted;
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/Node.cpp
Expand Up @@ -1600,7 +1600,8 @@ void Node::SetSecured(bool secure) {
void Node::SetSecuredClasses
(
uint8 const* _data,
uint8 const _length
uint8 const _length,
uint32 const _instance
)
{
uint32 i;
Expand Down Expand Up @@ -1628,7 +1629,7 @@ void Node::SetSecuredClasses
/* Check if this is a CC that is already registered with the node */
if (CommandClass *pCommandClass = GetCommandClass(_data[i], afterMark))
{
/* if it was specified int he NIF frame, and came in as part of the Security SupportedReport message
/* if it was specified the he NIF frame, and came in as part of the Security SupportedReport message
* then it can support both Clear Text and Secured Comms. So do a check first
*/
if (pCommandClass->IsInNIF()) {
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/Node.h
Expand Up @@ -407,8 +407,9 @@ namespace OpenZWave
* as Secured if they exist, and if they don't, it creates new Command Classes and sets them up as Secured
* @param _data a list of Command Classes that are Secured by the Device
* @param _length the length of the _data string
* @param _instance the instance of the Class thats Secured.
*/
void SetSecuredClasses( uint8 const* _data, uint8 const _length );
void SetSecuredClasses( uint8 const* _data, uint8 const _length, uint32 const _instance = 1);
void SetSecured(bool secure);
private:
/**
Expand Down
6 changes: 5 additions & 1 deletion cpp/src/ZWSecurity.cpp
Expand Up @@ -37,7 +37,7 @@
#include "command_classes/Security.h"
#include "aes/aescpp.h"


#define DEBUG
namespace OpenZWave {
//using namespace OpenZWave;

Expand Down Expand Up @@ -231,6 +231,10 @@ namespace OpenZWave {
csum ^= e_buffer[i];
}
e_buffer[len++] = csum;
#ifdef DEBUG
PrintHex("Encrypted Packet", e_buffer, len);
Log::Write(LogLevel_Info, "Length: %d", len);
#endif
return true;
}

Expand Down
13 changes: 13 additions & 0 deletions cpp/src/command_classes/MultiInstance.cpp
Expand Up @@ -30,6 +30,7 @@
#include "command_classes/Basic.h"
#include "command_classes/MultiInstance.h"
#include "command_classes/NoOperation.h"
#include "command_classes/Security.h"
#include "Defs.h"
#include "Msg.h"
#include "Driver.h"
Expand Down Expand Up @@ -539,6 +540,18 @@ void MultiInstance::HandleMultiChannelCapabilityReport
basic->SetEndPoint( i, endPoint );
}
}
/* if its the Security CC, on a instance > 1, then this has come from the Security CC found in a MultiInstance Capability Report.
* So we need to Query the endpoint for Secured CC's
*/
if ((commandClassId == Security::StaticGetCommandClassId()) && (i > 1)) {
Log::Write(LogLevel_Info, GetNodeId(), " Sending Security_Supported_Get to Instance %d", i);
Security *seccc = static_cast<Security*>(node->GetCommandClass(Security::StaticGetCommandClassId(), afterMark));
/* this will trigger a SecurityCmd_SupportedGet on the _instance of the Device. */
if (seccc) {
seccc->Init(i);
}
}

}
}
endPoint++;
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/command_classes/Security.cpp
Expand Up @@ -97,9 +97,11 @@ void Security::WriteXML

bool Security::Init
(
uint32 const _instance
)
{
Msg* msg = new Msg( "SecurityCmd_SupportedGet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
msg->SetInstance( this, _instance );
msg->Append( GetNodeId() );
msg->Append( 2 );
msg->Append( GetCommandClassId() );
Expand Down Expand Up @@ -174,14 +176,15 @@ bool Security::RequestValue
bool Security::HandleSupportedReport
(
uint8 const* _data,
uint32 const _length
uint32 const _length,
uint32 const _instance
)
{

#ifdef DEBUG
PrintHex("Security Classes", _data, _length);
#endif
GetNodeUnsafe()->SetSecuredClasses(_data, _length);
GetNodeUnsafe()->SetSecuredClasses(_data, _length, _instance);
return true;
}

Expand Down Expand Up @@ -216,7 +219,7 @@ bool Security::HandleMsg
value->OnValueRefreshed( m_secured );
value->Release();
}
HandleSupportedReport(&_data[2], _length-2);
HandleSupportedReport(&_data[2], _length-2, _instance);
break;
}
case SecurityCmd_SchemeReport:
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/command_classes/Security.h
Expand Up @@ -69,7 +69,7 @@ namespace OpenZWave

static uint8 const StaticGetCommandClassId(){ return 0x98; }
static string const StaticGetCommandClassName(){ return "COMMAND_CLASS_SECURITY"; }
bool Init();
bool Init(uint32 const _instance = 1);
bool ExchangeNetworkKeys();
// From CommandClass
virtual uint8 const GetCommandClassId()const{ return StaticGetCommandClassId(); }
Expand All @@ -86,7 +86,7 @@ namespace OpenZWave
Security( uint32 const _homeId, uint8 const _nodeId );
bool RequestState( uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue);
bool RequestValue( uint32 const _requestFlags, uint16 const _index, uint8 const _instance, Driver::MsgQueue const _queue);
bool HandleSupportedReport(uint8 const* _data, uint32 const _length);
bool HandleSupportedReport(uint8 const* _data, uint32 const _length, uint32 const _instance = 1);

bool m_schemeagreed;
bool m_secured;
Expand Down

0 comments on commit 5445f18

Please sign in to comment.