diff --git a/bacnet-stack/Makefile b/bacnet-stack/Makefile index 649b45a3..913a3335 100644 --- a/bacnet-stack/Makefile +++ b/bacnet-stack/Makefile @@ -7,9 +7,9 @@ BASEDIR = . # Note: you can strip out symbols using the strip command # to get an idea of how big the compile really is. #CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_ETHERNET=1 -CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_ARCNET=1 +#CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_ARCNET=1 #CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_MSTP=1 -#CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_BIP=1 +CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_BIP=1 SRCS = ports/linux/main.c \ ports/linux/ethernet.c \ diff --git a/bacnet-stack/bacfile.c b/bacnet-stack/bacfile.c index 5779a414..457e9a13 100644 --- a/bacnet-stack/bacfile.c +++ b/bacnet-stack/bacfile.c @@ -47,7 +47,7 @@ typedef struct static BACNET_FILE_LISTING BACnet_File_Listing[] = { - {0, "temp.txt"}, + {0, "test.log"}, {1, "script.txt"}, {0, NULL} // last file indication }; diff --git a/bacnet-stack/bip.h b/bacnet-stack/bip.h index 0b2eb02d..6a59701a 100644 --- a/bacnet-stack/bip.h +++ b/bacnet-stack/bip.h @@ -94,7 +94,7 @@ void bip_set_broadcast_addr(uint32_t net_address); // returns host byte order uint32_t bip_get_broadcast_addr(void); -void bip_set_interface_name(char *ifname); +void bip_set_interface(char *ifname); #ifdef __cplusplus } diff --git a/bacnet-stack/config.h b/bacnet-stack/config.h index 185b0a09..68ab95fd 100644 --- a/bacnet-stack/config.h +++ b/bacnet-stack/config.h @@ -11,8 +11,8 @@ // This is used in constructing messages and to tell others our limits // 50 is the minimum; adjust to your memory and physical layer constraints // Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 -#define MAX_APDU 50 -//#define MAX_APDU 480 +//#define MAX_APDU 50 +#define MAX_APDU 480 //#define MAX_APDU 1476 // for confirmed messages, this is the number of transactions diff --git a/bacnet-stack/datalink.c b/bacnet-stack/datalink.c index 910849be..77df8ba1 100644 --- a/bacnet-stack/datalink.c +++ b/bacnet-stack/datalink.c @@ -109,6 +109,22 @@ uint16_t datalink_receive( #endif } +void datalink_cleanup(void) +{ +#ifdef BACDL_ETHERNET + ethernet_cleanup(); +#endif +#ifdef BACDL_BIP + bip_cleanup(); +#endif +#ifdef BACDL_ARCNET + arcnet_cleanup(); +#endif +#ifdef BACDL_MSTP + dlmstp_cleanup(); +#endif +} + void datalink_get_broadcast_address( BACNET_ADDRESS *dest) // destination address { diff --git a/bacnet-stack/datalink.h b/bacnet-stack/datalink.h index 6d457c08..6c2e89ad 100644 --- a/bacnet-stack/datalink.h +++ b/bacnet-stack/datalink.h @@ -72,6 +72,8 @@ uint16_t datalink_receive( uint16_t max_pdu, // amount of space available in the PDU unsigned timeout); // number of milliseconds to wait for a packet +void datalink_cleanup(void); + void datalink_get_broadcast_address( BACNET_ADDRESS *dest); // destination address diff --git a/bacnet-stack/ports/linux/bip-init.c b/bacnet-stack/ports/linux/bip-init.c index 5d8ac0b2..1237467f 100644 --- a/bacnet-stack/ports/linux/bip-init.c +++ b/bacnet-stack/ports/linux/bip-init.c @@ -38,6 +38,54 @@ #include "bip.h" #include "net.h" +static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr, int request) +{ + int fd; + int rv; // return value + + strncpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name)); + fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); + if (fd < 0) + rv = fd; + else + rv = ioctl(fd, request, ifr); + + return rv; +} + +static int get_local_address_ioctl( + char *ifname, + struct in_addr *addr, + int request) +{ + struct ifreq ifr = { {{0}} }; + struct sockaddr_in *tcpip_address; + int rv; // return value + + rv = get_local_ifr_ioctl(ifname,&ifr,request); + if (rv >= 0) { + tcpip_address = (struct sockaddr_in *) &ifr.ifr_addr; + memcpy(addr, &tcpip_address->sin_addr, sizeof(struct in_addr)); + } + + return rv; +} + +void bip_set_interface(char *ifname) +{ + struct in_addr local_address; + struct in_addr broadcast_address; + + /* setup local address */ + get_local_address_ioctl(ifname, &local_address, SIOCGIFADDR); + bip_set_addr(local_address.s_addr); + fprintf(stderr,"IP Address: %s\n",inet_ntoa(local_address)); + /* setup local broadcast address */ + get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR); + bip_set_broadcast_addr(broadcast_address.s_addr); + fprintf(stderr,"Broadcast Address: %s\n",inet_ntoa(broadcast_address)); +} + bool bip_init(void) { int status = 0; // return from socket lib calls diff --git a/bacnet-stack/ports/linux/main.c b/bacnet-stack/ports/linux/main.c index 71c4afb2..a6141e3b 100644 --- a/bacnet-stack/ports/linux/main.c +++ b/bacnet-stack/ports/linux/main.c @@ -204,13 +204,7 @@ static void print_address_cache(void) static void sig_handler(int signo) { - #ifdef BACDL_ETHERNET - ethernet_cleanup(); - #endif - #ifdef BACDL_BIP - bip_cleanup(); - #endif - + datalink_cleanup(); print_address_cache(); exit(0); @@ -244,6 +238,10 @@ int main(int argc, char *argv[]) if (!bip_init()) return 1; #endif + #ifdef BACDL_ARCNET + if (!arcnet_init("arc0")) + return 1; + #endif // loop forever for (;;)