From 3835dc8998b5972c6d61dcd44b1a6a420a292066 Mon Sep 17 00:00:00 2001 From: skarg Date: Fri, 17 Jan 2014 04:29:20 +0000 Subject: [PATCH] Merged revision(s) 2707 from branches/obvius/bacnet-stack: Fix: As a BBMD, when forwarding NPDU to the local subnet (as an IP broacast) we omit BVLC header, resulting in corrupt packet. bvlc_send_mpdu(&dest, &npdu[4 + 6], npdu_len); // bad bvlc_send_mpdu(&dest, &npdu[0], npdu_len+4+6); // good Also added some debug_prints. To test, start bacserv, use VTS to add yourself to the BDT, then send a Who-Is to bacserv as a Forwarded-NPDU. Will be rebroadcast on local subnet but w/o BVLC header. ........ --- bacnet-stack/src/bvlc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bacnet-stack/src/bvlc.c b/bacnet-stack/src/bvlc.c index 22c01d76..95814c3b 100644 --- a/bacnet-stack/src/bvlc.c +++ b/bacnet-stack/src/bvlc.c @@ -989,12 +989,16 @@ uint16_t bvlc_receive( /* decode the 4 byte original address and 2 byte port */ bvlc_decode_bip_address(&npdu[4], &original_sin.sin_addr, &original_sin.sin_port); + debug_printf("BVLC: Received Forwarded-NPDU from %s:%04X.\n", + inet_ntoa(original_sin.sin_addr), ntohs(original_sin.sin_port)); npdu_len -= 6; /* Broadcast locally if received via unicast from a BDT member */ if (bvlc_bdt_member_mask_is_unicast(&sin)) { dest.sin_addr.s_addr = bip_get_broadcast_addr(); dest.sin_port = bip_get_port(); - bvlc_send_mpdu(&dest, &npdu[4 + 6], npdu_len); + debug_printf("BVLC: Received unicast from BDT member, re-broadcasting locally to %s:%04X.\n", + inet_ntoa(dest.sin_addr), ntohs(dest.sin_port)); + bvlc_send_mpdu(&dest, &npdu[0], npdu_len+4+6); } /* use the original addr from the BVLC for src */ dest.sin_addr.s_addr = original_sin.sin_addr.s_addr;