MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / HandleMsg

Method HandleMsg

cpp/src/command_classes/Security.cpp:170–286  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Handle a message from the Z-Wave network -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

168// Handle a message from the Z-Wave network
169//-----------------------------------------------------------------------------
170bool Security::HandleMsg
171(
172 uint8 const* _data,
173 uint32 const _length,
174 uint32 const _instance // = 1
175)
176{
177 switch( (SecurityCmd)_data[0] )
178 {
179 case SecurityCmd_SupportedReport:
180 {
181 /* this is a list of CommandClasses that should be Encrypted.
182 * and it might contain new command classes that were not present in the NodeInfoFrame
183 * so we have to run through, mark existing Command Classes as SetSecured (so SendMsg in the Driver
184 * class will route the unecrypted messages to our SendMsg) and for New Command
185 * Classes, create them, and of course, also do a SetSecured on them.
186 *
187 * This means we must do a SecurityCmd_SupportedGet request ASAP so we dont have
188 * Command Classes created after the Discovery Phase is completed!
189 */
190 Log::Write(LogLevel_Info, GetNodeId(), "Received SecurityCmd_SupportedReport from node %d (instance %d)", GetNodeId(), _instance );
191 m_secured = true;
192 if( ValueBool* value = static_cast<ValueBool*>( GetValue( _instance, 0 ) ) )
193 {
194 value->OnValueRefreshed( m_secured );
195 value->Release();
196 }
197 HandleSupportedReport(&_data[2], _length-3, _instance);
198 break;
199 }
200 case SecurityCmd_SchemeReport:
201 {
202 Log::Write(LogLevel_Info, GetNodeId(), "Received SecurityCmd_SchemeReport from node %d: %d", GetNodeId(), _data[1]);
203 uint8 schemes = _data[1];
204 if (m_schemeagreed == true) {
205 Log::Write(LogLevel_Warning, GetNodeId(), " Already Received a SecurityCmd_SchemeReport from the node. Ignoring");
206 break;
207 }
208 if( schemes == SecurityScheme_Zero )
209 {
210 /* We're good to go. We now should send our NetworkKey to the device if this is the first
211 * time we have seen it
212 */
213 Log::Write(LogLevel_Info, GetNodeId(), " Security scheme agreed." );
214 /* create the NetworkKey Packet. EncryptMessage will encrypt it for us (And request the NONCE) */
215 Msg * msg = new Msg ("SecurityCmd_NetworkKeySet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
216 msg->Append( GetNodeId() );
217 msg->Append( 18 );
218 msg->Append( GetCommandClassId() );
219 msg->Append( SecurityCmd_NetworkKeySet );
220 for (int i = 0; i < 16; i++)
221 msg->Append(GetDriver()->GetNetworkKey()[i]);
222 msg->Append( GetDriver()->GetTransmitOptions() );
223 msg->setEncrypted();
224 GetDriver()->SendMsg( msg, Driver::MsgQueue_Command);
225 m_schemeagreed = true;
226 }
227 else

Callers

nothing calls this directly

Calls 8

WriteFunction · 0.85
GetCommandClassIdFunction · 0.85
GetNetworkKeyMethod · 0.80
SendMsgMethod · 0.80
GetNodeIdFunction · 0.70
OnValueRefreshedMethod · 0.45
ReleaseMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected