getting the test system working.
This commit is contained in:
@@ -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 <stdio.h> /* Standard I/O */
|
#include <stdio.h> /* Standard I/O */
|
||||||
#include <stdlib.h> /* Standard Library */
|
#include <stdlib.h> /* Standard Library */
|
||||||
#include <errno.h> /* Error number and related */
|
#include <errno.h> /* Error number and related */
|
||||||
#include <sys/time.h> /* System time values */
|
|
||||||
#include <sys/types.h> /* System data types */
|
|
||||||
#include <sys/stat.h> /* File statistics */
|
|
||||||
#include <unistd.h> /* Command-line options */
|
|
||||||
#include <fcntl.h> /* FD-based file-control */
|
|
||||||
#include <string.h> /* string hanfling functions */
|
|
||||||
#include <signal.h> /* signal handling functions */
|
|
||||||
#include <time.h> /* time functions */
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdint.h> // for standard integer types uint8_t etc.
|
#include <stdint.h> // for standard integer types uint8_t etc.
|
||||||
#include <stdbool.h> // for the standard bool type.
|
#include <stdbool.h> // for the standard bool type.
|
||||||
|
//#include <sys/time.h> /* System time values */
|
||||||
|
//#include <sys/types.h> /* System data types */
|
||||||
|
//#include <sys/stat.h> /* File statistics */
|
||||||
|
//#include <unistd.h> /* Command-line options */
|
||||||
|
//#include <fcntl.h> /* FD-based file-control */
|
||||||
|
//#include <string.h> /* string hanfling functions */
|
||||||
|
//#include <signal.h> /* signal handling functions */
|
||||||
|
//#include <time.h> /* time functions */
|
||||||
|
//#include <stdarg.h>
|
||||||
|
|
||||||
#define ENUMS
|
#define ENUMS
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <net/route.h>
|
//#include <net/route.h>
|
||||||
#include <net/if.h>
|
//#include <net/if.h>
|
||||||
#include <features.h> /* for the glibc version number */
|
//#include <features.h> /* for the glibc version number */
|
||||||
|
|
||||||
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
|
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
|
||||||
#include <netpacket/packet.h>
|
#include <netpacket/packet.h>
|
||||||
#include <net/ethernet.h> /* the L2 protocols */
|
#include <net/ethernet.h> /* the L2 protocols */
|
||||||
@@ -26,13 +61,15 @@
|
|||||||
#include <linux/if_packet.h>
|
#include <linux/if_packet.h>
|
||||||
#include <linux/if_ether.h> /* The L2 protocols */
|
#include <linux/if_ether.h> /* The L2 protocols */
|
||||||
#endif
|
#endif
|
||||||
#include <netinet/in.h>
|
//#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
//#include <arpa/inet.h>
|
||||||
#include <sys/un.h>
|
//#include <sys/un.h>
|
||||||
#include <sys/ioctl.h>
|
//#include <sys/ioctl.h>
|
||||||
#include <netdb.h>
|
//#include <netdb.h>
|
||||||
|
|
||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
|
#include "ethernet.h"
|
||||||
|
#include "bacdcode.h"
|
||||||
|
|
||||||
// commonly used comparison address for ethernet
|
// commonly used comparison address for ethernet
|
||||||
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
||||||
@@ -50,18 +87,13 @@ bool ethernet_valid(void)
|
|||||||
return (eth802_sockfd >= 0);
|
return (eth802_sockfd >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ethernet_socket(void)
|
|
||||||
{
|
|
||||||
return eth802_sockfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ethernet_cleanup(void)
|
bool ethernet_cleanup(void)
|
||||||
{
|
{
|
||||||
if (ethernet_valid())
|
if (ethernet_valid())
|
||||||
close(eth802_sockfd);
|
close(eth802_sockfd);
|
||||||
eth802_sockfd = -1;
|
eth802_sockfd = -1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* opens an 802.2 socket to receive and send packets */
|
/* 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)
|
bool ethernet_init(char *interface_name)
|
||||||
{
|
{
|
||||||
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
||||||
debug_printf(2, "ethernet: Local MAC=%s\n",
|
|
||||||
hwaddrtoa(Ethernet_MAC_Address));
|
|
||||||
|
|
||||||
eth802_sockfd =
|
eth802_sockfd =
|
||||||
ethernet_bind(ð_addr, interface_name);
|
ethernet_bind(ð_addr, interface_name);
|
||||||
|
|
||||||
@@ -153,7 +182,6 @@ int ethernet_send(
|
|||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||||
int mtu_len = 0;
|
int mtu_len = 0;
|
||||||
int packet_len = 0;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// don't waste time if the socket is not valid
|
// don't waste time if the socket is not valid
|
||||||
@@ -207,7 +235,7 @@ int ethernet_send(
|
|||||||
}
|
}
|
||||||
/* packet length */
|
/* packet length */
|
||||||
mtu_len += encode_unsigned16(&mtu[12],
|
mtu_len += encode_unsigned16(&mtu[12],
|
||||||
3 /*DSAP,SSAP,LLC*/ + pdu_len)
|
3 /*DSAP,SSAP,LLC*/ + pdu_len);
|
||||||
// Logical PDU portion
|
// Logical PDU portion
|
||||||
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
|
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
|
||||||
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
|
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
|
||||||
@@ -221,8 +249,9 @@ int ethernet_send(
|
|||||||
(struct sockaddr *) ð_addr, sizeof(struct sockaddr));
|
(struct sockaddr *) ð_addr, sizeof(struct sockaddr));
|
||||||
/* did it get sent? */
|
/* did it get sent? */
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
fprintf("ethernet: Error sending packet: %s\n", strerror(errno));
|
fprintf(stderr,"ethernet: Error sending packet: %s\n",
|
||||||
return status;
|
strerror(errno));
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// got this far - must be good!
|
// got this far - must be good!
|
||||||
@@ -244,11 +273,11 @@ int ethernet_send_pdu(
|
|||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
src.mac[i] = Ethernet_MAC_Address[i];
|
src.mac[i] = Ethernet_MAC_Address[i];
|
||||||
src->mac_len++;
|
src.mac_len++;
|
||||||
}
|
}
|
||||||
/* function to send a packet out the 802.2 socket */
|
/* function to send a packet out the 802.2 socket */
|
||||||
/* returns 1 on success, 0 on failure */
|
/* returns 1 on success, 0 on failure */
|
||||||
return ethernet_send_pdu(dest, // destination address
|
return ethernet_send(dest, // destination address
|
||||||
&src, // source address
|
&src, // source address
|
||||||
pdu, // any data to be sent - may be null
|
pdu, // any data to be sent - may be null
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
@@ -264,7 +293,6 @@ uint16_t ethernet_receive(
|
|||||||
int received_bytes;
|
int received_bytes;
|
||||||
uint8_t buf[MAX_MPDU] = {0}; // data
|
uint8_t buf[MAX_MPDU] = {0}; // data
|
||||||
uint16_t pdu_len = 0; // return value
|
uint16_t pdu_len = 0; // return value
|
||||||
unsigned i = 0; // counter
|
|
||||||
|
|
||||||
/* Make sure the socket is open */
|
/* Make sure the socket is open */
|
||||||
if (eth802_sockfd <= 0)
|
if (eth802_sockfd <= 0)
|
||||||
@@ -300,7 +328,7 @@ uint16_t ethernet_receive(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)decode_unsigned16(&buf[12],&pdu_len)
|
(void)decode_unsigned16(&buf[12],&pdu_len);
|
||||||
pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ;
|
pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ;
|
||||||
// copy the buffer into the PDU
|
// copy the buffer into the PDU
|
||||||
if (pdu_len < max_pdu)
|
if (pdu_len < max_pdu)
|
||||||
@@ -311,6 +339,8 @@ uint16_t ethernet_receive(
|
|||||||
|
|
||||||
void ethernet_get_my_address(BACNET_ADDRESS *my_address)
|
void ethernet_get_my_address(BACNET_ADDRESS *my_address)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
my_address->mac_len = 0;
|
my_address->mac_len = 0;
|
||||||
my_address->net = 0; // local only, no routing
|
my_address->net = 0; // local only, no routing
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void Process_APDU(
|
|||||||
BACNET_ADDRESS *src, // source address
|
BACNET_ADDRESS *src, // source address
|
||||||
uint8_t *apdu, // APDU data
|
uint8_t *apdu, // APDU data
|
||||||
uint16_t pdu_len, // length of the PDU
|
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
|
uint16_t pdu_len) // length PDU
|
||||||
{
|
{
|
||||||
uint8_t invoke_id = 0;
|
uint8_t invoke_id = 0;
|
||||||
|
int apdu_offset = 0;
|
||||||
|
|
||||||
apdu_offset = npdu_decode(
|
apdu_offset = npdu_decode(
|
||||||
&src, // source address - get the SADR/SNET if in there
|
&src, // source address - get the SADR/SNET if in there
|
||||||
@@ -86,7 +87,6 @@ void Process_PDU(
|
|||||||
void Send_IAm(void)
|
void Send_IAm(void)
|
||||||
{
|
{
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
uint8_t invoke_id = 0;
|
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS src;
|
BACNET_ADDRESS src;
|
||||||
|
|
||||||
@@ -101,8 +101,7 @@ void Send_IAm(void)
|
|||||||
&dest,
|
&dest,
|
||||||
&src,
|
&src,
|
||||||
false, // true for confirmed messages
|
false, // true for confirmed messages
|
||||||
MESSAGE_PRIORITY_NORMAL,
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
invoke_id);
|
|
||||||
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
pdu_len += iam_encode_apdu(
|
pdu_len += iam_encode_apdu(
|
||||||
|
|||||||
Reference in New Issue
Block a user