Revised BBMD registration functions to return something approximating a goodness value. (Still too happy for invalid BBMDs, but it's a start.)
Fixed handling of bacapp_decode_context_data() for some of the more unusual (empty, etc) cases I've seen.
This commit is contained in:
@@ -694,11 +694,14 @@ int bacapp_decode_context_data(
|
||||
max_apdu_len = max_apdu_len;
|
||||
if (apdu && value && IS_CONTEXT_SPECIFIC(*apdu)) {
|
||||
value->context_specific = true;
|
||||
value->next = NULL;
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&apdu[0], &tag_number,
|
||||
&len_value_type);
|
||||
if (tag_len) {
|
||||
apdu_len = tag_len;
|
||||
apdu_len = tag_len;
|
||||
/* Empty construct : (closing tag) => returns NULL value */
|
||||
if (tag_len && tag_len <= max_apdu_len &&
|
||||
!decode_is_closing_tag_number(&apdu[0], tag_number)) {
|
||||
value->context_tag = tag_number;
|
||||
value->tag = bacapp_context_tag_type(property, tag_number);
|
||||
if (value->tag < MAX_BACNET_APPLICATION_TAG) {
|
||||
@@ -706,11 +709,16 @@ int bacapp_decode_context_data(
|
||||
bacapp_decode_data(&apdu[apdu_len], value->tag,
|
||||
len_value_type, value);
|
||||
apdu_len += len;
|
||||
} else if (len_value_type) {
|
||||
/* Unknown value : non null size (elementary type) */
|
||||
apdu_len += len_value_type;
|
||||
/* SHOULD NOT HAPPEN, EXCEPTED WHEN READING UNKNOWN CONTEXTUAL PROPERTY */
|
||||
} else {
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
value->next = NULL;
|
||||
else if ( tag_len == 1 ) /* and is a Closing tag */
|
||||
apdu_len = 0; /* Don't advance over that closing tag. */
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
|
||||
+21
-9
@@ -45,12 +45,12 @@
|
||||
#endif
|
||||
#include "debug.h"
|
||||
|
||||
/** @file bvlc.c Handle the BACnet Virtual Link Control (BVLC) */
|
||||
/** @file bvlc.c Handle the BACnet Virtual Link Control (BVLC),
|
||||
* which includes: BACnet Broadcast Management Device,
|
||||
* Broadcast Distribution Table, and
|
||||
* Foreign Device Registration.
|
||||
*/
|
||||
|
||||
/* Handle the BACnet Virtual Link Control (BVLC), which includes:
|
||||
BACnet Broadcast Management Device,
|
||||
Broadcast Distribution Table, and
|
||||
Foreign Device Registration */
|
||||
typedef struct {
|
||||
/* true if valid entry - false if not */
|
||||
bool valid;
|
||||
@@ -733,13 +733,24 @@ static void bvlc_fdt_forward_npdu(
|
||||
return;
|
||||
}
|
||||
|
||||
void bvlc_register_with_bbmd(
|
||||
uint32_t bbmd_address, /* in network byte order */
|
||||
uint16_t bbmd_port, /* in network byte order */
|
||||
|
||||
/** Register as a foreign device with the indicated BBMD.
|
||||
* @param bbmd_address - IPv4 address (long) of BBMD to register with,
|
||||
* in network byte order.
|
||||
* @param bbmd_port - Network port of BBMD, in network byte order
|
||||
* @param time_to_live_seconds - Lease time to use when registering.
|
||||
* @return Positive number (of bytes sent) on success,
|
||||
* 0 if no registration request is sent, or
|
||||
* -1 if registration fails.
|
||||
*/
|
||||
int bvlc_register_with_bbmd(
|
||||
uint32_t bbmd_address,
|
||||
uint16_t bbmd_port,
|
||||
uint16_t time_to_live_seconds)
|
||||
{
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
uint16_t mtu_len = 0;
|
||||
int retval = 0;
|
||||
|
||||
/* Store the BBMD address and port so that we
|
||||
won't broadcast locally. */
|
||||
@@ -752,7 +763,8 @@ void bvlc_register_with_bbmd(
|
||||
mtu_len =
|
||||
(uint16_t) bvlc_encode_register_foreign_device(&mtu[0],
|
||||
time_to_live_seconds);
|
||||
bvlc_send_mpdu(&Remote_BBMD, &mtu[0], mtu_len);
|
||||
retval = bvlc_send_mpdu(&Remote_BBMD, &mtu[0], mtu_len);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void bvlc_send_result(
|
||||
|
||||
Reference in New Issue
Block a user