fixed dos-unix line feed issue.
This commit is contained in:
+190
-195
@@ -34,7 +34,7 @@
|
||||
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#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 "bip.h"
|
||||
#include "net.h" /* custom per port */
|
||||
@@ -43,16 +43,16 @@
|
||||
BACnet Broadcast Management Device,
|
||||
Broadcast Distribution Table, and
|
||||
Foreign Device Registration */
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
{
|
||||
|
||||
/* true if valid entry - false if not */
|
||||
bool valid;
|
||||
bool valid;
|
||||
|
||||
/* BACnet/IP address */
|
||||
struct in_addr dest_address;
|
||||
|
||||
|
||||
uint16_t dest_port;
|
||||
|
||||
/* Broadcast Distribution Mask - stored in host byte order */
|
||||
@@ -71,12 +71,12 @@ registration.*/
|
||||
seconds remaining before the BBMD will purge the registrant's FDT
|
||||
entry if no re-registration occurs. This value will be initialized
|
||||
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
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
bool valid;
|
||||
|
||||
/* BACnet/IP address */
|
||||
struct in_addr dest_address;
|
||||
|
||||
@@ -103,7 +103,7 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
||||
|
||||
if (FD_Table[i].valid)
|
||||
|
||||
|
||||
{
|
||||
|
||||
if (FD_Table[i].seconds_remaining)
|
||||
|
||||
@@ -113,14 +113,13 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
||||
|
||||
FD_Table[i].seconds_remaining = 0;
|
||||
|
||||
|
||||
else
|
||||
|
||||
FD_Table[i].seconds_remaining -= seconds;
|
||||
|
||||
if (FD_Table[i].seconds_remaining == 0)
|
||||
|
||||
|
||||
if (FD_Table[i].seconds_remaining == 0)
|
||||
{
|
||||
|
||||
FD_Table[i].valid = false;
|
||||
|
||||
@@ -130,69 +129,68 @@ int bvlc_encode_address_entry(
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_bip_address(
|
||||
uint8_t * pdu,
|
||||
int bvlc_encode_bip_address(
|
||||
uint8_t * pdu,
|
||||
struct in_addr *address, /* in host format */
|
||||
uint16_t port)
|
||||
struct in_addr *address, /* in host format */
|
||||
uint16_t port)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
|
||||
len = encode_unsigned32(&pdu[0], address->s_addr);
|
||||
|
||||
len += encode_unsigned16(&pdu[len], port);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_decode_bip_address(
|
||||
uint8_t * pdu,
|
||||
int bvlc_decode_bip_address(
|
||||
struct in_addr *address, /* in host format */
|
||||
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)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
uint16_t port,
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
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;
|
||||
|
||||
|
||||
int bvlc_encode_bvlc_result(uint8_t * pdu,
|
||||
|
||||
BACNET_BVLC_RESULT result_code)
|
||||
{
|
||||
@@ -200,10 +198,10 @@ int bvlc_encode_address_entry(
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_RESULT;
|
||||
|
||||
/* 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. */
|
||||
encode_unsigned16(&pdu[2], 6);
|
||||
@@ -216,75 +214,75 @@ int bvlc_encode_address_entry(
|
||||
return 6;
|
||||
|
||||
}
|
||||
|
||||
return 6;
|
||||
|
||||
|
||||
int bvlc_encode_write_bdt_init(
|
||||
uint8_t * pdu,
|
||||
unsigned entries)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
unsigned entries)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE;
|
||||
|
||||
/* 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. */
|
||||
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||
|
||||
len = 4;
|
||||
|
||||
}
|
||||
|
||||
len = 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_read_bdt(
|
||||
}
|
||||
uint8_t * pdu)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
int len = 0;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE;
|
||||
|
||||
/* 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. */
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
encode_unsigned16(&pdu[2], 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) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE_ACK;
|
||||
@@ -292,10 +290,10 @@ int bvlc_encode_address_entry(
|
||||
/* 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. */
|
||||
|
||||
/* 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. */
|
||||
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||
|
||||
len = 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -303,8 +301,8 @@ int bvlc_encode_address_entry(
|
||||
|
||||
}
|
||||
|
||||
return len;
|
||||
|
||||
|
||||
int bvlc_encode_forwarded_npdu(uint8_t * pdu,
|
||||
BACNET_ADDRESS * src,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
@@ -312,10 +310,10 @@ int bvlc_encode_address_entry(
|
||||
|
||||
int len = 0;
|
||||
|
||||
unsigned npdu_length)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
unsigned i; /* for loop counter */
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
@@ -323,8 +321,8 @@ int bvlc_encode_address_entry(
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
of the entire BVLL message, including the two octets of the
|
||||
|
||||
pdu[1] = BVLC_FORWARDED_NPDU;
|
||||
length field itself, most significant octet first. */
|
||||
encode_unsigned16(&pdu[2], 4 + 6 + npdu_length);
|
||||
|
||||
len = 4;
|
||||
|
||||
@@ -332,10 +330,10 @@ int bvlc_encode_address_entry(
|
||||
|
||||
pdu[len] = src->adr[i];
|
||||
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
|
||||
pdu[len] = src->adr[i];
|
||||
len++;
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < npdu_length; i++) {
|
||||
|
||||
pdu[len] = npdu[i];
|
||||
@@ -348,9 +346,9 @@ int bvlc_encode_address_entry(
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_register_foreign_device(uint8_t * pdu,
|
||||
|
||||
@@ -367,9 +365,9 @@ void bvlc_internet_to_bacnet_address(
BACNET_ADDRESS * src, /* returns the BACn
|
||||
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
|
||||
of the entire BVLL message, including the two octets of the
|
||||
length field itself, most significant octet first. */
|
||||
encode_unsigned16(&pdu[2], 6);
|
||||
|
||||
encode_unsigned16(&pdu[2], time_to_live_seconds);
|
||||
|
||||
@@ -381,10 +379,10 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
|
||||
|
||||
int bvlc_encode_read_fdt(
|
||||
uint8_t * pdu)
|
||||
{
|
||||
|
||||
int len = 0;
|
||||
@@ -392,46 +390,44 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
||||
|
||||
if (pdu) {
|
||||
|
||||
int len = 0;
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
of the entire BVLL message, including the two octets of the
|
||||
|
||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
||||
length field itself, most significant octet first. */
|
||||
encode_unsigned16(&pdu[2], 4);
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
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,
|
||||
unsigned entries)
|
||||
{
|
||||
|
||||
int bvlc_encode_read_fdt_ack_init(
|
||||
uint8_t * pdu,
|
||||
int len = 0;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE_ACK;
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
of the entire BVLL message, including the two octets of the
|
||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE_ACK;
|
||||
|
||||
/* 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. */
|
||||
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||
|
||||
len = 4;
|
||||
|
||||
}
|
||||
@@ -443,14 +439,14 @@ 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)
|
||||
{
|
||||
struct in_addr *address,
|
||||
uint16_t port)
|
||||
{
|
||||
|
||||
|
||||
int len = 0;
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
@@ -462,9 +458,8 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
||||
length field itself, most significant octet first. */
|
||||
encode_unsigned16(&pdu[2], 10);
|
||||
|
||||
length field itself, most significant octet first. */
|
||||
encode_unsigned16(&pdu[2], 10);
|
||||
|
||||
/* FDT Entry */
|
||||
encode_unsigned32(&pdu[0], address->s_addr);
|
||||
|
||||
encode_unsigned16(&pdu[4], port);
|
||||
|
||||
@@ -472,65 +467,65 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_distribute_broadcast_to_network(uint8_t * pdu,
|
||||
|
||||
uint8_t * npdu,
|
||||
uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
|
||||
int len = 0; /* return value */
|
||||
|
||||
int len = 0; /* return value */
|
||||
|
||||
unsigned i; /* for loop counter */
|
||||
|
||||
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
|
||||
|
||||
/* 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,
|
||||
of the entire BVLL message, including the two octets of the
|
||||
length field itself, most significant octet first. */
|
||||
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
||||
|
||||
for (i = 0; i < npdu_length; i++) {
|
||||
|
||||
pdu[len] = npdu[i];
|
||||
|
||||
length field itself, most significant octet first. */
|
||||
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
||||
|
||||
for (i = 0; i < npdu_length; i++) {
|
||||
|
||||
pdu[len] = npdu[i];
|
||||
|
||||
len++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_original_unicast_npdu(
|
||||
uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
|
||||
int len = 0; /* return value */
|
||||
|
||||
unsigned i = 0; /* loop counter */
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_original_unicast_npdu(uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
|
||||
unsigned npdu_length)
|
||||
{
|
||||
|
||||
int len = 0; /* return value */
|
||||
|
||||
unsigned i = 0; /* loop counter */
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
pdu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
||||
|
||||
/* The 2-octet BVLC Length field is the length, in octets,
|
||||
@@ -547,51 +542,51 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int bvlc_encode_original_broadcast_npdu(uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
|
||||
unsigned npdu_length)
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
{
|
||||
|
||||
int len = 0; /* return value */
|
||||
|
||||
unsigned i = 0; /* loop counter */
|
||||
|
||||
|
||||
if (pdu) {
|
||||
|
||||
if (pdu) {
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
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
|
||||
length field itself, most significant octet first. */
|
||||
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
||||
|
||||
for (i = 0; i < npdu_length; i++) {
|
||||
|
||||
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
|
||||
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
|
||||
length field itself, most significant octet first. */
|
||||
len = encode_unsigned16(&pdu[2], 4 + npdu_length) + 2;
|
||||
|
||||
for (i = 0; i < npdu_length; i++) {
|
||||
|
||||
pdu[len] = npdu[i];
|
||||
|
||||
len++;
|
||||
|
||||
len++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* copy the source internet address to the BACnet address */
|
||||
/* FIXME: IPv6? */
|
||||
/* FIXME: is sockaddr_in host or network order? */
|
||||
@@ -613,17 +608,17 @@ void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source intern
|
||||
|
||||
src->mac_len = len;
|
||||
|
||||
|
||||
src->mac_len = len;
|
||||
src->net = 0;
|
||||
|
||||
src->len = 0;
|
||||
|
||||
|
||||
src->len = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* copy the source internet address to the BACnet address */
|
||||
/* FIXME: IPv6? */
|
||||
|
||||
+3
-4
@@ -41,13 +41,12 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* called from BACnet/IP handler */
|
||||
void bvlc_handler(uint8_t * buf, int len, struct sockaddr_in *sin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __cplusplus */
|
||||
#endif /*
|
||||
|
||||
Reference in New Issue
Block a user