From 17259b37f3d4baa6a93410b2120fef0632b80e27 Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Thu, 30 Oct 2025 12:00:01 -0500 Subject: [PATCH] Fixing Makefile build for bip6 with win32 MinGW and in github workflows. (#1125) --- .github/workflows/gcc.yml | 17 ++-- Makefile | 26 +++---- apps/Makefile | 67 +++++++++++----- apps/lib/Makefile | 26 ++++--- apps/readpropm/Makefile | 2 +- build.bat | 1 - ports/win32/arcnet.c | 129 +++++++++++++++++++++++++++++++ src/Makefile | 2 +- src/bacnet/basic/bbmd6/h_bbmd6.c | 46 +---------- src/bacnet/datalink/datalink.h | 4 +- 10 files changed, 216 insertions(+), 104 deletions(-) create mode 100644 ports/win32/arcnet.c diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 16d61b53..928fd98f 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -277,18 +277,19 @@ jobs: sudo apt-get update -qq sudo apt-get install -qq build-essential sudo apt-get install -qq mingw-w64 - - name: Build Win32 Demo Apps - run: | - export CC=i686-w64-mingw32-gcc - export LD=i686-w64-mingw32-ld i686-w64-mingw32-gcc --version - make win32 + - name: Build Win32 Demo BACnet/IP Apps + run: make PREFIX=i686-w64-mingw32- LEGACY=true BACNET_PORT=win32 clean bip + - name: Build Win32 Demo BACnet/IPv6 Apps + run: make PREFIX=i686-w64-mingw32- LEGACY=true BACNET_PORT=win32 clean bip6 + - name: Build Win32 Demo BACnet MS/TP Apps + run: make PREFIX=i686-w64-mingw32- LEGACY=true BACNET_PORT=win32 clean mstp - name: Build Win32 Demo IP to IPv6 Router - run: make LEGACY=true BUILD=win32 router-ipv6 + run: make PREFIX=i686-w64-mingw32- LEGACY=true BACNET_PORT=win32 clean router-ipv6 - name: Build Win32 Demo IP to MS/TP Router - run: make LEGACY=true BUILD=win32 router-mstp + run: make PREFIX=i686-w64-mingw32- LEGACY=true BACNET_PORT=win32 clean router-mstp - name: Build Win32 Demo Gateway - run: make LEGACY=true BUILD=win32 gateway + run: make PREFIX=i686-w64-mingw32- LEGACY=true BACNET_PORT=win32 clean gateway piface: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 3195fc51..f9745f75 100644 --- a/Makefile +++ b/Makefile @@ -11,22 +11,16 @@ all: apps .PHONY: bsd bsd: - $(MAKE) BACNET_PORT=bsd -s -C apps all + $(MAKE) LEGACY=true BACNET_PORT=bsd -s -C apps all .PHONY: win32 win32: - $(MAKE) BACNET_PORT=win32 -s -C apps all + $(MAKE) LEGACY=true BACNET_PORT=win32 -s -C apps all .PHONY: mingw32 mingw32: i686-w64-mingw32-gcc --version - ORIGINAL_CC=$(CC) ; \ - ORIGINAL_LD=$(LD) ; \ - export CC=i686-w64-mingw32-gcc ; \ - export LD=i686-w64-mingw32-ld ; \ - $(MAKE) BACNET_PORT=win32 LEGACY=true -s -C apps all ; \ - export CC=$(ORIGINAL_CC) ; \ - export LD=$(ORIGINAL_LD) + $(MAKE) PREFIX=i686-w64-mingw32- BACNET_PORT=win32 LEGACY=true BACDL=bip6 -s -C apps all .PHONY: mstpwin32-clean mstpwin32-clean: @@ -40,25 +34,25 @@ mstpwin32: mstp: $(MAKE) BACDL=mstp -s -C apps all -.PHONY: bip6-win32 -bip6-win32: - $(MAKE) BACDL=bip6 BACNET_PORT=win32 -s -C apps all +.PHONY: mingw32-bip6 +mingw32-bip6: + $(MAKE) PREFIX=i686-w64-mingw32- BACNET_PORT=win32 LEGACY=true BACDL=bip6 -s -C apps all .PHONY: bip6 bip6: - $(MAKE) BACDL=bip6 -s -C apps all + $(MAKE) LEGACY=true BACDL=bip6 -s -C apps all .PHONY: bip bip: - $(MAKE) BACDL=bip -s -C apps all + $(MAKE) LEGACY=true BACDL=bip -s -C apps all .PHONY: bip-client bip-client: - $(MAKE) BACDL=bip BBMD=client -s -C apps all + $(MAKE) LEGACY=true BACDL=bip BBMD=client -s -C apps all .PHONY: ethernet ethernet: - $(MAKE) BACDL=ethernet -s -C apps all + $(MAKE) LEGACY=true BACDL=ethernet -s -C apps all # note: requires additional libraries to be installed # see .github/workflows/gcc.yml diff --git a/apps/Makefile b/apps/Makefile index 81689739..af85bfa0 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,11 +1,15 @@ -# tools - only if you need them. -# Most platforms have this already defined -# CC = gcc -# AR = ar -# MAKE = make -# SIZE = size # -# Assumes rm and cp are available +# Set PREFIX to prepend to GCC compiler tools for cross-compilation. +# Assumes rm and cp are natively available +# +PREFIX ?= +CC = $(PREFIX)gcc +AR = $(PREFIX)ar +RANLIB = $(PREFIX)ranlib +NM = $(PREFIX)nm +SIZE = $(PREFIX)size +OBJCOPY = $(PREFIX)objcopy +OBJDUMP = $(PREFIX)objdump # Passing parameters via command line or from Makefile export to this one BACNET_DEFINES ?= @@ -20,6 +24,9 @@ BACNET_LIB ?= -L$(BACNET_LIB_DIR) -l$(BACNET_LIB_NAME) # Use BACDL=mstp or BACDL=bip and BBMD=server when invoking make ifeq (${BACDL_DEFINE},) +ifeq (${BACDL},) +BACDL = bip +endif ifeq (${BACDL},ethernet) BACDL_DEFINE=-DBACDL_ETHERNET=1 endif @@ -39,6 +46,9 @@ ifeq (${BACDL},bsc) BACDL_DEFINE=-DBACDL_BSC=1 BACNET_DEFINE=-DBACFILE=1 endif +ifeq (${BACDL},zigbee) +BACDL_DEFINE=-DBACDL_ZIGBEE=1 +endif ifeq (${BACDL},none) BACDL_DEFINE=-DBACDL_NONE=1 endif @@ -51,11 +61,11 @@ endif ifeq (${BACDL},all) BACDL_DEFINE=-DBACDL_ALL=1 endif -ifeq (${BACDL},) -BACDL_DEFINE ?= -DBACDL_BIP=1 -BBMD_DEFINE ?= -DBBMD_ENABLED=1 -DBBMD_CLIENT_ENABLED -endif +ifneq (,$(filter $(BACDL),bip all)) +ifeq (${BBMD},) +BBMD=full +endif ifeq (${BBMD},none) BBMD_DEFINE = -DBBMD_ENABLED=0 endif @@ -68,7 +78,25 @@ endif ifeq (${BBMD},full) BBMD_DEFINE = -DBBMD_ENABLED=1 -DBBMD_CLIENT_ENABLED endif +endif +ifneq (,$(filter $(BACDL),bip6 all)) +ifeq (${BBMD6},) +BBMD6=client +endif +ifeq (${BBMD6},none) +BBMD_DEFINE = -DBBMD6_ENABLED=0 +endif +ifeq (${BBMD6},server) +BBMD_DEFINE = -DBBMD6_ENABLED=1 +endif +ifeq (${BBMD6},client) +BBMD_DEFINE = -DBBMD6_ENABLED=0 -DBBMD6_CLIENT_ENABLED +endif +ifeq (${BBMD6},full) +BBMD_DEFINE = -DBBMD6_ENABLED=1 -DBBMD6_CLIENT_ENABLED +endif +endif endif # Define WEAK_FUNC for unsupported or specific compilers @@ -175,7 +203,7 @@ WARNINGS ?= $(WARNING_ALL) ifeq (${BUILD},debug) OPTIMIZATION = -O0 DEBUGGING = -g -DDEBUG_ENABLED=1 -ifeq (${BACDL_DEFINE},-DBACDL_BIP=1) +ifeq (${BACDL},bip) BACNET_DEFINES += -DBIP_DEBUG endif endif @@ -226,16 +254,16 @@ SUBDIRS = lib readprop writeprop readfile writefile reinit server dcc \ who-am-i you-are apdu writegroup \ delete-object server-discover server-basic server-mini -ifeq (${BACDL_DEFINE},-DBACDL_BIP=1) - SUBDIRS += whoisrouter iamrouter initrouter whatisnetnum netnumis - ifneq (${BBMD},none) - SUBDIRS += readbdt readfdt writebdt - endif +ifneq (,$(filter $(BACDL),bip all)) +SUBDIRS += whoisrouter iamrouter initrouter whatisnetnum netnumis +ifneq (${BBMD},none) +SUBDIRS += readbdt readfdt writebdt +endif endif ifeq (${BACNET_PORT},linux) ifneq (${OSTYPE},cygwin) - SUBDIRS += mstpcap mstpcrc +SUBDIRS += mstpcap mstpcrc endif endif @@ -274,6 +302,7 @@ TARGETS = all clean $(TARGETS): %: $(patsubst %, %.%, $(SUBDIRS)) $(foreach TGT, $(TARGETS), $(patsubst %, %.$(TGT), $(SUBDIRS))): + $(info recipe: $@...) $(MAKE) -C $(subst ., , $@) .PHONY: lib @@ -283,7 +312,7 @@ $(BACNET_LIB_TARGET): $(MAKE) -B -C lib clean: - $(MAKE) -C lib clean + $(MAKE) BACDL=all -C lib clean .PHONY: gateway gateway: $(BACNET_LIB_TARGET) diff --git a/apps/lib/Makefile b/apps/lib/Makefile index 1f4a5ce8..e96eda99 100644 --- a/apps/lib/Makefile +++ b/apps/lib/Makefile @@ -95,37 +95,38 @@ PORT_ALL_SRC = \ PORT_NONE_SRC = \ $(BACNET_SRC_DIR)/bacnet/datalink/datalink.c -ifeq (${BACDL_DEFINE},-DBACDL_BIP=1) +$(info $(BACNET_LIB_TARGET) datalink $(BACDL)) +ifeq ($(BACDL),bip) BACNET_PORT_SRC = ${PORT_BIP_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_BIP6=1) +ifeq ($(BACDL),bip6) BACNET_PORT_SRC = ${PORT_BIP6_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_MSTP=1) -BACNET_PORT_SRC = ${PORT_MSTP_SRC} ${APPS_ENVIRONMENT_SRC} +ifeq ($(BACDL),mstp) +BACNET_PORT_SRC = ${PORT_MSTP_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_ARCNET=1) +ifeq ($(BACDL),arcnet) BACNET_PORT_SRC = ${PORT_ARCNET_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_ETHERNET=1) +ifeq ($(BACDL),ethernet) BACNET_PORT_SRC = ${PORT_ETHERNET_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_ZIGBEE=1) +ifeq ($(BACDL),zigbee) BACNET_PORT_SRC = ${PORT_ZIGBEE_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_NONE=1) +ifeq ($(BACDL),none) BACNET_PORT_SRC = ${PORT_NONE_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_BSC=1) +ifeq ($(BACDL),bsc) BACNET_PORT_SRC = ${PORT_BSC_SRC} ${APPS_ENVIRONMENT_SRC} endif -ifeq (${BACDL_DEFINE},-DBACDL_ALL=1) +ifeq ($(BACDL),all) BACNET_PORT_SRC = ${PORT_ALL_SRC} endif -ifeq (${BACDL},bip-mstp) +ifeq ($(BACDL),bip-mstp) BACNET_PORT_SRC = ${PORT_BIP_SRC} ${PORT_MSTP_SRC} endif -ifeq (${BACDL},bip-bip6) +ifeq ($(BACDL),bip-bip6) BACNET_PORT_SRC = ${PORT_BIP_SRC} ${PORT_BIP6_SRC} endif ifneq (${BACDL_DEFINE},) @@ -170,6 +171,7 @@ all: $(BACNET_LIB_TARGET) lib: $(BACNET_LIB_TARGET) $(BACNET_LIB_TARGET): $(OBJS) Makefile + $(info $(BACNET_LIB_TARGET) SRCS: $(notdir $(SRCS))) ${AR} rcs $@ $(OBJS) .c.o: diff --git a/apps/readpropm/Makefile b/apps/readpropm/Makefile index bc8413d4..a6184ff0 100644 --- a/apps/readpropm/Makefile +++ b/apps/readpropm/Makefile @@ -17,7 +17,7 @@ all: ${BACNET_LIB_TARGET} Makefile ${TARGET_BIN} ${TARGET_BIN}: ${OBJS} Makefile ${BACNET_LIB_TARGET} ${CC} ${PFLAGS} ${OBJS} ${LFLAGS} -o $@ - size $@ + ${SIZE} $@ cp $@ ../../bin ${BACNET_LIB_TARGET}: diff --git a/build.bat b/build.bat index a2703f9a..a3c2ca8e 100644 --- a/build.bat +++ b/build.bat @@ -5,7 +5,6 @@ rem assumes rm, cp, size are already in path set CC=mingw32-gcc.exe set AR=mingw32-gcc-ar.exe set NM=mingw32-gcc-nm.exe -set NM=mingw32-gcc-nm.exe set OBJCOPY=objcopy.exe set SIZE=size.exe set MAKE=mingw32-make.exe diff --git a/ports/win32/arcnet.c b/ports/win32/arcnet.c new file mode 100644 index 00000000..2457aed7 --- /dev/null +++ b/ports/win32/arcnet.c @@ -0,0 +1,129 @@ +/** + * @file + * @brief Provides port specific functions for ARCNET + * @author Steve Karg + * @date October 2025 + * @copyright SPDX-License-Identifier: MIT + */ +#include +#include "bacnet/bacdef.h" +#include "bacnet/npdu.h" +#include "bacnet/datalink/arcnet.h" + +/* my local device data - MAC address */ +uint8_t ARCNET_MAC_Address = 0; +/* ARCNET file handle */ +static int ARCNET_Sock_FD = -1; +/* Broadcast address */ +#define ARCNET_BROADCAST 0 + +/* +Hints: + +When using a PCI20-485D ARCNET card from Contemporary Controls, +you might need to know about the following settings: + +Assuming a 20MHz clock on the COM20020 chip: + +clockp Clock Prescaler DataRate +------ --------------- -------- +0 8 2.5 Mbps +1 16 1.25 Mbps +2 32 625 Kbps +3 64 312.5 Kbps +4 128 156.25Kbps + +1. Install the arcnet driver and arcnet raw mode driver +2. The hardware address (MAC address) is set using the dipswitch + on the back of the card. 0 is broadcast, so don't use 0. +3. The backplane mode on the PCI20-485D card is done in hardware, + so the driver does not need to do backplane mode. If you + use another type of PCI20 card, you could pass in backplane=1 or + backplane=0 as an option to the modprobe of com20020_pci. +*/ + +bool arcnet_valid(void) +{ + return (ARCNET_Sock_FD >= 0); +} + +void arcnet_cleanup(void) +{ + if (arcnet_valid()) { + /* close the interface */ + } + ARCNET_Sock_FD = -1; + + return; +} + +bool arcnet_init(char *interface_name) +{ + (void)interface_name; + return arcnet_valid(); +} + +/* function to send a PDU out the socket */ +/* returns number of bytes sent on success, negative on failure */ +int arcnet_send_pdu( + BACNET_ADDRESS *dest, /* destination address */ + BACNET_NPDU_DATA *npdu_data, /* network information */ + uint8_t *pdu, /* any data to be sent - may be null */ + unsigned pdu_len) +{ + int bytes = 0; + + (void)dest; + (void)npdu_data; + (void)pdu; + (void)pdu_len; + + return bytes; +} + +/* receives an framed packet */ +/* returns the number of octets in the PDU, or zero on failure */ +uint16_t arcnet_receive( + BACNET_ADDRESS *src, /* source address */ + uint8_t *pdu, /* PDU data */ + uint16_t pdu_size, /* amount of space available in the PDU */ + unsigned timeout) +{ + (void)src; + (void)pdu; + (void)timeout; + (void)pdu_size; + return 0; +} + +void arcnet_get_my_address(BACNET_ADDRESS *my_address) +{ + int i = 0; + + my_address->mac_len = 1; + my_address->mac[0] = ARCNET_MAC_Address; + my_address->net = 0; /* DNET=0 is local only, no routing */ + my_address->len = 0; + for (i = 0; i < MAX_MAC_LEN; i++) { + my_address->adr[i] = 0; + } + + return; +} + +void arcnet_get_broadcast_address(BACNET_ADDRESS *dest) +{ /* destination address */ + int i = 0; /* counter */ + + if (dest) { + dest->mac[0] = ARCNET_BROADCAST; + dest->mac_len = 1; + dest->net = BACNET_BROADCAST_NETWORK; + dest->len = 0; /* always zero when DNET is broadcast */ + for (i = 0; i < MAX_MAC_LEN; i++) { + dest->adr[i] = 0; + } + } + + return; +} diff --git a/src/Makefile b/src/Makefile index 08c8b35b..99b48911 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ # # Assumes rm and cp are available -CFLAGS += -Dbacnet_stack_EXPORTS +CFLAGS += -DBACNET_STACK_EXPORTS ifeq ($(STATIC),1) CFLAGS += -DBACNET_STACK_STATIC_DEFINE diff --git a/src/bacnet/basic/bbmd6/h_bbmd6.c b/src/bacnet/basic/bbmd6/h_bbmd6.c index 49903814..f4226c46 100644 --- a/src/bacnet/basic/bbmd6/h_bbmd6.c +++ b/src/bacnet/basic/bbmd6/h_bbmd6.c @@ -364,7 +364,7 @@ static void bbmd6_send_pdu_bdt(uint8_t *mtu, unsigned int mtu_len) if (mtu) { bip6_get_addr(&my_addr); - for (i = 0; i < MAX_BBMD_ENTRIES; i++) { + for (i = 0; i < MAX_BBMD6_ENTRIES; i++) { if (BBMD_Table[i].valid) { if (bvlc6_address_different( &my_addr, &BBMD_Table[i].bip6_address)) { @@ -391,7 +391,7 @@ static void bbmd6_send_pdu_fdt(uint8_t *mtu, unsigned int mtu_len) if (mtu) { bip6_get_addr(&my_addr); - for (i = 0; i < MAX_FD_ENTRIES; i++) { + for (i = 0; i < MAX_FD6_ENTRIES; i++) { if (FD_Table[i].valid) { if (bvlc6_address_different( &my_addr, &FD_Table[i].bip6_address)) { @@ -401,46 +401,6 @@ static void bbmd6_send_pdu_fdt(uint8_t *mtu, unsigned int mtu_len) } } } - -/** - * The Forward NPDU send function for Broadcast Distribution Table - * - * @param addr - Points to a #BACNET_IP6_ADDRESS structure containing the - * source IPv6 address. - * @param vmac_src - Source-Virtual-Address - * @param npdu - the bytes of NPDU+APDU data to send - * @param npdu_len - the number of bytes of NPDU+APDU data to send - */ -static void bbmd6_send_forward_npdu( - BACNET_IP6_ADDRESS *address, - uint32_t vmac_src, - uint8_t *npdu, - unsigned int npdu_len) -{ - uint8_t mtu[BIP6_MPDU_MAX] = { 0 }; - uint16_t mtu_len = 0; - unsigned i = 0; /* loop counter */ - - for (i = 0; i < MAX_BBMD_ENTRIES; i++) { - if (BBMD_Table[i].valid) { - if (bbmd6_address_match_self(&BBMD_Table[i].bip6_address)) { - /* don't forward to our selves */ - } else { - bip6_send_mpdu(&BBMD_Table[i].bip6_address, mtu, mtu_len); - } - } - } - for (i = 0; i < MAX_FD_ENTRIES; i++) { - if (FD_Table[i].valid) { - if (bbmd6_address_match_self(&FD_Table[i].bip6_address)) { - /* don't forward to our selves */ - } else { - bip6_send_mpdu(&FD_Table[i].bip6_address, mtu, mtu_len); - } - } - } -} - #endif /** @@ -840,10 +800,8 @@ int bvlc6_bbmd_enabled_handler( uint16_t mtu_len) { uint16_t result_code = BVLC6_RESULT_SUCCESSFUL_COMPLETION; - uint32_t vmac_me = 0; uint32_t vmac_src = 0; uint32_t vmac_dst = 0; - uint32_t vmac_target = 0; uint8_t message_type = 0; uint16_t message_length = 0; int header_len = 0; diff --git a/src/bacnet/datalink/datalink.h b/src/bacnet/datalink/datalink.h index 83a0e1c0..1c5c5e4f 100644 --- a/src/bacnet/datalink/datalink.h +++ b/src/bacnet/datalink/datalink.h @@ -93,7 +93,7 @@ void routed_get_my_address(BACNET_ADDRESS *my_address); #else #define datalink_get_my_address bip_get_my_address #endif -#define datalink_maintenance_timer(s) bvlc_maintenance_timer(s) +#define datalink_maintenance_timer bvlc_maintenance_timer #elif defined(BACDL_BIP6) && !defined(BACDL_MULTIPLE) #define MAX_MPDU BIP6_MPDU_MAX @@ -104,7 +104,7 @@ void routed_get_my_address(BACNET_ADDRESS *my_address); #define datalink_cleanup bip6_cleanup #define datalink_get_broadcast_address bip6_get_broadcast_address #define datalink_get_my_address bip6_get_my_address -#define datalink_maintenance_timer(s) bvlc6_maintenance_timer(s) +#define datalink_maintenance_timer bvlc6_maintenance_timer #elif defined(BACDL_ZIGBEE) && !defined(BACDL_MULTIPLE) /* A BACnet/ZigBee Data Link Layer (BZLL) */