fixed dos-unix line feed issue.
This commit is contained in:
+315
-320
@@ -1,88 +1,88 @@
|
|||||||
/*####COPYRIGHTBEGIN####
|
/*####COPYRIGHTBEGIN####
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
Copyright (C) 2006 Steve Karg
|
Copyright (C) 2006 Steve Karg
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to:
|
along with this program; if not, write to:
|
||||||
The Free Software Foundation, Inc.
|
The Free Software Foundation, Inc.
|
||||||
59 Temple Place - Suite 330
|
59 Temple Place - Suite 330
|
||||||
Boston, MA 02111-1307, USA.
|
Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
As a special exception, if other files instantiate templates or
|
As a special exception, if other files instantiate templates or
|
||||||
use macros or inline functions from this file, or you compile
|
use macros or inline functions from this file, or you compile
|
||||||
this file and link it with other works to produce a work based
|
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
|
on this file, this file does not by itself cause the resulting
|
||||||
work to be covered by the GNU General Public License. However
|
work to be covered by the GNU General Public License. However
|
||||||
the source code for this file must still be made available in
|
the source code for this file must still be made available in
|
||||||
accordance with section (3) of the GNU General Public License.
|
accordance with section (3) of the GNU General Public License.
|
||||||
|
|
||||||
This exception does not invalidate any other reasons why a work
|
This exception does not invalidate any other reasons why a work
|
||||||
based on this file might be covered by the GNU General Public
|
based on this file might be covered by the GNU General Public
|
||||||
License.
|
License.
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
####COPYRIGHTEND####*/
|
####COPYRIGHTEND####*/
|
||||||
|
|
||||||
#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 <time.h> /* for the standard bool type. */
|
#include <time.h> /* for the standard bool type. */
|
||||||
#include "bacdcode.h"
|
#include "bacdcode.h"
|
||||||
#include "bip.h"
|
#include "bip.h"
|
||||||
#include "net.h" /* custom per port */
|
#include "net.h" /* custom per port */
|
||||||
|
|
||||||
/* Handle the BACnet Virtual Link Control (BVLC), which includes:
|
/* Handle the BACnet Virtual Link Control (BVLC), which includes:
|
||||||
BACnet Broadcast Management Device,
|
BACnet Broadcast Management Device,
|
||||||
Broadcast Distribution Table, and
|
Broadcast Distribution Table, and
|
||||||
Foreign Device Registration */
|
Foreign Device Registration */
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
||||||
/* true if valid entry - false if not */
|
/* true if valid entry - false if not */
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
/* BACnet/IP address */
|
/* BACnet/IP address */
|
||||||
struct in_addr dest_address;
|
struct in_addr dest_address;
|
||||||
|
|
||||||
uint16_t dest_port;
|
uint16_t dest_port;
|
||||||
|
|
||||||
/* Broadcast Distribution Mask - stored in host byte order */
|
/* Broadcast Distribution Mask - stored in host byte order */
|
||||||
struct in_addr broadcast_mask;
|
struct in_addr broadcast_mask;
|
||||||
|
|
||||||
} BBMD_TABLE_ENTRY;
|
} BBMD_TABLE_ENTRY;
|
||||||
|
|
||||||
|
#define MAX_BBMD_ENTRIES 128
|
||||||
#define MAX_BBMD_ENTRIES 128
|
static BBMD_TABLE_ENTRY BBMD_Table[MAX_BBMD_ENTRIES];
|
||||||
static BBMD_TABLE_ENTRY BBMD_Table[MAX_BBMD_ENTRIES];
|
|
||||||
|
/*Each device that registers as a foreign device shall be placed
|
||||||
|
in an entry in the BBMD's Foreign Device Table (FDT). Each
|
||||||
/*Each device that registers as a foreign device shall be placed
|
entry shall consist of the 6-octet B/IP address of the registrant;
|
||||||
in an entry in the BBMD's Foreign Device Table (FDT). Each
|
the 2-octet Time-to-Live value supplied at the time of
|
||||||
entry shall consist of the 6-octet B/IP address of the registrant;
|
registration; and a 2-octet value representing the number of
|
||||||
seconds remaining before the BBMD will purge the registrant's FDT
|
seconds remaining before the BBMD will purge the registrant's FDT
|
||||||
entry if no re-registration occurs. This value will be initialized
|
entry if no re-registration occurs. This value will be initialized
|
||||||
seconds remaining before the BBMD will purge the registrant's FDT
|
to the 2-octet Time-to-Live value supplied at the time of
|
||||||
entry if no re-registration occurs. This value will be initialized
|
registration.*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
typedef struct
|
|
||||||
{
|
bool valid;
|
||||||
|
|
||||||
/* BACnet/IP address */
|
/* BACnet/IP address */
|
||||||
struct in_addr dest_address;
|
struct in_addr dest_address;
|
||||||
/* BACnet/IP address */
|
|
||||||
struct in_addr dest_address;
|
uint16_t dest_port;
|
||||||
|
|
||||||
uint16_t dest_port;
|
/* seconds for valid entry lifetime */
|
||||||
uint16_t time_to_live;
|
uint16_t time_to_live;
|
||||||
|
|
||||||
time_t seconds_remaining; /* includes 30 second grace period */
|
time_t seconds_remaining; /* includes 30 second grace period */
|
||||||
@@ -92,7 +92,7 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
|||||||
#define MAX_FD_ENTRIES 128
|
#define MAX_FD_ENTRIES 128
|
||||||
static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
||||||
|
|
||||||
#define MAX_FD_ENTRIES 128
|
|
||||||
void bvlc_maintenance_timer(unsigned seconds)
|
void bvlc_maintenance_timer(unsigned seconds)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
|||||||
|
|
||||||
if (FD_Table[i].valid)
|
if (FD_Table[i].valid)
|
||||||
|
|
||||||
|
{
|
||||||
if (FD_Table[i].valid)
|
|
||||||
if (FD_Table[i].seconds_remaining)
|
if (FD_Table[i].seconds_remaining)
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -113,15 +113,14 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
|||||||
|
|
||||||
FD_Table[i].seconds_remaining = 0;
|
FD_Table[i].seconds_remaining = 0;
|
||||||
|
|
||||||
|
else
|
||||||
FD_Table[i].seconds_remaining = 0;
|
|
||||||
FD_Table[i].seconds_remaining -= seconds;
|
FD_Table[i].seconds_remaining -= seconds;
|
||||||
else
|
|
||||||
if (FD_Table[i].seconds_remaining == 0)
|
if (FD_Table[i].seconds_remaining == 0)
|
||||||
FD_Table[i].seconds_remaining -= seconds;
|
|
||||||
|
{
|
||||||
if (FD_Table[i].seconds_remaining == 0)
|
|
||||||
|
|
||||||
FD_Table[i].valid = false;
|
FD_Table[i].valid = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -130,80 +129,79 @@ int bvlc_encode_address_entry(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_bip_address(
|
int bvlc_encode_bip_address(
|
||||||
|
uint8_t * pdu,
|
||||||
int bvlc_encode_bip_address(
|
struct in_addr *address, /* in host format */
|
||||||
uint8_t * pdu,
|
uint16_t port)
|
||||||
struct in_addr *address, /* in host format */
|
{
|
||||||
uint16_t port)
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
len = encode_unsigned32(&pdu[0], address->s_addr);
|
len = encode_unsigned32(&pdu[0], address->s_addr);
|
||||||
|
|
||||||
len += encode_unsigned16(&pdu[len], port);
|
len += encode_unsigned16(&pdu[len], port);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
return len;
|
||||||
|
|
||||||
return len;
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_decode_bip_address(
|
int bvlc_decode_bip_address(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
int bvlc_decode_bip_address(
|
struct in_addr *address, /* in host format */
|
||||||
uint16_t * port)
|
uint16_t * port)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/* used for both read and write entries */
|
||||||
|
int bvlc_encode_address_entry(uint8_t * pdu,
|
||||||
|
struct in_addr *address,
|
||||||
|
uint16_t port,
|
||||||
struct in_addr *mask)
|
struct in_addr *mask)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint16_t port,
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
len = bvlc_encode_bip_address(pdu, address, port);
|
len = bvlc_encode_bip_address(pdu, address, port);
|
||||||
|
|
||||||
|
len += encode_unsigned32(&pdu[len], mask->s_addr);
|
||||||
if (pdu) {
|
|
||||||
|
}
|
||||||
len = bvlc_encode_bip_address(pdu, address, port);
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
int bvlc_encode_bvlc_result(uint8_t * pdu,
|
||||||
|
|
||||||
|
|
||||||
BACNET_BVLC_RESULT result_code)
|
BACNET_BVLC_RESULT result_code)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
{
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
if (pdu) {
|
pdu[1] = BVLC_RESULT;
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
encode_unsigned16(&pdu[2], 6);
|
encode_unsigned16(&pdu[2], 6);
|
||||||
@@ -216,86 +214,86 @@ int bvlc_encode_address_entry(
|
|||||||
return 6;
|
return 6;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 6;
|
|
||||||
int bvlc_encode_write_bdt_init(
|
int bvlc_encode_write_bdt_init(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
unsigned entries)
|
unsigned entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t * pdu,
|
int len = 0;
|
||||||
unsigned entries)
|
|
||||||
{
|
|
||||||
|
if (pdu) {
|
||||||
int len = 0;
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE;
|
pdu[1] = BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||||
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
}
|
||||||
|
|
||||||
len = 4;
|
|
||||||
|
return len;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_read_bdt(
|
int bvlc_encode_read_bdt(
|
||||||
}
|
uint8_t * pdu)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (pdu) {
|
||||||
int len = 0;
|
|
||||||
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
if (pdu) {
|
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
|
encode_unsigned16(&pdu[2], 4);
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
return len;
|
|
||||||
|
int bvlc_encode_read_bdt_ack_init(
|
||||||
}
|
uint8_t * pdu,
|
||||||
|
unsigned entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (pdu) {
|
||||||
int len = 0;
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE_ACK;
|
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE_ACK;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE_ACK;
|
length field itself, most significant octet first. */
|
||||||
|
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
|
||||||
of the entire BVLL message, including the two octets of the
|
len = 4;
|
||||||
length field itself, most significant octet first. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -303,19 +301,19 @@ int bvlc_encode_address_entry(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
|
||||||
|
int bvlc_encode_forwarded_npdu(uint8_t * pdu,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
uint8_t * npdu,
|
uint8_t * npdu,
|
||||||
unsigned npdu_length)
|
unsigned npdu_length)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint8_t * npdu,
|
|
||||||
unsigned npdu_length)
|
unsigned i; /* for loop counter */
|
||||||
{
|
|
||||||
|
|
||||||
int len = 0;
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
@@ -323,19 +321,19 @@ int bvlc_encode_address_entry(
|
|||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
|
length field itself, most significant octet first. */
|
||||||
pdu[1] = BVLC_FORWARDED_NPDU;
|
encode_unsigned16(&pdu[2], 4 + 6 + npdu_length);
|
||||||
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
|
|
||||||
pdu[len] = src->adr[i];
|
pdu[len] = src->adr[i];
|
||||||
len = 4;
|
|
||||||
|
len++;
|
||||||
for (i = 0; i < 6; i++) {
|
|
||||||
|
}
|
||||||
pdu[len] = src->adr[i];
|
|
||||||
for (i = 0; i < npdu_length; i++) {
|
for (i = 0; i < npdu_length; i++) {
|
||||||
|
|
||||||
pdu[len] = npdu[i];
|
pdu[len] = npdu[i];
|
||||||
@@ -344,13 +342,13 @@ int bvlc_encode_address_entry(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
len++;
|
|
||||||
|
|
||||||
}
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_register_foreign_device(uint8_t * pdu,
|
int bvlc_encode_register_foreign_device(uint8_t * pdu,
|
||||||
|
|
||||||
@@ -363,13 +361,13 @@ void bvlc_internet_to_bacnet_address(
BACNET_ADDRESS * src, /* returns the BACn
|
|||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
|
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
|
||||||
if (pdu) {
|
|
||||||
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
of the entire BVLL message, including the two octets of the
|
||||||
|
length field itself, most significant octet first. */
|
||||||
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
|
encode_unsigned16(&pdu[2], 6);
|
||||||
|
|
||||||
encode_unsigned16(&pdu[2], time_to_live_seconds);
|
encode_unsigned16(&pdu[2], time_to_live_seconds);
|
||||||
|
|
||||||
@@ -381,57 +379,55 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
|||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
int bvlc_encode_read_fdt(
|
||||||
|
uint8_t * pdu)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
int len = 0;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
of the entire BVLL message, including the two octets of the
|
||||||
|
length field itself, most significant octet first. */
|
||||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
encode_unsigned16(&pdu[2], 4);
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
len = 4;
|
||||||
of the entire BVLL message, including the two octets of the
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
len = 4;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
int bvlc_encode_read_fdt_ack_init(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
unsigned entries)
|
unsigned entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
int bvlc_encode_read_fdt_ack_init(
|
int len = 0;
|
||||||
uint8_t * pdu,
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
|
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE_ACK;
|
||||||
if (pdu) {
|
|
||||||
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
of the entire BVLL message, including the two octets of the
|
||||||
|
length field itself, most significant octet first. */
|
||||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE_ACK;
|
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
|
||||||
of the entire BVLL message, including the two octets of the
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -442,15 +438,15 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
int bvlc_encode_delete_fdt_entry(uint8_t * pdu,
|
||||||
|
struct in_addr *address,
|
||||||
|
|
||||||
uint16_t port)
|
uint16_t port)
|
||||||
uint8_t * pdu,
|
{
|
||||||
struct in_addr *address,
|
|
||||||
uint16_t port)
|
int len = 0;
|
||||||
{
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
@@ -461,76 +457,75 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
|||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
encode_unsigned16(&pdu[2], 10);
|
encode_unsigned16(&pdu[2], 10);
|
||||||
of the entire BVLL message, including the two octets of the
|
|
||||||
length field itself, most significant octet first. */
|
/* FDT Entry */
|
||||||
encode_unsigned16(&pdu[2], 10);
|
encode_unsigned32(&pdu[0], address->s_addr);
|
||||||
|
|
||||||
|
|
||||||
encode_unsigned16(&pdu[4], port);
|
encode_unsigned16(&pdu[4], port);
|
||||||
|
|
||||||
encode_unsigned16(&pdu[4], port);
|
len = 10;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
int bvlc_encode_distribute_broadcast_to_network(uint8_t * pdu,
|
||||||
|
|
||||||
int bvlc_encode_distribute_broadcast_to_network(
|
uint8_t * npdu,
|
||||||
uint8_t * pdu,
|
unsigned npdu_length)
|
||||||
uint8_t * npdu,
|
{
|
||||||
|
|
||||||
int len = 0; /* return value */
|
int len = 0; /* return value */
|
||||||
|
|
||||||
int len = 0; /* return value */
|
unsigned i; /* for loop counter */
|
||||||
|
|
||||||
unsigned i; /* for loop counter */
|
|
||||||
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
|
pdu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
|
of the entire BVLL message, including the two octets of the
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
length field itself, most significant octet first. */
|
||||||
of the entire BVLL message, including the two octets of the
|
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
||||||
length field itself, most significant octet first. */
|
|
||||||
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
for (i = 0; i < npdu_length; i++) {
|
||||||
|
|
||||||
for (i = 0; i < npdu_length; i++) {
|
pdu[len] = npdu[i];
|
||||||
|
|
||||||
pdu[len] = npdu[i];
|
len++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return len;
|
||||||
|
|
||||||
return len;
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
int bvlc_encode_original_unicast_npdu(uint8_t * pdu,
|
||||||
|
uint8_t * npdu,
|
||||||
int bvlc_encode_original_unicast_npdu(
|
|
||||||
uint8_t * pdu,
|
unsigned npdu_length)
|
||||||
uint8_t * npdu,
|
{
|
||||||
unsigned npdu_length)
|
|
||||||
{
|
int len = 0; /* return value */
|
||||||
|
|
||||||
int len = 0; /* return value */
|
unsigned i = 0; /* loop counter */
|
||||||
|
|
||||||
unsigned i = 0; /* loop counter */
|
|
||||||
|
if (pdu) {
|
||||||
|
|
||||||
if (pdu) {
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
pdu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
@@ -546,52 +541,52 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
int bvlc_encode_original_broadcast_npdu(uint8_t * pdu,
|
||||||
|
uint8_t * npdu,
|
||||||
|
|
||||||
uint8_t * pdu,
|
unsigned npdu_length)
|
||||||
uint8_t * npdu,
|
{
|
||||||
unsigned npdu_length)
|
|
||||||
{
|
int len = 0; /* return value */
|
||||||
|
|
||||||
unsigned i = 0; /* loop counter */
|
unsigned i = 0; /* loop counter */
|
||||||
|
|
||||||
|
|
||||||
|
if (pdu) {
|
||||||
|
|
||||||
if (pdu) {
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
|
||||||
|
|
||||||
pdu[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
|
of the entire BVLL message, including the two octets of the
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
length field itself, most significant octet first. */
|
||||||
of the entire BVLL message, including the two octets of the
|
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
||||||
length field itself, most significant octet first. */
|
|
||||||
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
for (i = 0; i < npdu_length; i++) {
|
||||||
|
|
||||||
for (i = 0; i < npdu_length; i++) {
|
pdu[len] = npdu[i];
|
||||||
|
|
||||||
pdu[len] = npdu[i];
|
len++;
|
||||||
|
|
||||||
len++;
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
return len;
|
||||||
|
|
||||||
return len;
|
}
|
||||||
|
|
||||||
}
|
|
||||||
/* copy the source internet address to the BACnet address */
|
/* copy the source internet address to the BACnet address */
|
||||||
/* FIXME: IPv6? */
|
/* FIXME: IPv6? */
|
||||||
/* FIXME: is sockaddr_in host or network order? */
|
/* FIXME: is sockaddr_in host or network order? */
|
||||||
@@ -599,31 +594,31 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
|||||||
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
||||||
struct sockaddr_in *sin)
|
struct sockaddr_in *sin)
|
||||||
{ /* source internet address */
|
{ /* source internet address */
|
||||||
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
|
||||||
struct sockaddr_in *sin) /* source internet address */
|
int len = 0;
|
||||||
{
|
|
||||||
|
|
||||||
int len = 0;
|
if (src && sin)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (src && sin)
|
|
||||||
|
len = encode_unsigned32(&src->mac[0], sin->sin_addr.s_addr);
|
||||||
|
|
||||||
len += encode_unsigned16(&src->mac[4], sin->sin_port);
|
len += encode_unsigned16(&src->mac[4], sin->sin_port);
|
||||||
|
|
||||||
src->mac_len = len;
|
src->mac_len = len;
|
||||||
len += encode_unsigned16(&src->mac[4], sin->sin_port);
|
|
||||||
|
src->net = 0;
|
||||||
src->mac_len = len;
|
|
||||||
src->len = 0;
|
src->len = 0;
|
||||||
src->net = 0;
|
|
||||||
|
}
|
||||||
src->len = 0;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
/* copy the source internet address to the BACnet address */
|
||||||
|
/* FIXME: IPv6? */
|
||||||
|
|||||||
+50
-51
@@ -1,53 +1,52 @@
|
|||||||
/*####COPYRIGHTBEGIN####
|
/*####COPYRIGHTBEGIN####
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
Copyright (C) 2006 Steve Karg
|
Copyright (C) 2006 Steve Karg
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to:
|
along with this program; if not, write to:
|
||||||
The Free Software Foundation, Inc.
|
The Free Software Foundation, Inc.
|
||||||
59 Temple Place - Suite 330
|
59 Temple Place - Suite 330
|
||||||
Boston, MA 02111-1307, USA.
|
Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
As a special exception, if other files instantiate templates or
|
As a special exception, if other files instantiate templates or
|
||||||
use macros or inline functions from this file, or you compile
|
use macros or inline functions from this file, or you compile
|
||||||
this file and link it with other works to produce a work based
|
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
|
on this file, this file does not by itself cause the resulting
|
||||||
work to be covered by the GNU General Public License. However
|
work to be covered by the GNU General Public License. However
|
||||||
the source code for this file must still be made available in
|
the source code for this file must still be made available in
|
||||||
accordance with section (3) of the GNU General Public License.
|
accordance with section (3) of the GNU General Public License.
|
||||||
|
|
||||||
This exception does not invalidate any other reasons why a work
|
This exception does not invalidate any other reasons why a work
|
||||||
based on this file might be covered by the GNU General Public
|
based on this file might be covered by the GNU General Public
|
||||||
License.
|
License.
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
####COPYRIGHTEND####*/
|
####COPYRIGHTEND####*/
|
||||||
#ifndef BVLC_H
|
#ifndef BVLC_H
|
||||||
#define BVLC_H
|
#define BVLC_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 "bip.h"
|
#include "bip.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
/* called from BACnet/IP handler */
|
/* called from BACnet/IP handler */
|
||||||
void bvlc_handler(uint8_t * buf, int len, struct sockaddr_in *sin);
|
void bvlc_handler(uint8_t * buf, int len, struct sockaddr_in *sin);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
#ifdef __cplusplus
|
}
|
||||||
}
|
#endif /* __cplusplus */
|
||||||
#endif /* __cplusplus */
|
#endif /*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user