Cleaned up compiler warnings and errors. Still needs to be finished.
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "bacdef.h"
|
||||
#include "npdu.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+38
-23
@@ -129,9 +129,11 @@ int bvlc_decode_bip_address(
|
||||
uint16_t * port)
|
||||
{
|
||||
int len = 0;
|
||||
uint32_t raw_address = 0;
|
||||
|
||||
if (pdu) {
|
||||
(void) decode_unsigned32(&pdu[0], &(address->s_addr));
|
||||
(void) decode_unsigned32(&pdu[0], &raw_address);
|
||||
address->s_addr = raw_address;
|
||||
(void) decode_unsigned16(&pdu[4], port);
|
||||
len = 6;
|
||||
}
|
||||
@@ -535,28 +537,33 @@ bool bvlc_create_bdt(
|
||||
struct in_addr dest_address;
|
||||
uint16_t dest_port;
|
||||
unsigned i = 0;
|
||||
uint32_t raw_address = 0;
|
||||
|
||||
for (i = 0; i < MAX_BBMD_ENTRIES; i++) {
|
||||
if (npdu_length >= 10) {
|
||||
BBMD_Table[i].valid = true;
|
||||
decode_unsigned32(&pdu[0], &dest_address.s_addr);
|
||||
decode_unsigned32(&npdu[0], &raw_address);
|
||||
dest_address.s_addr = raw_address;
|
||||
BBMD_Table[i].dest_address.s_addr = ntohl(dest_address.s_addr);
|
||||
decode_unsigned16(&pdu[4], &dest_port);
|
||||
decode_unsigned16(&npdu[4], &dest_port);
|
||||
BBMD_Table[i].dest_port = ntohs(dest_port);
|
||||
decode_unsigned32(&pdu[6], &dest_address.s_addr);
|
||||
decode_unsigned32(&npdu[6], &raw_address);
|
||||
dest_address.s_addr = raw_address;
|
||||
BBMD_Table[i].broadcast_mask.s_addr = ntohl(dest_address.s_addr);
|
||||
npdu_length -= 10;
|
||||
} else {
|
||||
BBMD_Table[i].valid = false;
|
||||
BBMD_Table[i].dest_address.s_addr = 0;
|
||||
BBMD_Table[i].dest_port = 0;
|
||||
BBMD_Table[i].broadcast_mask = 0;
|
||||
BBMD_Table[i].broadcast_mask.s_addr = 0;
|
||||
}
|
||||
}
|
||||
/* did they all fit? */
|
||||
if (npdu_length < 10) {
|
||||
status = true;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool bvlc_register_foreign_device(
|
||||
@@ -597,11 +604,12 @@ bool bvlc_register_foreign_device(
|
||||
|
||||
bool bvlc_delete_foreign_device(uint8_t * pdu)
|
||||
{
|
||||
struct sockaddr_in sin; /* the ip address */
|
||||
uint16_t port; /* the decoded port */
|
||||
struct sockaddr_in sin = {0}; /* the ip address */
|
||||
uint16_t port = 0; /* the decoded port */
|
||||
bool status = false; /* return value */
|
||||
unsigned i = 0;
|
||||
|
||||
bvlc_decode_bip_address(pdu, &sin, &port);
|
||||
bvlc_decode_bip_address(pdu, &sin.sin_addr, &port);
|
||||
for (i = 0; i < MAX_FD_ENTRIES; i++) {
|
||||
if (FD_Table[i].valid) {
|
||||
if ((FD_Table[i].dest_address.s_addr == sin.sin_addr.s_addr) &&
|
||||
@@ -653,12 +661,12 @@ void bvlc_bdt_forward_npdu(
|
||||
bip_dest.sin_port = htons(BBMD_Table[i].dest_port);
|
||||
/* don't send to my broadcast address and same port */
|
||||
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr())) &&
|
||||
(bip_dest.sin_port == htons(bip_get_port))) {
|
||||
(bip_dest.sin_port == htons(bip_get_port()))) {
|
||||
continue;
|
||||
}
|
||||
/* don't send to my ip address and same port */
|
||||
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_addr())) &&
|
||||
(bip_dest.sin_port == htons(bip_get_port))) {
|
||||
(bip_dest.sin_port == htons(bip_get_port()))) {
|
||||
continue;
|
||||
}
|
||||
/* Send the packet */
|
||||
@@ -672,6 +680,14 @@ void bvlc_bdt_forward_npdu(
|
||||
return;
|
||||
}
|
||||
|
||||
void bvlc_broadcast_forward_npdu(
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t npdu_len) /* amount of space available in the NPDU */
|
||||
{
|
||||
/* FIXME: write the code... */
|
||||
}
|
||||
|
||||
void bvlc_fdt_forward_npdu(
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
@@ -693,7 +709,7 @@ void bvlc_fdt_forward_npdu(
|
||||
&mtu[0],
|
||||
&src,
|
||||
npdu,
|
||||
npdu_length);
|
||||
max_npdu);
|
||||
/* load destination IP address */
|
||||
bvlc_dest.sin_family = AF_INET;
|
||||
/* loop through the FDT and send one to each entry */
|
||||
@@ -719,9 +735,7 @@ void bvlc_send_mpdu(
|
||||
uint16_t mtu_len) /* amount of data to send */
|
||||
{
|
||||
int bytes_sent = 0;
|
||||
unsigned i = 0; /* loop counter */
|
||||
struct sockaddr_in bvlc_dest;
|
||||
BACNET_ADDRESS src;
|
||||
|
||||
/* assumes that the driver has already been initialized */
|
||||
if (bip_socket() < 0) {
|
||||
@@ -760,7 +774,7 @@ int bvlc_send_bdt(struct sockaddr_in *dest)
|
||||
|
||||
mtu_len = bvlc_encode_read_bdt_ack(&mtu[0], sizeof(mtu));
|
||||
if (mtu_len) {
|
||||
bvlc_send_mpdu(&sin, &mtu[0], mtu_len);
|
||||
bvlc_send_mpdu(dest, &mtu[0], mtu_len);
|
||||
}
|
||||
|
||||
return mtu_len;
|
||||
@@ -800,7 +814,7 @@ uint16_t bvlc_receive(
|
||||
uint16_t max_npdu, /* amount of space available in the NPDU */
|
||||
unsigned timeout) /* number of milliseconds to wait for a packet */
|
||||
{
|
||||
uint16_t pdu_len = 0; /* return value */
|
||||
uint16_t npdu_len = 0; /* return value */
|
||||
fd_set read_fds;
|
||||
int max = 0;
|
||||
struct timeval select_timeout;
|
||||
@@ -852,7 +866,7 @@ uint16_t bvlc_receive(
|
||||
return 0;
|
||||
}
|
||||
/* the signature of a BACnet/IP packet */
|
||||
if (buf[0] != BVLL_TYPE_BACNET_IP) {
|
||||
if (npdu[0] != BVLL_TYPE_BACNET_IP) {
|
||||
return 0;
|
||||
}
|
||||
function_type = npdu[1];
|
||||
@@ -1068,25 +1082,26 @@ int bvlc_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
int bytes_sent = 0;
|
||||
uint32_t raw_address = 0;
|
||||
|
||||
/* bip datalink doesn't need to know the npdu data */
|
||||
(void) npdu_data;
|
||||
/* assumes that the driver has already been initialized */
|
||||
if (BIP_Socket < 0)
|
||||
return BIP_Socket;
|
||||
if (bip_socket() < 0)
|
||||
return bip_socket();
|
||||
|
||||
mtu[0] = BVLL_TYPE_BACNET_IP;
|
||||
bvlc_dest.sin_family = AF_INET;
|
||||
if (dest->net == BACNET_BROADCAST_NETWORK) {
|
||||
/* broadcast */
|
||||
bvlc_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr);
|
||||
bvlc_dest.sin_port = htons(BIP_Port);
|
||||
bvlc_dest.sin_addr.s_addr = bip_get_broadcast_addr();
|
||||
bvlc_dest.sin_port = bip_get_port();
|
||||
memset(&(bvlc_dest.sin_zero), '\0', 8);
|
||||
mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
|
||||
} else if (dest->mac_len == 6) {
|
||||
/* valid unicast */
|
||||
(void) decode_unsigned32(&dest->mac[0],
|
||||
&(bvlc_dest.sin_addr.s_addr));
|
||||
(void) decode_unsigned32(&dest->mac[0], &raw_address);
|
||||
bvlc_dest.sin_addr.s_addr = raw_address;
|
||||
(void) decode_unsigned16(&dest->mac[4], &(bvlc_dest.sin_port));
|
||||
memset(&(bvlc_dest.sin_zero), '\0', 8);
|
||||
mtu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
||||
@@ -1103,7 +1118,7 @@ int bvlc_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
mtu_len += pdu_len;
|
||||
|
||||
/* Send the packet */
|
||||
bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0,
|
||||
bytes_sent = sendto(bip_socket(), (char *) mtu, mtu_len, 0,
|
||||
(struct sockaddr *) &bvlc_dest, sizeof(struct sockaddr));
|
||||
|
||||
return bytes_sent;
|
||||
|
||||
Reference in New Issue
Block a user