diff --git a/ports/linux/bip6.c b/ports/linux/bip6.c index c70ab760..03d8a103 100644 --- a/ports/linux/bip6.c +++ b/ports/linux/bip6.c @@ -255,6 +255,26 @@ int bip6_send_mpdu( (struct sockaddr *) &bvlc_dest, sizeof(bvlc_dest)); } +/** + * The common send function for BACnet/IPv6 application layer + * + * @param dest - Points to a #BACNET_ADDRESS structure containing the + * destination address. + * @param npdu_data - Points to a BACNET_NPDU_DATA structure containing the + * destination network layer control flags and data. + * @param pdu - the bytes of data to send + * @param pdu_len - the number of bytes of data to send + * @return Upon successful completion, returns the number of bytes sent. + * Otherwise, -1 shall be returned and errno set to indicate the error. + */ +int bip6_send_pdu(BACNET_ADDRESS *dest, + BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, + unsigned pdu_len) +{ + return bvlc6_send_pdu(dest, npdu_data, pdu, pdu_len); +} + /** * BACnet/IP Datalink Receive handler. * diff --git a/ports/win32/bip6.c b/ports/win32/bip6.c index 83fb52ce..8542d7dc 100644 --- a/ports/win32/bip6.c +++ b/ports/win32/bip6.c @@ -378,6 +378,26 @@ int bip6_send_mpdu( (struct sockaddr *) &bvlc_dest, sizeof(bvlc_dest)); } +/** + * The common send function for BACnet/IPv6 application layer + * + * @param dest - Points to a #BACNET_ADDRESS structure containing the + * destination address. + * @param npdu_data - Points to a BACNET_NPDU_DATA structure containing the + * destination network layer control flags and data. + * @param pdu - the bytes of data to send + * @param pdu_len - the number of bytes of data to send + * @return Upon successful completion, returns the number of bytes sent. + * Otherwise, -1 shall be returned and errno set to indicate the error. + */ +int bip6_send_pdu(BACNET_ADDRESS *dest, + BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, + unsigned pdu_len) +{ + return bvlc6_send_pdu(dest, npdu_data, pdu, pdu_len); +} + /** * BACnet/IP Datalink Receive handler. * diff --git a/src/bacnet/basic/bbmd6/h_bbmd6.c b/src/bacnet/basic/bbmd6/h_bbmd6.c index 18e9af6b..6ddd22fa 100644 --- a/src/bacnet/basic/bbmd6/h_bbmd6.c +++ b/src/bacnet/basic/bbmd6/h_bbmd6.c @@ -238,12 +238,12 @@ static bool bbmd6_address_from_bacnet_address( * destination address. * @param npdu_data - Points to a BACNET_NPDU_DATA structure containing the * destination network layer control flags and data. - * @param mtu - the bytes of data to send - * @param mtu_len - the number of bytes of data to send + * @param pdu - the bytes of data to send + * @param pdu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -int bip6_send_pdu(BACNET_ADDRESS *dest, +int bvlc6_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, uint8_t *pdu, unsigned pdu_len) diff --git a/src/bacnet/basic/bbmd6/h_bbmd6.h b/src/bacnet/basic/bbmd6/h_bbmd6.h index e803e2ca..c24130a6 100644 --- a/src/bacnet/basic/bbmd6/h_bbmd6.h +++ b/src/bacnet/basic/bbmd6/h_bbmd6.h @@ -48,6 +48,11 @@ extern "C" { uint8_t * npdu, uint16_t npdu_len); BACNET_STACK_EXPORT + int bvlc6_send_pdu(BACNET_ADDRESS *dest, + BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, + unsigned pdu_len); + BACNET_STACK_EXPORT int bvlc6_register_with_bbmd( BACNET_IP6_ADDRESS *bbmd_addr, uint32_t vmac_src, diff --git a/src/bacnet/datalink/bvlc6.c b/src/bacnet/datalink/bvlc6.c index 13294b62..d949b85f 100644 --- a/src/bacnet/datalink/bvlc6.c +++ b/src/bacnet/datalink/bvlc6.c @@ -34,7 +34,6 @@ #include /* for standard integer types uint8_t etc. */ #include /* for the standard bool type. */ -#include #include "bacnet/bacenum.h" #include "bacnet/bacdcode.h" #include "bacnet/bacint.h" @@ -1252,12 +1251,13 @@ int bvlc6_decode_register_foreign_device( * BVLC Function: 1-octet X'0A' Delete-Foreign-Device * BVLC Length: 2-octets X'0019' Length of the BVLL message * Source-Virtual-Address: 3-octets - * FDT Entry: 18-octets + * FDT Entry: 18-octets The FDT entry is the B/IPv6 address + * of the foreign device to be deleted. */ int bvlc6_encode_delete_foreign_device(uint8_t *pdu, uint16_t pdu_size, uint32_t vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) + BACNET_IP6_ADDRESS *bip6_address) { int bytes_encoded = 0; const uint16_t length = 0x0019; @@ -1270,14 +1270,9 @@ int bvlc6_encode_delete_foreign_device(uint8_t *pdu, offset = 4; encode_unsigned24(&pdu[offset], vmac_src); offset += 3; - if (fdt_entry) { + if (bip6_address) { bvlc6_encode_address( - &pdu[offset], pdu_size - offset, &fdt_entry->bip6_address); - offset += BIP6_ADDRESS_MAX; - encode_unsigned16(&pdu[offset], fdt_entry->ttl_seconds); - offset += 2; - encode_unsigned16( - &pdu[offset], fdt_entry->ttl_seconds_remaining); + &pdu[offset], pdu_size - offset, bip6_address); bytes_encoded = (int)length; } } @@ -1291,18 +1286,19 @@ int bvlc6_encode_delete_foreign_device(uint8_t *pdu, * @param pdu - buffer from which to decode the message * @param pdu_len - length of the buffer that needs decoding * @param vmac_src - Source-Virtual-Address - * @param fdt_entry - FDT Entry + * @param fdt_entry - The FDT entry is the B/IPv6 address of the + * foreign device to be deleted. * * @return number of bytes decoded */ int bvlc6_decode_delete_foreign_device(uint8_t *pdu, uint16_t pdu_len, uint32_t *vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) + BACNET_IP6_ADDRESS *bip6_address) { int bytes_consumed = 0; - - const uint16_t length = BIP6_ADDRESS_MAX + 3 + 2 + 2 - 4; + /* BVLL length less the header length */ + const uint16_t length = 0x0019 - (1 + 1 + 2); uint16_t offset = 0; if (pdu && (pdu_len >= length)) { @@ -1311,14 +1307,9 @@ int bvlc6_decode_delete_foreign_device(uint8_t *pdu, bytes_consumed = 3; } offset += 3; - if (fdt_entry) { + if (bip6_address) { bvlc6_decode_address( - &pdu[offset], pdu_len - offset, &fdt_entry->bip6_address); - offset += BIP6_ADDRESS_MAX; - decode_unsigned16(&pdu[offset], &fdt_entry->ttl_seconds); - offset += 2; - decode_unsigned16(&pdu[offset], &fdt_entry->ttl_seconds_remaining); - bytes_consumed = (int)length; + &pdu[offset], pdu_len - offset, bip6_address); } bytes_consumed = (int)length; } @@ -1430,7 +1421,7 @@ int bvlc6_encode_distribute_broadcast_to_network(uint8_t *pdu, uint16_t npdu_len) { int bytes_encoded = 0; - uint16_t length = 7; + uint16_t length = 1 + 1 + 2 + 3; uint16_t i = 0; length += npdu_len; @@ -1439,7 +1430,7 @@ int bvlc6_encode_distribute_broadcast_to_network(uint8_t *pdu, pdu, pdu_size, BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac); - if (npdu && length) { + if (npdu && (npdu_len > 0)) { for (i = 0; i < npdu_len; i++) { pdu[7 + i] = npdu[i]; } @@ -1986,23 +1977,19 @@ static void test_BVLC6_Delete_Foreign_Device_Message(Test *pTest, const int msg_len = 0x0019; len = bvlc6_encode_delete_foreign_device( - pdu, sizeof(pdu), vmac_src, fdt_entry); + pdu, sizeof(pdu), vmac_src, &fdt_entry->bip6_address); ct_test(pTest, len == msg_len); test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_DELETE_FOREIGN_DEVICE); ct_test(pTest, length == msg_len); test_len += bvlc6_decode_delete_foreign_device( - &pdu[4], length - 4, &test_vmac_src, &test_fdt_entry); + &pdu[4], length - 4, &test_vmac_src, &test_fdt_entry.bip6_address); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); - test_BVLC6_Address( - pTest, &fdt_entry->bip6_address, &test_fdt_entry.bip6_address); - ct_test(pTest, fdt_entry->ttl_seconds == test_fdt_entry.ttl_seconds); - ct_test(pTest, - fdt_entry->ttl_seconds_remaining == - test_fdt_entry.ttl_seconds_remaining); + test_BVLC6_Address(pTest, &fdt_entry->bip6_address, + &test_fdt_entry.bip6_address); } static void test_BVLC6_Delete_Foreign_Device(Test *pTest) diff --git a/src/bacnet/datalink/bvlc6.h b/src/bacnet/datalink/bvlc6.h index 5a8229a9..75cfeb18 100644 --- a/src/bacnet/datalink/bvlc6.h +++ b/src/bacnet/datalink/bvlc6.h @@ -378,13 +378,13 @@ extern "C" { uint8_t * pdu, uint16_t pdu_size, uint32_t vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY * fdt_entry); + BACNET_IP6_ADDRESS *bip6_address); BACNET_STACK_EXPORT int bvlc6_decode_delete_foreign_device( uint8_t * pdu, uint16_t pdu_len, uint32_t * vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY * fdt_entry); + BACNET_IP6_ADDRESS *bip6_address); BACNET_STACK_EXPORT int bvlc6_encode_secure_bvll( diff --git a/test/Makefile b/test/Makefile index c8855970..127a822a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,6 +16,9 @@ logfile: report: cat ${LOGFILE} + cat ${LOGFILE} | grep Failed: | \ + awk 'BEGIN { err = 0 } $$2 > 0 { print "Unit Tests Failed!"; err = 1} \ + END {exit err}' abort: logfile abort.mak $(MAKE) -s -f abort.mak clean all diff --git a/test/bvlc6.mak b/test/bvlc6.mak index d5f5e6bc..cbae0c4a 100644 --- a/test/bvlc6.mak +++ b/test/bvlc6.mak @@ -38,4 +38,7 @@ depend: clean: rm -rf ${TARGET} $(OBJS) +test: ${TARGET} + ./${TARGET} + include: .depend