summaryrefslogtreecommitdiff
path: root/src/daemon/dlt_daemon_client.c
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/dlt_daemon_client.c
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/dlt_daemon_client.c')
-rw-r--r--src/daemon/dlt_daemon_client.c221
1 files changed, 213 insertions, 8 deletions
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);
+}