From ca272743e6f856d0bf47e63e59aeb9bf3886651d Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Wed, 11 Feb 2015 11:24:45 -0200 Subject: [PATCH 1/3] check for invalid input on gateway To prevent incomplete or chunked data being sent by the gateway --- libraries/MySensors/MyGateway.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/MySensors/MyGateway.cpp b/libraries/MySensors/MyGateway.cpp index 909112e..d87e8ab 100644 --- a/libraries/MySensors/MyGateway.cpp +++ b/libraries/MySensors/MyGateway.cpp @@ -179,6 +179,9 @@ void MyGateway::parseAndSend(char *commandBuffer) { } i++; } + // Check for invalid input + if (i != 6) + return; if (destination==GATEWAY_ADDRESS && command==C_INTERNAL) { // Handle messages directed to gateway From 57e8947218e301be8a229e8746ec25f108d9b4a1 Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Wed, 11 Feb 2015 11:42:07 -0200 Subject: [PATCH 2/3] Write parentNodeId to eeprom only when differ --- libraries/MySensors/MySensor.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index a2a63b5..1b0cf41 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -51,9 +51,11 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b } if (_parentNodeId != AUTO) { - nc.parentNodeId = _parentNodeId; - // Save static parent id in eeprom - eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId); + if (_parentNodeId != nc.parentNodeId) { + nc.parentNodeId = _parentNodeId; + // Save static parent id in eeprom + eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId); + } autoFindParent = false; } else { autoFindParent = true; From d92918c80a3f3a846b823c42dc3556fac903a318 Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Wed, 11 Feb 2015 12:22:27 -0200 Subject: [PATCH 3/3] Accept a new parent only when autoFindParent is 1 In a gateway, I_FIND_PARENT_RESPONSE messages was returning as true by process(). With this commit it will return as false, is this the right expected behavior? --- libraries/MySensors/MyGateway.cpp | 1 + libraries/MySensors/MySensor.cpp | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/MySensors/MyGateway.cpp b/libraries/MySensors/MyGateway.cpp index 909112e..c65978f 100644 --- a/libraries/MySensors/MyGateway.cpp +++ b/libraries/MySensors/MyGateway.cpp @@ -37,6 +37,7 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da Serial.begin(BAUD_RATE); repeaterMode = true; isGateway = true; + autoFindParent = false; setupRepeaterMode(); if (inDataCallback != NULL) { diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index a2a63b5..955ea98 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -300,17 +300,19 @@ boolean MySensor::process() { } if (command == C_INTERNAL) { - if (type == I_FIND_PARENT_RESPONSE && !isGateway) { - // We've received a reply to a FIND_PARENT message. Check if the distance is - // shorter than we already have. - uint8_t distance = msg.getByte(); - if (distance