2424
2525#ifdef MY_SIGNING_FEATURE
2626// Macros for manipulating signing requirement table
27- #define DO_SIGN (node ) (node == 0 ? (~doSign[ 0 ]& 1 ) : (~doSign[ node>>4 ]&(node%16 )))
28- #define SET_SIGN (node ) (node == 0 ? (doSign[ 0 ]&=~ 1 ) : (doSign[ node>>4 ]&=~(node%16 )))
29- #define CLEAR_SIGN (node ) (node == 0 ? (doSign[ 0 ]|= 1 ) : (doSign[ node>>4 ]|=(node%16 )))
27+ #define DO_SIGN (node ) (~_doSign[ node>>3 ]&(1 <<( node%8 )))
28+ #define SET_SIGN (node ) (_doSign[ node>>3 ]&=~(1 <<( node%8 )))
29+ #define CLEAR_SIGN (node ) (_doSign[ node>>3 ]|=(1 <<( node%8 )))
3030#endif
3131
3232// Inline function and macros
@@ -268,6 +268,9 @@ void MySensor::setupNode() {
268268 if (signer.requestSignatures ()) {
269269 wait (2000 );
270270 }
271+ #else
272+ // We do not support signing, make sure gateway knows this
273+ sendRoute (build (msg, nc.nodeId , GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_REQUEST_SIGNING, false ).set (false ));
271274#endif
272275
273276 // Send presentation for this radio node (attach
@@ -393,7 +396,9 @@ boolean MySensor::sendRoute(MyMessage &message) {
393396 }
394397 // After this point, only the 'last' member of the message structure is allowed to be altered if the message has been signed,
395398 // or signature will become invalid and the message rejected by the receiver
396- } 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+ }
397402#endif
398403
399404 if (dest == GATEWAY_ADDRESS || !repeaterMode) {
@@ -585,11 +590,18 @@ boolean MySensor::process() {
585590 }
586591#endif
587592
588- // Add string termination, good if we later would want to print it.
589- msg.data [mGetLength (msg)] = ' \0 ' ;
590- 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 " ),
591602 msg.sender , msg.last , msg.destination , msg.sensor , mGetCommand (msg), msg.type , mGetPayloadType (msg), mGetLength (msg), mGetSigned (msg), msg.getString (convBuf));
592- mSetSigned (msg,0 ); // Clear the sign-flag now as verification (and debug printing) is completed
603+ }
604+ }
593605
594606 if (!(mGetVersion (msg) == PROTOCOL_VERSION)) {
595607 debug (PSTR (" ver mismatch\n " ));
@@ -607,6 +619,7 @@ boolean MySensor::process() {
607619
608620 if (destination == nc.nodeId ) {
609621 // This message is addressed to this node
622+ mSetSigned (msg,0 );
610623
611624 if (repeaterMode && last != nc.parentNodeId ) {
612625 // Message is from one of the child nodes. Add it to routing table.
0 commit comments