From c12014406245cb8fea5b0ddef45d5fe990f6ac0f Mon Sep 17 00:00:00 2001 From: Colin Kuebler Date: Wed, 15 May 2024 15:56:17 -0400 Subject: [PATCH 1/3] refactor(npdu): fail early on protocol version mismatch --- lib/npdu.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/npdu.js b/lib/npdu.js index 6878ba83..abeddcf4 100644 --- a/lib/npdu.js +++ b/lib/npdu.js @@ -52,7 +52,10 @@ module.exports.decodeFunction = (buffer, offset) => { module.exports.decode = (buffer, offset) => { let adrLen; const orgOffset = offset; - offset++; + const protocolVersion = buffer[offset++]; + if (protocolVersion !== BACNET_PROTOCOL_VERSION) { + return undefined; + } const funct = buffer[offset++]; let destination; if (funct & baEnum.NpduControlBit.DESTINATION_SPECIFIED) { @@ -80,9 +83,6 @@ module.exports.decode = (buffer, offset) => { offset += 2; } } - if (buffer[orgOffset + 0] !== BACNET_PROTOCOL_VERSION) { - return undefined; - } return { len: offset - orgOffset, funct, From 41e1645f910ca9f9f518738dd9366ae913d4b8bc Mon Sep 17 00:00:00 2001 From: Colin Kuebler Date: Wed, 15 May 2024 16:02:47 -0400 Subject: [PATCH 2/3] feat(client): expose net and adr from remote, if available --- lib/client.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/client.js b/lib/client.js index ebf4c6bd..553a7b98 100644 --- a/lib/client.js +++ b/lib/client.js @@ -478,6 +478,12 @@ class Client extends EventEmitter { } header.apduType = baApdu.getDecodedType(buffer, offset); header.expectingReply = !!(result.funct & baEnum.NpduControlBit.EXPECTING_REPLY); + if (result.source) { + // SNET of the host. Integer. + header.sender.net = result.source.net; + // SADR of the host. Integer[]. + header.sender.adr = result.source.adr; + } this._handlePdu(buffer, offset, msgLength, header); } From 034e70b7d367c22df29a5c516ae6a5d7e71303c9 Mon Sep 17 00:00:00 2001 From: Colin Kuebler Date: Thu, 16 May 2024 13:22:58 -0400 Subject: [PATCH 3/3] chore: add contributor --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 63f82d72..aaaf97bb 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,9 @@ { "name": "Ingo Fischer", "email": "iobroker@fischer-ka.de" + }, + { + "name": "Colin Kuebler (kueblc)" } ], "engines": {