summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@jp.adit-jv.com>2015-10-16 16:55:27 +0900
committerLutz Helwing <lutz_helwing@mentor.com>2015-12-07 10:07:26 +0100
commit5acb7dd008a57f6da3bf7b9cf85cfc2c86cac151 (patch)
treeb6ddea5671215bc52b43d69a4b37b8481aa10d23 /src/daemon
parent280afb856b74e6089cdd2aa1af7f50c628583475 (diff)
downloadDLT-daemon-5acb7dd008a57f6da3bf7b9cf85cfc2c86cac151.tar.gz
Dlt MultiNode
MultiNode allows to connect DLT Daemons running on different operating systems, e.g. in a virtualized environment. The central component is the Gateway DLT Daemon which connects external DLT Clients, like the DLT Viewer running on a host computer, with Passive DLT Daemons running on nodes without a physical connection to external DLT clients. The Gateway DLT Daemon itself acts as a DLT client when connecting to a Passive DLT Daemon. To use the Gateway functionality, it has to be enabled in dlt.conf: GatewayMode = 1 All communication between passive nodes and DLT Viewer has to be send via the Gateway node. The Gateway node forwards log messages coming from passive nodes to all connected DLT clients. It also forwards command and control requests coming from DLT clients to the corresponding passive node. The Gateway DLT Daemon read a configuration file (dlt_gateway.conf) at startup with information about Passive DLT Daemon connections. Afterwards, the Daemon will try to connect to the passive DLT Daemons. If the connection cannot be established after the configured timeout, the Gateway DLT Daemon will give up connecting. The configuration file has to contain the following information about a passive node: [PassiveNode1] IPaddress = 192.168.2.35 Port = 3490 EcuID = ECU2 Connect = OnStartup ; timeout in seconds Timeout = 10 Precondition is, that the passive node is configured with the correct ECU id, ECU2 in this case. If the passive node sends messages with another than configured ECU id, the Gateway DLT Daemon will shut down the connection. It is also possible to connect to a passive DLT daemon using the dlt-passive-node-ctrl application. In this case "Connect=OnDemand" has to be configured in the configuration file. To connect to PassiveNode1, "dlt-passive-node-ctrl -n ECU2 -c 1" has to be executed. With "dlt-passive-node-ctrl -s" the status of passive node connections can be retrieved. Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/CMakeLists.txt2
-rw-r--r--src/daemon/dlt-daemon.c365
-rw-r--r--src/daemon/dlt-daemon.h26
-rw-r--r--src/daemon/dlt.conf5
-rw-r--r--src/daemon/dlt_daemon_client.c221
-rw-r--r--src/daemon/dlt_daemon_client.h26
-rw-r--r--src/daemon/dlt_daemon_connection.c24
-rw-r--r--src/daemon/dlt_daemon_connection_types.h6
-rw-r--r--src/daemon/dlt_daemon_event_handler.c9
-rw-r--r--src/daemon/dlt_daemon_event_handler_types.h1
10 files changed, 539 insertions, 146 deletions
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 128dbe8..7a04b64 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -20,7 +20,7 @@ if(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
message( STATUS "Added ${systemd_SRCS} to dlt-daemon")
endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
-set(dlt_daemon_SRCS dlt-daemon.c dlt_daemon_common.c dlt_daemon_connection.c dlt_daemon_event_handler.c dlt_daemon_socket.c dlt_daemon_unix_socket.c dlt_daemon_serial.c dlt_daemon_client.c dlt_daemon_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_offline_trace.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_config_file_parser.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage_behavior.c)
+set(dlt_daemon_SRCS dlt-daemon.c dlt_daemon_common.c dlt_daemon_connection.c dlt_daemon_event_handler.c ${CMAKE_SOURCE_DIR}/src/gateway/dlt_gateway.c dlt_daemon_socket.c dlt_daemon_unix_socket.c dlt_daemon_serial.c dlt_daemon_client.c dlt_daemon_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_offline_trace.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/lib/dlt_client.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_config_file_parser.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage_behavior.c)
add_executable(dlt-daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
target_link_libraries(dlt-daemon rt ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 79be6ba..c8af773 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -64,6 +64,7 @@
#include "dlt_daemon_connection.h"
#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_offline_logstorage.h"
+#include "dlt_gateway.h"
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
#include "sd-daemon.h"
@@ -246,6 +247,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
strncpy(daemon_local->flags.ctrlSockPath,
DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
sizeof(daemon_local->flags.ctrlSockPath) - 1);
+ daemon_local->flags.gatewayMode = 0;
/* open configuration file */
if(daemon_local->flags.cvalue[0])
@@ -482,6 +484,11 @@ int option_file_parser(DltDaemonLocal *daemon_local)
value,
DLT_DAEMON_FLAG_MAX-1);
}
+ else if(strcmp(token,"GatewayMode")==0)
+ {
+ daemon_local->flags.gatewayMode = atoi(value);
+ //printf("Option: %s=%s\n",token,value);
+ }
else
{
fprintf(stderr, "Unknown option: %s=%s\n",token,value);
@@ -631,6 +638,22 @@ int main(int argc, char* argv[])
DLT_TIMER_ECU);
}
+ /* initiate gateway */
+ if (daemon_local.flags.gatewayMode == 1)
+ {
+ if (dlt_gateway_init(&daemon_local, daemon_local.flags.vflag) == -1)
+ {
+ dlt_log(LOG_CRIT, "Fail to create gateway\n");
+ return -1;
+ }
+
+ /* create gateway timer */
+ create_timer_fd(&daemon_local,
+ DLT_GATEWAY_TIMER_INTERVAL,
+ DLT_GATEWAY_TIMER_INTERVAL,
+ &daemon_local.timer_gateway.fd,
+ DLT_TIMER_GATEWAY);
+ }
if (dlt_connection_create_remaining(&daemon_local) == -1)
{
/* TODO: Perform clean-up */
@@ -656,7 +679,6 @@ int main(int argc, char* argv[])
&daemon_local);
}
-
dlt_daemon_log_internal(&daemon, &daemon_local, "Exiting Daemon...", daemon_local.flags.vflag);
dlt_daemon_local_cleanup(&daemon, &daemon_local, daemon_local.flags.vflag);
@@ -1409,7 +1431,10 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, cha
return 0;
}
-int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+int dlt_daemon_process_client_connect(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
+ int verbose)
{
socklen_t cli_size;
struct sockaddr cli;
@@ -1418,31 +1443,40 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (daemon_local==0))
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_client_connect()\n");
+ dlt_log(LOG_ERR,
+ "Invalid function parameters used for function "
+ "dlt_daemon_process_client_connect()\n");
return -1;
}
/* event from TCP server socket, new connection */
cli_size = sizeof(cli);
- if ((in_sock = accept(daemon_local->sock,&cli, &cli_size)) < 0)
+ if ((in_sock = accept(receiver->fd,&cli, &cli_size)) < 0)
{
dlt_log(LOG_ERR, "accept() failed!\n");
return -1 ;
}
- /* check if file file descriptor was already used, and make it invalid if it is reused */
+ /* check if file file descriptor was already used, and make it invalid if it
+ * is reused. */
/* This prevents sending messages to wrong file descriptor */
- dlt_daemon_applications_invalidate_fd(daemon,in_sock,verbose);
- dlt_daemon_contexts_invalidate_fd(daemon,in_sock,verbose);
+ dlt_daemon_applications_invalidate_fd(daemon, in_sock, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon, in_sock, verbose);
/* Set socket timeout in reception */
struct timeval timeout_send;
timeout_send.tv_sec = daemon_local->timeoutOnSend;
timeout_send.tv_usec = 0;
- if (setsockopt (in_sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout_send, sizeof(timeout_send)) < 0)
+ if (setsockopt (in_sock,
+ SOL_SOCKET,
+ SO_SNDTIMEO,
+ (char *)&timeout_send,
+ sizeof(timeout_send)) < 0)
+ {
dlt_log(LOG_WARNING, "setsockopt failed\n");
+ }
if (dlt_connection_create(daemon_local,
&daemon_local->pEvent,
@@ -1457,26 +1491,42 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_
if (daemon_local->flags.vflag)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE, "New connection to client established, #connections: %d\n",daemon_local->client_connections);
+ snprintf(str,
+ DLT_DAEMON_TEXTBUFSIZE,
+ "New connection to client established, #connections: %d\n",
+ daemon_local->client_connections);
dlt_log(LOG_INFO, str);
}
// send connection info about connected
- dlt_daemon_control_message_connection_info(in_sock,daemon,daemon_local,DLT_CONNECTION_STATUS_CONNECTED,"",verbose);
+ dlt_daemon_control_message_connection_info(in_sock,
+ daemon,
+ daemon_local,
+ DLT_CONNECTION_STATUS_CONNECTED,
+ "",
+ verbose);
// send ecu version string
- if(daemon_local->flags.sendECUSoftwareVersion > 0)
+ if (daemon_local->flags.sendECUSoftwareVersion > 0)
{
- if(daemon_local->flags.sendECUSoftwareVersion > 0)
- dlt_daemon_control_get_software_version(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, daemon_local->flags.vflag);
+ if (daemon_local->flags.sendECUSoftwareVersion > 0)
+ {
+ dlt_daemon_control_get_software_version(DLT_DAEMON_SEND_TO_ALL,
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag);
+ }
- if(daemon_local->flags.sendTimezone > 0)
+ if (daemon_local->flags.sendTimezone > 0)
{
- dlt_daemon_control_message_timezone(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,daemon_local->flags.vflag);
+ dlt_daemon_control_message_timezone(DLT_DAEMON_SEND_TO_ALL,
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag);
}
}
- if (daemon_local->client_connections==1)
+ if (daemon_local->client_connections == 1)
{
if (daemon_local->flags.vflag)
{
@@ -1497,25 +1547,30 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_
return 0;
}
-int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+int dlt_daemon_process_client_messages(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
+ int verbose)
{
int bytes_to_be_removed=0;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (daemon_local==0))
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_client_messages()\n");
+ dlt_log(LOG_ERR,
+ "Invalid function parameters used for function "
+ "dlt_daemon_process_client_messages()\n");
return -1;
}
- if (dlt_receiver_receive_socket(&(daemon_local->receiverSock))<=0)
+ if (dlt_receiver_receive_socket(receiver) <= 0)
{
- dlt_daemon_close_socket(daemon_local->receiverSock.fd,
+ dlt_daemon_close_socket(receiver->fd,
daemon,
daemon_local,
verbose);
- daemon_local->receiverSock.fd = -1;
+ receiver->fd = -1;
/* FIXME: Why the hell do we need to close the socket
* on control message reception ??
*/
@@ -1523,15 +1578,26 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon
}
/* Process all received messages */
- while (dlt_message_read(&(daemon_local->msg),(uint8_t*)daemon_local->receiverSock.buf,daemon_local->receiverSock.bytesRcvd,daemon_local->flags.nflag,daemon_local->flags.vflag)==DLT_MESSAGE_ERROR_OK)
+ while (dlt_message_read(&(daemon_local->msg),
+ (uint8_t*)receiver->buf,
+ receiver->bytesRcvd,
+ daemon_local->flags.nflag,
+ daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK)
{
/* Check for control message */
- if ( 0 < daemon_local->receiverSock.fd && DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)) )
+ if (0 < receiver->fd &&
+ DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)))
{
- dlt_daemon_client_process_control(daemon_local->receiverSock.fd, daemon,daemon_local, &(daemon_local->msg), daemon_local->flags.vflag);
+ dlt_daemon_client_process_control(receiver->fd,
+ daemon,
+ daemon_local,
+ &(daemon_local->msg),
+ daemon_local->flags.vflag);
}
- bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader);
+ bytes_to_be_removed = daemon_local->msg.headersize +
+ daemon_local->msg.datasize -
+ sizeof(DltStorageHeader);
if (daemon_local->msg.found_serialheader)
{
bytes_to_be_removed += sizeof(dltSerialHeader);
@@ -1541,56 +1607,76 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon
bytes_to_be_removed += daemon_local->msg.resync_offset;
}
- if (dlt_receiver_remove(&(daemon_local->receiverSock),bytes_to_be_removed) == DLT_RETURN_ERROR)
+ if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1)
{
- dlt_log(LOG_WARNING,"Can't remove bytes from receiver for sockets\n");
+ dlt_log(LOG_WARNING,
+ "Can't remove bytes from receiver for sockets\n");
return -1;
}
} /* while */
-
- if (dlt_receiver_move_to_begin(&(daemon_local->receiverSock)) == DLT_RETURN_ERROR)
+ if (dlt_receiver_move_to_begin(receiver) == -1)
{
- dlt_log(LOG_WARNING,"Can't move bytes to beginning of receiver buffer for sockets\n");
+ dlt_log(LOG_WARNING,
+ "Can't move bytes to beginning of receiver buffer for sockets\n");
return -1;
}
return 0;
}
-int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+int dlt_daemon_process_client_messages_serial(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
+ int verbose)
{
int bytes_to_be_removed=0;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (daemon_local==0))
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_client_messages_serial()\n");
+ dlt_log(LOG_ERR,
+ "Invalid function parameters used for function "
+ "dlt_daemon_process_client_messages_serial()\n");
return -1;
}
- if (dlt_receiver_receive_fd(&(daemon_local->receiverSerial))<=0)
+ if (dlt_receiver_receive_fd(receiver) <= 0)
{
- dlt_log(LOG_WARNING, "dlt_receiver_receive_fd() for messages from serial interface failed!\n");
+ dlt_log(LOG_WARNING,
+ "dlt_receiver_receive_fd() for messages from serial interface "
+ "failed!\n");
return -1;
}
/* Process all received messages */
- while (dlt_message_read(&(daemon_local->msg),(uint8_t*)daemon_local->receiverSerial.buf,daemon_local->receiverSerial.bytesRcvd,daemon_local->flags.mflag,daemon_local->flags.vflag)==DLT_MESSAGE_ERROR_OK)
+ while (dlt_message_read(&(daemon_local->msg),
+ (uint8_t*)receiver->buf,
+ receiver->bytesRcvd,
+ daemon_local->flags.mflag,
+ daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK)
{
/* Check for control message */
if (DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)))
{
- if (dlt_daemon_client_process_control(daemon_local->receiverSerial.fd, daemon,daemon_local, &(daemon_local->msg), daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_client_process_control(receiver->fd,
+ daemon,
+ daemon_local,
+ &(daemon_local->msg),
+ daemon_local->flags.vflag)
+ == -1)
{
- dlt_log(LOG_WARNING,"Can't process control messages\n");
+ dlt_log(LOG_WARNING, "Can't process control messages\n");
return -1;
}
}
- bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader);
+ bytes_to_be_removed = daemon_local->msg.headersize +
+ daemon_local->msg.datasize -
+ sizeof(DltStorageHeader);
+
if (daemon_local->msg.found_serialheader)
{
bytes_to_be_removed += sizeof(dltSerialHeader);
@@ -1600,18 +1686,20 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal
bytes_to_be_removed += daemon_local->msg.resync_offset;
}
- if (dlt_receiver_remove(&(daemon_local->receiverSerial),bytes_to_be_removed) == DLT_RETURN_ERROR)
+ if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1)
{
- dlt_log(LOG_WARNING,"Can't remove bytes from receiver for serial connection\n");
+ dlt_log(LOG_WARNING,
+ "Can't remove bytes from receiver for serial connection\n");
return -1;
}
} /* while */
-
- if (dlt_receiver_move_to_begin(&(daemon_local->receiverSerial)) == DLT_RETURN_ERROR)
+ if (dlt_receiver_move_to_begin(receiver) == -1)
{
- dlt_log(LOG_WARNING,"Can't move bytes to beginning of receiver buffer for serial connection\n");
+ dlt_log(LOG_WARNING,
+ "Can't move bytes to beginning of receiver buffer for serial "
+ "connection\n");
return -1;
}
@@ -1621,6 +1709,7 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal
int dlt_daemon_process_control_connect(
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
int verbose)
{
socklen_t ctrl_size;
@@ -1629,24 +1718,27 @@ int dlt_daemon_process_control_connect(
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (daemon_local==0))
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_control_connect()\n");
+ dlt_log(LOG_ERR,
+ "Invalid function parameters used for function "
+ "dlt_daemon_process_control_connect()\n");
return -1;
}
/* event from UNIX server socket, new connection */
ctrl_size = sizeof(ctrl);
- if ((in_sock = accept(daemon_local->ctrlsock, &ctrl, &ctrl_size)) < 0)
+ if ((in_sock = accept(receiver->fd, &ctrl, &ctrl_size)) < 0)
{
dlt_log(LOG_ERR, "accept() on UNIX socket failed!\n");
return -1 ;
}
- /* check if file file descriptor was already used, and make it invalid if it is reused */
+ /* check if file file descriptor was already used, and make it invalid if it
+ * is reused */
/* This prevents sending messages to wrong file descriptor */
- dlt_daemon_applications_invalidate_fd(daemon,in_sock,verbose);
- dlt_daemon_contexts_invalidate_fd(daemon,in_sock,verbose);
+ dlt_daemon_applications_invalidate_fd(daemon, in_sock, verbose);
+ dlt_daemon_contexts_invalidate_fd(daemon, in_sock, verbose);
if (dlt_connection_create(daemon_local,
&daemon_local->pEvent,
@@ -1661,8 +1753,8 @@ int dlt_daemon_process_control_connect(
if (verbose)
{
- snprintf(str,DLT_DAEMON_TEXTBUFSIZE, "New connection to client established, #connections: %d\n",
- daemon_local->client_connections);
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE,
+ "New connection to control client established\n");
dlt_log(LOG_INFO, str);
}
@@ -1673,25 +1765,28 @@ int dlt_daemon_process_control_connect(
int dlt_daemon_process_control_messages(
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
int verbose)
{
int bytes_to_be_removed=0;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (daemon_local==0))
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_control_messages()\n");
+ dlt_log(LOG_ERR,
+ "Invalid function parameters used for function "
+ "dlt_daemon_process_control_messages()\n");
return -1;
}
- if (dlt_receiver_receive_socket(&(daemon_local->receiverCtrlSock)) <= 0)
+ if (dlt_receiver_receive_socket(receiver) <= 0)
{
- dlt_daemon_close_socket(daemon_local->receiverCtrlSock.fd,
+ dlt_daemon_close_socket(receiver->fd,
daemon,
daemon_local,
verbose);
- daemon_local->receiverCtrlSock.fd = -1;
+ receiver->fd = -1;
/* FIXME: Why the hell do we need to close the socket
* on control message reception ??
*/
@@ -1701,25 +1796,24 @@ int dlt_daemon_process_control_messages(
/* Process all received messages */
while (dlt_message_read(
&(daemon_local->msg),
- (uint8_t*)daemon_local->receiverCtrlSock.buf,
- daemon_local->receiverCtrlSock.bytesRcvd,
+ (uint8_t*)receiver->buf,
+ receiver->bytesRcvd,
daemon_local->flags.nflag,
daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK)
{
/* Check for control message */
- if (daemon_local->receiverCtrlSock.fd > 0 &&
+ if (receiver->fd > 0 &&
DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)))
{
- dlt_daemon_client_process_control(
- daemon_local->receiverCtrlSock.fd,
- daemon,daemon_local,
- &(daemon_local->msg),
- daemon_local->flags.vflag);
+ dlt_daemon_client_process_control(receiver->fd,
+ daemon,daemon_local,
+ &(daemon_local->msg),
+ daemon_local->flags.vflag);
}
- bytes_to_be_removed =
- daemon_local->msg.headersize+daemon_local->msg.datasize -
- sizeof(DltStorageHeader);
+ bytes_to_be_removed = daemon_local->msg.headersize +
+ daemon_local->msg.datasize -
+ sizeof(DltStorageHeader);
if (daemon_local->msg.found_serialheader)
{
@@ -1730,16 +1824,16 @@ int dlt_daemon_process_control_messages(
bytes_to_be_removed += daemon_local->msg.resync_offset;
}
- if (dlt_receiver_remove(&(daemon_local->receiverCtrlSock),bytes_to_be_removed)==-1)
+ if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1)
{
- dlt_log(LOG_WARNING,"Can't remove bytes from receiver for sockets\n");
+ dlt_log(LOG_WARNING,
+ "Can't remove bytes from receiver for sockets\n");
return -1;
}
} /* while */
-
- if (dlt_receiver_move_to_begin(&(daemon_local->receiverCtrlSock)) == -1)
+ if (dlt_receiver_move_to_begin(receiver) == -1)
{
dlt_log(LOG_WARNING,"Can't move bytes to beginning of receiver buffer for sockets\n");
return -1;
@@ -1748,40 +1842,46 @@ int dlt_daemon_process_control_messages(
return 0;
}
-int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+int dlt_daemon_process_user_messages(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
+ int verbose)
{
- int offset=0;
- int run_loop=1;
+ int offset = 0;
+ int run_loop = 1;
DltUserHeader *userheader;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (daemon_local==0))
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_messages()\n");
+ dlt_log(LOG_ERR,
+ "Invalid function parameters used for function "
+ "dlt_daemon_process_user_messages()\n");
return -1;
}
/* read data from FIFO */
- if (dlt_receiver_receive_fd(&(daemon_local->receiver))<0)
+ if (dlt_receiver_receive_fd(receiver) < 0)
{
- dlt_log(LOG_WARNING, "dlt_receiver_receive_fd() for user messages failed!\n");
+ dlt_log(LOG_WARNING,
+ "dlt_receiver_receive_fd() for user messages failed!\n");
return -1;
}
/* look through buffer as long as data is in there */
do
{
- if (daemon_local->receiver.bytesRcvd < (int32_t)sizeof(DltUserHeader))
+ if (receiver->bytesRcvd < (int32_t)sizeof(DltUserHeader))
{
break;
}
/* resync if necessary */
- offset=0;
+ offset = 0;
do
{
- userheader = (DltUserHeader*) (daemon_local->receiver.buf+offset);
+ userheader = (DltUserHeader*) (receiver->buf+offset);
/* Check for user header pattern */
if (dlt_user_check_userheader(userheader))
@@ -1790,88 +1890,111 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
}
offset++;
-
- }
- while ((int32_t)(sizeof(DltUserHeader)+offset)<=daemon_local->receiver.bytesRcvd);
+ } while ((int32_t)(sizeof(DltUserHeader) + offset) <=
+ receiver->bytesRcvd);
/* Check for user header pattern */
- if (dlt_user_check_userheader(userheader)==0)
+ if (dlt_user_check_userheader(userheader) == 0)
{
break;
}
/* Set new start offset */
- if (offset>0)
+ if (offset > 0)
{
- daemon_local->receiver.buf+=offset;
- daemon_local->receiver.bytesRcvd-=offset;
+ receiver->buf += offset;
+ receiver->bytesRcvd -= offset;
}
switch (userheader->message)
{
case DLT_USER_MESSAGE_OVERFLOW:
{
- if (dlt_daemon_process_user_message_overflow(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_overflow(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
case DLT_USER_MESSAGE_REGISTER_CONTEXT:
{
- if (dlt_daemon_process_user_message_register_context(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_register_context(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
case DLT_USER_MESSAGE_UNREGISTER_CONTEXT:
{
- if (dlt_daemon_process_user_message_unregister_context(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_unregister_context(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
case DLT_USER_MESSAGE_LOG:
{
- if (dlt_daemon_process_user_message_log(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_log(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
#ifdef DLT_SHM_ENABLE
case DLT_USER_MESSAGE_LOG_SHM:
{
- if (dlt_daemon_process_user_message_log_shm(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_log_shm(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
#endif
case DLT_USER_MESSAGE_REGISTER_APPLICATION:
{
- if (dlt_daemon_process_user_message_register_application(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_register_application(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
case DLT_USER_MESSAGE_UNREGISTER_APPLICATION:
{
- if (dlt_daemon_process_user_message_unregister_application(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_unregister_application(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
case DLT_USER_MESSAGE_APP_LL_TS:
{
- if (dlt_daemon_process_user_message_set_app_ll_ts(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_set_app_ll_ts(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
@@ -1885,26 +2008,34 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
}
case DLT_USER_MESSAGE_MARKER:
{
- if (dlt_daemon_process_user_message_marker(daemon, daemon_local, daemon_local->flags.vflag)==-1)
+ if (dlt_daemon_process_user_message_marker(
+ daemon,
+ daemon_local,
+ daemon_local->flags.vflag) == -1)
{
- run_loop=0;
+ run_loop = 0;
}
break;
}
default:
{
- snprintf(str, DLT_DAEMON_TEXTBUFSIZE, "Invalid user message type received: %d!\n", userheader->message);
+ snprintf(str,
+ DLT_DAEMON_TEXTBUFSIZE,
+ "Invalid user message type received: %d!\n",
+ userheader->message);
dlt_log(LOG_ERR,str);
/* remove user header */
- if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader)) == DLT_RETURN_ERROR)
+ if (dlt_receiver_remove(receiver, sizeof(DltUserHeader)) == -1)
{
- dlt_log(LOG_WARNING,"Can't remove bytes from receiver for user messages\n");
+ dlt_log(LOG_WARNING,
+ "Can't remove bytes from receiver for user messages\n");
return -1;
}
- /* In next invocation of do-while loop, a resync will be triggered if additional data was received */
- run_loop=0;
+ /* In next invocation of do-while loop, a resync will be triggered
+ * if additional data was received */
+ run_loop = 0;
break;
}
@@ -1914,9 +2045,11 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
while (run_loop);
/* keep not read data in buffer */
- if (dlt_receiver_move_to_begin(&(daemon_local->receiver)) == DLT_RETURN_ERROR)
+ if (dlt_receiver_move_to_begin(receiver) == -1)
{
- dlt_log(LOG_WARNING,"Can't move bytes to beginning of receiver buffer for user messages\n");
+ dlt_log(LOG_WARNING,
+ "Can't move bytes to beginning of receiver buffer for user "
+ "messages\n");
return -1;
}
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 02a55b3..2dffcc9 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -75,7 +75,7 @@
#include "dlt_user_shared.h"
#include "dlt_user_shared_cfg.h"
#include "dlt_daemon_event_handler_types.h"
-
+#include "dlt_gateway_types.h"
#include <dlt_offline_trace.h>
#include <sys/time.h>
@@ -123,8 +123,8 @@ typedef struct
char daemonFifoName[NAME_MAX + 1]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
unsigned int port; /**< port number */
char ctrlSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to Control socket */
+ int gatewayMode; /**< (Boolean) Gateway Mode */
} DltDaemonFlags;
-
/**
* The global parameters of a dlt daemon.
*/
@@ -137,6 +137,7 @@ typedef struct
int ctrlsock; /**< handle for control socket connection */
DltFile file; /**< struct for file access */
DltEventHandler pEvent; /**< struct for message producer event handling */
+ DltGateway pGateway; /**< struct for passive node connection handling */
DltMessage msg; /**< one dlt message */
DltReceiver receiver; /**< receiver for fifo connection */
DltReceiver receiverSock; /**< receiver for socket connection */
@@ -157,6 +158,7 @@ typedef struct
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
DltReceiver timer_wd; /**< file descriptor for watchdog timer */
#endif
+ DltReceiver timer_gateway; /**< timer for gateway reconnection handling */
} DltDaemonLocal;
typedef struct
@@ -188,16 +190,16 @@ int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_
void dlt_daemon_daemonize(int verbose);
void dlt_daemon_signal_handler(int sig);
-int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-int dlt_daemon_process_one_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-int dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
-
-int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local,int verbose);
-int dlt_daemon_process_control_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local,int verbose);
+int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *revc, int verbose);
+int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+int dlt_daemon_process_one_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+int dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+
+int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
+int dlt_daemon_process_control_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose);
int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf
index 5deec60..aab9c7d 100644
--- a/src/daemon/dlt.conf
+++ b/src/daemon/dlt.conf
@@ -24,6 +24,9 @@ SendContextRegistration = 1
# Set ECU ID (Default: ECU1)
ECUId = ECU1
+# Enable Gateway mode (Default: 0)
+# GatewayMode = 1
+
# Size of shared memory (Default: 100000)
SharedMemorySize = 100000
@@ -147,4 +150,4 @@ ControlSocketPath = /tmp/dlt-ctrl.sock
# OfflineLogstorageMaxCounter = 999
# Maximal used memory for Logstorage Cache in KB (Default: 30000 KB)
-# OfflineLogstorageCacheSize = 30000 \ No newline at end of file
+# OfflineLogstorageCacheSize = 30000
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index 7658787..a96c329 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -62,6 +62,8 @@
#include "dlt_daemon_connection.h"
#include "dlt_daemon_offline_logstorage.h"
+#include "dlt_gateway.h"
+
/** Global text output buffer, mainly used for creation of error/warning strings */
static char str[DLT_DAEMON_TEXTBUFSIZE];
@@ -402,10 +404,11 @@ int dlt_daemon_client_send_control_message( int sock, DltDaemon *daemon, DltDaem
int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
{
uint32_t id,id_tmp=0;
+ DltStandardHeaderExtra extra;
PRINT_FUNCTION_VERBOSE(verbose);
- if ((daemon==0) || (msg==0))
+ if (daemon == NULL || daemon_local == NULL|| msg == NULL)
{
return -1;
}
@@ -415,10 +418,24 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca
return -1;
}
+ extra = msg->headerextra;
+
+ /* check if the message needs to be forwarded */
+ if (daemon_local->flags.gatewayMode == 1)
+ {
+ if (strcmp(daemon_local->flags.evalue, extra.ecu) != 0)
+ {
+ return dlt_gateway_forward_control_message(&daemon_local->pGateway,
+ daemon_local,
+ msg,
+ extra.ecu,
+ verbose);
+ }
+ }
id_tmp = *((uint32_t*)(msg->databuffer));
id=DLT_ENDIAN_GET_32(msg->standardheader->htyp ,id_tmp);
- if ((id > 0) && ((id < DLT_SERVICE_ID_LAST_ENTRY) || ((id == DLT_SERVICE_ID_OFFLINE_LOGSTORAGE))))
+ if ((id > 0) && (id != DLT_SERVICE_ID_CALLSW_CINJECTION))
{
/* Control message handling */
switch (id)
@@ -546,6 +563,23 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca
dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose);
break;
}
+ case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT:
+ {
+ dlt_daemon_control_passive_node_connect(sock,
+ daemon,
+ daemon_local,
+ msg,
+ verbose);
+ break;
+ }
+ case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS:
+ {
+ dlt_daemon_control_passive_node_connect_status(sock,
+ daemon,
+ daemon_local,
+ verbose);
+ break;
+ }
default:
{
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
@@ -1747,6 +1781,7 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal
int dlt_daemon_process_one_s_timer(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
int verbose)
{
uint64_t expir = 0;
@@ -1755,7 +1790,7 @@ int dlt_daemon_process_one_s_timer(DltDaemon *daemon,
PRINT_FUNCTION_VERBOSE(verbose);
- if((daemon_local == NULL) || (daemon == NULL))
+ if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL))
{
snprintf(local_str,
DLT_DAEMON_TEXTBUFSIZE,
@@ -1765,7 +1800,7 @@ int dlt_daemon_process_one_s_timer(DltDaemon *daemon,
return -1;
}
- res = read(daemon_local->timer_one_s.fd, &expir, sizeof(expir));
+ res = read(receiver->fd, &expir, sizeof(expir));
if(res < 0)
{
@@ -1805,6 +1840,7 @@ int dlt_daemon_process_one_s_timer(DltDaemon *daemon,
int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
int verbose)
{
uint64_t expir = 0;
@@ -1813,7 +1849,7 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon,
PRINT_FUNCTION_VERBOSE(verbose);
- if((daemon_local == NULL) || (daemon == NULL))
+ if((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL))
{
snprintf(str,
DLT_DAEMON_TEXTBUFSIZE,
@@ -1823,7 +1859,7 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon,
return -1;
}
- res = read(daemon_local->timer_sixty_s.fd, &expir, sizeof(expir));
+ res = read(receiver->fd, &expir, sizeof(expir));
if(res < 0)
{
@@ -1867,6 +1903,7 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon,
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
int verbose)
{
uint64_t expir = 0;
@@ -1875,7 +1912,7 @@ int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
PRINT_FUNCTION_VERBOSE(verbose);
- if((daemon_local == NULL) || (daemon == NULL))
+ if((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL))
{
snprintf(local_str,
DLT_DAEMON_TEXTBUFSIZE,
@@ -1885,7 +1922,7 @@ int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
return res;
}
- res = read(daemon_local->timer_wd.fd, &expir, sizeof(expir));
+ res = read(receiver->fd, &expir, sizeof(expir));
if(res < 0)
{
@@ -1910,10 +1947,12 @@ int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
#else
int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
+ DltReceiver *receiver,
int verbose)
{
(void)daemon;
(void)daemon_local;
+ (void)receiver;
(void)verbose;
dlt_log(LOG_DEBUG, "Timer watchdog not enabled\n");
@@ -2015,3 +2054,169 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
}
}
+
+void dlt_daemon_control_passive_node_connect(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltMessage *msg,
+ int verbose)
+{
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ DltServicePassiveNodeConnect *req;
+ uint32_t id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
+
+ if (daemon == NULL || daemon_local == NULL || msg == NULL ||
+ msg->databuffer == NULL)
+ {
+ return;
+ }
+
+ /* return error, if gateway mode not enabled*/
+ if (daemon_local->flags.gatewayMode == 0)
+ {
+ dlt_log(LOG_WARNING,
+ "Received passive node connection status request, "
+ "but GatewayMode is disabled\n");
+
+ dlt_daemon_control_service_response(
+ sock,
+ daemon,
+ daemon_local,
+ DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
+ DLT_SERVICE_RESPONSE_ERROR,
+ verbose);
+
+ return;
+ }
+
+ req = (DltServicePassiveNodeConnect *) msg->databuffer;
+
+ if (dlt_gateway_process_on_demand_request(&daemon_local->pGateway,
+ daemon_local,
+ req->node_id,
+ req->connection_status,
+ verbose) < 0)
+ {
+ dlt_daemon_control_service_response(sock,
+ daemon,
+ daemon_local,
+ id,
+ DLT_SERVICE_RESPONSE_ERROR,
+ verbose);
+ }
+ else
+ {
+ dlt_daemon_control_service_response(sock,
+ daemon,
+ daemon_local,
+ id,
+ DLT_SERVICE_RESPONSE_OK,
+ verbose);
+ }
+}
+
+void dlt_daemon_control_passive_node_connect_status(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose)
+{
+ DltMessage msg;
+ DltServicePassiveNodeConnectionInfo *resp;
+ DltGatewayConnection *con = NULL;
+ unsigned int i = 0;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if (daemon == NULL || daemon_local == NULL)
+ {
+ return;
+ }
+
+ if (dlt_message_init(&msg, verbose) == -1)
+ {
+ return;
+ }
+
+ /* return error, if gateway mode not enabled*/
+ if (daemon_local->flags.gatewayMode == 0)
+ {
+ dlt_log(LOG_WARNING,
+ "Received passive node connection status request, "
+ "but GatewayMode is disabled\n");
+
+ dlt_daemon_control_service_response(
+ sock,
+ daemon,
+ daemon_local,
+ DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
+ DLT_SERVICE_RESPONSE_ERROR,
+ verbose);
+
+ return;
+ }
+
+ /* prepare payload of data */
+ msg.datasize = sizeof(DltServicePassiveNodeConnectionInfo);
+ if (msg.databuffer && (msg.databuffersize < msg.datasize))
+ {
+ msg.databuffer = NULL;
+ }
+ if (msg.databuffer == NULL)
+ {
+ msg.databuffer = (uint8_t *) malloc(msg.datasize);
+ if (msg.databuffer == NULL)
+ {
+ dlt_log(LOG_CRIT, "Cannot allocate memory for message response\n");
+ return;
+ }
+ msg.databuffersize = msg.datasize;
+ }
+
+ resp = (DltServicePassiveNodeConnectionInfo *) msg.databuffer;
+ memset(resp, 0, msg.datasize);
+ resp->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS;
+ resp->status = DLT_SERVICE_RESPONSE_OK;
+ resp->num_connections = daemon_local->pGateway.num_connections;
+
+ for (i = 0; i < resp->num_connections; i++)
+ {
+ if ((i * DLT_ID_SIZE) > DLT_ENTRY_MAX)
+ {
+ dlt_log(LOG_ERR,
+ "Maximal message size reached. Skip further information\n");
+ break;
+ }
+
+ con = &daemon_local->pGateway.connections[i];
+ if (con == NULL)
+ {
+ dlt_log(LOG_CRIT, "Passive node connection structure is NULL\n");
+ dlt_daemon_control_service_response(
+ sock,
+ daemon,
+ daemon_local,
+ DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
+ DLT_SERVICE_RESPONSE_ERROR,
+ verbose);
+
+ /* free message */
+ dlt_message_free(&msg, verbose);
+
+ return;
+ }
+
+ resp->connection_status[i] = con->status;
+ memcpy(&resp->node_id[i * DLT_ID_SIZE], con->ecuid, DLT_ID_SIZE);
+ }
+
+ dlt_daemon_client_send_control_message(sock,
+ daemon,
+ daemon_local,
+ &msg,
+ "",
+ "",
+ verbose);
+ /* free message */
+ dlt_message_free(&msg, verbose);
+}
diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h
index 4b5ebcb..7128ddb 100644
--- a/src/daemon/dlt_daemon_client.h
+++ b/src/daemon/dlt_daemon_client.h
@@ -265,4 +265,30 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal
*/
void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose);
+/**
+ * Process and generate response to received passive node connect control
+ * message
+ * @param sock connection handle used for sending response
+ * @param daemon pointer to dlt daemon structure
+ * @param daemon_local pointer to dlt daemon local structure
+ * @param msg pointer to received control message
+ * @param verbose if set to true verbose information is printed out.
+ */
+void dlt_daemon_control_passive_node_connect(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ DltMessage *msg,
+ int verbose);
+/**
+ * Process and generate response to received passive node connection status
+ * control message
+ * @param sock connection handle used for sending response
+ * @param daemon pointer to dlt daemon structure
+ * @param daemon_local pointer to dlt daemon local structure
+ * @param verbose if set to true verbose information is printed out.
+ */
+void dlt_daemon_control_passive_node_connect_status(int sock,
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose);
#endif /* DLT_DAEMON_CLIENT_H */
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 1a7af3f..1629cc3 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -45,6 +45,7 @@
#include "dlt-daemon_cfg.h"
#include "dlt_daemon_common.h"
#include "dlt_common.h"
+#include "dlt_gateway.h"
/** @brief Generic sending function.
*
@@ -171,7 +172,8 @@ DltConnection *dlt_connection_get_next(DltConnection *current, int type_mask)
* @return DltReceiver structure or NULL if none corresponds to the type.
*/
static DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
- DltConnectionType type)
+ DltConnectionType type,
+ int fd)
{
DltReceiver *ret = NULL;
@@ -206,6 +208,16 @@ static DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
case DLT_CONNECTION_CONTROL_MSG:
ret = &daemon_local->receiverCtrlSock;
break;
+ case DLT_CONNECTION_GATEWAY:
+ /* FIXME: This is complete different approach compared to having the
+ * receiver as part of daemon_local structure. Approaches need
+ * to be harmonized.
+ */
+ ret = dlt_gateway_get_connection_receiver(&daemon_local->pGateway, fd);
+ break;
+ case DLT_CONNECTION_GATEWAY_TIMER:
+ ret = &daemon_local->timer_gateway;
+ break;
default:
ret = NULL;
}
@@ -265,6 +277,12 @@ void *dlt_connection_get_callback(DltConnection *con)
case DLT_CONNECTION_CONTROL_MSG:
ret = dlt_daemon_process_control_messages;
break;
+ case DLT_CONNECTION_GATEWAY:
+ ret = dlt_gateway_process_passive_node_messages;
+ break;
+ case DLT_CONNECTION_GATEWAY_TIMER:
+ ret = dlt_gateway_process_gateway_timer;
+ break;
default:
ret = NULL;
}
@@ -332,7 +350,7 @@ int dlt_connection_create(DltDaemonLocal *daemon_local,
temp->fd = fd;
temp->type = type;
- temp->receiver = dlt_connection_get_receiver(daemon_local, type);
+ temp->receiver = dlt_connection_get_receiver(daemon_local, type, fd);
/* Now give the ownership of the newly created connection
* to the event handler, by registering for events.
@@ -358,7 +376,7 @@ int dlt_connection_create_remaining(DltDaemonLocal *daemon_local)
for (i = 0 ; i < DLT_CONNECTION_TYPE_MAX ; i++)
{
int fd = 0;
- DltReceiver *rec = dlt_connection_get_receiver(daemon_local, i);
+ DltReceiver *rec = dlt_connection_get_receiver(daemon_local, i, fd);
if (rec == NULL)
{
diff --git a/src/daemon/dlt_daemon_connection_types.h b/src/daemon/dlt_daemon_connection_types.h
index c35b43e..5edb875 100644
--- a/src/daemon/dlt_daemon_connection_types.h
+++ b/src/daemon/dlt_daemon_connection_types.h
@@ -41,6 +41,8 @@ typedef enum {
DLT_CONNECTION_SYSTEMD_TIMER,
DLT_CONNECTION_CONTROL_CONNECT,
DLT_CONNECTION_CONTROL_MSG,
+ DLT_CONNECTION_GATEWAY,
+ DLT_CONNECTION_GATEWAY_TIMER,
DLT_CONNECTION_TYPE_MAX
} DltConnectionType;
@@ -53,7 +55,9 @@ typedef enum {
#define DLT_CON_MASK_SYSTEMD_TIMER (1 << DLT_CONNECTION_SYSTEMD_TIMER)
#define DLT_CON_MASK_CONTROL_CONNECT (1 << DLT_CONNECTION_CONTROL_CONNECT)
#define DLT_CON_MASK_CONTROL_MSG (1 << DLT_CONNECTION_CONTROL_MSG)
-#define DLT_CON_MASK_ALL (0xff)
+#define DLT_CON_MASK_GATEWAY (1 << DLT_CONNECTION_GATEWAY)
+#define DLT_CON_MASK_GATEWAY_TIMER (1 << DLT_CONNECTION_GATEWAY_TIMER)
+#define DLT_CON_MASK_ALL (0xffff)
/* TODO: squash the DltReceiver structure in there
* and remove any other duplicates of FDs
diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c
index 3762ca2..5b5a8ac 100644
--- a/src/daemon/dlt_daemon_event_handler.c
+++ b/src/daemon/dlt_daemon_event_handler.c
@@ -91,7 +91,7 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
int nfds = 0;
int i = 0;
char str[DLT_DAEMON_TEXTBUFSIZE];
- int (*callback)(DltDaemon *, DltDaemonLocal *, int) = NULL;
+ int (*callback)(DltDaemon *, DltDaemonLocal *, DltReceiver *, int) = NULL;
/*CM Change begin*/
nfds = epoll_wait(pEvent->epfd,
@@ -142,7 +142,6 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
type);
continue;
}
-
/* Get the function to be used to handle the event */
callback = dlt_connection_get_callback((DltConnection *)ev->data.ptr);
@@ -161,7 +160,10 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
((DltConnection *)ev->data.ptr)->receiver->fd = fd;
/* From now on, callback is correct */
- if (callback(daemon, daemon_local, daemon_local->flags.vflag) == -1)
+ if (callback(daemon,
+ daemon_local,
+ ((DltConnection *)ev->data.ptr)->receiver,
+ daemon_local->flags.vflag) == -1)
{
snprintf(str,
DLT_DAEMON_TEXTBUFSIZE,
@@ -171,7 +173,6 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
return -1;
}
}
-
return 0;
}
diff --git a/src/daemon/dlt_daemon_event_handler_types.h b/src/daemon/dlt_daemon_event_handler_types.h
index 080c331..a2945b4 100644
--- a/src/daemon/dlt_daemon_event_handler_types.h
+++ b/src/daemon/dlt_daemon_event_handler_types.h
@@ -46,6 +46,7 @@ typedef enum {
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
DLT_TIMER_SYSTEMD,
#endif
+ DLT_TIMER_GATEWAY,
DLT_TIMER_UNKNOWN
} DltTimers;