From 9f858fdb4fef5b54ef6284936601ea8cc27161a5 Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Thu, 9 Jan 2025 08:57:05 -0600 Subject: [PATCH] Added bvlc6.sh script to enable foreign-device-registration for client tools. (#889) --- bin/bvlc6.sh | 18 ++++++++++++++++++ src/bacnet/datalink/dlenv.c | 29 +++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100755 bin/bvlc6.sh diff --git a/bin/bvlc6.sh b/bin/bvlc6.sh new file mode 100755 index 00000000..c3ac2c17 --- /dev/null +++ b/bin/bvlc6.sh @@ -0,0 +1,18 @@ +#!/bin/bash +echo Example of parameters for Foreign Device Registration +BACNET_IP_PORT=47809 +export BACNET_IP_PORT +echo This console will use port ${BACNET_IP_PORT} to communicate. +echo +BACNET_BBMD_PORT=47808 +export BACNET_BBMD_PORT +echo The BBMD is located at the port ${BACNET_BBMD_PORT} and +echo is at the dotted IP address passed on the command line. +BACNET_BBMD_ADDRESS=${1} +export BACNET_BBMD_ADDRESS +echo The BBMD IP address is ${BACNET_BBMD_ADDRESS} +echo When the demo client applications see the BBMD address, +echo they register as a Foreign Device to it. +echo +echo Launching new shell using the BBMD environment... +/bin/bash diff --git a/src/bacnet/datalink/dlenv.c b/src/bacnet/datalink/dlenv.c index 580fdf1d..c3cddf81 100644 --- a/src/bacnet/datalink/dlenv.c +++ b/src/bacnet/datalink/dlenv.c @@ -1,6 +1,6 @@ /** * @file - * @brief Environment variables used for the BACnet command line tools + * @brief Datalink environment variables used for the BACnet command line tools * @author Steve Karg * @date 2009 * @copyright SPDX-License-Identifier: MIT @@ -35,7 +35,9 @@ #include "bacnet/datalink/bsc/bsc-event.h" #endif -/** @file dlenv.c Initialize the DataLink configuration. */ +/* enable debugging */ +static bool Datalink_Debug; + /* timer used to renew Foreign Device Registration */ #if defined(BACDL_BIP) || defined(BACDL_BIP6) static uint16_t BBMD_Timer_Seconds; @@ -53,8 +55,6 @@ static uint16_t BBMD_Result = 0; #if BBMD_ENABLED static BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY BBMD_Table_Entry; #endif -/* enable debugging */ -static bool BIP_DL_Debug = false; /* Debug toggle */ @@ -63,7 +63,7 @@ static bool BIP_DL_Debug = false; */ void bip_dl_debug_enable(void) { - BIP_DL_Debug = true; + Datalink_Debug = true; } /** @@ -71,7 +71,7 @@ void bip_dl_debug_enable(void) */ void bip_dl_debug_disable(void) { - BIP_DL_Debug = false; + Datalink_Debug = false; } /* Simple setters for BBMD registration variables. */ @@ -169,7 +169,7 @@ static int bbmd_register_as_foreign_device(void) BBMD_Address_Valid = bip_get_addr_by_name(pEnv, &BBMD_Address); } if (BBMD_Address_Valid) { - if (BIP_DL_Debug) { + if (Datalink_Debug) { fprintf( stderr, "Registering with BBMD at %u.%u.%u.%u:%u for %u seconds\n", @@ -199,7 +199,7 @@ static int bbmd_register_as_foreign_device(void) bdt_entry_valid = bip_get_addr_by_name(pEnv, &BBMD_Table_Entry.dest_address); if (entry_number == 1) { - if (BIP_DL_Debug) { + if (Datalink_Debug) { fprintf( stderr, "BBMD 1 address overridden %s=%s!\n", bbmd_env, pEnv); @@ -218,7 +218,7 @@ static int bbmd_register_as_foreign_device(void) if (pEnv) { bdt_entry_port = strtol(pEnv, NULL, 0); if (entry_number == 1) { - if (BIP_DL_Debug) { + if (Datalink_Debug) { fprintf( stderr, "BBMD 1 port overridden %s=%s!\n", bbmd_env, pEnv); @@ -247,7 +247,7 @@ static int bbmd_register_as_foreign_device(void) } bvlc_broadcast_distribution_table_entry_append( bvlc_bdt_list(), &BBMD_Table_Entry); - if (BIP_DL_Debug) { + if (Datalink_Debug) { fprintf( stderr, "BBMD %4u: %u.%u.%u.%u:%u %u.%u.%u.%u\n", entry_number, @@ -315,7 +315,7 @@ static int bbmd6_register_as_foreign_device(void) } pEnv = getenv("BACNET_BBMD6_ADDRESS"); if (bvlc6_address_from_ascii(pEnv, &bip6_addr)) { - if (BIP_DL_Debug) { + if (Datalink_Debug) { fprintf( stderr, "Registering with BBMD6 at %s for %u seconds\n", pEnv, (unsigned)bip6_port, (unsigned)BBMD_TTL_Seconds); @@ -374,7 +374,7 @@ void dlenv_network_port_init(void) Network_Port_Type_Set(instance, PORT_TYPE_BIP); bip_get_addr(&addr); prefix = bip_get_subnet_prefix(); - if (BIP_DL_Debug) { + if (Datalink_Debug) { fprintf( stderr, "BIP: Setting Network Port %lu address %u.%u.%u.%u:%u/%u\n", (unsigned long)instance, (unsigned)addr.address[0], @@ -729,6 +729,10 @@ void dlenv_maintenance_timer(uint16_t elapsed_seconds) * - BACNET_BIP6_PORT - UDP/IP port number (0..65534) used for BACnet/IPv6 * communications. Default is 47808 (0xBAC0). * - BACNET_BIP6_BROADCAST - FF05::BAC0 or FF02::BAC0 or ... + * - BACNET_BBMD6_PORT - UDP/IPv6 port number (0..65534) used for Foreign + * Device Registration. Defaults to 47808 (0xBAC0). + * - BACNET_BBMD6_TIMETOLIVE - 0..65535 seconds, defaults to 60000 + * - BACNET_BBMD6_ADDRESS - IPv6 address * - BACDL_BSC: (BACnet Secure Connect) * - BACNET_SC_PRIMARY_HUB_URI * - BACNET_SC_FAILOVER_HUB_URI @@ -785,6 +789,7 @@ void dlenv_init(void) if (pEnv) { bip6_debug_enable(); bvlc6_debug_enable(); + Datalink_Debug = true; } pEnv = getenv("BACNET_BIP6_BROADCAST"); if (pEnv) {