updated the linux data link layers for changed apdu that passes npdu.

This commit is contained in:
skarg
2006-08-13 11:19:42 +00:00
parent a30d497669
commit 3560e3d06f
11 changed files with 66 additions and 96 deletions
+2 -7
View File
@@ -38,6 +38,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h"
/* specific defines for ARCNET */ /* specific defines for ARCNET */
#define MAX_HEADER (1+1+2+2+1+1+1+1) #define MAX_HEADER (1+1+2+2+1+1+1+1)
@@ -51,16 +52,10 @@ extern "C" {
void arcnet_cleanup(void); void arcnet_cleanup(void);
bool arcnet_init(char *interface_name); bool arcnet_init(char *interface_name);
/* function to send a packet out the 802.2 socket */
/* returns 0 on success, non-zero on failure */
int arcnet_send(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns zero on success, non-zero on failure */ /* returns zero on success, non-zero on failure */
int arcnet_send_pdu(BACNET_ADDRESS * dest, /* destination address */ 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 */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
+1 -1
View File
@@ -147,7 +147,7 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t mtu[MAX_MPDU] = { 0 }; uint8_t mtu[MAX_MPDU] = { 0 };
int mtu_len = 0; int mtu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_ADDRESS src; BACNET_ADDRESS src = { 0 };
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
if (BIP_Socket < 0) if (BIP_Socket < 0)
+1
View File
@@ -2,6 +2,7 @@
#define CONFIG_H #define CONFIG_H
/* declare a single physical layer */ /* declare a single physical layer */
/*#include "bip.h" */
/*#include "ethernet.h" */ /*#include "ethernet.h" */
/*#include "arcnet.h" */ /*#include "arcnet.h" */
/*#include "mstp.h" */ /*#include "mstp.h" */
+7 -10
View File
@@ -40,20 +40,17 @@
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h" #include "npdu.h"
#ifdef BACDL_ETHERNET #if defined(BACDL_ETHERNET)
#include "ethernet.h" #include "ethernet.h"
#endif #elif defined(BACDL_ARCNET)
#ifdef BACDL_ARCNET
#include "arcnet.h" #include "arcnet.h"
#endif #elif defined(BACDL_MSTP)
#ifdef BACDL_MSTP
#include "dlmstp.h" #include "dlmstp.h"
#endif #elif defined(BACDL_BIP)
#ifdef BACDL_BIP
#include "bip.h" #include "bip.h"
#else
#define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
+1
View File
@@ -25,6 +25,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include "config.h" #include "config.h"
#include "config.h" #include "config.h"
#include "txbuf.h" #include "txbuf.h"
+1
View File
@@ -25,6 +25,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include "config.h" #include "config.h"
#include "config.h" #include "config.h"
#include "txbuf.h" #include "txbuf.h"
+6 -4
View File
@@ -6,10 +6,10 @@ BASEDIR = .
#CFLAGS = -Wall -I. -O2 -g #CFLAGS = -Wall -I. -O2 -g
# Note: you can strip out symbols using the strip command # Note: you can strip out symbols using the strip command
# to get an idea of how big the compile really is. # to get an idea of how big the compile really is.
#DEFINES = -DBACFILE=1 -DBACDL_ETHERNET=1 DEFINES = -DBACFILE=1 -DPRINT_ENABLED=1 -DBIG_ENDIAN=0 -DBACDL_ETHERNET=1
#DEFINES = -DBACFILE=1 -DBACDL_ARCNET=1 #DEFINES = -DBACFILE=1 -DPRINT_ENABLED=1 -DBIG_ENDIAN=0 -DBACDL_ARCNET=1
#DEFINES = -DBACFILE=1 -DBACDL_MSTP=1 #DEFINES = -DBACFILE=1 -DPRINT_ENABLED=1 -DBIG_ENDIAN=0 -DBACDL_MSTP=1
DEFINES = -DBACFILE=1 -DBACDL_BIP=1 -DPRINT_ENABLED=1 -DBIG_ENDIAN=0 #DEFINES = -DBACFILE=1 -DPRINT_ENABLED=1 -DBIG_ENDIAN=0 -DBACDL_BIP=1
BACNET_PORT = ../../ports/linux BACNET_PORT = ../../ports/linux
BACNET_OBJECT = ../object BACNET_OBJECT = ../object
BACNET_HANDLER = ../handler BACNET_HANDLER = ../handler
@@ -22,6 +22,8 @@ TARGET = bacserv
SRCS = server.c \ SRCS = server.c \
$(BACNET_PORT)/bip-init.c \ $(BACNET_PORT)/bip-init.c \
$(BACNET_PORT)/ethernet.c \
$(BACNET_PORT)/arcnet.c \
$(BACNET_ROOT)/bip.c \ $(BACNET_ROOT)/bip.c \
$(BACNET_HANDLER)/txbuf.c \ $(BACNET_HANDLER)/txbuf.c \
$(BACNET_HANDLER)/noserv.c \ $(BACNET_HANDLER)/noserv.c \
+2
View File
@@ -112,8 +112,10 @@ int main(int argc, char *argv[])
/* allow the device ID to be set */ /* allow the device ID to be set */
if (argc > 1) if (argc > 1)
Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0)); Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0));
#if defined(BACDL_BIP)
if (argc > 2) if (argc > 2)
bip_set_port(strtol(argv[2], NULL, 0)); bip_set_port(strtol(argv[2], NULL, 0));
#endif
printf("BACnet Server Demo - Device #%u\r\n", printf("BACnet Server Demo - Device #%u\r\n",
Device_Object_Instance_Number()); Device_Object_Instance_Number());
Init_Service_Handlers(); Init_Service_Handlers();
+2 -7
View File
@@ -38,6 +38,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h"
/* specific defines for Ethernet */ /* specific defines for Ethernet */
#define MAX_HEADER (6+6+2+1+1+1) #define MAX_HEADER (6+6+2+1+1+1)
@@ -51,16 +52,10 @@ extern "C" {
void ethernet_cleanup(void); void ethernet_cleanup(void);
bool ethernet_init(char *interface_name); bool ethernet_init(char *interface_name);
/* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int ethernet_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 */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
+19 -28
View File
@@ -34,6 +34,7 @@
#include <stdint.h> #include <stdint.h>
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h"
#include "arcnet.h" #include "arcnet.h"
#include "net.h" #include "net.h"
@@ -182,18 +183,23 @@ bool arcnet_init(char *interface_name)
return arcnet_valid(); return arcnet_valid();
} }
/* function to send a packet out the socket */ /* function to send a PDU out the socket */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int arcnet_send(BACNET_ADDRESS * dest, /* destination address */ int arcnet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, /* source address */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
BACNET_ADDRESS src = { 0 }; /* source address */
int bytes = 0; int bytes = 0;
uint8_t mtu[512] = { 0 }; uint8_t mtu[512] = { 0 };
int mtu_len = 0; int mtu_len = 0;
int npdu_len = 0;
struct archdr *pkt = (struct archdr *) mtu; struct archdr *pkt = (struct archdr *) mtu;
src.mac[0] = ARCNET_MAC_Address;
src.mac_len = 1;
/* don't waste time if the socket is not valid */ /* don't waste time if the socket is not valid */
if (ARCNET_Sock_FD < 0) { if (ARCNET_Sock_FD < 0) {
fprintf(stderr, "arcnet: socket is invalid!\n"); fprintf(stderr, "arcnet: socket is invalid!\n");
@@ -206,24 +212,25 @@ int arcnet_send(BACNET_ADDRESS * dest, /* destination address */
fprintf(stderr, "arcnet: invalid destination MAC address!\n"); fprintf(stderr, "arcnet: invalid destination MAC address!\n");
return -2; return -2;
} }
if (src->mac_len == 1) if (src.mac_len == 1)
pkt->hard.source = src->mac[0]; pkt->hard.source = src.mac[0];
else { else {
fprintf(stderr, "arcnet: invalid source MAC address!\n"); fprintf(stderr, "arcnet: invalid source MAC address!\n");
return -3; return -3;
} }
if ((ARC_HDR_SIZE + pdu_len) > 512) {
fprintf(stderr, "arcnet: PDU is too big to send!\n");
return -4;
}
/* Logical PDU portion */ /* Logical PDU portion */
pkt->soft.raw[0] = 0xCD; /* SC for BACnet */ pkt->soft.raw[0] = 0xCD; /* SC for BACnet */
pkt->soft.raw[1] = 0x82; /* DSAP for BACnet */ pkt->soft.raw[1] = 0x82; /* DSAP for BACnet */
pkt->soft.raw[2] = 0x82; /* SSAP for BACnet */ pkt->soft.raw[2] = 0x82; /* SSAP for BACnet */
pkt->soft.raw[3] = 0x03; /* Control byte in header */ pkt->soft.raw[3] = 0x03; /* LLC Control byte in header */
memcpy(&pkt->soft.raw[4], pdu, pdu_len); npdu_len = npdu_encode_pdu(&pkt->soft.raw[4], dest, &src, npdu_data);
/* packet length */ /* packet length */
mtu_len = ARC_HDR_SIZE + 4 /*SC,DSAP,SSAP,LLC */ + pdu_len; mtu_len = ARC_HDR_SIZE + 4 /*SC,DSAP,SSAP,LLC */ + npdu_len + pdu_len;
if (mtu_len > 512) {
fprintf(stderr, "arcnet: PDU is too big to send!\n");
return -4;
}
memcpy(&pkt->soft.raw[4+npdu_len], pdu, pdu_len);
/* Send the packet */ /* Send the packet */
bytes = bytes =
sendto(ARCNET_Sock_FD, &mtu, mtu_len, 0, sendto(ARCNET_Sock_FD, &mtu, mtu_len, 0,
@@ -237,22 +244,6 @@ int arcnet_send(BACNET_ADDRESS * dest, /* destination address */
return bytes; return bytes;
} }
/* 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 */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
BACNET_ADDRESS src = { 0 }; /* source address */
src.mac[0] = ARCNET_MAC_Address;
src.mac_len = 1;
return arcnet_send(dest, /* destination address */
&src, /* source address */
pdu, /* any data to be sent - may be null */
pdu_len); /* number of bytes of data */
}
/* receives an framed packet */ /* receives an framed packet */
/* returns the number of octets in the PDU, or zero on failure */ /* returns the number of octets in the PDU, or zero on failure */
uint16_t arcnet_receive(BACNET_ADDRESS * src, /* source address */ uint16_t arcnet_receive(BACNET_ADDRESS * src, /* source address */
+24 -39
View File
@@ -177,16 +177,23 @@ bool ethernet_init(char *interface_name)
} }
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns bytes sent success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, /* source address */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
int i = 0; /* counter */
int bytes = 0; int bytes = 0;
uint8_t mtu[MAX_MPDU] = { 0 }; BACNET_ADDRESS src = { 0 }; /* source address for npdu*/
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
int mtu_len = 0; int mtu_len = 0;
int i = 0; int len = 0;
for (i = 0; i < 6; i++) {
src.mac[i] = Ethernet_MAC_Address[i];
src.mac_len++;
}
/* don't waste time if the socket is not valid */ /* don't waste time if the socket is not valid */
if (eth802_sockfd < 0) { if (eth802_sockfd < 0) {
@@ -196,8 +203,7 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
/* load destination ethernet MAC address */ /* load destination ethernet MAC address */
if (dest->mac_len == 6) { if (dest->mac_len == 6) {
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
mtu[mtu_len] = dest->mac[i]; mtu[i] = dest->mac[i];
mtu_len++;
} }
} else { } else {
fprintf(stderr, "ethernet: invalid destination MAC address!\n"); fprintf(stderr, "ethernet: invalid destination MAC address!\n");
@@ -205,28 +211,28 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
} }
/* load source ethernet MAC address */ /* load source ethernet MAC address */
if (src->mac_len == 6) { if (src.mac_len == 6) {
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
mtu[mtu_len] = src->mac[i]; mtu[6 + i] = src.mac[i];
mtu_len++;
} }
} else { } else {
fprintf(stderr, "ethernet: invalid source MAC address!\n"); fprintf(stderr, "ethernet: invalid source MAC address!\n");
return -3; return -3;
} }
if ((14 + 3 + pdu_len) > MAX_MPDU) { /* Logical PDU portion */
mtu[14] = 0x82; /* DSAP for BACnet */
mtu[15] = 0x82; /* SSAP for BACnet */
mtu[16] = 0x03; /* Control byte in header */
len = npdu_encode_pdu(&mtu[17], dest, &src, npdu_data);
mtu_len = 17 + len;
if ((mtu_len + pdu_len) > MAX_MPDU) {
fprintf(stderr, "ethernet: PDU is too big to send!\n"); fprintf(stderr, "ethernet: PDU is too big to send!\n");
return -4; return -4;
} }
/* packet length */
mtu_len += encode_unsigned16(&mtu[12],
3 /*DSAP,SSAP,LLC */ + pdu_len);
/* Logical PDU portion */
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
mtu[mtu_len++] = 0x03; /* Control byte in header */
memcpy(&mtu[mtu_len], pdu, pdu_len); memcpy(&mtu[mtu_len], pdu, pdu_len);
mtu_len += pdu_len; mtu_len += pdu_len;
/* packet length */
encode_unsigned16(&mtu[12],mtu_len);
/* Send the packet */ /* Send the packet */
bytes = bytes =
@@ -240,27 +246,6 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
return bytes; return bytes;
} }
/* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */
int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
int i = 0; /* counter */
BACNET_ADDRESS src = { 0 }; /* source address */
for (i = 0; i < 6; i++) {
src.mac[i] = Ethernet_MAC_Address[i];
src.mac_len++;
}
/* function to send a packet out the 802.2 socket */
/* returns 1 on success, 0 on failure */
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 */
}
/* receives an 802.2 framed packet */ /* receives an 802.2 framed packet */
/* returns the number of octets in the PDU, or zero on failure */ /* returns the number of octets in the PDU, or zero on failure */
uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */ uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */