Run clang-format and enable CI check for it (#755)
* pre-commit: Update and enable clang-format check There is newer version from clang-format so use that. We do not yet want 18 as that is little bit too new. * Format some thing by hand which clang-format "breaks" Clang-format will format some things little bit off in some cases. Format some things by hand so we get cleaner end result. * Run clang-format with ``` pre-commit run --all-files clang-format ``` We have already in previously checked places where clang-format does not make good format and ignored those (hopefully most of the things). --------- Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
+23
-14
@@ -17,9 +17,9 @@
|
||||
|
||||
#ifdef TEST_PACKET
|
||||
uint8_t test_packet[] = { 0x81, 0x0a, 0x00, 0x16, /* BVLC header */
|
||||
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */
|
||||
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19,
|
||||
0x55 }; /* APDU */
|
||||
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */
|
||||
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00,
|
||||
0x00, 0x02, 0x19, 0x55 }; /* APDU */
|
||||
#endif
|
||||
|
||||
void *dl_ip_thread(void *pArgs)
|
||||
@@ -146,14 +146,16 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
|
||||
/* setup socket options */
|
||||
|
||||
socket_opt = 1;
|
||||
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt,
|
||||
status = setsockopt(
|
||||
ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt,
|
||||
sizeof(socket_opt));
|
||||
if (status < 0) {
|
||||
close(ip_data->socket);
|
||||
return false;
|
||||
}
|
||||
|
||||
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt,
|
||||
status = setsockopt(
|
||||
ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt,
|
||||
sizeof(socket_opt));
|
||||
if (status < 0) {
|
||||
close(ip_data->socket);
|
||||
@@ -162,8 +164,9 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
|
||||
|
||||
/* Bind to device so we don't get routing loops between our
|
||||
different ports. */
|
||||
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
port->iface, strlen(port->iface));
|
||||
status = setsockopt(
|
||||
ip_data->socket, SOL_SOCKET, SO_BINDTODEVICE, port->iface,
|
||||
strlen(port->iface));
|
||||
if (status < 0) {
|
||||
close(ip_data->socket);
|
||||
return false;
|
||||
@@ -176,7 +179,8 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_port = ip_data->port;
|
||||
|
||||
status = bind(ip_data->socket, (const struct sockaddr *)&sin,
|
||||
status = bind(
|
||||
ip_data->socket, (const struct sockaddr *)&sin,
|
||||
sizeof(struct sockaddr));
|
||||
if (status < 0) {
|
||||
close(ip_data->socket);
|
||||
@@ -192,7 +196,8 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
|
||||
PRINT(INFO, "IP Address: %s\n", inet_ntoa(ip_data->local_addr));
|
||||
PRINT(
|
||||
INFO, "IP Broadcast Address: %s\n", inet_ntoa(ip_data->broadcast_addr));
|
||||
PRINT(INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port),
|
||||
PRINT(
|
||||
INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port),
|
||||
(port->params.bip_params.port));
|
||||
|
||||
return true;
|
||||
@@ -235,7 +240,8 @@ int dl_ip_send(
|
||||
buff_len += pdu_len;
|
||||
|
||||
/* send the packet */
|
||||
bytes_sent = sendto(data->socket, (char *)data->buff, buff_len, 0,
|
||||
bytes_sent = sendto(
|
||||
data->socket, (char *)data->buff, buff_len, 0,
|
||||
(struct sockaddr *)&bip_dest, sizeof(struct sockaddr));
|
||||
|
||||
PRINT(DEBUG, "send to %s\n", inet_ntoa(bip_dest.sin_addr));
|
||||
@@ -279,8 +285,9 @@ int dl_ip_recv(
|
||||
int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout);
|
||||
/* see if there is a packet for us */
|
||||
if (ret > 0) {
|
||||
received_bytes = recvfrom(data->socket, (char *)&data->buff[0],
|
||||
data->max_buff, 0, (struct sockaddr *)&sin, &sin_len);
|
||||
received_bytes = recvfrom(
|
||||
data->socket, (char *)&data->buff[0], data->max_buff, 0,
|
||||
(struct sockaddr *)&sin, &sin_len);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -319,7 +326,8 @@ int dl_ip_recv(
|
||||
(*msg_data)->pdu_len = buff_len;
|
||||
(*msg_data)->pdu = (uint8_t *)malloc((*msg_data)->pdu_len);
|
||||
/* fill up data message structure */
|
||||
memmove(&(*msg_data)->pdu[0], &data->buff[4],
|
||||
memmove(
|
||||
&(*msg_data)->pdu[0], &data->buff[4],
|
||||
(*msg_data)->pdu_len);
|
||||
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
||||
}
|
||||
@@ -352,7 +360,8 @@ int dl_ip_recv(
|
||||
(*msg_data)->pdu_len = buff_len;
|
||||
(*msg_data)->pdu = (uint8_t *)malloc((*msg_data)->pdu_len);
|
||||
/* fill up data message structure */
|
||||
memmove(&(*msg_data)->pdu[0], &data->buff[4 + 6],
|
||||
memmove(
|
||||
&(*msg_data)->pdu[0], &data->buff[4 + 6],
|
||||
(*msg_data)->pdu_len);
|
||||
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
||||
} else {
|
||||
|
||||
+21
-26
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Datalink IP module
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Datalink IP module
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef UDPMODULE_H
|
||||
#define UDPMODULE_H
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include "portthread.h"
|
||||
#include "bacnet/datalink/bip.h"
|
||||
|
||||
#define MAX_BIP_APDU 1476
|
||||
#define MAX_BIP_PDU (MAX_NPDU + MAX_BIP_APDU)
|
||||
#define MAX_BIP_MPDU (BIP_HEADER_MAX + MAX_BIP_PDU)
|
||||
#define MAX_BIP_APDU 1476
|
||||
#define MAX_BIP_PDU (MAX_NPDU + MAX_BIP_APDU)
|
||||
#define MAX_BIP_MPDU (BIP_HEADER_MAX + MAX_BIP_PDU)
|
||||
/* Yes, we know this is longer than an Ethernet Frame,
|
||||
a UDP payload and an IPv6 packet.
|
||||
Grandfathered in from BACnet Ethernet days,
|
||||
@@ -35,27 +35,22 @@ typedef struct ip_data {
|
||||
uint16_t max_buff;
|
||||
} IP_DATA;
|
||||
|
||||
void *dl_ip_thread(void *pArgs);
|
||||
|
||||
void *dl_ip_thread(
|
||||
void *pArgs);
|
||||
|
||||
bool dl_ip_init(
|
||||
ROUTER_PORT * port,
|
||||
IP_DATA * data);
|
||||
bool dl_ip_init(ROUTER_PORT *port, IP_DATA *data);
|
||||
|
||||
int dl_ip_send(
|
||||
IP_DATA * data,
|
||||
const BACNET_ADDRESS * dest,
|
||||
const uint8_t * pdu,
|
||||
IP_DATA *data,
|
||||
const BACNET_ADDRESS *dest,
|
||||
const uint8_t *pdu,
|
||||
unsigned pdu_len);
|
||||
|
||||
int dl_ip_recv(
|
||||
IP_DATA * data,
|
||||
MSG_DATA ** msg, /* on recieve fill up message */
|
||||
BACNET_ADDRESS * src,
|
||||
IP_DATA *data,
|
||||
MSG_DATA **msg, /* on recieve fill up message */
|
||||
BACNET_ADDRESS *src,
|
||||
unsigned timeout);
|
||||
|
||||
void dl_ip_cleanup(
|
||||
IP_DATA * data);
|
||||
void dl_ip_cleanup(IP_DATA *data);
|
||||
|
||||
#endif /* end of UDPMODULE_H */
|
||||
|
||||
+20
-12
@@ -140,8 +140,8 @@ int main(int argc, char *argv[])
|
||||
if (is_network_msg(bacmsg)) {
|
||||
msg_data->ref_count = 1;
|
||||
send_to_msgbox(msg_src, &msg_storage);
|
||||
} else if (msg_data->dest.net !=
|
||||
BACNET_BROADCAST_NETWORK) {
|
||||
} else if (
|
||||
msg_data->dest.net != BACNET_BROADCAST_NETWORK) {
|
||||
msg_data->ref_count = 1;
|
||||
port =
|
||||
find_dnet(msg_data->dest.net, &msg_data->dest);
|
||||
@@ -212,7 +212,8 @@ bool read_config(const char *filepath)
|
||||
|
||||
/* open configuration file */
|
||||
if (!config_read_file(&cfg, filepath)) {
|
||||
PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg),
|
||||
PRINT(
|
||||
ERROR, "Config file error: %d - %s\n", config_error_line(&cfg),
|
||||
config_error_text(&cfg));
|
||||
config_destroy(&cfg);
|
||||
return false;
|
||||
@@ -261,13 +262,15 @@ bool read_config(const char *filepath)
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd) {
|
||||
struct ifreq ifr;
|
||||
strncpy(ifr.ifr_name, current->iface,
|
||||
strncpy(
|
||||
ifr.ifr_name, current->iface,
|
||||
sizeof(ifr.ifr_name) - 1);
|
||||
result = ioctl(fd, SIOCGIFADDR, &ifr);
|
||||
if (result != -1) {
|
||||
close(fd);
|
||||
} else {
|
||||
PRINT(ERROR,
|
||||
PRINT(
|
||||
ERROR,
|
||||
"Error: Invalid interface for BIP device\n");
|
||||
return false;
|
||||
}
|
||||
@@ -304,7 +307,8 @@ bool read_config(const char *filepath)
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
} else {
|
||||
PRINT(ERROR,
|
||||
PRINT(
|
||||
ERROR,
|
||||
"Error: Invalid interface for MSTP device\n");
|
||||
return false;
|
||||
}
|
||||
@@ -465,13 +469,15 @@ bool parse_cmd(int argc, char *argv[])
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd) {
|
||||
struct ifreq ifr;
|
||||
strncpy(ifr.ifr_name, current->iface,
|
||||
strncpy(
|
||||
ifr.ifr_name, current->iface,
|
||||
sizeof(ifr.ifr_name) - 1);
|
||||
result = ioctl(fd, SIOCGIFADDR, &ifr);
|
||||
if (result != -1) {
|
||||
close(fd);
|
||||
} else {
|
||||
PRINT(ERROR,
|
||||
PRINT(
|
||||
ERROR,
|
||||
"Error: Invalid interface for BIP device \n");
|
||||
return false;
|
||||
}
|
||||
@@ -520,7 +526,8 @@ bool parse_cmd(int argc, char *argv[])
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
} else {
|
||||
PRINT(ERROR,
|
||||
PRINT(
|
||||
ERROR,
|
||||
"Error: Invalid interface for MSTP device\n");
|
||||
return false;
|
||||
}
|
||||
@@ -755,8 +762,8 @@ uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
|
||||
memmove(data, msg->data, sizeof(MSG_DATA));
|
||||
|
||||
apdu_offset = bacnet_npdu_decode(data->pdu, data->pdu_len, &data->dest,
|
||||
&addr, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(
|
||||
data->pdu, data->pdu_len, &data->dest, &addr, &npdu_data);
|
||||
apdu_len = data->pdu_len - apdu_offset;
|
||||
|
||||
srcport = find_snet(msg->origin);
|
||||
@@ -787,7 +794,8 @@ uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
|
||||
*buff = (uint8_t *)malloc(buff_len);
|
||||
memmove(*buff, npdu, npdu_len); /* copy newly formed NPDU */
|
||||
memmove(*buff + npdu_len, &data->pdu[apdu_offset],
|
||||
memmove(
|
||||
*buff + npdu_len, &data->pdu[apdu_offset],
|
||||
apdu_len); /* copy APDU */
|
||||
|
||||
} else {
|
||||
|
||||
+16
-31
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Message queue module
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Message queue module
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef MSGQUEUE_H
|
||||
#define MSGQUEUE_H
|
||||
|
||||
@@ -27,16 +27,9 @@ extern pthread_mutex_t msg_lock;
|
||||
|
||||
typedef int MSGBOX_ID;
|
||||
|
||||
typedef enum {
|
||||
DATA = 1,
|
||||
SERVICE
|
||||
} MSGTYPE;
|
||||
typedef enum { DATA = 1, SERVICE } MSGTYPE;
|
||||
|
||||
typedef enum {
|
||||
SHUTDOWN,
|
||||
CHG_IP,
|
||||
CHG_MAC
|
||||
} MSGSUBTYPE;
|
||||
typedef enum { SHUTDOWN, CHG_IP, CHG_MAC } MSGSUBTYPE;
|
||||
|
||||
typedef struct _message {
|
||||
MSGTYPE type;
|
||||
@@ -58,25 +51,17 @@ typedef struct _msg_data {
|
||||
MSGBOX_ID create_msgbox(void);
|
||||
|
||||
/* returns sent byte count */
|
||||
bool send_to_msgbox(
|
||||
MSGBOX_ID dest,
|
||||
BACMSG * msg);
|
||||
bool send_to_msgbox(MSGBOX_ID dest, BACMSG *msg);
|
||||
|
||||
/* returns received message */
|
||||
BACMSG *recv_from_msgbox(
|
||||
MSGBOX_ID src,
|
||||
BACMSG * msg,
|
||||
int flags);
|
||||
BACMSG *recv_from_msgbox(MSGBOX_ID src, BACMSG *msg, int flags);
|
||||
|
||||
void del_msgbox(
|
||||
MSGBOX_ID msgboxid);
|
||||
void del_msgbox(MSGBOX_ID msgboxid);
|
||||
|
||||
/* free message data structure */
|
||||
void free_data(
|
||||
MSG_DATA * data);
|
||||
void free_data(MSG_DATA *data);
|
||||
|
||||
/* check message reference counter and delete data if needed */
|
||||
void check_data(
|
||||
MSG_DATA * data);
|
||||
void check_data(MSG_DATA *data);
|
||||
|
||||
#endif /* end of MSGQUEUE_H */
|
||||
|
||||
@@ -105,8 +105,9 @@ void *dl_mstp_thread(void *pArgs)
|
||||
msg_data->dest.mac_len = 1;
|
||||
}
|
||||
|
||||
dlmstp_send_pdu(&mstp_port, &(msg_data->dest),
|
||||
msg_data->pdu, msg_data->pdu_len);
|
||||
dlmstp_send_pdu(
|
||||
&mstp_port, &(msg_data->dest), msg_data->pdu,
|
||||
msg_data->pdu_len);
|
||||
|
||||
check_data(msg_data);
|
||||
|
||||
@@ -129,13 +130,15 @@ void *dl_mstp_thread(void *pArgs)
|
||||
|
||||
if (pdu_len > 0) {
|
||||
msg_data = (MSG_DATA *)malloc(sizeof(MSG_DATA));
|
||||
memmove(&(msg_data->src),
|
||||
memmove(
|
||||
&(msg_data->src),
|
||||
(const void *)&(shared_port_data.Receive_Packet.address),
|
||||
sizeof(shared_port_data.Receive_Packet.address));
|
||||
msg_data->src.adr[0] = msg_data->src.mac[0];
|
||||
msg_data->src.len = 1;
|
||||
msg_data->pdu = (uint8_t *)malloc(pdu_len);
|
||||
memmove(msg_data->pdu,
|
||||
memmove(
|
||||
msg_data->pdu,
|
||||
(const void *)&(shared_port_data.Receive_Packet.pdu),
|
||||
pdu_len);
|
||||
msg_data->pdu_len = pdu_len;
|
||||
|
||||
+10
-11
@@ -1,19 +1,18 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Datalink for MS/TP module
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Datalink for MS/TP module
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef MSTPMODULE_H
|
||||
#define MSTPMODULE_H
|
||||
|
||||
#include "portthread.h"
|
||||
|
||||
void *dl_mstp_thread(
|
||||
void *pArgs);
|
||||
void *dl_mstp_thread(void *pArgs);
|
||||
|
||||
#endif /* end of MSTPMODULE_H */
|
||||
|
||||
+20
-12
@@ -14,8 +14,8 @@
|
||||
#include "network_layer.h"
|
||||
#include "bacnet/bacint.h"
|
||||
|
||||
uint16_t process_network_message(
|
||||
const BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
uint16_t
|
||||
process_network_message(const BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
{
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
ROUTER_PORT *srcport;
|
||||
@@ -28,8 +28,8 @@ uint16_t process_network_message(
|
||||
|
||||
memmove(data, msg->data, sizeof(MSG_DATA));
|
||||
|
||||
apdu_offset = bacnet_npdu_decode(data->pdu, data->pdu_len, &data->dest,
|
||||
NULL, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(
|
||||
data->pdu, data->pdu_len, &data->dest, NULL, &npdu_data);
|
||||
apdu_len = data->pdu_len - apdu_offset;
|
||||
|
||||
srcport = find_snet(msg->origin);
|
||||
@@ -71,9 +71,11 @@ uint16_t process_network_message(
|
||||
int net_count = apdu_len / 2;
|
||||
int i;
|
||||
for (i = 0; i < net_count; i++) {
|
||||
decode_unsigned16(&data->pdu[apdu_offset + 2 * i],
|
||||
decode_unsigned16(
|
||||
&data->pdu[apdu_offset + 2 * i],
|
||||
&net); /* decode received NET values */
|
||||
add_dnet(&srcport->route_info, net,
|
||||
add_dnet(
|
||||
&srcport->route_info, net,
|
||||
data->src); /* and update routing table */
|
||||
}
|
||||
break;
|
||||
@@ -110,9 +112,11 @@ uint16_t process_network_message(
|
||||
int net_count = data->pdu[apdu_offset];
|
||||
while (net_count--) {
|
||||
int i = 1;
|
||||
decode_unsigned16(&data->pdu[apdu_offset + i],
|
||||
decode_unsigned16(
|
||||
&data->pdu[apdu_offset + i],
|
||||
&net); /* decode received NET values */
|
||||
add_dnet(&srcport->route_info, net,
|
||||
add_dnet(
|
||||
&srcport->route_info, net,
|
||||
data->src); /* and update routing table */
|
||||
if (data->pdu[apdu_offset + i + 3] >
|
||||
0) { /* find next NET value */
|
||||
@@ -135,9 +139,11 @@ uint16_t process_network_message(
|
||||
int net_count = data->pdu[apdu_offset];
|
||||
while (net_count--) {
|
||||
int i = 1;
|
||||
decode_unsigned16(&data->pdu[apdu_offset + i],
|
||||
decode_unsigned16(
|
||||
&data->pdu[apdu_offset + i],
|
||||
&net); /* decode received NET values */
|
||||
add_dnet(&srcport->route_info, net,
|
||||
add_dnet(
|
||||
&srcport->route_info, net,
|
||||
data->src); /* and update routing table */
|
||||
if (data->pdu[apdu_offset + i + 3] >
|
||||
0) { /* find next NET value */
|
||||
@@ -299,7 +305,8 @@ uint16_t create_network_message(
|
||||
return buff_len;
|
||||
}
|
||||
|
||||
void send_network_message(BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
void send_network_message(
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
MSG_DATA *data,
|
||||
uint8_t **buff,
|
||||
void *val)
|
||||
@@ -334,7 +341,8 @@ void send_network_message(BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
}
|
||||
}
|
||||
|
||||
void init_npdu(BACNET_NPDU_DATA *npdu_data,
|
||||
void init_npdu(
|
||||
BACNET_NPDU_DATA *npdu_data,
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
bool data_expecting_reply)
|
||||
{
|
||||
|
||||
+16
-18
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Network layer for BACnet routing
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Network layer for BACnet routing
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef NETWORK_LAYER_H
|
||||
#define NETWORK_LAYER_H
|
||||
|
||||
@@ -24,25 +24,23 @@
|
||||
#include "bacport.h"
|
||||
#include "portthread.h"
|
||||
|
||||
uint16_t process_network_message(
|
||||
const BACMSG * msg,
|
||||
MSG_DATA * data,
|
||||
uint8_t ** buff);
|
||||
uint16_t
|
||||
process_network_message(const BACMSG *msg, MSG_DATA *data, uint8_t **buff);
|
||||
|
||||
uint16_t create_network_message(
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
MSG_DATA * data,
|
||||
uint8_t ** buff,
|
||||
MSG_DATA *data,
|
||||
uint8_t **buff,
|
||||
void *val);
|
||||
|
||||
void send_network_message(
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
MSG_DATA * data,
|
||||
uint8_t ** buff,
|
||||
MSG_DATA *data,
|
||||
uint8_t **buff,
|
||||
void *val);
|
||||
|
||||
void init_npdu(
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
BACNET_NPDU_DATA *npdu_data,
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
bool data_expecting_reply);
|
||||
|
||||
|
||||
+22
-41
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Network port storage and handling
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* @file
|
||||
* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
* @date 2012
|
||||
* @brief Network port storage and handling
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef PORTTHREAD_H
|
||||
#define PORTTHREAD_H
|
||||
|
||||
@@ -27,33 +27,21 @@
|
||||
|
||||
#define DEBUG_LEVEL 3
|
||||
#ifdef DEBUG_LEVEL
|
||||
#define PRINT(debug_level, ...) if(debug_level <= DEBUG_LEVEL) fprintf(stderr, __VA_ARGS__)
|
||||
#define PRINT(debug_level, ...) \
|
||||
if (debug_level <= DEBUG_LEVEL) \
|
||||
fprintf(stderr, __VA_ARGS__)
|
||||
#else
|
||||
#define PRINT(...)
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BIP = 1,
|
||||
MSTP = 2
|
||||
} DL_TYPE;
|
||||
typedef enum { BIP = 1, MSTP = 2 } DL_TYPE;
|
||||
|
||||
typedef enum {
|
||||
INIT,
|
||||
INIT_FAILED,
|
||||
RUNNING,
|
||||
FINISHED
|
||||
} PORT_STATE;
|
||||
typedef enum { INIT, INIT_FAILED, RUNNING, FINISHED } PORT_STATE;
|
||||
|
||||
/* router port thread function */
|
||||
typedef void *(
|
||||
*PORT_FUNC) (
|
||||
void *);
|
||||
typedef void *(*PORT_FUNC)(void *);
|
||||
|
||||
typedef enum {
|
||||
PARITY_NONE,
|
||||
PARITY_EVEN,
|
||||
PARITY_ODD
|
||||
} PARITY;
|
||||
typedef enum { PARITY_NONE, PARITY_EVEN, PARITY_ODD } PARITY;
|
||||
|
||||
/* port specific parameters */
|
||||
typedef union _port_params {
|
||||
@@ -90,8 +78,8 @@ typedef struct _routing_table_entry {
|
||||
typedef struct _port {
|
||||
DL_TYPE type;
|
||||
PORT_STATE state;
|
||||
MSGBOX_ID main_id; /* same for every router port */
|
||||
MSGBOX_ID port_id; /* different for every router port */
|
||||
MSGBOX_ID main_id; /* same for every router port */
|
||||
MSGBOX_ID port_id; /* different for every router port */
|
||||
char *iface;
|
||||
PORT_FUNC func;
|
||||
RT_ENTRY route_info;
|
||||
@@ -103,21 +91,14 @@ extern ROUTER_PORT *head;
|
||||
extern int port_count;
|
||||
|
||||
/* get recieving router port */
|
||||
ROUTER_PORT *find_snet(
|
||||
MSGBOX_ID id);
|
||||
ROUTER_PORT *find_snet(MSGBOX_ID id);
|
||||
|
||||
/* get sending router port */
|
||||
ROUTER_PORT *find_dnet(
|
||||
uint16_t net,
|
||||
BACNET_ADDRESS * addr);
|
||||
ROUTER_PORT *find_dnet(uint16_t net, BACNET_ADDRESS *addr);
|
||||
|
||||
/* add reacheble network for specified router port */
|
||||
void add_dnet(
|
||||
RT_ENTRY * route_info,
|
||||
uint16_t net,
|
||||
BACNET_ADDRESS addr);
|
||||
void add_dnet(RT_ENTRY *route_info, uint16_t net, BACNET_ADDRESS addr);
|
||||
|
||||
void cleanup_dnets(
|
||||
DNET * dnets);
|
||||
void cleanup_dnets(DNET *dnets);
|
||||
|
||||
#endif /* end of PORTTHREAD_H */
|
||||
|
||||
Reference in New Issue
Block a user