Discard confirmed APDU from original broadcast in BIP and BIP6 datalink (#149)

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2021-01-13 13:59:16 -06:00
committed by GitHub
parent 0a9fbaf438
commit 69f876f1c9
5 changed files with 106 additions and 17 deletions
+32
View File
@@ -501,6 +501,38 @@ int bacnet_npdu_decode(uint8_t *npdu,
return len;
}
/**
* @brief Helper for datalink detecting an application confirmed service
* @param pdu [in] Buffer containing the NPDU and APDU of the received packet.
* @param pdu_len [in] The size of the received message in the pdu[] buffer.
* @return true if the PDU is a confirmed APDU
*/
bool npdu_confirmed_service(
uint8_t *pdu,
uint16_t pdu_len)
{
bool status = false;
int apdu_offset = 0;
BACNET_NPDU_DATA npdu_data = { 0 };
if (pdu_len > 0) {
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
/* only handle the version that we know how to handle */
apdu_offset =
bacnet_npdu_decode(&pdu[0], pdu_len, NULL, NULL, &npdu_data);
if ((!npdu_data.network_layer_message) && (apdu_offset > 0) &&
(apdu_offset < pdu_len)) {
if ((pdu[apdu_offset] & 0xF0) ==
PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
status = true;
}
}
}
}
return status;
}
#ifdef BAC_TEST
#include <assert.h>
#include <string.h>