private void onReceiveMessage(ZWaveContext context, ZWaveMessage message) { var response = message.Message; var foundNodes = new List<byte>(); for (var i = 7; i < 35; i++) { for (var j = 0; j < 8; j++) { if ((response[i] & (0x01 << j)) != 0) { var nodeId = (byte)((i - 7) * 8 + (j + 1)); if (nodeId != context.ControllerId) { foundNodes.Add(nodeId); } } } } if (foundNodes.Any()) { context.DoParallelFor(foundNodes.Select(x => new LoadNodeProtocolInfo(x)).ToArray()); context.DoParallelFor(foundNodes.Select(x => new LoadNodeCapabilities(x)).ToArray()); } }
private void onReceiveResponse(ZWaveContext context, ZWaveMessage message) { var msg = message.Message; var sleeping = !((msg[4] & (0x01<<7)) > 0x00); lock (context) { context.Nodes.Add( new ZWaveNode { NodeId = Data.NodeId, Sleeping = sleeping, Basictype = (ZWaveType.Basic)msg[7], GenericType = (ZWaveType.Generic)msg[8], SpecificType = (ZWaveType.Specific)msg[9] }); #if DEBUG context.WorkUnitContext.LogLine( "\tNodeID: {0}, Sleeping: {1}, Basic Type: {2}, Generic Type: {3}, Specific Type: {4}", Data.NodeId, sleeping, context.Nodes.Last().Basictype.ToString(), context.Nodes.Last().GenericType.ToString(), context.Nodes.Last().SpecificType.ToString()); #endif } }
public static void GetSupported(ZWaveNode node) { var message = ZWaveMessage.BuildSendDataRequest(node.Id, new byte[] { (byte)CommandClass.Security, (byte)SecurityCommand.SupportedGet }); SendMessage(node, message); }
internal byte SendMessage(byte[] message, bool disablecallback = false) { ZWaveMessage zmsg = new ZWaveMessage() { Node = this, Message = message }; return(zp.SendMessage(zmsg, disablecallback)); }
internal byte SendMessage(byte[] message, bool disableCallback = false) { var msg = new ZWaveMessage() { Node = this, Message = message }; return(zwavePort.SendMessage(msg, disableCallback)); }
private static void SetNetworkKey(ZWaveNode node) { byte[] t_msg = new byte[18]; t_msg[0] = (byte)CommandClass.Security; t_msg[1] = (byte)SecurityCommand.NetworkKeySet; var privateNetworkKey = GetSecurityData(node).GetPrivateNetworkKey(); if (privateNetworkKey == null) { privateNetworkKey = GetSecurityData(node).GeneratePrivateNetworkKey(); } Array.Copy(privateNetworkKey, 0, t_msg, 2, 16); byte[] f_msg = ZWaveMessage.BuildSendDataRequest(node.Id, t_msg); SendMessage(node, f_msg); }
private void onReceiveResponse(ZWaveContext context, ZWaveMessage message) { for (var i = 10; i < 6 + message.Message[6]; i++) { var node = context.Nodes.FirstOrDefault(x => x.NodeId == Data.NodeId); if (node != null) { if (node.Capabilities == null) { node.Capabilities = new List<ZWaveCommandClass>(); } node.Capabilities.Add((ZWaveCommandClass)message.Message[i]); } } }
public static ZWaveMessage SendToSleep(ZWaveNode node) { ZWaveMessage msg = null; var wakeUpStatus = (WakeUpStatus)node.GetData("WakeUpStatus", new WakeUpStatus()).Value; if (!wakeUpStatus.IsSleeping) { // 0x01, 0x09, 0x00, 0x13, 0x2b, 0x02, 0x84, 0x08, 0x25, 0xee, 0x8b msg = node.SendDataRequest(new byte[] { (byte)CommandClass.WakeUp, (byte)Command.WakeUpNoMoreInfo, 0x25 }).Wait(); wakeUpStatus.IsSleeping = true; var nodeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 1 /* 1 = sleeping, 0 = awake */, 0); node.OnNodeUpdated(nodeEvent); } return(msg); }
internal byte SendMessage(byte[] message, bool disableCallback = false) { var msg = new ZWaveMessage() { Node = this, Message = message }; return zwavePort.SendMessage(msg, disableCallback); }
private bool HandleBasicMessage(byte[] message, byte cmdType) { bool handled = false; int start = 1; switch (cmdType) { case 0xFF: // Send COMMAND_SCHEME_GET to start the secure device inclusion hostNode.security.getScheme(hostNode); handled = true; break; case (byte)SecurityCommand.NonceGet: Utility.logMessage("Received COMMAND_NONCE_GET for node: " + hostNode.Id); /* the Device wants to send us a Encrypted Packet, and thus requesting for our latest NONCE */ hostNode.security.SendNonceReport(hostNode); handled = true; break; case (byte)SecurityCommand.MessageEncap: Utility.logMessage("Received COMMAND_MESSAGE_ENCAP for node: " + hostNode.Id); /* We recieved a Encrypted single packet from the Device. Decrypt it. */ hostNode.security.DecryptMessage(hostNode, message, start); handled = true; break; case (byte)SecurityCommand.NonceReport: Utility.logMessage("Received COMMAND_NONCE_REPORT for node: " + hostNode.Id); /* we recieved a NONCE from a device, so assume that there is something in a queue to send out */ hostNode.security.ProcessNonceReport(hostNode, message, start); handled = true; break; case (byte)SecurityCommand.MessageEncapNonceGet: Utility.logMessage("Received COMMAND_MESSAGE_ENCAP_NONCE_GET for node: " + hostNode.Id); /* we recieved a encrypted packet from the device, and the device is also asking us to send a * new NONCE to it, hence there must be multiple packets.*/ hostNode.security.DecryptMessage(hostNode, message, start); /* Regardless of the success/failure of Decrypting, send a new NONCE */ hostNode.security.SendNonceReport(hostNode); handled = true; break; case (byte)SecurityCommand.NetworkKeySet: Utility.logMessage("Received COMMAND_NETWORK_KEY_SET for node: " + hostNode.Id + ", " + (start + 1)); /* we shouldn't get a NetworkKeySet from a node if we are the controller * as we send it out to the Devices */ handled = true; break; case (byte)SecurityCommand.NetworkKeyVerify: Utility.logMessage("Received COMMAND_NETWORK_KEY_VERIFY for node: " + hostNode.Id + ", " + (start + 1)); /* * if we can decrypt this packet, then we are assured that our NetworkKeySet is successfull * and thus should set the Flag referenced in SecurityCmd_SchemeReport */ byte[] msg = ZWaveMessage.CreateRequest(hostNode.Id, new byte[] { (byte)CommandClass.Security, (byte)SecurityCommand.SupportedGet }); hostNode.security.encryptAndSend(hostNode, msg); handled = true; break; case (byte)SecurityCommand.SupportedReport: Utility.logMessage("Received COMMAND_SUPPORTED_REPORT for node: " + hostNode.Id); /* this is a list of CommandClasses that should be Encrypted. * and it might contain new command classes that were not present in the NodeInfoFrame * so we have to run through, mark existing Command Classes as SetSecured (so SendMsg in the Driver * class will route the unecrypted messages to our SendMsg) and for New Command * Classes, create them, and of course, also do a SetSecured on them. * * This means we must do a SecurityCmd_SupportedGet request ASAP so we dont have * Command Classes created after the Discovery Phase is completed! */ hostNode.SetSecuredClasses(message); handled = true; break; case (byte)SecurityCommand.SchemeInherit: Utility.logMessage("Received COMMAND_SCHEME_INHERIT for node: " + hostNode.Id); /* only used in a Controller Replication Type enviroment. */ break; case (byte)SecurityCommand.SchemeReport: Utility.logMessage("Received COMMAND_SCHEME_REPORT for node: " + hostNode.Id + ", " + (start + 1)); int schemes = message[start + 1]; if (schemeagreed) { handled = true; break; } if (schemes == (byte)SecurityScheme.SchemeZero) { byte[] t_msg = new byte[18]; t_msg[0] = (byte)CommandClass.Security; t_msg[1] = (byte)SecurityCommand.NetworkKeySet; Array.Copy(hostNode.security.PrivateNetworkKey, 0, t_msg, 2, 16); byte[] f_msg = ZWaveMessage.CreateRequest(hostNode.Id, t_msg); hostNode.security.encryptAndSend(hostNode, f_msg); schemeagreed = true; } else { Utility.logMessage(" No common security scheme. The device will continue as an unsecured node."); } handled = true; break; default: Utility.logMessage("Unknown security Command " + (byte)cmdType + " - message " + message); break; } return handled; }
public MessageReceivedEventArgs(ZWaveMessage message) { Message = message; }
private void onReceiveVersion(ZWaveContext context, ZWaveMessage message) { context.ProtocolVersion = Utils.ByteSubstring(message.Message, 11, 2); context.ApplicationVersion = Utils.ByteSubstring(message.Message, 13, 2); }
private void LoadMemoryId_OnReceive(ZWaveContext context, ZWaveMessage message) { context.HomeId = Utils.ByteSubstring(message.Message, 4, 4); context.ControllerId = message.Message[8]; }