summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManikandan C <mchockalingam@de.adit-jv.com>2018-10-29 16:32:17 +0100
committerChristoph Lipka <clipka@users.noreply.github.com>2018-11-23 11:10:47 +0100
commitd515020fa1bcb5d874084a68c9de9434dc9d994e (patch)
tree339074f3d4e0858dfbe1c528705ed3e4343521f3 /src
parent3cfb292aa43774428ce8dfe120fe16785942b086 (diff)
downloadDLT-daemon-d515020fa1bcb5d874084a68c9de9434dc9d994e.tar.gz
Gateway Improvements
-Support to send and parse periodic control messages -add application/contexts to passive ECU list -Refactor dlt_gateway_send_control_message -Gateway issues with corrupted data and on demand connection -Unit Test update Signed-off-by: Saya Sugiura ssugiura@jp.adit-jv.com Signed-off-by: Christoph Lipka clipka@jp.adit-jv.com Signed-off-by: S. Hameed shameed@jp.adit-jv.com Signed-off-by: ManikandanC Manikandan.Chockalingam@in.bosch.com
Diffstat (limited to 'src')
-rw-r--r--src/console/dlt-control-common.c1
-rw-r--r--src/console/dlt-control.c422
-rw-r--r--src/console/dlt-receive.c2
-rw-r--r--src/daemon/CMakeLists.txt10
-rw-r--r--src/daemon/dlt_daemon_client.c11
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c48
-rw-r--r--src/gateway/dlt_gateway.c1197
-rw-r--r--src/gateway/dlt_gateway.conf5
-rw-r--r--src/gateway/dlt_gateway.h44
-rw-r--r--src/gateway/dlt_gateway_types.h33
-rw-r--r--src/lib/dlt_client.c379
-rw-r--r--src/shared/dlt_common.c145
12 files changed, 1490 insertions, 807 deletions
diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c
index d299c6d..127eb4b 100644
--- a/src/console/dlt-control-common.c
+++ b/src/console/dlt-control-common.c
@@ -69,7 +69,6 @@
#define DLT_CTRL_APID "DLTC"
#define DLT_CTRL_CTID "DLTC"
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock"
-#define DLT_RECEIVE_TEXTBUFSIZE 1024
/** @brief Analyze the daemon answer
*
diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c
index 7e90c7c..4398b9d 100644
--- a/src/console/dlt-control.c
+++ b/src/console/dlt-control.c
@@ -65,7 +65,6 @@
#include "dlt_user.h"
#include "dlt-control-common.h"
-#define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */
#define DLT_GLOGINFO_APID_NUM_MAX 150
@@ -78,29 +77,11 @@
typedef struct
{
- char apid[DLT_ID_SIZE + 1]; /**< application id */
- char ctid[DLT_ID_SIZE + 1]; /**< context id */
- char *apid_desc; /**< apid description */
- char *ctid_desc; /**< ctxt description */
- int log_level; /**< log level */
- int trace_status; /**< trace_status */
- int disp; /**< display flag */
-} DltLoginfoDetail;
-
-typedef struct
-{
- DltLoginfoDetail info[DLT_GLOGINFO_DATA_MAX]; /**< structure for each ctxt/app entry*/
- int count; /**< Number of app and ctxt entries */
-} DltLoginfo;
-
-
-typedef struct
-{
uint32_t service_id; /**< service ID */
} PACKED DltServiceGetDefaultLogLevel;
DltClient g_dltclient;
-DltLoginfo g_get_loginfo;
+DltServiceGetLogInfoResponse *g_resp = NULL;
/* Function prototypes */
int dlt_receive_message_callback(DltMessage *message, void *data);
@@ -131,60 +112,6 @@ typedef struct {
} DltReceiveData;
-void hexAsciiToBinary (const char *ptr,uint8_t *binary,int *size)
-{
-
- char ch = *ptr;
- int pos = 0;
- binary[pos] = 0;
- int first = 1;
- int found;
-
- for(;;)
- {
-
- if(ch == 0)
- {
- *size = pos;
- return;
- }
-
-
- found = 0;
- if (ch >= '0' && ch <= '9')
- {
- binary[pos] = (binary[pos] << 4) + (ch - '0');
- found = 1;
- }
- else if (ch >= 'A' && ch <= 'F')
- {
- binary[pos] = (binary[pos] << 4) + (ch - 'A' + 10);
- found = 1;
- }
- else if (ch >= 'a' && ch <= 'f')
- {
- binary[pos] = (binary[pos] << 4) + (ch - 'a' + 10);
- found = 1;
- }
- if(found)
- {
- if(first)
- first = 0;
- else
- {
- first = 1;
- pos++;
- if(pos>=*size)
- return;
- binary[pos]=0;
- }
- }
-
- ch = *(++ptr);
- }
-
-}
-
/**
* Print usage information of tool.
*/
@@ -240,9 +167,19 @@ void usage()
void dlt_process_get_log_info(void)
{
char apid[DLT_ID_SIZE+1] = {0};
- int cnt;
+ char ctid[DLT_ID_SIZE+1] = {0};
+ AppIDsType app;
+ ContextIDsInfoType con;
+ int i = 0;
+ int j = 0;
+
+ g_resp = (DltServiceGetLogInfoResponse*) calloc(1, sizeof(DltServiceGetLogInfoResponse));
- dlt_getloginfo_init();
+ if (g_resp == NULL)
+ {
+ fprintf(stderr, "%s: Calloc failed for resp..\n", __func__);
+ return;
+ }
/* send control message*/
if (0 != dlt_client_get_log_info(&g_dltclient))
@@ -251,31 +188,43 @@ void dlt_process_get_log_info(void)
return;
}
- for (cnt = 0; cnt < g_get_loginfo.count; cnt++)
+ if (dlt_client_main_loop(&g_dltclient, NULL, 0) == DLT_RETURN_TRUE)
{
- if (strncmp(apid, g_get_loginfo.info[cnt].apid, DLT_ID_SIZE) != 0)
- {
- printf("APID:%4s ", g_get_loginfo.info[cnt].apid);
- apid[DLT_ID_SIZE] = 0;
- dlt_set_id(apid, g_get_loginfo.info[cnt].apid);
+ fprintf(stdout, "DLT-daemon's response is invalid.\n");
+ }
- if (g_get_loginfo.info[cnt].apid_desc != 0)
- {
- printf("%s\n", g_get_loginfo.info[cnt].apid_desc);
- }
- else
- {
- printf("\n");
- }
- }
+ for (i = 0; i < g_resp->log_info_type.count_app_ids; i++)
+ {
+ app = g_resp->log_info_type.app_ids[i];
+
+ dlt_set_id(apid, app.app_id);
- if (strncmp(apid, g_get_loginfo.info[cnt].apid, DLT_ID_SIZE) == 0)
+ if (app.app_description != 0)
{
- printf("%4s %2d %2d %s\n", g_get_loginfo.info[cnt].ctid, g_get_loginfo.info[cnt].log_level,
- g_get_loginfo.info[cnt].trace_status, g_get_loginfo.info[cnt].ctid_desc);
+ printf("APID:%4s %s\n", apid, app.app_description);
}
- }
- dlt_getloginfo_free();
+ else
+ {
+ printf("APID:%4s \n", apid);
+ }
+
+ for (j = 0; j < app.count_context_ids; j++)
+ {
+ con = app.context_id_info[j];
+
+ dlt_set_id(ctid, con.context_id);
+
+ printf("%4s %2d %2d %s\n",
+ ctid,
+ con.log_level,
+ con.trace_status,
+ con.context_description);
+ }
+ }
+
+ dlt_client_free_get_log_info(g_resp);
+ free(g_resp);
+ g_resp = NULL;
}
/**
@@ -437,7 +386,7 @@ int main(int argc, char* argv[])
}
case '?':
{
- if (optopt == 'o' || optopt == 'f')
+ if ((optopt == 'o') || (optopt == 'f'))
{
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
}
@@ -581,7 +530,7 @@ int main(int argc, char* argv[])
printf("ConId: %s\n",dltdata.cvalue);
printf("ServiceId: %d\n",dltdata.svalue);
printf("Message: %s\n",dltdata.xvalue);
- hexAsciiToBinary(dltdata.xvalue,buffer,&size);
+ dlt_hex_ascii_to_binary(dltdata.xvalue,buffer,&size);
printf("Size: %d\n",size);
/* send control message in hex */
if (dlt_client_send_inject_msg(&g_dltclient,
@@ -727,11 +676,11 @@ int main(int argc, char* argv[])
/* Wait timeout */
usleep(dltdata.tvalue*1000);
-
- /* Dlt Client Cleanup */
- dlt_client_cleanup(&g_dltclient,dltdata.vflag);
}
+ /* Dlt Client Cleanup */
+ dlt_client_cleanup(&g_dltclient,dltdata.vflag);
+
if (g_dltclient.socketPath != NULL)
free(g_dltclient.socketPath);
@@ -742,266 +691,10 @@ int main(int argc, char* argv[])
return 0;
}
-void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
-{
- char number16[6]={0};
- char *endptr;
- int count;
-
- if ((rp == NULL) || (rp_count == NULL) || (wp == NULL))
- {
- return;
- }
- /* ------------------------------------------------------
- from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
- ------------------------------------------------------ */
- number16[0] = '+';
- number16[1] = '0';
- number16[2] = 'x';
- for (count = 0; count < (len - 1); count++)
- {
- number16[3] = *(rp + *rp_count + 0);
- number16[4] = *(rp + *rp_count + 1);
- *(wp + count) = strtol(number16, &endptr, 16);
- *rp_count += 3;
- }
- *(wp + count) = 0;
- return;
-}
-
-uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count)
-{
- char num_work[8];
- char *endptr;
-
- if ((rp == NULL) || (rp_count == NULL))
- {
- return -1;
- }
- /* ------------------------------------------------------
- from: [89 13 ] -> to: ['+0x'1389\0] -> to num
- ------------------------------------------------------ */
- num_work[0] = '+';
- num_work[1] = '0';
- num_work[2] = 'x';
- num_work[3] = *(rp + *rp_count + 3);
- num_work[4] = *(rp + *rp_count + 4);
- num_work[5] = *(rp + *rp_count + 0);
- num_work[6] = *(rp + *rp_count + 1);
- num_work[7] = 0;
- *rp_count += 6;
-
- return strtol(num_work, &endptr, 16);
-}
-int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
-{
- char num_work[6];
- char *endptr;
-
- if ((rp == NULL) || (rp_count == NULL))
- {
- return -1;
- }
- /* ------------------------------------------------------
- from: [89 ] -> to: ['0x'89\0] -> to num
- ------------------------------------------------------ */
- num_work[0] = '0';
- num_work[1] = 'x';
- num_work[2] = *(rp + *rp_count + 0);
- num_work[3] = *(rp + *rp_count + 1);
- num_work[4] = 0;
- *rp_count += 3;
-
- return (signed char)strtol(num_work, &endptr, 16);
-}
-
-void dlt_getloginfo_init(void)
-{
- int cnt;
-
- g_get_loginfo.count = 0;
- for (cnt = 0; cnt < DLT_GLOGINFO_DATA_MAX; cnt++)
- {
- g_get_loginfo.info[cnt].apid_desc = NULL;
- g_get_loginfo.info[cnt].ctid_desc = NULL;
- }
-}
-
-void dlt_getloginfo_free(void)
-{
- int cnt;
-
- for (cnt = 0; cnt < DLT_GLOGINFO_DATA_MAX; cnt++)
- {
- if (g_get_loginfo.info[cnt].apid_desc != 0)
- {
- free(g_get_loginfo.info[cnt].apid_desc);
- }
- if (g_get_loginfo.info[cnt].ctid_desc != 0)
- {
- free(g_get_loginfo.info[cnt].ctid_desc);
- }
- }
-}
-
-/**
- * Function to parse the response text and identifying service id and its options.
- */
-int dlt_set_loginfo_parse_service_id(char *resp_text, int *service_id, int *service_opt, char *cb_result)
-{
- int ret;
- char get_log_info_tag[13];
- char service_opt_str[3];
-
- if ((resp_text == NULL) || (service_id == NULL) || (service_opt == NULL) || (cb_result == NULL))
- {
- return -1;
- }
- /* ascii type, syntax is 'get_log_info, ..' */
- /* check target id */
- strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info"));
- ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag)-1);
- if (ret == 0)
- {
- *service_id = DLT_SERVICE_ID_GET_LOG_INFO;
- *cb_result = 0;
- /* reading the response mode from the resp_text. eg. option 7*/
- service_opt_str[0] = *(resp_text+14);
- service_opt_str[1] = *(resp_text+15);
- service_opt_str[2] = 0;
- *service_opt = atoi( service_opt_str );
- }
-
- return ret;
-}
-
-/**
- * Main function to convert the response text in to proper get log info data and
- * filling it in the DltLoginfo structure.
- */
-int dlt_getloginfo_make_loginfo(char *resp_text, int service_opt)
-{
- char *rp;
- int rp_count;
- int loginfo_count;
- uint16_t reg_apid_count;
- uint16_t reg_ctid_count;
- uint16_t reg_apid_num;
- uint16_t reg_ctid_num;
- uint16_t reg_apid_dsc_len;
- uint16_t reg_ctid_dsc_len;
- char reg_apid[DLT_ID_SIZE+1];
- char reg_ctid[DLT_ID_SIZE+1];
- char *reg_apid_dsc;
- char *reg_ctid_dsc;
-
- if (resp_text == NULL)
- {
- return -1;
- }
- /* ------------------------------------------------------
- get_log_info data structure(all data is ascii)
-
- get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
- ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
- cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
- jj jj kk kk kk .. ..
- ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
- aa : get mode (fix value at 0x07)
- bb bb : list num of apid (little endian)
- cc cc cc cc: apid
- dd dd : list num of ctid (little endian)
- ee ee ee ee: ctid
- ff : log level
- gg : trase status
- hh hh : description length of ctid
- ii ii .. : description text of ctid
- jj jj : description length of apid
- kk kk .. : description text of apid
- ------------------------------------------------------ */
-
- /* create all target convert list */
-
- /* rp set header */
- rp = (resp_text + DLT_GET_LOG_INFO_HEADER);
- rp_count = 0;
- /* get reg_apid_num */
- reg_apid_num = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- loginfo_count = g_get_loginfo.count;
-
- if (reg_apid_num > DLT_GLOGINFO_APID_NUM_MAX)
- {
- fprintf(stderr, "GET_LOG_INFO ERROR: APID MAX Over\n");
- g_get_loginfo.count = 0;
- return -1;
- }
-
- /* search for target apid */
- for (reg_apid_count = 0; reg_apid_count < reg_apid_num; reg_apid_count++)
- {
- /* get reg_apid */
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_apid, DLT_ID_SIZE+1);
-
- /* get reg_ctid_num of current reg_apid */
- reg_ctid_num = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- if (loginfo_count + reg_ctid_num > DLT_GLOGINFO_DATA_MAX)
- {
- fprintf(stderr, "GET_LOG_INFO ERROR: LOG DATA MAX Over\n");
- g_get_loginfo.count = 0;
- return -1;
- }
- for (reg_ctid_count = 0; reg_ctid_count < reg_ctid_num; reg_ctid_count++)
- {
- /* get reg_ctid */
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_ctid, DLT_ID_SIZE+1);
-
- g_get_loginfo.info[ loginfo_count ].apid[DLT_ID_SIZE] = 0;
- dlt_set_id(g_get_loginfo.info[ loginfo_count ].apid, reg_apid);
- g_get_loginfo.info[ loginfo_count ].ctid[DLT_ID_SIZE] = 0;
- dlt_set_id(g_get_loginfo.info[ loginfo_count ].ctid, reg_ctid);
- g_get_loginfo.info[ loginfo_count ].log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
- g_get_loginfo.info[ loginfo_count ].trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
-
- /* Description Information */
- if (service_opt == DLT_SERVICE_GET_LOG_INFO_OPT7)
- {
- reg_ctid_dsc_len = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- reg_ctid_dsc = (char *)malloc(sizeof(char) * reg_ctid_dsc_len + 1);
- if (reg_ctid_dsc == 0)
- {
- fprintf(stderr, "malloc failed for ctxt desc\n");
- return -1;
- }
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_ctid_dsc, reg_ctid_dsc_len+1);
- g_get_loginfo.info[ loginfo_count ].ctid_desc = reg_ctid_dsc;
- }
- loginfo_count++;
- }
- /* Description Information */
- if (service_opt == DLT_SERVICE_GET_LOG_INFO_OPT7)
- {
- reg_apid_dsc_len = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- reg_apid_dsc = (char *)malloc(sizeof(char) * reg_apid_dsc_len + 1);
- if (reg_apid_dsc == 0)
- {
- fprintf(stderr, "malloc failed for apid desc\n");
- return -1;
- }
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_apid_dsc, reg_apid_dsc_len+1);
- g_get_loginfo.info[ loginfo_count - reg_ctid_num ].apid_desc = reg_apid_dsc;
- }
- }
- g_get_loginfo.count = loginfo_count;
-
- return 0;
-}
-
int dlt_receive_message_callback(DltMessage *message, void *data)
{
static char resp_text[DLT_RECEIVE_TEXTBUFSIZE];
- int ret;
- int service_id;
- int service_opt;
+ int ret = DLT_RETURN_ERROR;
char cb_result;
/* parameter check */
@@ -1040,10 +733,17 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
}
/* check service id */
- ret = dlt_set_loginfo_parse_service_id(resp_text, &service_id, &service_opt, &cb_result);
- if ((ret == 0) && (service_id == DLT_SERVICE_ID_GET_LOG_INFO ))
+ if (g_resp == NULL)
+ {
+ fprintf(stderr, "%s: g_resp isn't allocated.\n", __func__);
+ dlt_client_cleanup(&g_dltclient, 0);
+ return -1;
+ }
+
+ ret = dlt_set_loginfo_parse_service_id(resp_text, &g_resp->service_id, &g_resp->status, &cb_result);
+ if ((ret == 0) && (g_resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO))
{
- ret = dlt_getloginfo_make_loginfo(resp_text, service_opt);
+ ret = dlt_client_parse_get_log_info_resp_text(g_resp, resp_text);
if (ret != 0)
{
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c
index a4aef2e..fd19f83 100644
--- a/src/console/dlt-receive.c
+++ b/src/console/dlt-receive.c
@@ -82,8 +82,6 @@
#include "dlt_client.h"
-#define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */
-
#define DLT_RECEIVE_ECU_ID "RECV"
/* Function prototypes */
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 063913b..9a22ccd 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -32,13 +32,13 @@ install(TARGETS dlt-daemon
COMPONENT base)
if (WITH_DLT_UNIT_TESTS)
- add_library(dlt_daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
+ add_library(dlt_daemon ${dlt_daemon_SRCS})
target_link_libraries(dlt_daemon rt ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS dlt_daemon
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
- COMPONENT base)
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
+ COMPONENT base)
endif(WITH_DLT_UNIT_TESTS)
INSTALL(FILES dlt.conf
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index dd69326..bd3233f 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -68,17 +68,6 @@
#include "dlt_daemon_offline_logstorage.h"
#include "dlt_gateway.h"
-/* checks if received size is big enough for expected data */
-#define DLT_CHECK_RCV_DATA_SIZE(received, required) \
- ({ \
- int _ret = DLT_RETURN_OK; \
- if (((int)received - (int)required) < 0) { \
- dlt_vlog(LOG_WARNING, "%s: Received data not complete\n", __func__); \
- _ret = DLT_RETURN_ERROR; \
- } \
- _ret; \
- })
-
/** Global text output buffer, mainly used for creation of error/warning strings */
static char str[DLT_DAEMON_TEXTBUFSIZE];
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index fe4d8a7..109cc73 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -347,15 +347,47 @@ STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context(
int loglevel,
int verbose)
{
- // Need to be updated
- // To avoid compiler warning
- (void) daemon_local;
- (void) apid;
- (void) ctid;
- (void) ecuid;
- (void) loglevel;
- (void) verbose;
+ DltServiceSetLogLevel req = {0};
+ DltPassiveControlMessage ctrl = {0};
+ DltGatewayConnection *con = NULL;
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) ||
+ (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT))
+ {
+ dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ con = dlt_gateway_get_connection(&daemon_local->pGateway, ecuid, verbose);
+
+ if (con == NULL)
+ {
+ dlt_vlog(LOG_ERR,
+ "Failed to fond connection to passive node %s\n",
+ ecuid);
+ return DLT_RETURN_ERROR;
+ }
+
+ ctrl.id = DLT_SERVICE_ID_SET_LOG_LEVEL;
+ ctrl.type = CONTROL_MESSAGE_ON_DEMAND;
+
+ dlt_set_id(req.apid, apid);
+ dlt_set_id(req.ctid, ctid);
+
+ req.log_level = loglevel;
+
+ if (dlt_gateway_send_control_message(con, &ctrl, (void *) &req, verbose) != 0)
+ {
+ dlt_vlog(LOG_ERR,
+ "Failed to forward SET_LOG_LEVEL message to passive node %s\n",
+ ecuid);
+
+ return DLT_RETURN_ERROR;
+ }
+
+ return DLT_RETURN_OK;
return DLT_RETURN_OK;
}
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index dda1833..411630b 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -20,8 +20,9 @@
/*!
* \author
* Christoph Lipka <clipka@jp.adit-jv.com>
+ * Saya Sugiura <ssugiura@jp.adit-jv.com>
*
- * \copyright Copyright © 2015 Advanced Driver Information Technology. \n
+ * \copyright Copyright © 2015-2017 Advanced Driver Information Technology. \n
* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
*
* \file dlt_gateway.c
@@ -41,16 +42,17 @@
#include "dlt_config_file_parser.h"
#include "dlt_common.h"
#include "dlt-daemon_cfg.h"
+#include "dlt_daemon_common_cfg.h"
#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_client.h"
+#include "dlt_daemon_offline_logstorage.h"
typedef struct {
char *key; /* The configuration key*/
int (*func)(DltGatewayConnection *con, char *value); /* Conf handler */
int is_opt; /* If the configuration is optional or not */
} DltGatewayConf;
-#ifndef DLT_UNIT_TESTS
typedef enum {
GW_CONF_IP_ADDRESS = 0,
GW_CONF_PORT,
@@ -58,10 +60,11 @@ typedef enum {
GW_CONF_CONNECT,
GW_CONF_TIMEOUT,
GW_CONF_SEND_CONTROL,
+ GW_CONF_SEND_PERIODIC_CONTROL,
GW_CONF_SEND_SERIAL_HEADER,
GW_CONF_COUNT
} DltGatewayConfType;
-#endif
+
/**
* Check if given string is a valid IP address
*
@@ -72,11 +75,12 @@ typedef enum {
STATIC int dlt_gateway_check_ip(DltGatewayConnection *con, char *value)
{
struct sockaddr_in sa;
- int ret = -1;
+ int ret = DLT_RETURN_ERROR;
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
ret = inet_pton(AF_INET, value, &(sa.sin_addr));
@@ -89,17 +93,17 @@ STATIC int dlt_gateway_check_ip(DltGatewayConnection *con, char *value)
if (con->ip_address == NULL)
{
dlt_log(LOG_ERR, "Cannot copy passive node IP address string\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
else
{
dlt_log(LOG_ERR, "IP address is not valid\n");
}
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -113,25 +117,26 @@ STATIC int dlt_gateway_check_port(DltGatewayConnection *con, char *value)
{
int tmp = -1;
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
tmp = (int) strtol(value, NULL, 10);
/* port ranges for unprivileged applications */
- if (tmp > IPPORT_RESERVED && tmp <= USHRT_MAX)
+ if ((tmp > IPPORT_RESERVED) && (tmp <= USHRT_MAX))
{
con->port = tmp;
- return 0;
+ return DLT_RETURN_OK;
}
else
{
dlt_log(LOG_ERR, "Port number is invalid\n");
}
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -143,19 +148,20 @@ STATIC int dlt_gateway_check_port(DltGatewayConnection *con, char *value)
*/
STATIC int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
con->ecuid = strdup(value);
if (con->ecuid == NULL)
{
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
/**
@@ -168,9 +174,10 @@ STATIC int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value)
STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
if (strncasecmp(value, "OnStartup", strlen("OnStartup")) == 0)
@@ -185,10 +192,10 @@ STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
{
dlt_log(LOG_ERR, "Wrong connection trigger state given.\n");
con->trigger = DLT_GATEWAY_UNDEFINED;
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
/**
@@ -200,19 +207,20 @@ STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
*/
STATIC int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
con->timeout = (int) strtol(value, NULL, 10);
if (con->timeout > 0)
{
- return 0;
+ return DLT_RETURN_OK;
}
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -224,14 +232,57 @@ STATIC int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value)
*/
STATIC int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
con->send_serial = !!((int) strtol(value, NULL, 10));
- return 0;
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Allocate passive control messages
+ *
+ * @param con DltGatewayConnection to be updated
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_allocate_control_messages(DltGatewayConnection *con)
+{
+ if (con == NULL)
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (con->p_control_msgs == NULL)
+ {
+ con->p_control_msgs = calloc(1, sizeof(DltPassiveControlMessage));
+
+ if (!con->p_control_msgs)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+ else
+ {
+ con->p_control_msgs->next = calloc(1, sizeof(DltPassiveControlMessage));
+
+ if (!con->p_control_msgs->next)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ con->p_control_msgs = con->p_control_msgs->next;
+ }
+
+ return DLT_RETURN_OK;
}
/**
@@ -247,51 +298,202 @@ STATIC int dlt_gateway_check_control_messages(DltGatewayConnection *con,
/* list of allowed clients given */
char *token = NULL;
char *rest = NULL;
- int i = 0;
- char error_msg[DLT_DAEMON_TEXTBUFSIZE];
+ DltPassiveControlMessage *head = NULL;
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
if (strlen(value) == 0)
{
- memset(con->control_msgs,
- 0,
- sizeof(int) * DLT_GATEWAY_MAX_STARTUP_CTRL_MSG);
- return 0;
+ return DLT_RETURN_OK;
}
+ /* set on startup control msg id and interval*/
token = strtok_r(value, ",", &rest);
- while (token != NULL && i < DLT_GATEWAY_MAX_STARTUP_CTRL_MSG)
+
+ while (token != NULL)
{
+ if (dlt_gateway_allocate_control_messages(con) == -1)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
- con->control_msgs[i] = strtol(token, NULL, 16);
+ con->p_control_msgs->id = strtol(token, NULL, 16);
+ con->p_control_msgs->user_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
+ con->p_control_msgs->type = CONTROL_MESSAGE_ON_STARTUP;
+ con->p_control_msgs->req = CONTROL_MESSAGE_NOT_REQUESTED;
+ con->p_control_msgs->interval = -1;
- if (errno == EINVAL || errno == ERANGE)
+ if (head == NULL)
{
- snprintf(error_msg,
- DLT_DAEMON_TEXTBUFSIZE-1,
- "Control message ID is not an integer: %s\n", token);
- dlt_log(LOG_ERR, error_msg);
- return -1;
+ head = con->p_control_msgs;
}
- else if (con->control_msgs[i] < DLT_SERVICE_ID_SET_LOG_LEVEL ||
- con->control_msgs[i] >= DLT_SERVICE_ID_LAST_ENTRY)
+
+ if ((errno == EINVAL) || (errno == ERANGE))
{
- snprintf(error_msg,
- DLT_DAEMON_TEXTBUFSIZE-1,
- "Control message ID is not valid: %s\n", token);
- dlt_log(LOG_ERR, error_msg);
- return -1;
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not an integer: %s\n",
+ token);
+ return DLT_RETURN_ERROR;
+ }
+ else if ((con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) ||
+ (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY))
+ {
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not valid: %s\n",
+ token);
+ return DLT_RETURN_ERROR;
+ }
+
+ token = strtok_r(NULL, ",", &rest);
+ }
+
+ /* get back to head */
+ con->p_control_msgs = head;
+ con->head = head;
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Check the specified periodic control messages identifier
+ *
+ * @param con DltGatewayConnection to be updated
+ * @param value string to be tested
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_check_periodic_control_messages(DltGatewayConnection *con,
+ char *value)
+{
+ char *token = NULL;
+ char *rest = NULL;
+ DltPassiveControlMessage *head = NULL;
+
+ if ((con == NULL) || (value == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (strlen(value) == 0)
+ {
+ return DLT_RETURN_OK;
+ }
+
+ /* store head address */
+ head = con->p_control_msgs;
+
+ /* set periodic control msg id and interval*/
+ token = strtok_r(value, ",", &rest);
+
+ while (token != NULL)
+ {
+ char *p_token = NULL;
+ char *p_rest = NULL;
+ uint32_t id = 0;
+
+ p_token = strtok_r(token, ":", &p_rest);
+
+ if ((p_token != NULL) && (strlen(p_token) != 0))
+ {
+ id = strtol(p_token, NULL, 16);
+
+ /* get back to head */
+ con->p_control_msgs = head;
+
+ /* check if there is already id set in p_control_msgs */
+ while (con->p_control_msgs != NULL)
+ {
+ if (con->p_control_msgs->id == id)
+ {
+ con->p_control_msgs->type = CONTROL_MESSAGE_BOTH;
+ con->p_control_msgs->interval = strtol(p_rest, NULL, 10);
+ if (con->p_control_msgs->interval <= 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s interval is %d. It won't be send periodically.\n",
+ dlt_get_service_name(con->p_control_msgs->id),
+ con->p_control_msgs->interval);
+ }
+ break;
+ }
+
+ con->p_control_msgs = con->p_control_msgs->next;
+ }
+
+ /* if the id is not added yet, p_control_msgs supposed to be NULL */
+ if (con->p_control_msgs == NULL)
+ {
+ /* get back to head */
+ con->p_control_msgs = head;
+
+ /* go to last pointer */
+ while (con->p_control_msgs != NULL)
+ {
+ if (con->p_control_msgs->next == NULL)
+ {
+ break;
+ }
+
+ con->p_control_msgs = con->p_control_msgs->next;
+ }
+
+ if (dlt_gateway_allocate_control_messages(con) == -1)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ con->p_control_msgs->id = id;
+ con->p_control_msgs->user_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
+ con->p_control_msgs->type = CONTROL_MESSAGE_PERIODIC;
+ con->p_control_msgs->req = CONTROL_MESSAGE_NOT_REQUESTED;
+ con->p_control_msgs->interval = strtol(p_rest, NULL, 10);
+ if (con->p_control_msgs->interval <= 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s interval is %d. It won't be send periodically.\n",
+ dlt_get_service_name(con->p_control_msgs->id),
+ con->p_control_msgs->interval);
+ }
+
+ if (head == NULL)
+ {
+ head = con->p_control_msgs;
+ }
+ }
+ }
+
+ if ((errno == EINVAL) || (errno == ERANGE))
+ {
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not an integer: %s\n",
+ p_token);
+ return DLT_RETURN_ERROR;
+ }
+ else if ((con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) ||
+ (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY))
+ {
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not valid: %s\n",
+ p_token);
+ return DLT_RETURN_ERROR;
}
token = strtok_r(NULL, ",", &rest);
- i++;
}
- return 0;
+ /* get back to head */
+ con->p_control_msgs = head;
+ con->head = head;
+
+ return DLT_RETURN_OK;
}
/**
@@ -325,6 +527,10 @@ STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT] =
.key = "SendControl",
.func = dlt_gateway_check_control_messages,
.is_opt = 1 },
+ [GW_CONF_SEND_PERIODIC_CONTROL] = {
+ .key = "SendPeriodicControl",
+ .func = dlt_gateway_check_periodic_control_messages,
+ .is_opt = 1 },
[GW_CONF_SEND_SERIAL_HEADER] = {
.key = "SendSerialHeader",
.func = dlt_gateway_check_send_serial,
@@ -347,15 +553,16 @@ STATIC int dlt_gateway_check_param(DltGateway *gateway,
DltGatewayConfType ctype,
char *value)
{
- if (gateway == NULL || con == NULL || value == NULL)
+ if ((gateway == NULL) || (con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
if (ctype < GW_CONF_COUNT)
return configuration_entries[ctype].func(con, value);
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -371,13 +578,13 @@ int dlt_gateway_store_connection(DltGateway *gateway,
int verbose)
{
int i = 0;
- int ret = 0;
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || tmp == NULL)
+ if ((gateway == NULL) || (tmp == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
/* find next free entry in connection array */
@@ -391,9 +598,9 @@ int dlt_gateway_store_connection(DltGateway *gateway,
i++;
}
- if (&gateway->connections[i] == NULL)
+ if (&(gateway->connections[i]) == NULL)
{
- return -1;
+ return DLT_RETURN_ERROR;
}
/* store values */
@@ -407,9 +614,8 @@ int dlt_gateway_store_connection(DltGateway *gateway,
gateway->connections[i].timeout = tmp->timeout;
gateway->connections[i].handle = 0;
gateway->connections[i].status = DLT_GATEWAY_INITIALIZED;
- memcpy(gateway->connections[i].control_msgs,
- tmp->control_msgs,
- sizeof(tmp->control_msgs));
+ gateway->connections[i].p_control_msgs = tmp->p_control_msgs;
+ gateway->connections[i].head = tmp->head;
gateway->connections[i].send_serial = tmp->send_serial;
if (dlt_client_init_port(&gateway->connections[i].client,
@@ -417,9 +623,13 @@ int dlt_gateway_store_connection(DltGateway *gateway,
verbose) != 0)
{
free(gateway->connections[i].ip_address);
+ gateway->connections[i].ip_address = NULL;
free(gateway->connections[i].ecuid);
- dlt_log(LOG_CRIT, "dlt_client_init() failed for gateway connection\n");
- return -1;
+ gateway->connections[i].ecuid = NULL;
+ free(gateway->connections[i].p_control_msgs);
+ gateway->connections[i].p_control_msgs = NULL;
+ dlt_log(LOG_CRIT, "dlt_client_init_port() failed for gateway connection\n");
+ return DLT_RETURN_ERROR;
}
dlt_receiver_init(&gateway->connections[i].client.receiver,
gateway->connections[i].client.sock,
@@ -430,18 +640,10 @@ int dlt_gateway_store_connection(DltGateway *gateway,
{
dlt_log(LOG_ERR,
"dlt_client_set_server_ip() failed for gateway connection \n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- if (ret != 0)
- {
- free(gateway->connections[i].ip_address);
- free(gateway->connections[i].ecuid);
- dlt_log(LOG_ERR, "Gateway: DltClient initialization failed\n");
- return -1;
- }
-
- return 0;
+ return DLT_RETURN_OK;
}
/**
@@ -460,9 +662,10 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || config_file == 0 || config_file[0] == '\0')
+ if ((gateway == NULL) || (config_file == 0) || (config_file[0] == '\0'))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
/* read configuration file */
@@ -475,7 +678,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
{
dlt_config_file_release(file);
dlt_log(LOG_ERR, "Invalid number of sections in configuration file\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
gateway->connections = calloc(sizeof(DltGatewayConnection),
@@ -485,12 +688,11 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
{
dlt_config_file_release(file);
dlt_log(LOG_CRIT, "Memory allocation for gateway connections failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
for (i = 0; i < gateway->num_connections; i++)
{
- char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' };
DltGatewayConnection tmp;
int invalid = 0;
DltGatewayConfType j = 0;
@@ -515,20 +717,16 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
if ((ret != 0) && configuration_entries[j].is_opt)
{
/* Use default values for this key */
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Using default for %s.\n",
configuration_entries[j].key);
- dlt_log(LOG_WARNING, local_str);
continue;
}
else if (ret != 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Missing configuration for %s.\n",
configuration_entries[j].key);
- dlt_log(LOG_WARNING, local_str);
invalid = 1;
break;
}
@@ -538,22 +736,19 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
if (ret != 0)
{
- sprintf(local_str,
- "Configuration %s = %s is invalid.\n"
- "Using default.\n",
- configuration_entries[j].key, value);
- dlt_log(LOG_ERR, local_str);
+ dlt_vlog(LOG_ERR,
+ "Configuration %s = %s is invalid.\n"
+ "Using default.\n",
+ configuration_entries[j].key, value);
}
}
if (invalid)
{
- memset(local_str, 0, DLT_DAEMON_TEXTBUFSIZE);
- sprintf(local_str,
- "%s configuration is invalid.\n"
- "Ignoring.\n",
- section);
- dlt_log(LOG_ERR, local_str);
+ dlt_vlog(LOG_ERR,
+ "%s configuration is invalid.\n"
+ "Ignoring.\n",
+ section);
}
else
{
@@ -567,7 +762,9 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
/* strdup used inside some get_value function */
free(tmp.ecuid);
+ tmp.ecuid = NULL;
free(tmp.ip_address);
+ tmp.ip_address = NULL;
}
dlt_config_file_release(file);
@@ -580,7 +777,8 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose)
if (daemon_local == NULL)
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
DltGateway *gateway = &daemon_local->pGateway;
@@ -595,27 +793,29 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose)
verbose) != 0)
{
dlt_log(LOG_ERR, "Gateway initialization failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
{
dlt_log(LOG_CRIT, "Pointer to Gateway structure is NULL\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* ignore return value */
dlt_gateway_establish_connections(gateway, daemon_local, verbose);
- return 0;
+ return DLT_RETURN_OK;
}
void dlt_gateway_deinit(DltGateway *gateway, int verbose)
{
+ DltPassiveControlMessage *msg;
int i = 0;
if (gateway == NULL)
{
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
return;
}
@@ -626,11 +826,91 @@ void dlt_gateway_deinit(DltGateway *gateway, int verbose)
DltGatewayConnection *c = &gateway->connections[i];
dlt_client_cleanup(&c->client, verbose);
free(c->ip_address);
+ c->ip_address = NULL;
free(c->ecuid);
+ c->ecuid = NULL;
+ while (c->p_control_msgs != NULL)
+ {
+ msg = c->p_control_msgs->next;
+ free(c->p_control_msgs);
+ c->p_control_msgs = msg;
+ }
}
free(gateway->connections);
- free(gateway);
+ gateway->connections = NULL;
+}
+
+/**
+ * If connection to passive node established, add to event loop
+ *
+ * @param daemon_local DltDaemonLocal
+ * @param con DltGatewayConnection
+ * @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local,
+ DltGatewayConnection *con,
+ int verbose)
+{
+ DltPassiveControlMessage *control_msg = NULL;
+ int sendtime = 1;
+
+ if ((daemon_local == NULL) || (con == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ /* connection to passive node established, add to event loop */
+ con->status = DLT_GATEWAY_CONNECTED;
+ con->reconnect_cnt = 0;
+ con->timeout_cnt = 0;
+ con->sendtime_cnt = 0;
+
+ /* setup dlt connection and add to epoll event loop here */
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ con->client.sock,
+ EPOLLIN,
+ DLT_CONNECTION_GATEWAY) != 0)
+ {
+ dlt_log(LOG_ERR, "Gateway connection creation failed\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* immediately send configured control messages */
+ control_msg = con->p_control_msgs;
+
+ while (control_msg != NULL)
+ {
+ if ((control_msg->type == CONTROL_MESSAGE_ON_STARTUP) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH))
+ {
+ if (dlt_gateway_send_control_message(con,
+ control_msg,
+ NULL,
+ verbose) == DLT_RETURN_OK)
+ {
+ control_msg->req = CONTROL_MESSAGE_REQUESTED;
+ }
+ }
+
+ /* multiply periodic sending time */
+ if (((control_msg->type == CONTROL_MESSAGE_PERIODIC) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH)) &&
+ (control_msg->interval > 0))
+ {
+ sendtime *= control_msg->interval;
+ }
+ control_msg = control_msg->next;
+ }
+
+ /* set periodic sending time */
+ con->sendtime = sendtime;
+ con->sendtime_cnt = con->sendtime;
+
+ return DLT_RETURN_OK;
}
int dlt_gateway_establish_connections(DltGateway *gateway,
@@ -642,50 +922,37 @@ int dlt_gateway_establish_connections(DltGateway *gateway,
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || daemon_local == NULL)
+ if ((gateway == NULL) || (daemon_local == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
for (i = 0; i < gateway->num_connections; i++)
{
DltGatewayConnection *con = &(gateway->connections[i]);
+ DltPassiveControlMessage *control_msg = NULL;
+
if (con == NULL)
{
dlt_log(LOG_CRIT, "Cannot retrieve gateway connection details\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- if (con->status != DLT_GATEWAY_CONNECTED &&
- con->trigger != DLT_GATEWAY_ON_DEMAND &&
- con->trigger != DLT_GATEWAY_DISABLED)
+ if ((con->status != DLT_GATEWAY_CONNECTED) &&
+ (con->trigger != DLT_GATEWAY_ON_DEMAND) &&
+ (con->trigger != DLT_GATEWAY_DISABLED))
{
ret = dlt_client_connect(&con->client, verbose);
if (ret == 0)
{
- /* connection to passive node established, add to event loop */
- con->status = DLT_GATEWAY_CONNECTED;
- con->reconnect_cnt = 0;
- con->timeout_cnt = 0;
-
/* setup dlt connection and add to epoll event loop here */
- if (dlt_connection_create(daemon_local,
- &daemon_local->pEvent,
- con->client.sock,
- EPOLLIN,
- DLT_CONNECTION_GATEWAY) != 0)
+ if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK)
{
dlt_log(LOG_ERR, "Gateway connection creation failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
-
- /* immediately send configured control messages */
- dlt_gateway_send_control_message(con,
- gateway,
- daemon_local,
- verbose);
-
}
else
{
@@ -702,9 +969,53 @@ int dlt_gateway_establish_connections(DltGateway *gateway,
}
}
}
+ else if ((con->status == DLT_GATEWAY_CONNECTED) &&
+ (con->trigger != DLT_GATEWAY_DISABLED))
+ {
+ /* setup dlt connection and add to epoll event loop here */
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ con->client.sock,
+ EPOLLIN,
+ DLT_CONNECTION_GATEWAY) != 0)
+ {
+ dlt_log(LOG_ERR, "Gateway connection creation failed\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* immediately send periodic configured control messages */
+ control_msg = con->p_control_msgs;
+
+ while (control_msg != NULL)
+ {
+ if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH))
+ {
+ if (dlt_gateway_send_control_message(con,
+ control_msg,
+ NULL,
+ verbose) == DLT_RETURN_OK)
+ {
+ control_msg->req = CONTROL_MESSAGE_REQUESTED;
+ }
+ }
+ control_msg = control_msg->next;
+ }
+
+ /* check sendtime counter */
+ if (con->sendtime_cnt > 0)
+ {
+ con->sendtime_cnt--;
+ }
+
+ if (con->sendtime_cnt == 0)
+ {
+ con->sendtime_cnt = con->sendtime;
+ }
+ }
}
- return 0;
+ return DLT_RETURN_OK;
}
DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
@@ -713,6 +1024,7 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
if (gateway == NULL)
{
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
return NULL;
}
@@ -728,6 +1040,238 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
return NULL;
}
+/**
+ * Parse GET_LOG_INFO
+ *
+ * @param daemon DltDaemon
+ * @param daemon_local DltDaemonLocal
+ * @param msg DltMessage
+ * @param req 1 if requested from gateway, 0 otherwise
+ * @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_parse_get_log_info(DltDaemon *daemon,
+ char *ecu,
+ DltMessage *msg,
+ int req,
+ int verbose)
+{
+ char resp_text[DLT_RECEIVE_TEXTBUFSIZE] = {'\0'};
+ DltServiceGetLogInfoResponse *resp = NULL;
+ AppIDsType app;
+ ContextIDsInfoType con;
+ int i = 0;
+ int j = 0;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((msg == NULL) || (msg->databuffer == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceGetLogInfoResponse)) < 0)
+ {
+ return DLT_RETURN_ERROR;
+ }
+
+ /* if the request was send from gateway, clear all application and context list */
+ if (req == CONTROL_MESSAGE_REQUESTED)
+ {
+ /* clear application list */
+ if (dlt_daemon_applications_clear(daemon, ecu, verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_ERR, "Cannot clear applications list\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* clear context list */
+ if (dlt_daemon_contexts_clear(daemon, ecu, verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_ERR, "Cannot clear contexts list\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+
+ /* check response */
+ if (dlt_message_payload(msg,
+ resp_text,
+ DLT_RECEIVE_TEXTBUFSIZE,
+ DLT_OUTPUT_ASCII, 0) != DLT_RETURN_OK)
+ {
+ dlt_log(LOG_ERR, "GET_LOG_INFO payload failed\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* prepare pointer to message request */
+ resp = (DltServiceGetLogInfoResponse*) calloc(1, sizeof(DltServiceGetLogInfoResponse));
+
+ if (resp == NULL)
+ {
+ dlt_log(LOG_ERR,
+ "Get Log Info Response could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if (dlt_set_loginfo_parse_service_id(resp_text, &resp->service_id, &resp->status) != DLT_RETURN_OK)
+ {
+ dlt_log(LOG_ERR, "Parsing GET_LOG_INFO failed\n");
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+
+ if (dlt_client_parse_get_log_info_resp_text(resp, resp_text) != DLT_RETURN_OK)
+ {
+ dlt_log(LOG_ERR, "Parsing GET_LOG_INFO failed\n");
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (i = 0; i < resp->log_info_type.count_app_ids; i++)
+ {
+ app = resp->log_info_type.app_ids[i];
+
+ /* add application */
+ if (dlt_daemon_application_add(daemon,
+ app.app_id,
+ 0,
+ app.app_description,
+ -1,
+ ecu,
+ verbose) == 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s: dlt_daemon_application_add failed\n",
+ __func__);
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (j = 0; j < app.count_context_ids; j++)
+ {
+ con = app.context_id_info[j];
+
+ /* add context */
+ if (dlt_daemon_context_add(daemon,
+ app.app_id,
+ con.context_id,
+ con.log_level,
+ con.trace_status,
+ 0,
+ -1,
+ con.context_description,
+ ecu,
+ verbose) == 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s: dlt_daemon_context_add failed for %4s\n",
+ __func__,
+ app.app_id);
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+ }
+ }
+
+ /* free response */
+ dlt_client_cleanup_get_log_info(resp);
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Parse GET_DEFAULT_LOG_LEVEL
+ *
+ * @param daemon DltDaemon
+ * @param daemon_local DltDaemonLocal
+ * @param msg DltMessage
+ * @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ char *ecu,
+ DltMessage *msg,
+ int verbose)
+{
+ DltServiceGetDefaultLogLevelResponse *resp = NULL;
+ DltGatewayConnection *con = NULL;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon == NULL) || (daemon_local == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize,
+ sizeof(DltServiceGetDefaultLogLevelResponse)) < 0)
+ {
+ dlt_log(LOG_ERR, "Received data incomplete.\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* prepare pointer to message request */
+ resp = (DltServiceGetDefaultLogLevelResponse *) (msg->databuffer);
+
+ con = dlt_gateway_get_connection(&daemon_local->pGateway,
+ ecu,
+ verbose);
+
+ if (con == NULL)
+ {
+ dlt_vlog(LOG_ERR, "No information about passive ECU: %s\n",
+ ecu);
+
+ return DLT_RETURN_ERROR;
+ }
+
+ con->default_log_level = resp->log_level;
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Service offline logstorage
+ *
+ * @param daemon DltDaemon
+ * @param daemon_local DltDaemonLocal
+ * @param verbose int
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_control_service_logstorage(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose)
+{
+ unsigned int connection_type = 0;
+ int i = 0;
+
+ if (daemon_local->flags.offlineLogstorageMaxDevices <= 0)
+ {
+ dlt_log(LOG_INFO,
+ "Logstorage functionality not enabled or MAX device set is 0\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
+ {
+ connection_type = daemon->storage_handle[i].connection_type;
+
+ if (connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
+ {
+ /* Check if log level of running application needs an update */
+ dlt_daemon_logstorage_update_application_loglevel(daemon,
+ daemon_local,
+ i,
+ verbose);
+ }
+ }
+
+ return DLT_RETURN_OK;
+}
+
int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
DltReceiver *receiver,
@@ -739,9 +1283,10 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
DltMessage msg;
char local_str[DLT_DAEMON_TEXTBUFSIZE];
- if (daemon == NULL || daemon_local == NULL || receiver == NULL)
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
PRINT_FUNCTION_VERBOSE(verbose);
@@ -750,7 +1295,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
if (gateway == NULL)
{
dlt_log(LOG_ERR, "Gateway structure is NULL\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
for (i = 0; i < gateway->num_connections; i++)
@@ -765,7 +1310,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
if (con == NULL)
{
dlt_log(LOG_ERR, "Cannot associate fd to passive Node connection\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* now the corresponding passive node connection is available */
@@ -773,7 +1318,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
dlt_log(LOG_ERR,
"Cannot initialize DLT message for passive node forwarding\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* nearly copy and paste of dlt_client_main_loop function */
@@ -783,7 +1328,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
if (dlt_message_free(&msg, verbose) < 0)
{
dlt_log(LOG_ERR, "Cannot free DLT message\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
dlt_log(LOG_WARNING, "Connection to passive node lost\n");
@@ -804,7 +1349,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
}
}
- return 0;
+ return DLT_RETURN_OK;
}
while (dlt_message_read(&msg,
@@ -821,14 +1366,69 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
/* only forward messages if the received ECUid is the expected one */
if (strncmp(header->ecu, con->ecuid, strlen(con->ecuid)) == 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ uint32_t id;
+ uint32_t id_tmp;
+ DltPassiveControlMessage *control_msg = con->p_control_msgs;
+
+ dlt_vlog(LOG_DEBUG,
"Received ECUid (%s) similar to configured ECUid(%s). "
"Forwarding message (%s).\n",
header->ecu,
con->ecuid,
msg.databuffer);
- dlt_log(LOG_DEBUG, local_str);
+
+ id_tmp = *((uint32_t*)(msg.databuffer));
+ id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp);
+
+ /* if ID is GET_LOG_INFO, parse msg */
+ if (id == DLT_SERVICE_ID_GET_LOG_INFO)
+ {
+ while (control_msg)
+ {
+ if (control_msg->id == id)
+ {
+ if (dlt_gateway_parse_get_log_info(daemon,
+ header->ecu,
+ &msg,
+ control_msg->req,
+ verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_WARNING, "Parsing GET_LOG_INFO message failed!\n");
+ }
+
+ /* Check for logstorage */
+ dlt_gateway_control_service_logstorage(daemon,
+ daemon_local,
+ verbose);
+
+ /* initialize the flag */
+ control_msg->req = CONTROL_MESSAGE_NOT_REQUESTED;
+ break;
+ }
+ control_msg = control_msg->next;
+ }
+ }
+ else if (id == DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL)
+ {
+ if (dlt_gateway_parse_get_default_log_level(
+ daemon,
+ daemon_local,
+ header->ecu,
+ &msg,
+ verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_WARNING,
+ "Parsing GET_DEFAULT_LOG_LEVEL message failed!\n");
+ }
+ }
+
+ /* prepare storage header */
+ if (dlt_set_storageheader(msg.storageheader,
+ msg.headerextra.ecu) == DLT_RETURN_ERROR)
+ {
+ dlt_vlog(LOG_ERR, "%s: Can't set storage header\n", __func__);
+ return DLT_DAEMON_ERROR_UNKNOWN;
+ }
if (dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,
daemon,
@@ -846,27 +1446,25 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
}
else /* otherwise remove this connection and do not connect again */
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Received ECUid (%s) differs to configured ECUid(%s). "
"Discard this message.\n",
header->ecu,
con->ecuid);
- dlt_log(LOG_WARNING, local_str);
/* disconnect from passive node */
- con->status = DLT_GATEWAY_DISCONNECTED;
- con->trigger = DLT_GATEWAY_DISABLED;
- if (dlt_event_handler_unregister_connection(&daemon_local->pEvent,
- daemon_local,
- receiver->fd)
- != 0)
- {
- dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
- }
+ con->status = DLT_GATEWAY_DISCONNECTED;
+ con->trigger = DLT_GATEWAY_DISABLED;
+ if (dlt_event_handler_unregister_connection(&daemon_local->pEvent,
+ daemon_local,
+ receiver->fd)
+ != 0)
+ {
+ dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
+ }
- dlt_log(LOG_WARNING,
- "Disconnect from passive node due to invalid ECUid\n");
+ dlt_log(LOG_WARNING,
+ "Disconnect from passive node due to invalid ECUid\n");
}
if (msg.found_serialheader)
@@ -879,7 +1477,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
/* Return value ignored */
dlt_message_free(&msg,verbose);
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
@@ -891,7 +1489,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
/* Return value ignored */
dlt_message_free(&msg,verbose);
- return -1;
+ return DLT_RETURN_ERROR;
}
}
}
@@ -900,15 +1498,15 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
/* Return value ignored */
dlt_message_free(&msg, verbose);
- return -1;
+ return DLT_RETURN_ERROR;
}
if (dlt_message_free(&msg, verbose) == -1)
{
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
int dlt_gateway_process_gateway_timer(DltDaemon *daemon,
@@ -918,28 +1516,25 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon,
{
uint64_t expir = 0;
ssize_t res = 0;
- char local_str[DLT_DAEMON_TEXTBUFSIZE];
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL))
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "%s: invalid parameters",
+ dlt_vlog(LOG_ERR,
+ "%s: invalid parameters\n",
__func__);
- dlt_log(LOG_ERR, local_str);
- return -1;
+ return DLT_RETURN_WRONG_PARAMETER;
}
res = read(receiver->fd, &expir, sizeof(expir));
if(res < 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "%s: Fail to read timer (%s)\n", __func__, strerror(errno));
- dlt_log(LOG_WARNING, local_str);
+ dlt_vlog(LOG_WARNING,
+ "%s: Fail to read timer (%s)\n",
+ __func__,
+ strerror(errno));
/* Activity received on timer_wd, but unable to read the fd:
let's go on sending notification */
}
@@ -951,7 +1546,7 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon,
dlt_log(LOG_DEBUG, "Gateway Timer\n");
- return 0;
+ return DLT_RETURN_OK;
}
int dlt_gateway_forward_control_message(DltGateway *gateway,
@@ -963,12 +1558,15 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
int i = 0;
int ret = 0;
DltGatewayConnection *con = NULL;
+ uint32_t id_tmp;
+ uint32_t id;
PRINT_FUNCTION_VERBOSE(verbose);
if (gateway == NULL || daemon_local == NULL || msg == NULL || ecu == NULL)
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
for (i = 0; i < gateway->num_connections; i++)
@@ -985,13 +1583,13 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (con == NULL)
{
dlt_log(LOG_WARNING, "Unknown passive node identifier\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
if (con->status != DLT_GATEWAY_CONNECTED)
{
dlt_log(LOG_INFO, "Passive node is not connected\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
if (con->send_serial) /* send serial header */
@@ -1004,7 +1602,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (ret == -1)
{
dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
@@ -1015,7 +1613,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (ret == -1)
{
dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
else
{
@@ -1023,12 +1621,17 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (ret == -1)
{
dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
- dlt_log(LOG_INFO, "Control message forwarded\n");
- return 0;
+ id_tmp = *((uint32_t*)(msg->databuffer));
+ id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
+
+ dlt_vlog(LOG_INFO,
+ "Control message forwarded : %s\n",
+ dlt_get_service_name(id));
+ return DLT_RETURN_OK;
}
int dlt_gateway_process_on_demand_request(DltGateway *gateway,
@@ -1042,9 +1645,10 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || daemon_local == NULL || node_id == NULL)
+ if ((gateway == NULL) || (daemon_local == NULL) || (node_id == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
/* find connection by ECU id */
@@ -1060,7 +1664,7 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
if (con == NULL)
{
dlt_log(LOG_WARNING, "Specified ECUid not found\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
if (connection_status == 1) /* try to connect */
@@ -1069,23 +1673,17 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
{
if (dlt_client_connect(&con->client, verbose) == 0)
{
- con->status = DLT_GATEWAY_CONNECTED;
-
/* setup dlt connection and add to epoll event loop here */
- if (dlt_connection_create(daemon_local,
- &daemon_local->pEvent,
- con->client.sock,
- EPOLLIN,
- DLT_CONNECTION_GATEWAY) != 0)
+ if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK)
{
dlt_log(LOG_ERR, "Gateway connection creation failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
{
dlt_log(LOG_ERR, "Could not connect to passive node\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
@@ -1104,194 +1702,105 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
dlt_log(LOG_ERR,
"Remove passive node event handler connection failed\n");
}
-
- if (dlt_client_cleanup(&con->client, verbose) != 0)
- {
- dlt_log(LOG_ERR, "Could not cleanup DltClient structure\n");
- return -1;
- }
}
else
{
dlt_log(LOG_ERR, "Unknown command (connection_status)\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
-void dlt_gateway_send_control_message(DltGatewayConnection *con,
- DltGateway *gateway,
- DltDaemonLocal *daemon_local,
- int verbose)
+int dlt_gateway_send_control_message(DltGatewayConnection *con,
+ DltPassiveControlMessage *control_msg,
+ void *data,
+ int verbose)
{
- int i = 0;
- uint32_t len = 0;
- DltMessage msg;
- char local_str[DLT_DAEMON_TEXTBUFSIZE];
+ int ret = DLT_RETURN_OK;
PRINT_FUNCTION_VERBOSE(verbose);
- if (con == NULL || gateway == NULL || daemon_local == NULL)
+ if (con == NULL)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "%s: Invalid parameter given\n", __func__);
- dlt_log(LOG_WARNING, local_str);
- return;
+ dlt_vlog(LOG_WARNING,
+ "%s: Invalid parameter given\n",
+ __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
- for (i = 0; i < DLT_GATEWAY_MAX_STARTUP_CTRL_MSG; i++)
+ /* no (more) control message to be send */
+ if (control_msg->id == 0)
{
- if (con->control_msgs[i] == 0)
- {
- break; /* no (more) control message to be send */
- }
-
- memset(&msg, 0, sizeof(msg));
+ return DLT_RETURN_ERROR;
+ }
- if (dlt_message_init(&msg, verbose) == -1)
+ /* check sendtime counter and message interval */
+ /* sendtime counter is 0 on startup, otherwise positive value */
+ if ((control_msg->type != CONTROL_MESSAGE_ON_DEMAND) && (con->sendtime_cnt > 0))
+ {
+ if (control_msg->interval <= 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Initialization of message failed\n");
- dlt_log(LOG_WARNING, local_str);
- return;
+ return DLT_RETURN_ERROR;
}
- if (con->control_msgs[i] == DLT_SERVICE_ID_GET_LOG_INFO)
+ if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH))
{
- DltServiceGetLogInfoRequest *req;
- msg.databuffer = (uint8_t *)
- malloc(sizeof(DltServiceGetLogInfoRequest));
- if (msg.databuffer == NULL)
+ if ((con->sendtime_cnt - 1) % control_msg->interval != 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Initialization of 'GetLogInfo' failed\n");
- dlt_log(LOG_WARNING, local_str);
- dlt_message_free(&msg, verbose);
- return;
+ return DLT_RETURN_ERROR;
}
-
- req = (DltServiceGetLogInfoRequest *)msg.databuffer;
- req->service_id = DLT_SERVICE_ID_GET_LOG_INFO;
- req->options = 7;
- dlt_set_id(req->apid, "");
- dlt_set_id(req->ctid, "");
- dlt_set_id(req->com, "remo");
-
- msg.databuffersize = sizeof(DltServiceGetLogInfoRequest);
- msg.datasize = msg.databuffersize;
- }
- else if (con->control_msgs[i] == DLT_SERVICE_ID_GET_SOFTWARE_VERSION)
- {
- DltServiceGetSoftwareVersion *req;
-
- msg.databuffer = (uint8_t *)
- malloc(sizeof(DltServiceGetSoftwareVersion));
- if (msg.databuffer == NULL)
- {
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Initialization of 'GetSoftwareVersion' failed\n");
- dlt_log(LOG_WARNING, local_str);
- dlt_message_free(&msg, verbose);
- return;
- }
-
- req = (DltServiceGetSoftwareVersion *)msg.databuffer;
- req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
-
- msg.databuffersize = sizeof(DLT_SERVICE_ID_GET_SOFTWARE_VERSION);
- msg.datasize = msg.databuffersize;
- }
- else
- {
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Unknown control message. Skip.\n");
- dlt_log(LOG_WARNING, local_str);
- dlt_message_free(&msg, verbose);
- return;
- }
-
- /* prepare storage header */
- msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
-
- if (dlt_set_storageheader(msg.storageheader,"") == DLT_RETURN_ERROR)
- {
- dlt_message_free(&msg,0);
- return;
- }
-
- /* prepare standard header */
- msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
- msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
-
- #if (BYTE_ORDER==BIG_ENDIAN)
- msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF);
- #endif
-
- msg.standardheader->mcnt = 0;
-
- /* Set header extra parameters */
- dlt_set_id(msg.headerextra.ecu,"");
- //msg.headerextra.seid = 0;
- msg.headerextra.tmsp = dlt_uptime();
-
- /* Copy header extra parameters to headerbuffer */
- if (dlt_message_set_extraparameters(&msg,0) == DLT_RETURN_ERROR)
- {
- dlt_message_free(&msg,0);
- return;
}
+ }
- /* prepare extended header */
- msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer +
- sizeof(DltStorageHeader) +
- sizeof(DltStandardHeader) +
- DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) );
-
- msg.extendedheader->msin = DLT_MSIN_CONTROL_REQUEST;
-
- msg.extendedheader->noar = 1; /* number of arguments */
-
- dlt_set_id(msg.extendedheader->apid, "APP");
- dlt_set_id(msg.extendedheader->ctid, "CON");
-
- /* prepare length information */
- msg.headersize = sizeof(DltStorageHeader) +
- sizeof(DltStandardHeader) +
- sizeof(DltExtendedHeader) +
- DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
+ if (con->send_serial) /* send serial header */
+ {
+ ret = send(con->client.sock,
+ (void *)dltSerialHeader,
+ sizeof(dltSerialHeader),
+ 0);
- len=msg.headersize - sizeof(DltStorageHeader) + msg.datasize;
- if (len>UINT16_MAX)
+ if (ret == -1)
{
- fprintf(stderr,"Critical: Huge injection message discarded!\n");
- dlt_message_free(&msg,0);
-
- return;
+ dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
+ return DLT_RETURN_ERROR;
}
+ }
- msg.standardheader->len = DLT_HTOBE_16(len);
-
- /* forward message to passive node */
- if (dlt_gateway_forward_control_message(gateway,
- daemon_local,
- &msg,
- con->ecuid,
- verbose) != 0)
+ switch(control_msg->id)
+ {
+ case DLT_SERVICE_ID_GET_LOG_INFO:
+ return dlt_client_get_log_info(&con->client);
+ break;
+ case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
+ return dlt_client_get_default_log_level(&con->client);
+ break;
+ case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
+ return dlt_client_get_software_version(&con->client);
+ break;
+ case DLT_SERVICE_ID_SET_LOG_LEVEL:
+ if (data == NULL)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Failed to forward message to passive node.\n");
- dlt_log(LOG_WARNING, local_str);
+ dlt_vlog(LOG_WARNING,
+ "Insufficient data for %s received. Send control request failed.\n",
+ dlt_get_service_name(control_msg->id));
+ return DLT_RETURN_ERROR;
}
- dlt_message_free(&msg, verbose);
+ DltServiceSetLogLevel *req = (DltServiceSetLogLevel *) data;
+ return dlt_client_send_log_level(&con->client,
+ req->apid,
+ req->ctid,
+ req->log_level);
+ break;
+ default:
+ dlt_vlog(LOG_WARNING,
+ "Cannot forward request: %s.\n",
+ dlt_get_service_name(control_msg->id));
}
+
+ return DLT_RETURN_OK;
}
DltGatewayConnection *dlt_gateway_get_connection(DltGateway *gateway,
diff --git a/src/gateway/dlt_gateway.conf b/src/gateway/dlt_gateway.conf
index 645847a..c68aa4f 100644
--- a/src/gateway/dlt_gateway.conf
+++ b/src/gateway/dlt_gateway.conf
@@ -9,11 +9,14 @@ EcuID=ECU2
; Stop connecting to passive node, if not successful after 10 seconds
Timeout=10
; Send following control messages after connection is established
-; SendControl=0x03,0x13
+; SendControl=0x03,0x04,0x13
; Send Serial Header with control messages. Value in dlt.conf is used as default if not specified.
; SendSerialHeader=0
+; Send following control messages periodically (<control:interval[in seconds]>)
+; SendPeriodicControl=0x03:5,0x13:10
; Supported Control messages:
; DLT_SERVICE_ID_GET_LOG_INFO 0x03
+; DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL 0x04
; DLT_SERVICE_ID_GET_SOFTWARE_VERSION 0x13
diff --git a/src/gateway/dlt_gateway.h b/src/gateway/dlt_gateway.h
index 571a76a..2da2118 100644
--- a/src/gateway/dlt_gateway.h
+++ b/src/gateway/dlt_gateway.h
@@ -163,17 +163,18 @@ int dlt_gateway_process_on_demand_request(DltGateway *g,
int verbose);
/**
- * Send control message to passive node.
+ * Send control message to passive node
*
* @param con DltGatewayConnection
- * @param g DltGateway
- * @param daemon_local DltDaemonLocal
+ * @param control_msg DltPassiveControlMessage
+ * @param msg DltMessage
* @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
*/
-void dlt_gateway_send_control_message(DltGatewayConnection *con,
- DltGateway *g,
- DltDaemonLocal *daemon_local,
- int verbose);
+int dlt_gateway_send_control_message(DltGatewayConnection *con,
+ DltPassiveControlMessage *control_msg,
+ void *data,
+ int verbose);
/**
* Gets the connection handle of passive node with specified ECU
@@ -189,33 +190,4 @@ DltGatewayConnection *dlt_gateway_get_connection(DltGateway *g,
/* _ONLY_ for development purposes */
void print_gateway_connection_details(const DltGateway *g);
-#ifdef DLT_UNIT_TESTS
-typedef enum {
- GW_CONF_IP_ADDRESS = 0,
- GW_CONF_PORT,
- GW_CONF_ECUID,
- GW_CONF_CONNECT,
- GW_CONF_TIMEOUT,
- GW_CONF_SEND_CONTROL,
- GW_CONF_SEND_SERIAL_HEADER,
- GW_CONF_COUNT
-} DltGatewayConfType;
-int dlt_gateway_check_ip(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_port(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
- char *value);
-int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_control_messages(DltGatewayConnection *con,
- char *value);
-int dlt_gateway_check_param(DltGateway *gateway,
- DltGatewayConnection *con,
- DltGatewayConfType ctype,
- char *value);
-int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose);
-int dlt_gateway_store_connection(DltGateway *gateway,
- DltGatewayConnection *tmp,
- int verbose);
-#endif
#endif
diff --git a/src/gateway/dlt_gateway_types.h b/src/gateway/dlt_gateway_types.h
index 7c3d45e..4d0de0d 100644
--- a/src/gateway/dlt_gateway_types.h
+++ b/src/gateway/dlt_gateway_types.h
@@ -58,6 +58,7 @@
#ifndef DLT_GATEWAY_TYPES_H_
#define DLT_GATEWAY_TYPES_H_
+#include "dlt_protocol.h"
#include "dlt_client.h"
#define DLT_GATEWAY_CONFIG_PATH CONFIGURATION_FILES_DIR "/dlt_gateway.conf"
@@ -85,6 +86,32 @@ typedef enum
DLT_GATEWAY_DISABLED /* disable this connection due to problems */
} connection_trigger;
+typedef enum
+{
+ CONTROL_MESSAGE_UNDEFINED = -1,
+ CONTROL_MESSAGE_ON_STARTUP, /* send on startup */
+ CONTROL_MESSAGE_PERIODIC, /* send periodically */
+ CONTROL_MESSAGE_BOTH, /* send on startup and periodically */
+ CONTROL_MESSAGE_ON_DEMAND /* send on demand only */
+} control_msg_trigger;
+
+typedef enum
+{
+ CONTROL_MESSAGE_REQUEST_UNDEFINED = -1,
+ CONTROL_MESSAGE_NOT_REQUESTED, /* control msg not requested (default) */
+ CONTROL_MESSAGE_REQUESTED /* control msg requested */
+} control_msg_request;
+
+/* Passive control message */
+typedef struct DltPassiveControlMessage {
+ uint32_t id; /* msg ID */
+ uint32_t user_id;
+ control_msg_trigger type; /* on startup or periodic or both */
+ control_msg_request req; /* whether it is requested from gateway or not */
+ int interval; /* interval for periodic sending. if on startup, -1 */
+ struct DltPassiveControlMessage *next; /* for multiple passive control message */
+} DltPassiveControlMessage;
+
/* DLT Gateway connection structure */
typedef struct {
int handle; /* connection handle */
@@ -99,9 +126,13 @@ typedef struct {
int timeout; /* connection timeout */
int timeout_cnt; /* connection timeout counter */
int reconnect_cnt; /* reconnection counter */
- int control_msgs[DLT_GATEWAY_MAX_STARTUP_CTRL_MSG]; /* msg IDs send on startup */
+ int sendtime; /* periodic sending max time */
+ int sendtime_cnt; /* periodic sending counter */
+ DltPassiveControlMessage *p_control_msgs; /* passive control msgs */
+ DltPassiveControlMessage *head; /* to go back to the head pointer of p_control_msgs */
int send_serial; /* Send serial header with control messages */
DltClient client; /* DltClient structure */
+ int default_log_level; /* Default Log Level on passive node */
} DltGatewayConnection;
/* DltGateway structure */
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c
index 60a97f5..9c38827 100644
--- a/src/lib/dlt_client.c
+++ b/src/lib/dlt_client.c
@@ -412,6 +412,8 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
int ret;
int32_t len;
+ uint32_t id_tmp;
+ uint32_t id;
if ((client==0) || (client->sock<0) || (apid==0) || (ctid==0))
{
@@ -510,15 +512,26 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
{
/* via FileDescriptor */
ret=write(client->sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
- if (0 > ret){
- dlt_message_free(&msg,0);
- return DLT_RETURN_ERROR;
- }
+ if (0 > ret)
+ {
+ dlt_log(LOG_ERR, "Sending message failed\n");
+ dlt_message_free(&msg,0);
+ return DLT_RETURN_ERROR;
+ }
+
ret=write(client->sock, msg.databuffer,msg.datasize);
- if (0 > ret){
- dlt_message_free(&msg,0);
- return DLT_RETURN_ERROR;
- }
+ if (0 > ret){
+ dlt_log(LOG_ERR, "Sending message failed\n");
+ dlt_message_free(&msg,0);
+ return DLT_RETURN_ERROR;
+ }
+
+ id_tmp = *((uint32_t*)(msg.databuffer));
+ id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp);
+
+ dlt_vlog(LOG_INFO,
+ "Control message forwarded : %s\n",
+ dlt_get_service_name(id));
}
else
{
@@ -571,16 +584,19 @@ DltReturnValue dlt_client_send_inject_msg(DltClient *client, char *apid, char *c
DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel)
{
DltServiceSetLogLevel *req;
- uint8_t *payload;
+ int ret = DLT_RETURN_ERROR;
- payload = (uint8_t *) malloc(sizeof(DltServiceSetLogLevel));
-
- if(payload==0)
+ if ((client == NULL) || (apid == NULL) || (ctid == NULL))
{
- return DLT_RETURN_ERROR;
+ return ret;
}
- req = (DltServiceSetLogLevel *) payload;
+
+ req = (DltServiceSetLogLevel *) malloc(sizeof(DltServiceSetLogLevel));
+ if (req == NULL)
+ {
+ return ret;
+ }
memset(req, 0, sizeof(DltServiceSetLogLevel));
req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL;
dlt_set_id(req->apid,apid);
@@ -589,37 +605,35 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct
dlt_set_id(req->com,"remo");
/* free message */
- if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR)
- {
- free(payload);
- return DLT_RETURN_ERROR;
- }
+ ret = dlt_client_send_ctrl_msg(client,
+ "APP",
+ "CON",
+ (uint8_t*) req,
+ sizeof(DltServiceSetLogLevel));
- free(payload);
- return DLT_RETURN_OK;
+ free(req);
+
+ return ret;
}
-int dlt_client_get_log_info(DltClient *client)
+DltReturnValue dlt_client_get_log_info(DltClient *client)
{
DltServiceGetLogInfoRequest *req;
- uint8_t *payload;
- int ret_main_loop = 0;
- int ret = -1;
+ int ret = DLT_RETURN_ERROR;
if (client == NULL)
{
return ret;
}
- payload = (uint8_t *) malloc(sizeof(DltServiceGetLogInfoRequest));
- if (payload == 0)
+ req = (DltServiceGetLogInfoRequest *) malloc(sizeof(DltServiceGetLogInfoRequest));
+
+ if (req == NULL)
{
return ret;
}
- req = (DltServiceGetLogInfoRequest *) payload;
-
req->service_id = DLT_SERVICE_ID_GET_LOG_INFO;
req->options = 7;
dlt_set_id(req->apid, "");
@@ -627,20 +641,73 @@ int dlt_client_get_log_info(DltClient *client)
dlt_set_id(req->com, "remo");
/* send control message to daemon*/
- ret = dlt_client_send_ctrl_msg(client, "", "", payload, sizeof(DltServiceGetLogInfoRequest));
- free(payload);
- if (ret == -1)
+ ret = dlt_client_send_ctrl_msg(client,
+ "",
+ "",
+ (uint8_t *) req,
+ sizeof(DltServiceGetLogInfoRequest));
+
+ free(req);
+
+ return ret;
+}
+
+DltReturnValue dlt_client_get_default_log_level(DltClient *client)
+{
+ DltServiceGetDefaultLogLevelRequest *req;
+ int ret = DLT_RETURN_ERROR;
+
+ if (client == NULL)
{
- return -1;
+ return ret;
}
- ret_main_loop = dlt_client_main_loop(client, NULL, 0);
- if (ret_main_loop == 1)
+ req = (DltServiceGetDefaultLogLevelRequest *)
+ malloc(sizeof(DltServiceGetDefaultLogLevelRequest));
+
+ if (req == NULL)
{
- printf("DLT-daemon's response is invalid.\n");
+ return ret;
}
- return 0;
+ req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
+
+ /* send control message to daemon*/
+ ret = dlt_client_send_ctrl_msg(client,
+ "",
+ "",
+ (uint8_t *) req,
+ sizeof(DltServiceGetDefaultLogLevelRequest));
+
+ free(req);
+
+ return ret;
+}
+
+DltReturnValue dlt_client_get_software_version(DltClient *client)
+{
+ DltServiceGetSoftwareVersion *req;
+ int ret = DLT_RETURN_ERROR;
+
+ if (client == NULL)
+ {
+ return ret;
+ }
+
+ req = (DltServiceGetSoftwareVersion *) malloc(sizeof(DltServiceGetSoftwareVersion));
+
+ req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
+
+ /* send control message to daemon*/
+ ret = dlt_client_send_ctrl_msg(client,
+ "",
+ "",
+ (uint8_t *) req,
+ sizeof(DltServiceGetSoftwareVersion));
+
+ free(req);
+
+ return ret;
}
DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus)
@@ -905,3 +972,241 @@ int dlt_client_set_socket_path(DltClient *client, char *socket_path)
}
return DLT_RETURN_OK;
}
+/**
+ * free allocation when calloc failed
+ *
+ * @param resp DltServiceGetLogInfoResponse
+ * @param count_app_ids number of app_ids which needs to be freed
+ */
+STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoResponse *resp,
+ int count_app_ids)
+{
+ AppIDsType *app = NULL;
+ ContextIDsInfoType *con = NULL;
+ int i = 0;
+ int j = 0;
+
+ for (i = 0; i < count_app_ids; i++)
+ {
+ app = &(resp->log_info_type.app_ids[i]);
+
+ for (j = 0; j < app->count_context_ids; j++)
+ {
+ con = &(app->context_id_info[j]);
+
+ free(con->context_description);
+ con->context_description = NULL;
+ }
+
+ free(app->app_description);
+ app->app_description = NULL;
+
+ free(app->context_id_info);
+ app->context_id_info = NULL;
+ }
+
+ free(resp->log_info_type.app_ids);
+ resp->log_info_type.app_ids = NULL;
+
+ return;
+}
+
+int dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp,
+ char *resp_text)
+{
+ AppIDsType *app = NULL;
+ ContextIDsInfoType *con = NULL;
+ int i = 0;
+ int j = 0;
+ char *rp = NULL;
+ int rp_count = 0;
+
+ if ((resp == NULL) || (resp_text == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+
+ /* ------------------------------------------------------
+ get_log_info data structure(all data is ascii)
+
+ get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
+ ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
+ cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
+ jj jj kk kk kk .. ..
+ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
+ aa : get mode (fix value at 0x07)
+ bb bb : list num of apid (little endian)
+ cc cc cc cc: apid
+ dd dd : list num of ctid (little endian)
+ ee ee ee ee: ctid
+ ff : log level
+ gg : trace status
+ hh hh : description length of ctid
+ ii ii .. : description text of ctid
+ jj jj : description length of apid
+ kk kk .. : description text of apid
+ ------------------------------------------------------ */
+
+ rp = resp_text + DLT_GET_LOG_INFO_HEADER;
+ rp_count = 0;
+
+ /* check if status is acceptable */
+ if ((resp->status < GET_LOG_INFO_STATUS_MIN) ||
+ (resp->status > GET_LOG_INFO_STATUS_MAX))
+ {
+ if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX)
+ {
+ dlt_vlog(LOG_WARNING,
+ "The status(%d) is invalid: NO matching Context IDs\n",
+ resp->status);
+ }
+ else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW)
+ {
+ dlt_vlog(LOG_WARNING,
+ "The status(%d) is invalid: Response data over flow\n",
+ resp->status);
+ }
+ else
+ {
+ dlt_vlog(LOG_WARNING,
+ "The status(%d) is invalid\n",
+ resp->status);
+ }
+ return DLT_RETURN_ERROR;
+ }
+
+ /* count_app_ids */
+ resp->log_info_type.count_app_ids = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+
+ resp->log_info_type.app_ids = (AppIDsType *)calloc
+ (resp->log_info_type.count_app_ids, sizeof(AppIDsType));
+
+ if (resp->log_info_type.app_ids == NULL)
+ {
+ dlt_vlog(LOG_ERR, "calloc failed for app_ids\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, 0);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (i = 0; i < resp->log_info_type.count_app_ids; i++)
+ {
+ app = &(resp->log_info_type.app_ids[i]);
+ /* get app id */
+ dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id, DLT_ID_SIZE);
+
+ /* count_con_ids */
+ app->count_context_ids = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+
+ app->context_id_info = (ContextIDsInfoType *)calloc
+ (app->count_context_ids, sizeof(ContextIDsInfoType));
+
+ if (app->context_id_info == NULL)
+ {
+ dlt_vlog(LOG_ERR,
+ "calloc failed for context_id_info\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, i);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (j = 0; j < app->count_context_ids; j++)
+ {
+ con = &(app->context_id_info[j]);
+ /* get con id */
+ dlt_getloginfo_conv_ascii_to_id(rp,
+ &rp_count,
+ con->context_id,
+ DLT_ID_SIZE);
+
+ /* log_level */
+ if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7))
+ {
+ con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp,
+ &rp_count);
+ }
+
+ /* trace status */
+ if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7))
+ {
+ con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp,
+ &rp_count);
+ }
+
+ /* context desc */
+ if (resp->status == 7){
+ con->len_context_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+ con->context_description = (char *)calloc
+ (con->len_context_description + 1, sizeof(char));
+ if (con->context_description == 0)
+ {
+ dlt_log(LOG_ERR, "calloc failed for context description\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, i);
+ return DLT_RETURN_ERROR;
+ }
+ dlt_getloginfo_conv_ascii_to_id(rp,
+ &rp_count,
+ con->context_description,
+ con->len_context_description);
+ }
+ }
+
+ /* application desc */
+ if (resp->status == 7)
+ {
+ app->len_app_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+ app->app_description = (char *)calloc
+ (app->len_app_description + 1, sizeof(char));
+ if (app->app_description == 0)
+ {
+ dlt_log(LOG_ERR, "calloc failed for application description\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, i);
+ return DLT_RETURN_ERROR;
+ }
+ dlt_getloginfo_conv_ascii_to_id(rp,
+ &rp_count,
+ app->app_description,
+ app->len_app_description);
+ }
+ }
+
+ return DLT_RETURN_OK;
+}
+
+int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp)
+{
+ AppIDsType app;
+ int i = 0;
+ int j = 0;
+
+ if (resp == NULL)
+ {
+ return DLT_RETURN_OK;
+ }
+
+ for (i = 0; i < resp->log_info_type.count_app_ids; i++)
+ {
+ app = resp->log_info_type.app_ids[i];
+
+ for (j = 0; j < app.count_context_ids; j++)
+ {
+ free(app.context_id_info[j].context_description);
+ app.context_id_info[j].context_description = NULL;
+ }
+
+ free(app.context_id_info);
+ app.context_id_info = NULL;
+ free(app.app_description);
+ app.app_description = NULL;
+ }
+
+ free(resp->log_info_type.app_ids);
+ resp->log_info_type.app_ids = NULL;
+
+ free(resp);
+ resp = NULL;
+
+ return DLT_RETURN_OK;
+}
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 28df590..a77459d 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -3912,6 +3912,151 @@ void dlt_check_envvar()
}
}
+int dlt_set_loginfo_parse_service_id(char *resp_text,
+ uint32_t *service_id,
+ uint8_t *service_opt)
+{
+ int ret = -1;
+ char get_log_info_tag[GET_LOG_INFO_LENGTH];
+ char service_opt_str[SERVICE_OPT_LENGTH];
+
+ if ((resp_text == NULL) || (service_id == NULL) || (service_opt == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+ /* ascii type, syntax is 'get_log_info, ..' */
+ /* check target id */
+ strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info"));
+ ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag)-1);
+ if (ret == 0)
+ {
+ *service_id = DLT_SERVICE_ID_GET_LOG_INFO;
+ /* reading the response mode from the resp_text. eg. option 7*/
+ service_opt_str[0] = *(resp_text + GET_LOG_INFO_LENGTH + 1);
+ service_opt_str[1] = *(resp_text + GET_LOG_INFO_LENGTH + 2);
+ service_opt_str[2] = 0;
+ *service_opt = atoi(service_opt_str);
+ }
+
+ return ret;
+}
+
+int16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count)
+{
+ char num_work[5] = {0};
+ char *endptr;
+
+ if ((rp == NULL) || (rp_count == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+ /* ------------------------------------------------------
+ from: [89 13 ] -> to: ['+0x'1389\0] -> to num
+ ------------------------------------------------------ */
+ num_work[0] = *(rp + *rp_count + 3);
+ num_work[1] = *(rp + *rp_count + 4);
+ num_work[2] = *(rp + *rp_count + 0);
+ num_work[3] = *(rp + *rp_count + 1);
+ num_work[4] = 0;
+ *rp_count += 6;
+
+ return (unsigned char)strtol(num_work, &endptr, 16);
+}
+
+int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
+{
+ char num_work[3] = {0};
+ char *endptr;
+
+ if ((rp == NULL) || (rp_count == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+ /* ------------------------------------------------------
+ from: [89 ] -> to: ['0x'89\0] -> to num
+ ------------------------------------------------------ */
+ num_work[0] = *(rp + *rp_count + 0);
+ num_work[1] = *(rp + *rp_count + 1);
+ num_work[2] = 0;
+ *rp_count += 3;
+
+ return (signed char)strtol(num_work, &endptr, 16);
+}
+
+void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
+{
+ char number16[2] = {0};
+ char *endptr;
+ int count;
+
+ if ((rp == NULL) || (rp_count == NULL) || (wp == NULL))
+ {
+ return;
+ }
+ /* ------------------------------------------------------
+ from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
+ ------------------------------------------------------ */
+ for (count = 0; count < len; count++)
+ {
+ number16[0] = *(rp + *rp_count + 0);
+ number16[1] = *(rp + *rp_count + 1);
+ *(wp + count) = strtol(number16, &endptr, 16);
+ *rp_count += 3;
+ }
+ *(wp + count) = 0;
+ return;
+}
+
+void dlt_hex_ascii_to_binary(const char *ptr,uint8_t *binary,int *size)
+{
+ char ch = *ptr;
+ int pos = 0;
+ binary[pos] = 0;
+ int first = 1;
+ int found;
+
+ for(;;)
+ {
+ if(ch == 0)
+ {
+ *size = pos;
+ return;
+ }
+
+ found = 0;
+ if (ch >= '0' && ch <= '9')
+ {
+ binary[pos] = (binary[pos] << 4) + (ch - '0');
+ found = 1;
+ }
+ else if (ch >= 'A' && ch <= 'F')
+ {
+ binary[pos] = (binary[pos] << 4) + (ch - 'A' + 10);
+ found = 1;
+ }
+ else if (ch >= 'a' && ch <= 'f')
+ {
+ binary[pos] = (binary[pos] << 4) + (ch - 'a' + 10);
+ found = 1;
+ }
+ if(found)
+ {
+ if(first)
+ first = 0;
+ else
+ {
+ first = 1;
+ pos++;
+ if(pos>=*size)
+ return;
+ binary[pos]=0;
+ }
+ }
+
+ ch = *(++ptr);
+ }
+}
+
#ifndef DLT_USE_UNIX_SOCKET_IPC
int dlt_mkdir_recursive(const char *dir)
{