fix BVLC6 Delete-Foreign-Device-Table-Entry (#56)

* fix BVLC6 Delete-Foreign-Device-Table-Entry

* Add unit test failure detection to Makefile report target

* Fix the IPv6 layers for sending PDU

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2020-03-12 12:24:07 -05:00
committed by GitHub
parent 4a916468c6
commit 81d3a0b4a4
8 changed files with 74 additions and 36 deletions
+20
View File
@@ -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.
*
+20
View File
@@ -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.
*
+3 -3
View File
@@ -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)
+5
View File
@@ -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,
+18 -31
View File
@@ -34,7 +34,6 @@
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <time.h>
#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)
+2 -2
View File
@@ -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(
+3
View File
@@ -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
+3
View File
@@ -38,4 +38,7 @@ depend:
clean:
rm -rf ${TARGET} $(OBJS)
test: ${TARGET}
./${TARGET}
include: .depend