From 16f421695dfa1b365a23afe48f62fbd2c9ff2337 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Sat, 7 Nov 2015 00:06:54 +0100 Subject: [PATCH 01/11] Fix spi flash error when compiling in Arduino IDE 1.6.6 --- libraries/MySensors/utility/SPIFlash.cpp | 4 ++-- libraries/MySensors/utility/SPIFlash.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/utility/SPIFlash.cpp b/libraries/MySensors/utility/SPIFlash.cpp index 00e16018e..9fa26ad2b 100644 --- a/libraries/MySensors/utility/SPIFlash.cpp +++ b/libraries/MySensors/utility/SPIFlash.cpp @@ -32,7 +32,7 @@ // Please maintain this license information along with authorship // and copyright notices in any redistribution of this code -#include +#include "SPIFlash.h" uint8_t SPIFlash::UNIQUEID[8]; @@ -296,4 +296,4 @@ void SPIFlash::wakeup() { /// cleanup void SPIFlash::end() { SPI.end(); -} \ No newline at end of file +} diff --git a/libraries/MySensors/utility/SPIFlash.h b/libraries/MySensors/utility/SPIFlash.h index a308760fa..f661bfc5a 100644 --- a/libraries/MySensors/utility/SPIFlash.h +++ b/libraries/MySensors/utility/SPIFlash.h @@ -120,4 +120,4 @@ class SPIFlash { #endif }; -#endif \ No newline at end of file +#endif From 94cfcdc77ca1c4bd1d3b06f69e4cfa9f5d50c457 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Sat, 7 Nov 2015 00:30:24 +0100 Subject: [PATCH 02/11] Bump minor version --- libraries/MySensors/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/MySensors/Version.h b/libraries/MySensors/Version.h index c78226559..456f13a7a 100644 --- a/libraries/MySensors/Version.h +++ b/libraries/MySensors/Version.h @@ -6,6 +6,6 @@ #ifndef Version_h #define Version_h -#define LIBRARY_VERSION "1.5" +#define LIBRARY_VERSION "1.5.1" #endif From 4e70a2ca0c77de261af6eb7ddf6bf67ecf3208b1 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Tue, 8 Sep 2015 23:41:33 +0200 Subject: [PATCH 03/11] Fixed "invalid suffix on literal" warning --- .../BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino b/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino index 34e0a1720..bd3a81f42 100644 --- a/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino +++ b/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino @@ -75,7 +75,7 @@ void setup() digitalWrite(SECONDARY_BUTTON_PIN, HIGH); // Send the sketch version information to the gateway and Controller - sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER"."SKETCH_MINOR_VER); + sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER); // Register binary input sensor to sensor_node (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. From c5a9c2e03361e4e0d4b8c0be3708607e2b68973a Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Sun, 10 Jan 2016 13:57:49 +0100 Subject: [PATCH 04/11] Fix addressing bug in _doSign bitfield --- libraries/MySensors/MySensor.cpp | 6 +++--- libraries/MySensors/MySensor.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index 6c3a34806..8409e5d19 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -24,9 +24,9 @@ #ifdef MY_SIGNING_FEATURE // Macros for manipulating signing requirement table -#define DO_SIGN(node) (node == 0 ? (~doSign[0]&1) : (~doSign[node>>4]&(node%16))) -#define SET_SIGN(node) (node == 0 ? (doSign[0]&=~1) : (doSign[node>>4]&=~(node%16))) -#define CLEAR_SIGN(node) (node == 0 ? (doSign[0]|=1) : (doSign[node>>4]|=(node%16))) +#define DO_SIGN(node) (~_doSign[node>>3]&(1<<(node%8))) +#define SET_SIGN(node) (_doSign[node>>3]&=~(1<<(node%8))) +#define CLEAR_SIGN(node) (_doSign[node>>3]|=(1<<(node%8))) #endif // Inline function and macros diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index 18f4cb7f2..ba6edc313 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -366,7 +366,7 @@ class MySensor MyTransport& radio; #ifdef MY_SIGNING_FEATURE - uint16_t doSign[16]; // Bitfield indicating which sensors require signed communication + uint8_t doSign[32]; // Bitfield indicating which sensors require signed communication MyMessage msgSign; // Buffer for message to sign. MySigning& signer; #endif From ed75b16ea2d972b544e9719304d15f6ac1d18851 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Sun, 10 Jan 2016 13:59:56 +0100 Subject: [PATCH 05/11] Make sure nodes not supporting signing informs GW A node that does not support signing, still needs to inform the gateway about this to make sure the gateway carries a valid signing requirement table when a node Id that was requiering signing stops doing this. This fixes #286. --- libraries/MySensors/MySensor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index 8409e5d19..e101dd1fe 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -268,6 +268,9 @@ void MySensor::setupNode() { if (signer.requestSignatures()) { wait(2000); } +#else + // We do not support signing, make sure gateway knows this + sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_REQUEST_SIGNING, false).set(false)); #endif // Send presentation for this radio node (attach From ae7a8893895e7bcc3a952f119cb195ac7e7fb648 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Wed, 16 Dec 2015 09:47:05 +0100 Subject: [PATCH 06/11] Prevent SecureActuator from accepting ACKs as commands As ACKs are not currently signed, allowing ACKs as commands is a considerable security hole for this sketch. This is now resolved. --- libraries/MySensors/examples/SecureActuator/SecureActuator.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/MySensors/examples/SecureActuator/SecureActuator.ino b/libraries/MySensors/examples/SecureActuator/SecureActuator.ino index cb6935405..7399c01ab 100644 --- a/libraries/MySensors/examples/SecureActuator/SecureActuator.ino +++ b/libraries/MySensors/examples/SecureActuator/SecureActuator.ino @@ -102,7 +102,8 @@ void loop() void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. - if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS) { + // And acks are not accepted as control messages + if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS && !mGetAck(message)) { // Change relay state digitalWrite(message.sensor-1+LOCK_1, message.getBool()?LOCK_LOCK:LOCK_UNLOCK); // Store state in eeprom From 29a5bfbafa2f356dd8b5caebda23533cb28e6452 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Tue, 12 Jan 2016 08:39:05 +0100 Subject: [PATCH 07/11] Backport of bugfix (#259) in repeaters when forwarding signed messages --- libraries/MySensors/MySensor.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index e101dd1fe..b97ccae38 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -396,7 +396,9 @@ boolean MySensor::sendRoute(MyMessage &message) { } // After this point, only the 'last' member of the message structure is allowed to be altered if the message has been signed, // or signature will become invalid and the message rejected by the receiver - } else mSetSigned(message, 0); // Message is not supposed to be signed, make sure it is marked unsigned + } else if (nc.nodeId == message.sender) { + mSetSigned(message, 0); // Message is not supposed to be signed, make sure it is marked unsigned + } #endif if (dest == GATEWAY_ADDRESS || !repeaterMode) { @@ -588,11 +590,18 @@ boolean MySensor::process() { } #endif - // Add string termination, good if we later would want to print it. - msg.data[mGetLength(msg)] = '\0'; - debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"), + if (msg.destination == nc.nodeId) { + debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"), + msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf)); + } else { + if (repeaterMode && nc.nodeId != AUTO) { + debug(PSTR("read and forward: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"), + msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf)); + } else { + debug(PSTR("read and drop: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"), msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf)); - mSetSigned(msg,0); // Clear the sign-flag now as verification (and debug printing) is completed + } + } if(!(mGetVersion(msg) == PROTOCOL_VERSION)) { debug(PSTR("ver mismatch\n")); @@ -610,6 +619,7 @@ boolean MySensor::process() { if (destination == nc.nodeId) { // This message is addressed to this node + mSetSigned(msg,0); if (repeaterMode && last != nc.parentNodeId) { // Message is from one of the child nodes. Add it to routing table. From 56bc450549439e34a3252edcfdd0ef85f64ffe45 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Tue, 19 Jan 2016 13:18:12 +0100 Subject: [PATCH 08/11] Bumped version to 1.5.2 --- libraries/MySensors/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/MySensors/Version.h b/libraries/MySensors/Version.h index 456f13a7a..aacb06dec 100644 --- a/libraries/MySensors/Version.h +++ b/libraries/MySensors/Version.h @@ -6,6 +6,6 @@ #ifndef Version_h #define Version_h -#define LIBRARY_VERSION "1.5.1" +#define LIBRARY_VERSION "1.5.2" #endif From de28c0915cb1c791947edbd37a77344529818a7f Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Wed, 20 Jan 2016 09:15:41 +0100 Subject: [PATCH 09/11] Corrected doSign variable name (was _doSign) --- libraries/MySensors/MySensor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index b97ccae38..b87a4c455 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -24,9 +24,9 @@ #ifdef MY_SIGNING_FEATURE // Macros for manipulating signing requirement table -#define DO_SIGN(node) (~_doSign[node>>3]&(1<<(node%8))) -#define SET_SIGN(node) (_doSign[node>>3]&=~(1<<(node%8))) -#define CLEAR_SIGN(node) (_doSign[node>>3]|=(1<<(node%8))) +#define DO_SIGN(node) (~doSign[node>>3]&(1<<(node%8))) +#define SET_SIGN(node) (doSign[node>>3]&=~(1<<(node%8))) +#define CLEAR_SIGN(node) (doSign[node>>3]|=(1<<(node%8))) #endif // Inline function and macros From 6f9e3ca1fc7e5190cebed6bf436b0b4eefd5bd51 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Wed, 20 Jan 2016 09:16:40 +0100 Subject: [PATCH 10/11] Bumped version to 1.5.3 --- libraries/MySensors/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/MySensors/Version.h b/libraries/MySensors/Version.h index aacb06dec..79efa67d7 100644 --- a/libraries/MySensors/Version.h +++ b/libraries/MySensors/Version.h @@ -6,6 +6,6 @@ #ifndef Version_h #define Version_h -#define LIBRARY_VERSION "1.5.2" +#define LIBRARY_VERSION "1.5.3" #endif From 59550410a3f55f11b39aacfcaaa2dd8926682673 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Sun, 7 Feb 2016 12:48:36 +0100 Subject: [PATCH 11/11] Add NULL termination to payloads Messages addressed to "this" node, will have a null char appended to the payload after message verification is done, because some "getters" assume the message being a string. --- libraries/MySensors/MySensor.cpp | 1 + libraries/MySensors/Version.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index b87a4c455..6e85c5490 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -620,6 +620,7 @@ boolean MySensor::process() { if (destination == nc.nodeId) { // This message is addressed to this node mSetSigned(msg,0); + msg.data[mGetLength(msg)] = '\0'; // Add NULL termination so that "getters" works as expected if (repeaterMode && last != nc.parentNodeId) { // Message is from one of the child nodes. Add it to routing table. diff --git a/libraries/MySensors/Version.h b/libraries/MySensors/Version.h index 79efa67d7..bb45df07b 100644 --- a/libraries/MySensors/Version.h +++ b/libraries/MySensors/Version.h @@ -6,6 +6,6 @@ #ifndef Version_h #define Version_h -#define LIBRARY_VERSION "1.5.3" +#define LIBRARY_VERSION "1.5.4" #endif