diff --git a/bacnet-stack/ports/linux/ethernet.c b/bacnet-stack/ports/linux/ethernet.c index d803ca62..6c0c4732 100644 --- a/bacnet-stack/ports/linux/ethernet.c +++ b/bacnet-stack/ports/linux/ethernet.c @@ -1,23 +1,58 @@ +/*####COPYRIGHTBEGIN#### + ------------------------------------------- + Copyright (C) 2005 Steve Karg + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + The Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA. + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile + this file and link it with other works to produce a work based + on this file, this file does not by itself cause the resulting + work to be covered by the GNU General Public License. However + the source code for this file must still be made available in + accordance with section (3) of the GNU General Public License. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + ------------------------------------------- +####COPYRIGHTEND####*/ + #include /* Standard I/O */ #include /* Standard Library */ #include /* Error number and related */ -#include /* System time values */ -#include /* System data types */ -#include /* File statistics */ -#include /* Command-line options */ -#include /* FD-based file-control */ -#include /* string hanfling functions */ -#include /* signal handling functions */ -#include /* time functions */ -#include #include // for standard integer types uint8_t etc. #include // for the standard bool type. +//#include /* System time values */ +//#include /* System data types */ +//#include /* File statistics */ +//#include /* Command-line options */ +//#include /* FD-based file-control */ +//#include /* string hanfling functions */ +//#include /* signal handling functions */ +//#include /* time functions */ +//#include #define ENUMS #include -#include -#include -#include /* for the glibc version number */ +//#include +//#include +//#include /* for the glibc version number */ + #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1 #include #include /* the L2 protocols */ @@ -26,13 +61,15 @@ #include #include /* The L2 protocols */ #endif -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include #include "bacdef.h" +#include "ethernet.h" +#include "bacdcode.h" // commonly used comparison address for ethernet uint8_t Ethernet_Broadcast[MAX_MAC_LEN] = @@ -50,18 +87,13 @@ bool ethernet_valid(void) return (eth802_sockfd >= 0); } -static int ethernet_socket(void) -{ - return eth802_sockfd; -} - bool ethernet_cleanup(void) { - if (ethernet_valid()) - close(eth802_sockfd); - eth802_sockfd = -1; + if (ethernet_valid()) + close(eth802_sockfd); + eth802_sockfd = -1; - return true; + return true; } /* opens an 802.2 socket to receive and send packets */ @@ -132,9 +164,6 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac) bool ethernet_init(char *interface_name) { get_local_hwaddr(interface_name, Ethernet_MAC_Address); - debug_printf(2, "ethernet: Local MAC=%s\n", - hwaddrtoa(Ethernet_MAC_Address)); - eth802_sockfd = ethernet_bind(ð_addr, interface_name); @@ -153,7 +182,6 @@ int ethernet_send( int bytes = 0; uint8_t mtu[MAX_MPDU] = { 0 }; int mtu_len = 0; - int packet_len = 0; int i = 0; // don't waste time if the socket is not valid @@ -207,7 +235,7 @@ int ethernet_send( } /* packet length */ mtu_len += encode_unsigned16(&mtu[12], - 3 /*DSAP,SSAP,LLC*/ + pdu_len) + 3 /*DSAP,SSAP,LLC*/ + pdu_len); // Logical PDU portion mtu[mtu_len++] = 0x82; /* DSAP for BACnet */ mtu[mtu_len++] = 0x82; /* SSAP for BACnet */ @@ -221,8 +249,9 @@ int ethernet_send( (struct sockaddr *) ð_addr, sizeof(struct sockaddr)); /* did it get sent? */ if (bytes < 0) { - fprintf("ethernet: Error sending packet: %s\n", strerror(errno)); - return status; + fprintf(stderr,"ethernet: Error sending packet: %s\n", + strerror(errno)); + return status; } // got this far - must be good! @@ -244,11 +273,11 @@ int ethernet_send_pdu( for (i = 0; i < 6; i++) { src.mac[i] = Ethernet_MAC_Address[i]; - src->mac_len++; + src.mac_len++; } /* function to send a packet out the 802.2 socket */ /* returns 1 on success, 0 on failure */ - return ethernet_send_pdu(dest, // destination address + return ethernet_send(dest, // destination address &src, // source address pdu, // any data to be sent - may be null pdu_len); // number of bytes of data @@ -264,7 +293,6 @@ uint16_t ethernet_receive( int received_bytes; uint8_t buf[MAX_MPDU] = {0}; // data uint16_t pdu_len = 0; // return value - unsigned i = 0; // counter /* Make sure the socket is open */ if (eth802_sockfd <= 0) @@ -300,7 +328,7 @@ uint16_t ethernet_receive( return 0; } - (void)decode_unsigned16(&buf[12],&pdu_len) + (void)decode_unsigned16(&buf[12],&pdu_len); pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ; // copy the buffer into the PDU if (pdu_len < max_pdu) @@ -311,6 +339,8 @@ uint16_t ethernet_receive( void ethernet_get_my_address(BACNET_ADDRESS *my_address) { + int i = 0; + my_address->mac_len = 0; my_address->net = 0; // local only, no routing for (i = 0; i < 6; i++) diff --git a/bacnet-stack/ports/linux/main.c b/bacnet-stack/ports/linux/main.c index e54d79f2..f56189d8 100644 --- a/bacnet-stack/ports/linux/main.c +++ b/bacnet-stack/ports/linux/main.c @@ -57,7 +57,7 @@ void Process_APDU( BACNET_ADDRESS *src, // source address uint8_t *apdu, // APDU data uint16_t pdu_len, // length of the PDU - uint8_t invoke_id); // for confirmed messages + uint8_t invoke_id) // for confirmed messages { } @@ -68,6 +68,7 @@ void Process_PDU( uint16_t pdu_len) // length PDU { uint8_t invoke_id = 0; + int apdu_offset = 0; apdu_offset = npdu_decode( &src, // source address - get the SADR/SNET if in there @@ -86,7 +87,6 @@ void Process_PDU( void Send_IAm(void) { int pdu_len = 0; - uint8_t invoke_id = 0; BACNET_ADDRESS dest; BACNET_ADDRESS src; @@ -101,8 +101,7 @@ void Send_IAm(void) &dest, &src, false, // true for confirmed messages - MESSAGE_PRIORITY_NORMAL, - invoke_id); + MESSAGE_PRIORITY_NORMAL); // encode the APDU portion of the packet pdu_len += iam_encode_apdu(