Fixed WriteProperty error code for FD_BBMD_ADDRESS and FD_SUBSCRIPTION_LIFETIME (#925)

* Fixed WriteProperty error code for PROP_FD_BBMD_ADDRESS and PROP_FD_SUBSCRIPTION_LIFETIME properties.  

* Fixed dead-code warning after enabling all datalinks for basic network port object using the property list as the R/W checking for the port type.
This commit is contained in:
Steve Karg
2025-03-03 08:04:07 -06:00
committed by GitHub
parent 3e480f41e2
commit 5cd453c925
22 changed files with 1577 additions and 8353 deletions
+185 -77
View File
@@ -516,70 +516,126 @@ bool bvlc_broadcast_distribution_table_entry_forward_address(
* broadcast-mask [1] OCTET STRING
* }
*
* @param apdu - the APDU buffer, or NULL for length
* @param bdt_head - one BACnetBDTEntry
* @return length of the APDU buffer
*/
int bvlc_broadcast_distribution_table_entry_encode(
uint8_t *apdu,
const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_entry)
{
int len = 0;
int apdu_len = 0;
BACNET_OCTET_STRING octet_string;
if (bdt_entry) {
/* bbmd-address [0] BACnetHostNPort - opening */
len = encode_opening_tag(apdu, 0);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* host [0] BACnetHostAddress - opening */
len = encode_opening_tag(apdu, 0);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* CHOICE - ip-address [1] OCTET STRING */
octetstring_init(
&octet_string, &bdt_entry->dest_address.address[0], IP_ADDRESS_MAX);
len = encode_context_octet_string(apdu, 1, &octet_string);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* host [0] BACnetHostAddress - closing */
len = encode_closing_tag(apdu, 0);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* port [1] Unsigned16 */
len = encode_context_unsigned(apdu, 1, bdt_entry->dest_address.port);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* bbmd-address [0] BACnetHostNPort - closing */
len = encode_closing_tag(apdu, 0);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* broadcast-mask [1] OCTET STRING */
octetstring_init(
&octet_string, &bdt_entry->broadcast_mask.address[0],
IP_ADDRESS_MAX);
len = encode_context_octet_string(apdu, 1, &octet_string);
apdu_len += len;
}
return apdu_len;
}
/**
* @brief Encode the Broadcast-Distribution-Table for Network Port object
*
* BACnetLIST of BACnetBDTEntry
*
* @param apdu - the APDU buffer
* @param apdu_size - the APDU buffer size
* @param bdt_head - head of the BDT linked list
* @return length of the APDU buffer
*/
int bvlc_broadcast_distribution_table_encode(
uint8_t *apdu,
uint16_t apdu_size,
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head)
int bvlc_broadcast_distribution_table_list_encode(
uint8_t *apdu, const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head)
{
int len = 0;
int apdu_len = 0;
int entry_size = 0;
BACNET_OCTET_STRING octet_string;
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_entry;
const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_entry;
bdt_entry = bdt_head;
while (bdt_entry) {
if (bdt_entry->valid) {
/* bbmd-address [0] BACnetHostNPort - opening */
len = encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += len;
/* host [0] BACnetHostAddress - opening */
len = encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += len;
/* CHOICE - ip-address [1] OCTET STRING */
octetstring_init(
&octet_string, &bdt_entry->dest_address.address[0],
IP_ADDRESS_MAX);
len =
encode_context_octet_string(&apdu[apdu_len], 1, &octet_string);
bvlc_broadcast_distribution_table_entry_encode(apdu, bdt_entry);
apdu_len += len;
/* host [0] BACnetHostAddress - closing */
len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len;
/* port [1] Unsigned16 */
len = encode_context_unsigned(
&apdu[apdu_len], 1, bdt_entry->dest_address.port);
apdu_len += len;
/* bbmd-address [0] BACnetHostNPort - closing */
len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len;
/* broadcast-mask [1] OCTET STRING */
octetstring_init(
&octet_string, &bdt_entry->broadcast_mask.address[0],
IP_ADDRESS_MAX);
len =
encode_context_octet_string(&apdu[apdu_len], 1, &octet_string);
apdu_len += len;
}
if (!entry_size) {
entry_size = apdu_len;
if (apdu) {
apdu += len;
}
}
/* next entry */
bdt_entry = bdt_entry->next;
if ((apdu_len + entry_size) > apdu_size) {
/* check for available space */
break;
}
}
return apdu_len;
}
/**
* @brief Encode the Broadcast-Distribution-Table for Network Port object
* @param apdu - the APDU buffer
* @param apdu_size - the APDU buffer size
* @param bdt_head - head of the BDT linked list
* @return length of the APDU buffer, or BACNET_STATUS_ERROR on error
*/
int bvlc_broadcast_distribution_table_encode(
uint8_t *apdu,
uint16_t apdu_size,
const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head)
{
int len = 0;
len = bvlc_broadcast_distribution_table_list_encode(NULL, bdt_head);
if (len <= apdu_size) {
len = bvlc_broadcast_distribution_table_list_encode(apdu, bdt_head);
} else {
len = BACNET_STATUS_ERROR;
}
return len;
}
/**
* @brief Decode the Broadcast-Distribution-Table for Network Port object
* @param apdu - the APDU buffer
@@ -1105,6 +1161,86 @@ int bvlc_decode_register_foreign_device(
return bytes_consumed;
}
/**
* @brief Encode the Foreign_Device-Table for Network Port object
*
* BACnetLIST of BACnetFDTEntry
*
* BACnetFDTEntry ::= SEQUENCE {
* bacnetip-address [0] OCTET STRING, -- 6-octet B/IP registrant address
* time-to-live [1] Unsigned16, -- time to live in seconds
* remaining-time-to-live [2] Unsigned16 -- remaining time in seconds
* }
*
* @param apdu - the APDU buffer, or NULL for length
* @param fdt_head - head of the BDT linked list
* @return length of the APDU buffer
*/
int bvlc_foreign_device_table_entry_encode(
uint8_t *apdu, const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry)
{
int len = 0;
int apdu_len = 0;
BACNET_OCTET_STRING octet_string = { 0 };
if (fdt_entry && fdt_entry->valid) {
/* bacnetip-address [0] OCTET STRING */
len = bvlc_encode_address(
octetstring_value(&octet_string),
octetstring_capacity(&octet_string), &fdt_entry->dest_address);
octetstring_truncate(&octet_string, len);
len = encode_context_octet_string(apdu, 0, &octet_string);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* time-to-live [1] Unsigned16 */
len = encode_context_unsigned(apdu, 1, fdt_entry->ttl_seconds);
apdu_len += len;
if (apdu) {
apdu += len;
}
/* remaining-time-to-live [2] Unsigned16 */
len =
encode_context_unsigned(apdu, 2, fdt_entry->ttl_seconds_remaining);
apdu_len += len;
}
return apdu_len;
}
/**
* @brief Encode the Foreign_Device-Table for Network Port object
*
* BACnetLIST of BACnetFDTEntry
*
* @param apdu - the APDU buffer, or NULL for length
* @param fdt_head - head of the BDT linked list
* @return length of the APDU buffer
*/
int bvlc_foreign_device_table_list_encode(
uint8_t *apdu, const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head)
{
int len = 0;
int apdu_len = 0;
const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry;
fdt_entry = fdt_head;
while (fdt_entry) {
if (fdt_entry->valid) {
len = bvlc_foreign_device_table_entry_encode(apdu, fdt_entry);
apdu_len += len;
if (apdu) {
apdu += len;
}
}
/* next entry */
fdt_entry = fdt_entry->next;
}
return apdu_len;
}
/**
* @brief Encode the Foreign_Device-Table for Network Port object
*
@@ -1124,46 +1260,18 @@ int bvlc_decode_register_foreign_device(
int bvlc_foreign_device_table_encode(
uint8_t *apdu,
uint16_t apdu_size,
BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head)
const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head)
{
int len = 0;
int apdu_len = 0;
int entry_size = 0;
BACNET_OCTET_STRING octet_string = { 0 };
BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry;
fdt_entry = fdt_head;
while (fdt_entry) {
if (fdt_entry->valid) {
/* bacnetip-address [0] OCTET STRING */
len = bvlc_encode_address(
octetstring_value(&octet_string),
octetstring_capacity(&octet_string), &fdt_entry->dest_address);
octetstring_truncate(&octet_string, len);
len =
encode_context_octet_string(&apdu[apdu_len], 0, &octet_string);
apdu_len += len;
/* time-to-live [1] Unsigned16 */
len = encode_context_unsigned(
&apdu[apdu_len], 1, fdt_entry->ttl_seconds);
apdu_len += len;
/* remaining-time-to-live [2] Unsigned16 */
len = encode_context_unsigned(
&apdu[apdu_len], 2, fdt_entry->ttl_seconds_remaining);
apdu_len += len;
}
if (!entry_size) {
entry_size = apdu_len;
}
/* next entry */
fdt_entry = fdt_entry->next;
if ((apdu_len + entry_size) > apdu_size) {
/* check for available space */
break;
}
len = bvlc_foreign_device_table_list_encode(NULL, fdt_head);
if (len <= apdu_size) {
len = bvlc_foreign_device_table_list_encode(apdu, fdt_head);
} else {
len = BACNET_STATUS_ERROR;
}
return apdu_len;
return len;
}
/**
+17 -2
View File
@@ -321,11 +321,20 @@ int bvlc_broadcast_distribution_table_decode(
BACNET_ERROR_CODE *error_code,
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head);
BACNET_STACK_EXPORT
int bvlc_broadcast_distribution_table_entry_encode(
uint8_t *apdu,
const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_entry);
int bvlc_broadcast_distribution_table_list_encode(
uint8_t *apdu,
const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head);
BACNET_STACK_EXPORT
int bvlc_broadcast_distribution_table_encode(
uint8_t *apdu,
uint16_t apdu_size,
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head);
const BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_head);
BACNET_STACK_EXPORT
int bvlc_encode_write_broadcast_distribution_table(
@@ -416,10 +425,16 @@ int bvlc_decode_foreign_device_table_entry(
BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry);
BACNET_STACK_EXPORT
int bvlc_foreign_device_table_entry_encode(
uint8_t *apdu, const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head);
BACNET_STACK_EXPORT
int bvlc_foreign_device_table_list_encode(
uint8_t *apdu, const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head);
BACNET_STACK_EXPORT
int bvlc_foreign_device_table_encode(
uint8_t *apdu,
uint16_t apdu_size,
BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head);
const BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_head);
BACNET_STACK_EXPORT
int bvlc_encode_read_foreign_device_table(uint8_t *pdu, uint16_t pdu_size);
+24 -3
View File
@@ -520,6 +520,30 @@ bool bvlc6_address_different(
return status;
}
/**
* @brief Set the IPv6 address and port number
* @param addr - B/IPv6 address that be set
* @param address - B/IPv6 address bytes
* @param port - B/IPv6 address port
* @return true if the address is set
*/
bool bvlc6_address_n_port_set(
BACNET_IP6_ADDRESS *addr, uint8_t *address, uint16_t port)
{
bool status = false;
unsigned i;
if (addr) {
for (i = 0; i < IP6_ADDRESS_MAX; i += 2) {
addr->address[i] = address[i];
}
addr->port = port;
status = true;
}
return status;
}
/** Set a BVLC Address from 16-bit group chunks
*
* Data link layer addressing between B/IPv6 nodes consists of a 128-bit
@@ -1402,7 +1426,6 @@ int bvlc6_decode_delete_foreign_device(
if (pdu && (pdu_len >= length)) {
if (vmac_src) {
decode_unsigned24(&pdu[offset], vmac_src);
bytes_consumed = 3;
}
offset += 3;
if (bip6_address) {
@@ -1707,8 +1730,6 @@ int bvlc6_broadcast_distribution_table_list_encode(
if (apdu) {
apdu += len;
}
} else {
len = 0;
}
/* next entry */
bdt_entry = bdt_entry->next;
+3
View File
@@ -181,6 +181,9 @@ int bvlc6_address_to_ascii(
BACNET_STACK_EXPORT
bool bvlc6_address_from_ascii(BACNET_IP6_ADDRESS *addr, const char *addrstr);
BACNET_STACK_EXPORT
bool bvlc6_address_n_port_set(
BACNET_IP6_ADDRESS *addr, uint8_t *addr16, uint16_t port);
BACNET_STACK_EXPORT
bool bvlc6_address_set(
BACNET_IP6_ADDRESS *addr,