converted C++ comments using script
This commit is contained in:
@@ -152,7 +152,7 @@ void handler_get_alarm_summary(
|
|||||||
pdu_len);
|
pdu_len);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
if (bytes_sent <= 0) {
|
if (bytes_sent <= 0) {
|
||||||
//fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
/*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
bytes_sent = bytes_sent;
|
bytes_sent = bytes_sent;
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
|||||||
#include "bacint.h"
|
#include "bacint.h"
|
||||||
|
|
||||||
#ifdef TEST_PACKET
|
#ifdef TEST_PACKET
|
||||||
uint8_t test_packet[]={0x81, 0x0a, 0x00, 0x16, // BVLC header
|
uint8_t test_packet[]={0x81, 0x0a, 0x00, 0x16, /* BVLC header */
|
||||||
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, // NPDU
|
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */
|
||||||
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55}; // APDU
|
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55}; /* APDU */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int get_local_address_ioctl(
|
extern int get_local_address_ioctl(
|
||||||
@@ -36,18 +36,18 @@ void* dl_ip_thread(void *pArgs) {
|
|||||||
BACMSG msg_storage, *bacmsg = NULL;
|
BACMSG msg_storage, *bacmsg = NULL;
|
||||||
MSG_DATA *msg_data;
|
MSG_DATA *msg_data;
|
||||||
ROUTER_PORT *port = (ROUTER_PORT*)pArgs;
|
ROUTER_PORT *port = (ROUTER_PORT*)pArgs;
|
||||||
IP_DATA ip_data; // port specific parameters
|
IP_DATA ip_data; /* port specific parameters */
|
||||||
BACNET_ADDRESS address = { 0 };
|
BACNET_ADDRESS address = { 0 };
|
||||||
int status;
|
int status;
|
||||||
uint8_t shutdown = 0;
|
uint8_t shutdown = 0;
|
||||||
|
|
||||||
// initialize router port
|
/* initialize router port */
|
||||||
if (!dl_ip_init(port, &ip_data)) {
|
if (!dl_ip_init(port, &ip_data)) {
|
||||||
port->state = INIT_FAILED;
|
port->state = INIT_FAILED;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate buffer
|
/* allocate buffer */
|
||||||
ip_data.max_buff = MAX_BIP_MPDU;
|
ip_data.max_buff = MAX_BIP_MPDU;
|
||||||
ip_data.buff = (uint8_t*)malloc(ip_data.max_buff);
|
ip_data.buff = (uint8_t*)malloc(ip_data.max_buff);
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ void* dl_ip_thread(void *pArgs) {
|
|||||||
|
|
||||||
while (!shutdown) {
|
while (!shutdown) {
|
||||||
|
|
||||||
// check for incoming messages
|
/* check for incoming messages */
|
||||||
bacmsg = recv_from_msgbox(port->port_id, &msg_storage);
|
bacmsg = recv_from_msgbox(port->port_id, &msg_storage);
|
||||||
|
|
||||||
if (bacmsg) {
|
if (bacmsg) {
|
||||||
@@ -117,7 +117,7 @@ void* dl_ip_thread(void *pArgs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup procedure
|
/* cleanup procedure */
|
||||||
dl_ip_cleanup(&ip_data);
|
dl_ip_cleanup(&ip_data);
|
||||||
port->state = FINISHED;
|
port->state = FINISHED;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -127,17 +127,17 @@ bool dl_ip_init(ROUTER_PORT *port,
|
|||||||
IP_DATA *ip_data) {
|
IP_DATA *ip_data) {
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int socket_opt = 0;
|
int socket_opt = 0;
|
||||||
int status = 0; // for error checking
|
int status = 0; /* for error checking */
|
||||||
|
|
||||||
// setup port for later use
|
/* setup port for later use */
|
||||||
ip_data->port = htons(port->params.bip_params.port);
|
ip_data->port = htons(port->params.bip_params.port);
|
||||||
|
|
||||||
// get local address
|
/* get local address */
|
||||||
status = get_local_address_ioctl(port->iface, &ip_data->local_addr, SIOCGIFADDR);
|
status = get_local_address_ioctl(port->iface, &ip_data->local_addr, SIOCGIFADDR);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// get broadcast address
|
/* get broadcast address */
|
||||||
status = get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, SIOCGIFBRDADDR);
|
status = get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, SIOCGIFBRDADDR);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -147,7 +147,7 @@ bool dl_ip_init(ROUTER_PORT *port,
|
|||||||
if (ip_data->socket < 0)
|
if (ip_data->socket < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// setup socket options
|
/* setup socket options */
|
||||||
|
|
||||||
socket_opt = 1;
|
socket_opt = 1;
|
||||||
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, sizeof(socket_opt));
|
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, sizeof(socket_opt));
|
||||||
@@ -162,7 +162,7 @@ bool dl_ip_init(ROUTER_PORT *port,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind the socket to the local port number
|
/* bind the socket to the local port number */
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
sin.sin_port = ip_data->port;
|
sin.sin_port = ip_data->port;
|
||||||
@@ -175,7 +175,7 @@ bool dl_ip_init(ROUTER_PORT *port,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add BIP address to router port structure
|
/* add BIP address to router port structure */
|
||||||
memcpy(&port->route_info.mac[0], &ip_data->local_addr.s_addr, 4);
|
memcpy(&port->route_info.mac[0], &ip_data->local_addr.s_addr, 4);
|
||||||
memcpy(&port->route_info.mac[4], &port->params.bip_params.port, 2);
|
memcpy(&port->route_info.mac[4], &port->params.bip_params.port, 2);
|
||||||
port->route_info.mac_len = 6;
|
port->route_info.mac_len = 6;
|
||||||
@@ -204,7 +204,7 @@ int dl_ip_send(IP_DATA *data,
|
|||||||
data->buff[0] = BVLL_TYPE_BACNET_IP;
|
data->buff[0] = BVLL_TYPE_BACNET_IP;
|
||||||
bip_dest.sin_family = AF_INET;
|
bip_dest.sin_family = AF_INET;
|
||||||
if (dest->net == BACNET_BROADCAST_NETWORK) {
|
if (dest->net == BACNET_BROADCAST_NETWORK) {
|
||||||
// broadcast
|
/* broadcast */
|
||||||
bip_dest.sin_addr.s_addr = data->broadcast_addr.s_addr;
|
bip_dest.sin_addr.s_addr = data->broadcast_addr.s_addr;
|
||||||
bip_dest.sin_port = data->port;
|
bip_dest.sin_port = data->port;
|
||||||
data->buff[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
|
data->buff[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
|
||||||
@@ -213,7 +213,7 @@ int dl_ip_send(IP_DATA *data,
|
|||||||
memcpy(&bip_dest.sin_port, &dest->mac[4], 2);
|
memcpy(&bip_dest.sin_port, &dest->mac[4], 2);
|
||||||
data->buff[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
data->buff[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
||||||
} else {
|
} else {
|
||||||
// invalid address
|
/* invalid address */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ int dl_ip_send(IP_DATA *data,
|
|||||||
memcpy(&data->buff[buff_len], pdu, pdu_len);
|
memcpy(&data->buff[buff_len], pdu, pdu_len);
|
||||||
buff_len += pdu_len;
|
buff_len += pdu_len;
|
||||||
|
|
||||||
// send the packet
|
/* send the packet */
|
||||||
bytes_sent =
|
bytes_sent =
|
||||||
sendto(data->socket, (char *) data->buff, buff_len, 0,
|
sendto(data->socket, (char *) data->buff, buff_len, 0,
|
||||||
(struct sockaddr *) &bip_dest, sizeof(struct sockaddr));
|
(struct sockaddr *) &bip_dest, sizeof(struct sockaddr));
|
||||||
@@ -241,13 +241,13 @@ int dl_ip_recv(
|
|||||||
unsigned timeout)
|
unsigned timeout)
|
||||||
{
|
{
|
||||||
int received_bytes = 0;
|
int received_bytes = 0;
|
||||||
uint16_t buff_len = 0; // return value
|
uint16_t buff_len = 0; /* return value */
|
||||||
fd_set read_fds;
|
fd_set read_fds;
|
||||||
struct timeval select_timeout;
|
struct timeval select_timeout;
|
||||||
struct sockaddr_in sin = { 0 };
|
struct sockaddr_in sin = { 0 };
|
||||||
socklen_t sin_len = sizeof(sin);
|
socklen_t sin_len = sizeof(sin);
|
||||||
|
|
||||||
// make sure the socket is open
|
/* make sure the socket is open */
|
||||||
if (data->socket < 0)
|
if (data->socket < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ int dl_ip_recv(
|
|||||||
sin.sin_addr.s_addr = 0x7E1D40A; sin.sin_port = 0xC0BA;
|
sin.sin_addr.s_addr = 0x7E1D40A; sin.sin_port = 0xC0BA;
|
||||||
#else
|
#else
|
||||||
int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout);
|
int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout);
|
||||||
// see if there is a packet for us
|
/* see if there is a packet for us */
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
received_bytes =
|
received_bytes =
|
||||||
recvfrom(data->socket, (char *) &data->buff[0], data->max_buff, 0,
|
recvfrom(data->socket, (char *) &data->buff[0], data->max_buff, 0,
|
||||||
@@ -278,12 +278,12 @@ int dl_ip_recv(
|
|||||||
#endif
|
#endif
|
||||||
PRINT(DEBUG, "received from %s\n", inet_ntoa(sin.sin_addr));
|
PRINT(DEBUG, "received from %s\n", inet_ntoa(sin.sin_addr));
|
||||||
|
|
||||||
// check for errors
|
/* check for errors */
|
||||||
if (received_bytes <= 0) {
|
if (received_bytes <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the signature of a BACnet/IP packet
|
/* the signature of a BACnet/IP packet */
|
||||||
if (data->buff[0] != BVLL_TYPE_BACNET_IP)
|
if (data->buff[0] != BVLL_TYPE_BACNET_IP)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -302,18 +302,18 @@ int dl_ip_recv(
|
|||||||
memcpy(&src->mac[4], &sin.sin_port, 2);
|
memcpy(&src->mac[4], &sin.sin_port, 2);
|
||||||
|
|
||||||
(void) decode_unsigned16(&data->buff[2], &buff_len);
|
(void) decode_unsigned16(&data->buff[2], &buff_len);
|
||||||
// subtract off the BVLC header
|
/* subtract off the BVLC header */
|
||||||
buff_len -= 4;
|
buff_len -= 4;
|
||||||
if (buff_len < data->max_buff) {
|
if (buff_len < data->max_buff) {
|
||||||
// allocate data message stucture
|
/* allocate data message stucture */
|
||||||
(*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA));
|
(*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA));
|
||||||
(*msg_data)->pdu_len = buff_len;
|
(*msg_data)->pdu_len = buff_len;
|
||||||
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len);
|
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len);
|
||||||
// fill up data message structure
|
/* fill up data message structure */
|
||||||
memmove(&(*msg_data)->pdu[0], &data->buff[4], (*msg_data)->pdu_len);
|
memmove(&(*msg_data)->pdu[0], &data->buff[4], (*msg_data)->pdu_len);
|
||||||
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
||||||
}
|
}
|
||||||
// ignore packets that are too large
|
/* ignore packets that are too large */
|
||||||
else {
|
else {
|
||||||
buff_len = 0;
|
buff_len = 0;
|
||||||
|
|
||||||
@@ -336,18 +336,18 @@ int dl_ip_recv(
|
|||||||
memcpy(&src->mac[4], &sin.sin_port, 2);
|
memcpy(&src->mac[4], &sin.sin_port, 2);
|
||||||
|
|
||||||
(void) decode_unsigned16(&data->buff[2], &buff_len);
|
(void) decode_unsigned16(&data->buff[2], &buff_len);
|
||||||
// subtract off the BVLC header
|
/* subtract off the BVLC header */
|
||||||
buff_len -= 10;
|
buff_len -= 10;
|
||||||
if (buff_len < data->max_buff) {
|
if (buff_len < data->max_buff) {
|
||||||
// allocate data message stucture
|
/* allocate data message stucture */
|
||||||
(*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA));
|
(*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA));
|
||||||
(*msg_data)->pdu_len = buff_len;
|
(*msg_data)->pdu_len = buff_len;
|
||||||
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len);
|
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len);
|
||||||
// fill up data message structure
|
/* fill up data message structure */
|
||||||
memmove(&(*msg_data)->pdu, &data->buff[4+6], (*msg_data)->pdu_len);
|
memmove(&(*msg_data)->pdu, &data->buff[4+6], (*msg_data)->pdu_len);
|
||||||
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
||||||
} else {
|
} else {
|
||||||
// ignore packets that are too large
|
/* ignore packets that are too large */
|
||||||
buff_len = 0;
|
buff_len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,10 +364,10 @@ int dl_ip_recv(
|
|||||||
|
|
||||||
void dl_ip_cleanup(
|
void dl_ip_cleanup(
|
||||||
IP_DATA *ip_data) {
|
IP_DATA *ip_data) {
|
||||||
// free buffer
|
/* free buffer */
|
||||||
if (ip_data->buff)
|
if (ip_data->buff)
|
||||||
free(ip_data->buff);
|
free(ip_data->buff);
|
||||||
// close socket
|
/* close socket */
|
||||||
if (ip_data->socket > 0)
|
if (ip_data->socket > 0)
|
||||||
close(ip_data->socket);
|
close(ip_data->socket);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ int dl_ip_send(
|
|||||||
|
|
||||||
int dl_ip_recv(
|
int dl_ip_recv(
|
||||||
IP_DATA *data,
|
IP_DATA *data,
|
||||||
MSG_DATA **msg, // on recieve fill up message
|
MSG_DATA **msg, /* on recieve fill up message */
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS *src,
|
||||||
unsigned timeout);
|
unsigned timeout);
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h> // for time
|
#include <time.h> /* for time */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libconfig.h> // read config files
|
#include <libconfig.h> /* read config files */
|
||||||
#include <unistd.h> // for getopt
|
#include <unistd.h> /* for getopt */
|
||||||
#include <termios.h> // used in kbhit()
|
#include <termios.h> /* used in kbhit() */
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
@@ -42,7 +42,7 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
|||||||
|
|
||||||
#define KEY_ESC 27
|
#define KEY_ESC 27
|
||||||
|
|
||||||
ROUTER_PORT *head = NULL; // pointer to list of router ports
|
ROUTER_PORT *head = NULL; /* pointer to list of router ports */
|
||||||
|
|
||||||
int port_count;
|
int port_count;
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ int main(
|
|||||||
{
|
{
|
||||||
MSGBOX_ID msg_src = bacmsg->origin;
|
MSGBOX_ID msg_src = bacmsg->origin;
|
||||||
|
|
||||||
// allocate message structure
|
/* allocate message structure */
|
||||||
msg_data = malloc(sizeof(MSG_DATA));
|
msg_data = malloc(sizeof(MSG_DATA));
|
||||||
if (!msg_data) {
|
if (!msg_data) {
|
||||||
PRINT(ERROR, "Error: Could not allocate memory\n");
|
PRINT(ERROR, "Error: Could not allocate memory\n");
|
||||||
@@ -141,13 +141,13 @@ int main(
|
|||||||
buff_len = process_msg(bacmsg, msg_data, &buff);
|
buff_len = process_msg(bacmsg, msg_data, &buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if buff_len
|
/* if buff_len */
|
||||||
// >0 - form new message and send
|
/* >0 - form new message and send */
|
||||||
// =-1 - try to find next router
|
/* =-1 - try to find next router */
|
||||||
// other value - discard message
|
/* other value - discard message */
|
||||||
|
|
||||||
if (buff_len > 0) {
|
if (buff_len > 0) {
|
||||||
// form new message
|
/* form new message */
|
||||||
msg_data->pdu = buff;
|
msg_data->pdu = buff;
|
||||||
msg_data->pdu_len = buff_len;
|
msg_data->pdu_len = buff_len;
|
||||||
msg_storage.origin = head->main_id;
|
msg_storage.origin = head->main_id;
|
||||||
@@ -176,11 +176,11 @@ int main(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (buff_len == -1) {
|
} else if (buff_len == -1) {
|
||||||
uint16_t net = msg_data->dest.net; // NET to find
|
uint16_t net = msg_data->dest.net; /* NET to find */
|
||||||
PRINT(INFO, "Searching NET...\n");
|
PRINT(INFO, "Searching NET...\n");
|
||||||
send_network_message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, msg_data, &buff, &net);
|
send_network_message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, msg_data, &buff, &net);
|
||||||
} else {
|
} else {
|
||||||
// if invalid message send Reject-Message-To-Network
|
/* if invalid message send Reject-Message-To-Network */
|
||||||
PRINT(ERROR, "Error: Invalid message\n");
|
PRINT(ERROR, "Error: Invalid message\n");
|
||||||
free_data(msg_data);
|
free_data(msg_data);
|
||||||
}
|
}
|
||||||
@@ -223,20 +223,20 @@ bool read_config(
|
|||||||
|
|
||||||
config_init(&cfg);
|
config_init(&cfg);
|
||||||
|
|
||||||
// open configuration file
|
/* open configuration file */
|
||||||
if (!config_read_file(&cfg, filepath)) {
|
if (!config_read_file(&cfg, filepath)) {
|
||||||
PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), config_error_text(&cfg));
|
PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), config_error_text(&cfg));
|
||||||
config_destroy(&cfg);
|
config_destroy(&cfg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get router "port" count
|
/* get router "port" count */
|
||||||
setting = config_lookup(&cfg, "ports");
|
setting = config_lookup(&cfg, "ports");
|
||||||
if (setting != NULL) {
|
if (setting != NULL) {
|
||||||
int count = config_setting_length(setting);
|
int count = config_setting_length(setting);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// lookup and initialize router "port" parameters
|
/* lookup and initialize router "port" parameters */
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
const char *dev_type;
|
const char *dev_type;
|
||||||
const char *iface;
|
const char *iface;
|
||||||
@@ -244,7 +244,7 @@ bool read_config(
|
|||||||
const char *str_param;
|
const char *str_param;
|
||||||
config_setting_t *port = config_setting_get_elem(setting, i);
|
config_setting_t *port = config_setting_get_elem(setting, i);
|
||||||
|
|
||||||
// create new list node to store port information
|
/* create new list node to store port information */
|
||||||
if (head == NULL) {
|
if (head == NULL) {
|
||||||
head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT));
|
head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT));
|
||||||
head->next = NULL;
|
head->next = NULL;
|
||||||
@@ -268,7 +268,7 @@ bool read_config(
|
|||||||
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char));
|
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char));
|
||||||
strcpy(current->iface, iface);
|
strcpy(current->iface, iface);
|
||||||
|
|
||||||
// check if interface is valid
|
/* check if interface is valid */
|
||||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd) {
|
if (fd) {
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
@@ -306,7 +306,7 @@ bool read_config(
|
|||||||
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char));
|
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char));
|
||||||
strcpy(current->iface, iface);
|
strcpy(current->iface, iface);
|
||||||
|
|
||||||
// check if interface is valid
|
/* check if interface is valid */
|
||||||
fd = open(current->iface, O_NOCTTY | O_NONBLOCK);
|
fd = open(current->iface, O_NOCTTY | O_NONBLOCK);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -421,7 +421,7 @@ bool parse_cmd(
|
|||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
print_help();
|
print_help();
|
||||||
|
|
||||||
// begin checking cmd parameters
|
/* begin checking cmd parameters */
|
||||||
opt = getopt_long(argc, argv, optString, Options, &index);
|
opt = getopt_long(argc, argv, optString, Options, &index);
|
||||||
printf("opt = %c\r\n", opt);
|
printf("opt = %c\r\n", opt);
|
||||||
while (opt != -1) {
|
while (opt != -1) {
|
||||||
@@ -435,7 +435,7 @@ bool parse_cmd(
|
|||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
|
|
||||||
// create new list node to store port information
|
/* create new list node to store port information */
|
||||||
if (head == NULL) {
|
if (head == NULL) {
|
||||||
head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT));
|
head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT));
|
||||||
head->next = NULL;
|
head->next = NULL;
|
||||||
@@ -458,11 +458,11 @@ bool parse_cmd(
|
|||||||
current->iface = "eth0";
|
current->iface = "eth0";
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup default parameters
|
/* setup default parameters */
|
||||||
current->params.bip_params.port = 0xBAC0; // 47808
|
current->params.bip_params.port = 0xBAC0; /* 47808 */
|
||||||
current->route_info.net = get_next_free_dnet();
|
current->route_info.net = get_next_free_dnet();
|
||||||
|
|
||||||
// check if interface is valid
|
/* check if interface is valid */
|
||||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd) {
|
if (fd) {
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
@@ -484,7 +484,7 @@ bool parse_cmd(
|
|||||||
if (result) {
|
if (result) {
|
||||||
current->params.bip_params.port = (uint16_t)result;
|
current->params.bip_params.port = (uint16_t)result;
|
||||||
} else {
|
} else {
|
||||||
current->params.bip_params.port = 0xBAC0; // 47808
|
current->params.bip_params.port = 0xBAC0; /* 47808 */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
@@ -508,7 +508,7 @@ bool parse_cmd(
|
|||||||
current->iface = "/dev/ttyS0";
|
current->iface = "/dev/ttyS0";
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if interface is valid
|
/* check if interface is valid */
|
||||||
fd = open(current->iface, O_NOCTTY | O_NONBLOCK);
|
fd = open(current->iface, O_NOCTTY | O_NONBLOCK);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -517,7 +517,7 @@ bool parse_cmd(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup default parameters
|
/* setup default parameters */
|
||||||
current->route_info.mac[0] = 127;
|
current->route_info.mac[0] = 127;
|
||||||
current->route_info.mac_len = 1;
|
current->route_info.mac_len = 1;
|
||||||
current->params.mstp_params.max_master = 127;
|
current->params.mstp_params.max_master = 127;
|
||||||
@@ -619,7 +619,7 @@ void init_port_threads(
|
|||||||
port->func,
|
port->func,
|
||||||
port);
|
port);
|
||||||
|
|
||||||
pthread_detach(*thread); // for proper thread termination
|
pthread_detach(*thread); /* for proper thread termination */
|
||||||
|
|
||||||
port = port->next;
|
port = port->next;
|
||||||
}
|
}
|
||||||
@@ -634,7 +634,7 @@ bool init_router() {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
port = head;
|
port = head;
|
||||||
// add main message box id to all ports
|
/* add main message box id to all ports */
|
||||||
while (port != NULL) {
|
while (port != NULL) {
|
||||||
port->main_id = msgboxid;
|
port->main_id = msgboxid;
|
||||||
port = port->next;
|
port = port->next;
|
||||||
@@ -642,7 +642,7 @@ bool init_router() {
|
|||||||
|
|
||||||
init_port_threads(head);
|
init_port_threads(head);
|
||||||
|
|
||||||
// wait for port initialization
|
/* wait for port initialization */
|
||||||
port = head;
|
port = head;
|
||||||
while (port != NULL) {
|
while (port != NULL) {
|
||||||
if (port->state == RUNNING) {
|
if (port->state == RUNNING) {
|
||||||
@@ -672,9 +672,9 @@ void cleanup() {
|
|||||||
msg.type = SERVICE;
|
msg.type = SERVICE;
|
||||||
msg.subtype = SHUTDOWN;
|
msg.subtype = SHUTDOWN;
|
||||||
|
|
||||||
del_msgbox(head->main_id); // close routers message box
|
del_msgbox(head->main_id); /* close routers message box */
|
||||||
|
|
||||||
// send shutdown message to all router ports
|
/* send shutdown message to all router ports */
|
||||||
port = head;
|
port = head;
|
||||||
while (port != NULL) {
|
while (port != NULL) {
|
||||||
if (port->state == RUNNING)
|
if (port->state == RUNNING)
|
||||||
@@ -736,11 +736,11 @@ uint16_t process_msg(BACMSG *msg,
|
|||||||
if (srcport && destport) {
|
if (srcport && destport) {
|
||||||
data->src.net = srcport->route_info.net;
|
data->src.net = srcport->route_info.net;
|
||||||
|
|
||||||
// if received from another router save real source address (not other router source address)
|
/* if received from another router save real source address (not other router source address) */
|
||||||
if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && data->src.net != addr.net)
|
if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && data->src.net != addr.net)
|
||||||
memmove(&data->src, &addr, sizeof(BACNET_ADDRESS));
|
memmove(&data->src, &addr, sizeof(BACNET_ADDRESS));
|
||||||
|
|
||||||
// encode both source and destination for broadcast and router-to-router communication
|
/* encode both source and destination for broadcast and router-to-router communication */
|
||||||
if (data->dest.net == BACNET_BROADCAST_NETWORK || destport->route_info.net != data->dest.net) {
|
if (data->dest.net == BACNET_BROADCAST_NETWORK || destport->route_info.net != data->dest.net) {
|
||||||
npdu_len = npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data);
|
npdu_len = npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data);
|
||||||
}
|
}
|
||||||
@@ -751,15 +751,15 @@ uint16_t process_msg(BACMSG *msg,
|
|||||||
buff_len = npdu_len + data->pdu_len - apdu_offset;
|
buff_len = npdu_len + data->pdu_len - apdu_offset;
|
||||||
|
|
||||||
*buff = (uint8_t*)malloc(buff_len);
|
*buff = (uint8_t*)malloc(buff_len);
|
||||||
memmove(*buff, npdu, npdu_len); // copy newly formed NPDU
|
memmove(*buff, npdu, npdu_len); /* copy newly formed NPDU */
|
||||||
memmove(*buff+npdu_len, &data->pdu[apdu_offset], apdu_len); // copy APDU
|
memmove(*buff+npdu_len, &data->pdu[apdu_offset], apdu_len); /* copy APDU */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// request net search
|
/* request net search */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete received message
|
/* delete received message */
|
||||||
free_data((MSG_DATA*)msg->data);
|
free_data((MSG_DATA*)msg->data);
|
||||||
|
|
||||||
return buff_len;
|
return buff_len;
|
||||||
@@ -771,7 +771,7 @@ int kbhit()
|
|||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
|
||||||
if (! initialized) {
|
if (! initialized) {
|
||||||
// use termios to turn off line buffering
|
/* use termios to turn off line buffering */
|
||||||
struct termios term;
|
struct termios term;
|
||||||
tcgetattr(STDIN, &term);
|
tcgetattr(STDIN, &term);
|
||||||
term.c_lflag &= ~ICANON;
|
term.c_lflag &= ~ICANON;
|
||||||
@@ -787,12 +787,12 @@ int kbhit()
|
|||||||
|
|
||||||
bool is_network_msg(BACMSG *msg) {
|
bool is_network_msg(BACMSG *msg) {
|
||||||
|
|
||||||
uint8_t control_byte; // NPDU control byte
|
uint8_t control_byte; /* NPDU control byte */
|
||||||
MSG_DATA *data = (MSG_DATA*)msg->data;
|
MSG_DATA *data = (MSG_DATA*)msg->data;
|
||||||
|
|
||||||
control_byte = data->pdu[1];
|
control_byte = data->pdu[1];
|
||||||
|
|
||||||
return control_byte & 0x80; // check 7th bit
|
return control_byte & 0x80; /* check 7th bit */
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t get_next_free_dnet() {
|
uint16_t get_next_free_dnet() {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ void free_data(
|
|||||||
void check_data(
|
void check_data(
|
||||||
MSG_DATA *data) {
|
MSG_DATA *data) {
|
||||||
|
|
||||||
// lock and decrement messages reference count
|
/* lock and decrement messages reference count */
|
||||||
pthread_mutex_lock(&msg_lock);
|
pthread_mutex_lock(&msg_lock);
|
||||||
if (--data->ref_count == 0) {
|
if (--data->ref_count == 0) {
|
||||||
free_data(data);
|
free_data(data);
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ typedef struct _message {
|
|||||||
MSGTYPE type;
|
MSGTYPE type;
|
||||||
MSGSUBTYPE subtype;
|
MSGSUBTYPE subtype;
|
||||||
void *data;
|
void *data;
|
||||||
// add timestamp
|
/* add timestamp */
|
||||||
} BACMSG;
|
} BACMSG;
|
||||||
|
|
||||||
// specific message type data structures
|
/* specific message type data structures */
|
||||||
typedef struct _msg_data {
|
typedef struct _msg_data {
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS src;
|
BACNET_ADDRESS src;
|
||||||
@@ -61,12 +61,12 @@ typedef struct _msg_data {
|
|||||||
|
|
||||||
MSGBOX_ID create_msgbox();
|
MSGBOX_ID create_msgbox();
|
||||||
|
|
||||||
// returns sent byte count
|
/* returns sent byte count */
|
||||||
bool send_to_msgbox(
|
bool send_to_msgbox(
|
||||||
MSGBOX_ID dest,
|
MSGBOX_ID dest,
|
||||||
BACMSG *msg);
|
BACMSG *msg);
|
||||||
|
|
||||||
// returns received message
|
/* returns received message */
|
||||||
BACMSG* recv_from_msgbox(
|
BACMSG* recv_from_msgbox(
|
||||||
MSGBOX_ID src,
|
MSGBOX_ID src,
|
||||||
BACMSG *msg);
|
BACMSG *msg);
|
||||||
@@ -74,11 +74,11 @@ BACMSG* recv_from_msgbox(
|
|||||||
void del_msgbox(
|
void del_msgbox(
|
||||||
MSGBOX_ID msgboxid);
|
MSGBOX_ID msgboxid);
|
||||||
|
|
||||||
// free message data structure
|
/* free message data structure */
|
||||||
void free_data(
|
void free_data(
|
||||||
MSG_DATA *data);
|
MSG_DATA *data);
|
||||||
|
|
||||||
// check message reference counter and delete data if needed
|
/* check message reference counter and delete data if needed */
|
||||||
void check_data(
|
void check_data(
|
||||||
MSG_DATA *data);
|
MSG_DATA *data);
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void* dl_mstp_thread(void* pArgs) {
|
|||||||
port->state = RUNNING;
|
port->state = RUNNING;
|
||||||
|
|
||||||
while (!shutdown) {
|
while (!shutdown) {
|
||||||
// message loop
|
/* message loop */
|
||||||
BACMSG msg_storage, * bacmsg;
|
BACMSG msg_storage, * bacmsg;
|
||||||
MSG_DATA * msg_data;
|
MSG_DATA * msg_data;
|
||||||
|
|
||||||
|
|||||||
@@ -47,25 +47,25 @@ uint16_t process_network_message(
|
|||||||
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
|
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
|
||||||
PRINT(INFO, "Recieved Who-Is-Router-To-Network message\n");
|
PRINT(INFO, "Recieved Who-Is-Router-To-Network message\n");
|
||||||
if (apdu_len) {
|
if (apdu_len) {
|
||||||
// if NET specified
|
/* if NET specified */
|
||||||
decode_unsigned16(&data->pdu[apdu_offset], &net);
|
decode_unsigned16(&data->pdu[apdu_offset], &net);
|
||||||
if (srcport->route_info.net == net) {
|
if (srcport->route_info.net == net) {
|
||||||
PRINT(INFO, "Message discarded: NET directly connected\n");
|
PRINT(INFO, "Message discarded: NET directly connected\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
destport = find_dnet(net, NULL); // see if NET can be reached
|
destport = find_dnet(net, NULL); /* see if NET can be reached */
|
||||||
if (destport) {
|
if (destport) {
|
||||||
// if TRUE send reply
|
/* if TRUE send reply */
|
||||||
PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
|
PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
|
||||||
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||||
data, buff, &net);
|
data, buff, &net);
|
||||||
} else {
|
} else {
|
||||||
data->dest.net = net; // NET to look for
|
data->dest.net = net; /* NET to look for */
|
||||||
return -1; // else initiate NET search procedure
|
return -1; /* else initiate NET search procedure */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if NET is omitted (message sent with -1)
|
/* if NET is omitted (message sent with -1) */
|
||||||
PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
|
PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
|
||||||
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||||
data, buff, NULL);
|
data, buff, NULL);
|
||||||
@@ -79,15 +79,15 @@ uint16_t process_network_message(
|
|||||||
int net_count = apdu_len / 2;
|
int net_count = apdu_len / 2;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < net_count; i++) {
|
for (i = 0; i < net_count; i++) {
|
||||||
decode_unsigned16(&data->pdu[apdu_offset+2*i], &net); // decode received NET values
|
decode_unsigned16(&data->pdu[apdu_offset+2*i], &net); /* decode received NET values */
|
||||||
add_dnet(&srcport->route_info, net, data->src); // and update routing table
|
add_dnet(&srcport->route_info, net, data->src); /* and update routing table */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
|
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
|
||||||
{
|
{
|
||||||
// first octet of the message contains rejection reason
|
/* first octet of the message contains rejection reason */
|
||||||
// next two octets contain NET (can be decoded for additional info on error)
|
/* next two octets contain NET (can be decoded for additional info on error) */
|
||||||
error_code = data->pdu[apdu_offset];
|
error_code = data->pdu[apdu_offset];
|
||||||
switch (error_code) {
|
switch (error_code) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -114,9 +114,9 @@ uint16_t process_network_message(
|
|||||||
int net_count = data->pdu[apdu_offset];
|
int net_count = data->pdu[apdu_offset];
|
||||||
while (net_count--) {
|
while (net_count--) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
decode_unsigned16(&data->pdu[apdu_offset+i], &net); // decode received NET values
|
decode_unsigned16(&data->pdu[apdu_offset+i], &net); /* decode received NET values */
|
||||||
add_dnet(&srcport->route_info, net, data->src); // and update routing table
|
add_dnet(&srcport->route_info, net, data->src); /* and update routing table */
|
||||||
if (data->pdu[apdu_offset+i+3] > 0) // find next NET value
|
if (data->pdu[apdu_offset+i+3] > 0) /* find next NET value */
|
||||||
i = data->pdu[apdu_offset+i+3] + 4;
|
i = data->pdu[apdu_offset+i+3] + 4;
|
||||||
else
|
else
|
||||||
i = i + 4;
|
i = i + 4;
|
||||||
@@ -132,9 +132,9 @@ uint16_t process_network_message(
|
|||||||
int net_count = data->pdu[apdu_offset];
|
int net_count = data->pdu[apdu_offset];
|
||||||
while (net_count--) {
|
while (net_count--) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
decode_unsigned16(&data->pdu[apdu_offset+i], &net); // decode received NET values
|
decode_unsigned16(&data->pdu[apdu_offset+i], &net); /* decode received NET values */
|
||||||
add_dnet(&srcport->route_info, net, data->src); // and update routing table
|
add_dnet(&srcport->route_info, net, data->src); /* and update routing table */
|
||||||
if (data->pdu[apdu_offset+i+3] > 0) // find next NET value
|
if (data->pdu[apdu_offset+i+3] > 0) /* find next NET value */
|
||||||
i = data->pdu[apdu_offset+i+3] + 4;
|
i = data->pdu[apdu_offset+i+3] + 4;
|
||||||
else
|
else
|
||||||
i = i + 4;
|
i = i + 4;
|
||||||
@@ -148,7 +148,7 @@ uint16_t process_network_message(
|
|||||||
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
||||||
case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK:
|
case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK:
|
||||||
case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK:
|
case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK:
|
||||||
// hell if I know what to do with these messages
|
/* hell if I know what to do with these messages */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -173,9 +173,9 @@ uint16_t create_network_message(
|
|||||||
data_expecting_reply = true;
|
data_expecting_reply = true;
|
||||||
init_npdu(&npdu_data, network_message_type, data_expecting_reply);
|
init_npdu(&npdu_data, network_message_type, data_expecting_reply);
|
||||||
|
|
||||||
*buff = (uint8_t*)malloc(128); // resolve different length
|
*buff = (uint8_t*)malloc(128); /* resolve different length */
|
||||||
|
|
||||||
// manual destination setup for Init-RT-Table-Ack message
|
/* manual destination setup for Init-RT-Table-Ack message */
|
||||||
data->dest.net = BACNET_BROADCAST_NETWORK;
|
data->dest.net = BACNET_BROADCAST_NETWORK;
|
||||||
buff_len = npdu_encode_pdu(*buff, &data->dest, NULL, &npdu_data);
|
buff_len = npdu_encode_pdu(*buff, &data->dest, NULL, &npdu_data);
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ uint16_t create_network_message(
|
|||||||
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
||||||
case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK:
|
case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK:
|
||||||
case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK:
|
case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK:
|
||||||
// hell if I know what to do with these messages
|
/* hell if I know what to do with these messages */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ void send_network_message(
|
|||||||
|
|
||||||
buff_len = create_network_message(network_message_type, data, buff, val);
|
buff_len = create_network_message(network_message_type, data, buff, val);
|
||||||
|
|
||||||
// form network message
|
/* form network message */
|
||||||
data->pdu = *buff;
|
data->pdu = *buff;
|
||||||
data->pdu_len = buff_len;
|
data->pdu_len = buff_len;
|
||||||
msg.origin = head->main_id;
|
msg.origin = head->main_id;
|
||||||
|
|||||||
@@ -40,17 +40,17 @@ ROUTER_PORT* find_dnet(
|
|||||||
ROUTER_PORT *port = head;
|
ROUTER_PORT *port = head;
|
||||||
DNET *dnet;
|
DNET *dnet;
|
||||||
|
|
||||||
// for broadcast messages no search is needed
|
/* for broadcast messages no search is needed */
|
||||||
if (net == BACNET_BROADCAST_NETWORK)
|
if (net == BACNET_BROADCAST_NETWORK)
|
||||||
return port;
|
return port;
|
||||||
|
|
||||||
while(port != NULL) {
|
while(port != NULL) {
|
||||||
|
|
||||||
// check if DNET is directly connected to the router
|
/* check if DNET is directly connected to the router */
|
||||||
if (net == port->route_info.net)
|
if (net == port->route_info.net)
|
||||||
return port;
|
return port;
|
||||||
|
|
||||||
// else search router ports DNET list
|
/* else search router ports DNET list */
|
||||||
else if (port->route_info.dnets) {
|
else if (port->route_info.dnets) {
|
||||||
dnet = port->route_info.dnets;
|
dnet = port->route_info.dnets;
|
||||||
while (dnet != NULL) {
|
while (dnet != NULL) {
|
||||||
@@ -88,7 +88,7 @@ void add_dnet(
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
while (dnet != NULL) {
|
while (dnet != NULL) {
|
||||||
if (dnet->net == net) // make sure NETs are not repeated
|
if (dnet->net == net) /* make sure NETs are not repeated */
|
||||||
return;
|
return;
|
||||||
tmp = dnet;
|
tmp = dnet;
|
||||||
dnet = dnet->next;
|
dnet = dnet->next;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ typedef enum {
|
|||||||
FINISHED
|
FINISHED
|
||||||
} PORT_STATE;
|
} PORT_STATE;
|
||||||
|
|
||||||
// router port thread function
|
/* router port thread function */
|
||||||
typedef void* (*PORT_FUNC)(
|
typedef void* (*PORT_FUNC)(
|
||||||
void*);
|
void*);
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ typedef enum {
|
|||||||
PARITY_ODD
|
PARITY_ODD
|
||||||
}PARITY;
|
}PARITY;
|
||||||
|
|
||||||
// port specific parameters
|
/* port specific parameters */
|
||||||
typedef union _port_params {
|
typedef union _port_params {
|
||||||
struct {
|
struct {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
@@ -72,16 +72,16 @@ typedef union _port_params {
|
|||||||
} mstp_params;
|
} mstp_params;
|
||||||
} PORT_PARAMS;
|
} PORT_PARAMS;
|
||||||
|
|
||||||
// list node for reacheble networks
|
/* list node for reacheble networks */
|
||||||
typedef struct _dnet {
|
typedef struct _dnet {
|
||||||
uint8_t mac[MAX_MAC_LEN];
|
uint8_t mac[MAX_MAC_LEN];
|
||||||
uint8_t mac_len;
|
uint8_t mac_len;
|
||||||
uint16_t net;
|
uint16_t net;
|
||||||
bool state; // enabled or disabled
|
bool state; /* enabled or disabled */
|
||||||
struct _dnet *next;
|
struct _dnet *next;
|
||||||
} DNET;
|
} DNET;
|
||||||
|
|
||||||
// information for routing table
|
/* information for routing table */
|
||||||
typedef struct _routing_table_entry {
|
typedef struct _routing_table_entry {
|
||||||
uint8_t mac[MAX_MAC_LEN];
|
uint8_t mac[MAX_MAC_LEN];
|
||||||
uint8_t mac_len;
|
uint8_t mac_len;
|
||||||
@@ -92,28 +92,28 @@ typedef struct _routing_table_entry {
|
|||||||
typedef struct _port {
|
typedef struct _port {
|
||||||
DL_TYPE type;
|
DL_TYPE type;
|
||||||
PORT_STATE state;
|
PORT_STATE state;
|
||||||
MSGBOX_ID main_id; // same for every router port
|
MSGBOX_ID main_id; /* same for every router port */
|
||||||
MSGBOX_ID port_id; // different for every router port
|
MSGBOX_ID port_id; /* different for every router port */
|
||||||
char *iface;
|
char *iface;
|
||||||
PORT_FUNC func;
|
PORT_FUNC func;
|
||||||
RT_ENTRY route_info;
|
RT_ENTRY route_info;
|
||||||
PORT_PARAMS params;
|
PORT_PARAMS params;
|
||||||
struct _port *next; // pointer to next list node
|
struct _port *next; /* pointer to next list node */
|
||||||
} ROUTER_PORT;
|
} ROUTER_PORT;
|
||||||
|
|
||||||
extern ROUTER_PORT *head;
|
extern ROUTER_PORT *head;
|
||||||
extern int port_count;
|
extern int port_count;
|
||||||
|
|
||||||
// get recieving router port
|
/* get recieving router port */
|
||||||
ROUTER_PORT* find_snet(
|
ROUTER_PORT* find_snet(
|
||||||
MSGBOX_ID id);
|
MSGBOX_ID id);
|
||||||
|
|
||||||
// get sending router port
|
/* get sending router port */
|
||||||
ROUTER_PORT* find_dnet(
|
ROUTER_PORT* find_dnet(
|
||||||
uint16_t net,
|
uint16_t net,
|
||||||
BACNET_ADDRESS *addr);
|
BACNET_ADDRESS *addr);
|
||||||
|
|
||||||
// add reacheble network for specified router port
|
/* add reacheble network for specified router port */
|
||||||
void add_dnet(
|
void add_dnet(
|
||||||
RT_ENTRY *route_info,
|
RT_ENTRY *route_info,
|
||||||
uint16_t net,
|
uint16_t net,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ uint32_t timeGetTime(
|
|||||||
struct timespec now;
|
struct timespec now;
|
||||||
uint32_t ticks;
|
uint32_t ticks;
|
||||||
|
|
||||||
// clock_gettime(CLOCK_MONOTONIC, &now);
|
/* clock_gettime(CLOCK_MONOTONIC, &now); */
|
||||||
clock_serv_t cclock;
|
clock_serv_t cclock;
|
||||||
mach_timespec_t mts;
|
mach_timespec_t mts;
|
||||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||||
@@ -145,7 +145,7 @@ uint32_t timer_reset(
|
|||||||
void timer_init(
|
void timer_init(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
//clock_gettime(CLOCK_MONOTONIC, &start);
|
/*clock_gettime(CLOCK_MONOTONIC, &start); */
|
||||||
clock_serv_t cclock;
|
clock_serv_t cclock;
|
||||||
mach_timespec_t mts;
|
mach_timespec_t mts;
|
||||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
#include "bacaddr.h"
|
#include "bacaddr.h"
|
||||||
#include "mstp.h"
|
#include "mstp.h"
|
||||||
//#include "dlmstp.h"
|
/*#include "dlmstp.h" */
|
||||||
#include "dlmstp_linux.h"
|
#include "dlmstp_linux.h"
|
||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
@@ -602,7 +602,7 @@ void dlmstp_set_mac_address(
|
|||||||
void * poPort,
|
void * poPort,
|
||||||
uint8_t mac_address)
|
uint8_t mac_address)
|
||||||
{
|
{
|
||||||
// SHARED_MSTP_DATA * poSharedData;
|
/* SHARED_MSTP_DATA * poSharedData; */
|
||||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||||
if(!mstp_port)
|
if(!mstp_port)
|
||||||
{
|
{
|
||||||
@@ -633,7 +633,7 @@ void dlmstp_set_mac_address(
|
|||||||
uint8_t dlmstp_mac_address(
|
uint8_t dlmstp_mac_address(
|
||||||
void * poPort)
|
void * poPort)
|
||||||
{
|
{
|
||||||
// SHARED_MSTP_DATA * poSharedData;
|
/* SHARED_MSTP_DATA * poSharedData; */
|
||||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||||
if(!mstp_port)
|
if(!mstp_port)
|
||||||
{
|
{
|
||||||
@@ -660,7 +660,7 @@ void dlmstp_set_max_info_frames(
|
|||||||
void * poPort,
|
void * poPort,
|
||||||
uint8_t max_info_frames)
|
uint8_t max_info_frames)
|
||||||
{
|
{
|
||||||
// SHARED_MSTP_DATA * poSharedData;
|
/* SHARED_MSTP_DATA * poSharedData; */
|
||||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||||
if(!mstp_port)
|
if(!mstp_port)
|
||||||
{
|
{
|
||||||
@@ -688,7 +688,7 @@ void dlmstp_set_max_info_frames(
|
|||||||
uint8_t dlmstp_max_info_frames(
|
uint8_t dlmstp_max_info_frames(
|
||||||
void * poPort)
|
void * poPort)
|
||||||
{
|
{
|
||||||
// SHARED_MSTP_DATA * poSharedData;
|
/* SHARED_MSTP_DATA * poSharedData; */
|
||||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||||
if(!mstp_port)
|
if(!mstp_port)
|
||||||
{
|
{
|
||||||
@@ -713,7 +713,7 @@ void dlmstp_set_max_master(
|
|||||||
void * poPort,
|
void * poPort,
|
||||||
uint8_t max_master)
|
uint8_t max_master)
|
||||||
{
|
{
|
||||||
// SHARED_MSTP_DATA * poSharedData;
|
/* SHARED_MSTP_DATA * poSharedData; */
|
||||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||||
if(!mstp_port)
|
if(!mstp_port)
|
||||||
{
|
{
|
||||||
@@ -743,7 +743,7 @@ void dlmstp_set_max_master(
|
|||||||
uint8_t dlmstp_max_master(
|
uint8_t dlmstp_max_master(
|
||||||
void * poPort)
|
void * poPort)
|
||||||
{
|
{
|
||||||
// SHARED_MSTP_DATA * poSharedData;
|
/* SHARED_MSTP_DATA * poSharedData; */
|
||||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||||
if(!mstp_port)
|
if(!mstp_port)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#define DLMSTP_LINUX_H
|
#define DLMSTP_LINUX_H
|
||||||
|
|
||||||
#include "mstp.h"
|
#include "mstp.h"
|
||||||
//#include "dlmstp.h"
|
/*#include "dlmstp.h" */
|
||||||
#include "bits/pthreadtypes.h"
|
#include "bits/pthreadtypes.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user