summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dlt/dlt_client.h11
-rw-r--r--src/console/dlt-control.c4
-rw-r--r--src/console/dlt-receive.c4
-rw-r--r--src/daemon/CMakeLists.txt2
-rw-r--r--src/daemon/dlt-daemon.c162
-rw-r--r--src/daemon/dlt-daemon.h13
-rw-r--r--src/daemon/dlt.conf5
-rw-r--r--src/daemon/dlt_daemon_common_cfg.h6
-rw-r--r--src/daemon/dlt_daemon_connection.c12
-rw-r--r--src/daemon/dlt_daemon_connection_types.h4
-rw-r--r--src/daemon/dlt_daemon_unix_socket.c109
-rw-r--r--src/daemon/dlt_daemon_unix_socket.h67
-rw-r--r--src/lib/dlt_client.c50
-rw-r--r--src/tests/dlt-test-client.c4
-rw-r--r--src/tests/dlt-test-multi-process-client.c4
-rw-r--r--src/tests/dlt-test-stress-client.c4
-rw-r--r--tests/dlt_test_receiver.c4
17 files changed, 440 insertions, 25 deletions
diff --git a/include/dlt/dlt_client.h b/include/dlt/dlt_client.h
index f1d1f4c..1dcc3a6 100644
--- a/include/dlt/dlt_client.h
+++ b/include/dlt/dlt_client.h
@@ -78,14 +78,23 @@
#include "dlt_types.h"
#include "dlt_common.h"
+typedef enum
+{
+ DLT_CLIENT_MODE_UNDEFINED = -1,
+ DLT_CLIENT_MODE_TCP,
+ DLT_CLIENT_MODE_SERIAL,
+ DLT_CLIENT_MODE_UNIX
+} DltClientMode;
+
typedef struct
{
DltReceiver receiver; /**< receiver pointer to dlt receiver structure */
int sock; /**< sock Connection handle/socket */
char *servIP; /**< servIP IP adress/Hostname of TCP/IP interface */
char *serialDevice; /**< serialDevice Devicename of serial device */
+ char *socketPath; /**< socketPath Unix socket path */
speed_t baudrate; /**< baudrate Baudrate of serial interface, as speed_t */
- int serial_mode; /**< serial_mode Serial mode enabled =1, disabled =0 */
+ DltClientMode mode; /**< mode DltClientMode */
} DltClient;
#ifdef __cplusplus
diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c
index 49b7de8..15a1435 100644
--- a/src/console/dlt-control.c
+++ b/src/console/dlt-control.c
@@ -424,9 +424,9 @@ int main(int argc, char* argv[])
dlt_client_register_message_callback(dlt_receive_message_callback);
/* Setup DLT Client structure */
- g_dltclient.serial_mode = dltdata.yflag;
+ g_dltclient.mode = dltdata.yflag;
- if (g_dltclient.serial_mode==0)
+ if (g_dltclient.mode==DLT_CLIENT_MODE_TCP)
{
for (index = optind; index < argc; index++)
{
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c
index ef3ba20..ad8228b 100644
--- a/src/console/dlt-receive.c
+++ b/src/console/dlt-receive.c
@@ -435,9 +435,9 @@ int main(int argc, char* argv[])
dlt_client_register_message_callback(dlt_receive_message_callback);
/* Setup DLT Client structure */
- dltclient.serial_mode = dltdata.yflag;
+ dltclient.mode = dltdata.yflag;
- if (dltclient.serial_mode==0)
+ if (dltclient.mode==DLT_CLIENT_MODE_TCP)
{
for (index = optind; index < argc; index++)
{
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 70758cd..f665a4d 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_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)
+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)
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 4e6b4b4..20dda80 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -31,6 +31,7 @@
#include <ctype.h>
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), (), and recv() */
+#include <sys/un.h>
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
@@ -56,6 +57,7 @@
#include "dlt_daemon_common_cfg.h"
#include "dlt_daemon_socket.h"
+#include "dlt_daemon_unix_socket.h"
#include "dlt_daemon_serial.h"
#include "dlt_daemon_client.h"
@@ -229,6 +231,9 @@ int option_file_parser(DltDaemonLocal *daemon_local)
memset(daemon_local->flags.pathToECUSoftwareVersion, 0, sizeof(daemon_local->flags.pathToECUSoftwareVersion));
daemon_local->flags.sendTimezone = 0;
daemon_local->flags.offlineLogstorageMaxDevices = 0;
+ strncpy(daemon_local->flags.ctrlSockPath,
+ DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
+ sizeof(daemon_local->flags.ctrlSockPath) - 1);
/* open configuration file */
if(daemon_local->flags.cvalue[0])
@@ -420,6 +425,17 @@ int option_file_parser(DltDaemonLocal *daemon_local)
{
daemon_local->flags.offlineLogstorageMaxDevices = atoi(value);
}
+ else if(strcmp(token,"ControlSocketPath")==0)
+ {
+ memset(
+ daemon_local->flags.ctrlSockPath,
+ 0,
+ DLT_DAEMON_FLAG_MAX);
+ strncpy(
+ daemon_local->flags.ctrlSockPath,
+ value,
+ DLT_DAEMON_FLAG_MAX-1);
+ }
else
{
fprintf(stderr, "Unknown option: %s=%s\n",token,value);
@@ -753,6 +769,12 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
dlt_log(LOG_ERR,"Could not initialize receiver for socket\n");
return -1;
}
+ if (dlt_receiver_init(&(daemon_local->receiverCtrlSock),
+ daemon_local->ctrlsock, DLT_DAEMON_RCVBUFSIZESOCK)==-1)
+ {
+ dlt_log(LOG_ERR,"Could not initialize receiver for control socket\n");
+ return -1;
+ }
if (daemon_local->flags.yvalue[0])
{
if (dlt_receiver_init(&(daemon_local->receiverSerial),daemon_local->fdserial,DLT_DAEMON_RCVBUFSIZESERIAL) == DLT_RETURN_ERROR)
@@ -939,6 +961,16 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
return -1;
}
+ /* create and open unix socket to receive incoming connections from
+ * control application */
+ if (dlt_daemon_unix_socket_open(
+ &(daemon_local->ctrlsock),
+ daemon_local->flags.ctrlSockPath))
+ {
+ dlt_log(LOG_ERR, "Could not initialize control socket.\n");
+ return -1;
+ }
+
/* Init serial */
if (dlt_daemon_init_serial(daemon_local) < 0)
{
@@ -1502,6 +1534,136 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal
return 0;
}
+int dlt_daemon_process_control_connect(
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose)
+{
+ socklen_t ctrl_size;
+ struct sockaddr_un ctrl;
+ int in_sock = -1;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon==0) || (daemon_local==0))
+ {
+ 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)
+ {
+ 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 */
+ /* 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);
+
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ in_sock,
+ EPOLLIN,
+ DLT_CONNECTION_CONTROL_MSG))
+ {
+ dlt_log(LOG_ERR, "Failed to register new client. \n");
+ /* TODO: Perform clean-up */
+ return -1;
+ }
+
+ if (verbose)
+ {
+ snprintf(str,DLT_DAEMON_TEXTBUFSIZE, "New connection to client established, #connections: %d\n",
+ daemon_local->client_connections);
+ dlt_log(LOG_INFO, str);
+ }
+
+ return 0;
+}
+
+// FIXME: More or less copy of dlt_daemon_process_control_messages
+int dlt_daemon_process_control_messages(
+ DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose)
+{
+ int bytes_to_be_removed=0;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon==0) || (daemon_local==0))
+ {
+ 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)
+ {
+ dlt_daemon_close_socket(daemon_local->receiverCtrlSock.fd,
+ daemon,
+ daemon_local,
+ verbose);
+ daemon_local->receiverCtrlSock.fd = -1;
+ /* FIXME: Why the hell do we need to close the socket
+ * on control message reception ??
+ */
+ //return 0;
+ }
+
+ /* Process all received messages */
+ while (dlt_message_read(
+ &(daemon_local->msg),
+ (uint8_t*)daemon_local->receiverCtrlSock.buf,
+ daemon_local->receiverCtrlSock.bytesRcvd,
+ daemon_local->flags.nflag,
+ daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK)
+ {
+ /* Check for control message */
+ if (daemon_local->receiverCtrlSock.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);
+ }
+
+ 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);
+ }
+ if (daemon_local->msg.resync_offset)
+ {
+ bytes_to_be_removed += daemon_local->msg.resync_offset;
+ }
+
+ if (dlt_receiver_remove(&(daemon_local->receiverCtrlSock),bytes_to_be_removed)==-1)
+ {
+ 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)
+ {
+ dlt_log(LOG_WARNING,"Can't move bytes to beginning of receiver buffer for sockets\n");
+ return -1;
+ }
+
+ return 0;
+}
+
int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
int offset=0;
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 0e2fe37..ab18d1f 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -80,6 +80,7 @@
#include <sys/time.h>
#include "dlt_daemon_offline_logstorage.h"
+#define DLT_DAEMON_FLAG_MAX 256
/**
* The flags of a dlt daemon.
@@ -102,20 +103,21 @@ typedef struct
char cvalue[NAME_MAX + 1]; /**< (String: Directory) Filename of DLT configuration file (Default: /etc/dlt.conf) */
int sharedMemorySize; /**< (int) Size of shared memory (Default: 100000) */
int sendMessageTime; /**< (Boolean) Send periodic Message Time if client is connected (Default: 0) */
- char offlineTraceDirectory[256]; /**< (String: Directory) Store DLT messages to local directory (Default: /etc/dlt.conf) */
+ char offlineTraceDirectory[DLT_DAEMON_FLAG_MAX]; /**< (String: Directory) Store DLT messages to local directory (Default: /etc/dlt.conf) */
int offlineTraceFileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */
int offlineTraceMaxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */
int offlineTraceFilenameTimestampBased; /**< (int) timestamp based or index based (Default: 1 Timestamp based) */
int loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */
int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */
- char loggingFilename[256]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */
+ char loggingFilename[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */
int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */
- char pathToECUSoftwareVersion[256]; /**< (String: Filename) The file from which to read the ECU version from. */
+ char pathToECUSoftwareVersion[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The file from which to read the ECU version from. */
int sendTimezone; /**< (Boolean) Send Timezone perdiodically */
int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */
char userPipesDir[NAME_MAX + 1]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
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 */
} DltDaemonFlags;
/**
@@ -127,12 +129,14 @@ typedef struct
int fp; /**< handle for own fifo */
int sock; /**< handle for tcp connection to client */
int fdserial; /**< handle for serial connection */
+ int ctrlsock; /**< handle for control socket connection */
DltFile file; /**< struct for file access */
DltEventHandler pEvent; /**< struct for message producer event handling */
DltMessage msg; /**< one dlt message */
DltReceiver receiver; /**< receiver for fifo connection */
DltReceiver receiverSock; /**< receiver for socket connection */
DltReceiver receiverSerial; /**< receiver for serial connection */
+ DltReceiver receiverCtrlSock; /**< receiver for control socket */
int client_connections; /**< counter for nr. of client connections */
size_t baudrate; /**< Baudrate of serial connection */
#ifdef DLT_SHM_ENABLE
@@ -187,6 +191,9 @@ int dlt_daemon_process_one_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_loc
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_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf
index d9b0987..23d40ec 100644
--- a/src/daemon/dlt.conf
+++ b/src/daemon/dlt.conf
@@ -54,6 +54,11 @@ RingbufferMaxSize = 10000000
RingbufferStepSize = 500000
########################################################################
+# Control Application #
+########################################################################
+ControlSocketPath = /tmp/dlt-ctrl.sock
+
+########################################################################
# Offline Trace memory #
########################################################################
diff --git a/src/daemon/dlt_daemon_common_cfg.h b/src/daemon/dlt_daemon_common_cfg.h
index e0f99da..d08a20e 100644
--- a/src/daemon/dlt_daemon_common_cfg.h
+++ b/src/daemon/dlt_daemon_common_cfg.h
@@ -74,6 +74,7 @@
/* Changable */
/*************/
+
/* Default Path for runtime configuration */
#define DLT_RUNTIME_DEFAULT_DIRECTORY "/tmp"
/* Path and filename for runtime configuration (applications) */
@@ -83,6 +84,10 @@
/* Path and filename for runtime configuration */
#define DLT_RUNTIME_CONFIGURATION "/dlt-runtime.cfg"
+/* Default Path for control socket */
+#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \
+ "/dlt-ctrl.sock"
+
/* Size of text buffer */
#define DLT_DAEMON_COMMON_TEXTBUFSIZE 255
@@ -120,4 +125,3 @@
#define DLT_DAEMON_REMO_STRING "remo"
#endif /* DLT_DAEMON_COMMON_CFG_H */
-
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 0eee668..1a7af3f 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -200,6 +200,12 @@ static DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local,
ret = &daemon_local->timer_wd;
break;
#endif
+ case DLT_CONNECTION_CONTROL_CONNECT:
+ /* FALL THROUGH */
+ /* There must be the same structure for this case */
+ case DLT_CONNECTION_CONTROL_MSG:
+ ret = &daemon_local->receiverCtrlSock;
+ break;
default:
ret = NULL;
}
@@ -253,6 +259,12 @@ void *dlt_connection_get_callback(DltConnection *con)
ret = dlt_daemon_process_systemd_timer;
break;
#endif
+ case DLT_CONNECTION_CONTROL_CONNECT:
+ ret = dlt_daemon_process_control_connect;
+ break;
+ case DLT_CONNECTION_CONTROL_MSG:
+ ret = dlt_daemon_process_control_messages;
+ break;
default:
ret = NULL;
}
diff --git a/src/daemon/dlt_daemon_connection_types.h b/src/daemon/dlt_daemon_connection_types.h
index 4f4bb1c..c35b43e 100644
--- a/src/daemon/dlt_daemon_connection_types.h
+++ b/src/daemon/dlt_daemon_connection_types.h
@@ -39,6 +39,8 @@ typedef enum {
DLT_CONNECTION_ONE_S_TIMER,
DLT_CONNECTION_SIXTY_S_TIMER,
DLT_CONNECTION_SYSTEMD_TIMER,
+ DLT_CONNECTION_CONTROL_CONNECT,
+ DLT_CONNECTION_CONTROL_MSG,
DLT_CONNECTION_TYPE_MAX
} DltConnectionType;
@@ -49,6 +51,8 @@ typedef enum {
#define DLT_CON_MASK_ONE_S_TIMER (1 << DLT_CONNECTION_ONE_S_TIMER)
#define DLT_CON_MASK_SIXTY_S_TIMER (1 << DLT_CONNECTION_SIXTY_S_TIMER)
#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)
/* TODO: squash the DltReceiver structure in there
diff --git a/src/daemon/dlt_daemon_unix_socket.c b/src/daemon/dlt_daemon_unix_socket.c
new file mode 100644
index 0000000..05af5cb
--- /dev/null
+++ b/src/daemon/dlt_daemon_unix_socket.c
@@ -0,0 +1,109 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2015, Advanced Driver Information Technology
+ * Copyright of Advanced Driver Information Technology, Bosch and Denso
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author
+ * Christoph Lipka <clipka@jp.adit-jv.com>
+ *
+ * \copyright Copyright © 2015 ADIT. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt_daemon_unix_socket.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include <syslog.h>
+#include <errno.h>
+#include "dlt-daemon.h"
+#include "dlt_common.h"
+#include "dlt-daemon_cfg.h"
+#include "dlt_daemon_socket.h"
+#include "dlt_daemon_unix_socket.h"
+
+char err_string[DLT_DAEMON_TEXTBUFSIZE];
+
+int dlt_daemon_unix_socket_open(int *sock, char *sock_path)
+{
+ struct sockaddr_un addr;
+
+ if (sock == NULL || sock_path == NULL)
+ {
+ dlt_log(LOG_ERR, "dlt_daemon_unix_socket_open: arguments invalid");
+ return -1;
+ }
+
+ if ((*sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ {
+ dlt_log(LOG_WARNING, "unix socket: socket() error");
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ memcpy(addr.sun_path, sock_path, sizeof(addr.sun_path));
+
+ unlink(sock_path);
+
+ if (bind(*sock, (struct sockaddr *) &addr, sizeof(addr)) == -1)
+ {
+ dlt_log(LOG_WARNING, "unix socket: bind() error");
+ return -1;
+ }
+
+ if (listen(*sock, 1) == -1)
+ {
+ dlt_log(LOG_WARNING, "unix socket: listen error");
+ return -1;
+ }
+
+ return 0;
+}
+
+int dlt_daemon_unix_socket_close(int sock)
+{
+ int ret = close(sock);
+
+ if (ret != 0)
+ {
+ sprintf(err_string, "unix socket close failed: %s", strerror(errno));
+ dlt_log(LOG_WARNING, err_string);
+ }
+
+ return ret;
+}
+
+int dlt_daemon_unix_socket_send(
+ int sock,
+ void *data1,
+ int size1,
+ void *data2,
+ int size2,
+ char serialheader)
+{
+ /* re-use socket send function */
+ return dlt_daemon_socket_send(
+ sock,
+ data1,
+ size1,
+ data2,
+ size2,
+ serialheader);
+}
diff --git a/src/daemon/dlt_daemon_unix_socket.h b/src/daemon/dlt_daemon_unix_socket.h
new file mode 100644
index 0000000..5db4145
--- /dev/null
+++ b/src/daemon/dlt_daemon_unix_socket.h
@@ -0,0 +1,67 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2015, Advanced Driver Information Technology
+ * Copyright of Advanced Driver Information Technology, Bosch and Denso.
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Christoph Lipka <clipka@jp.adit-jv.com>
+ *
+ * \copyright Copyright © 2015 ADIT. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt_daemon_unix_socket.h
+ */
+
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt_daemon_unix_socket.h **
+** **
+** TARGET : linux **
+** **
+** PROJECT : DLT **
+** **
+** AUTHOR : Christoph Lipka clipka@jp.adit-jv.com **
+** **
+** PURPOSE : **
+** **
+** REMARKS : **
+** **
+** PLATFORM DEPENDANT [yes/no]: yes **
+** **
+** TO BE CHANGED BY USER [yes/no]: no **
+** **
+*******************************************************************************/
+
+/*******************************************************************************
+** Author Identity **
+********************************************************************************
+** **
+** Initials Name Company **
+** -------- ------------------------- ---------------------------------- **
+** cl Christoph Lipka ADIT **
+*******************************************************************************/
+
+#ifndef DLT_DAEMON_UNIX_SOCKET_H
+#define DLT_DAEMON_UNIX_SOCKET_H
+
+int dlt_daemon_unix_socket_open(int *sock, char *socket_path);
+int dlt_daemon_socket_close(int sock);
+
+int dlt_daemon_unix_socket_send(int sock,void* data1,int size1,void* data2,
+ int size2,char serialheader);
+
+#endif /* DLT_DAEMON_UNIX_SOCKET_H */
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c
index 2bae2eb..3de3845 100644
--- a/src/lib/dlt_client.c
+++ b/src/lib/dlt_client.c
@@ -77,6 +77,7 @@
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <netdb.h>
#include <sys/stat.h>
+#include <sys/un.h>
#endif
#if defined(_MSC_VER)
@@ -116,7 +117,8 @@ DltReturnValue dlt_client_init(DltClient *client, int verbose)
client->servIP = 0;
client->serialDevice = 0;
client->baudrate = DLT_CLIENT_INITIAL_BAUDRATE;
- client->serial_mode = 0;
+ client->socketPath = 0;
+ client->mode=DLT_CLIENT_MODE_TCP;
client->receiver.buffer = 0;
return DLT_RETURN_OK;
@@ -126,6 +128,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose)
{
char portnumbuffer[33];
struct addrinfo hints, *servinfo, *p;
+ struct sockaddr_un addr;
int rv;
char *env_daemon_port;
/* the port may be specified by an environment variable, defaults to DLT_DAEMON_TCP_PORT */
@@ -149,8 +152,9 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose)
servPort = DLT_DAEMON_TCP_PORT;
}
- if (client->serial_mode==0)
+ switch (client->mode)
{
+ case DLT_CLIENT_MODE_TCP:
snprintf(portnumbuffer, 32, "%d", servPort);
if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
@@ -182,9 +186,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose)
{
printf("Connected to DLT daemon (%s)\n",client->servIP);
}
- }
- else
- {
+ break;
+ case DLT_CLIENT_MODE_SERIAL:
/* open serial connection */
client->sock=open(client->serialDevice,O_RDWR);
if (client->sock<0)
@@ -218,6 +221,39 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose)
{
printf("Connected to %s\n", client->serialDevice);
}
+ break;
+ case DLT_CLIENT_MODE_UNIX:
+ if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ {
+ fprintf(stderr, "ERROR: (unix) socket error: %s\n", strerror(errno));
+ return DLT_RETURN_ERROR;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ memcpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path)-1);
+
+ if (connect(client->sock,
+ (struct sockaddr_un *)&addr,
+ sizeof(addr)) == -1)
+ {
+ fprintf(stderr, "ERROR: (unix) connect error: %s\n", strerror(errno));
+ return DLT_RETURN_ERROR;
+ }
+
+ if (client->sock < 0)
+ {
+ fprintf(stderr,"ERROR: Failed to open device %s\n",
+ client->socketPath);
+ return DLT_RETURN_ERROR;
+ }
+ break;
+ default:
+ if (verbose)
+ {
+ fprintf(stderr, "ERROR: Mode not supported: %d\n", client->mode);
+ }
+ return DLT_RETURN_ERROR;
}
if (dlt_receiver_init(&(client->receiver),client->sock,DLT_CLIENT_RCVBUFSIZE) != DLT_RETURN_OK)
@@ -271,7 +307,7 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
while (1)
{
- if (client->serial_mode==0)
+ if (client->mode==0)
{
/* wait for data from socket */
ret = dlt_receiver_receive_socket(&(client->receiver));
@@ -437,7 +473,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
msg.standardheader->len = DLT_HTOBE_16(len);
/* Send data (without storage header) */
- if (client->serial_mode)
+ if (client->mode)
{
/* via FileDescriptor */
ret=write(client->sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
diff --git a/src/tests/dlt-test-client.c b/src/tests/dlt-test-client.c
index 83a6fe6..9df7e3e 100644
--- a/src/tests/dlt-test-client.c
+++ b/src/tests/dlt-test-client.c
@@ -277,9 +277,9 @@ int main(int argc, char* argv[])
dlt_client_register_message_callback(dlt_testclient_message_callback);
/* Setup DLT Client structure */
- dltclient.serial_mode = dltdata.yflag;
+ dltclient.mode = dltdata.yflag;
- if (dltclient.serial_mode==0)
+ if (dltclient.mode==0)
{
for (index = optind; index < argc; index++)
{
diff --git a/src/tests/dlt-test-multi-process-client.c b/src/tests/dlt-test-multi-process-client.c
index c943578..bdefaaa 100644
--- a/src/tests/dlt-test-multi-process-client.c
+++ b/src/tests/dlt-test-multi-process-client.c
@@ -166,7 +166,7 @@ int init_dlt_connect(DltClient *client, const s_parameters *params, int argc, ch
return -1;
if(params->serial > 0)
{
- client->serial_mode = 1;
+ client->mode = 1;
client->serialDevice = argv[argc - 1];
dlt_client_setbaudrate(client, params->baudrate);
}
@@ -203,7 +203,7 @@ int main(int argc, char *argv[]) {
err = dlt_client_connect(&client, params.verbose);
if (err != DLT_RETURN_OK) {
- printf("Failed to connect %s.\n", client.serial_mode > 0 ? client.serialDevice : client.servIP);
+ printf("Failed to connect %s.\n", client.mode > 0 ? client.serialDevice : client.servIP);
return err;
}
diff --git a/src/tests/dlt-test-stress-client.c b/src/tests/dlt-test-stress-client.c
index fc62230..e0ca808 100644
--- a/src/tests/dlt-test-stress-client.c
+++ b/src/tests/dlt-test-stress-client.c
@@ -298,9 +298,9 @@ int main(int argc, char* argv[])
dlt_client_register_message_callback(dlt_testclient_message_callback);
/* Setup DLT Client structure */
- dltclient.serial_mode = dltdata.yflag;
+ dltclient.mode = dltdata.yflag;
- if (dltclient.serial_mode==0)
+ if (dltclient.mode==0)
{
for (index = optind; index < argc; index++)
{
diff --git a/tests/dlt_test_receiver.c b/tests/dlt_test_receiver.c
index a0e86f7..9b93728 100644
--- a/tests/dlt_test_receiver.c
+++ b/tests/dlt_test_receiver.c
@@ -235,9 +235,9 @@ int main(int argc, char* argv[])
dlt_client_register_message_callback(dlt_receive_filetransfer_callback);
/* Setup DLT Client structure */
- dltclient.serial_mode = dltdata.yflag;
+ dltclient.mode = dltdata.yflag;
- if (dltclient.serial_mode==0)
+ if (dltclient.mode==0)
{
for (index = optind; index < argc; index++)
{