Changed NPDU handler to check for BACnet version before attempting to decode. Thanks, Piotr!

This commit is contained in:
skarg
2010-03-17 00:35:51 +00:00
parent 6a97eb5424
commit 52518b9d57
+19 -19
View File
@@ -47,32 +47,32 @@ void npdu_handler(
BACNET_ADDRESS dest = { 0 }; BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data); /* only handle the version that we know how to handle */
if (npdu_data.network_layer_message) { if (pdu[0] == BACNET_PROTOCOL_VERSION) {
/*FIXME: network layer message received! Handle it! */ apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
if (npdu_data.network_layer_message) {
/*FIXME: network layer message received! Handle it! */
#if PRINT_ENABLED #if PRINT_ENABLED
printf("NPDU: Network Layer Message discarded!\n"); printf("NPDU: Network Layer Message discarded!\n");
#endif #endif
} else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) { } else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) {
if ((npdu_data.protocol_version == BACNET_PROTOCOL_VERSION) && if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) {
((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK))) { /* only handle the version that we know how to handle */
/* only handle the version that we know how to handle */ /* and we are not a router, so ignore messages with
/* and we are not a router, so ignore messages with routing information cause they are not for us */
routing information cause they are not for us */ apdu_handler(src, &pdu[apdu_offset],
apdu_handler(src, &pdu[apdu_offset], (uint16_t) (pdu_len - apdu_offset));
(uint16_t) (pdu_len - apdu_offset)); } else {
} else {
if (dest.net) {
#if PRINT_ENABLED #if PRINT_ENABLED
printf("NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net); printf("NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net);
#endif
} else {
#if PRINT_ENABLED
printf("NPDU: BACnet Protocol Version=%u. Discarded!\n",
(unsigned)npdu_data.protocol_version);
#endif #endif
} }
} }
} else {
#if PRINT_ENABLED
printf("NPDU: BACnet Protocol Version=%u. Discarded!\n",
(unsigned)pdu[0]);
#endif
} }
return; return;