Skip to content

Commit 29a5bfb

Browse files
committed
Backport of bugfix (#259) in repeaters when forwarding signed messages
1 parent ae7a889 commit 29a5bfb

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ boolean MySensor::sendRoute(MyMessage &message) {
396396
}
397397
// After this point, only the 'last' member of the message structure is allowed to be altered if the message has been signed,
398398
// or signature will become invalid and the message rejected by the receiver
399-
} else mSetSigned(message, 0); // Message is not supposed to be signed, make sure it is marked unsigned
399+
} else if (nc.nodeId == message.sender) {
400+
mSetSigned(message, 0); // Message is not supposed to be signed, make sure it is marked unsigned
401+
}
400402
#endif
401403

402404
if (dest == GATEWAY_ADDRESS || !repeaterMode) {
@@ -588,11 +590,18 @@ boolean MySensor::process() {
588590
}
589591
#endif
590592

591-
// Add string termination, good if we later would want to print it.
592-
msg.data[mGetLength(msg)] = '\0';
593-
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
593+
if (msg.destination == nc.nodeId) {
594+
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
595+
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf));
596+
} else {
597+
if (repeaterMode && nc.nodeId != AUTO) {
598+
debug(PSTR("read and forward: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
599+
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf));
600+
} else {
601+
debug(PSTR("read and drop: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
594602
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf));
595-
mSetSigned(msg,0); // Clear the sign-flag now as verification (and debug printing) is completed
603+
}
604+
}
596605

597606
if(!(mGetVersion(msg) == PROTOCOL_VERSION)) {
598607
debug(PSTR("ver mismatch\n"));
@@ -610,6 +619,7 @@ boolean MySensor::process() {
610619

611620
if (destination == nc.nodeId) {
612621
// This message is addressed to this node
622+
mSetSigned(msg,0);
613623

614624
if (repeaterMode && last != nc.parentNodeId) {
615625
// Message is from one of the child nodes. Add it to routing table.

0 commit comments

Comments
 (0)