summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/daemon/dlt_daemon_client.c3
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c64
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.h13
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.c145
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.h26
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.c1
6 files changed, 190 insertions, 62 deletions
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index a96c329..2b23817 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -266,7 +266,8 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc
* newly introduced dlt_daemon_log_internal */
if(daemon_local->flags.offlineLogstorageMaxDevices > 0)
{
- dlt_daemon_logstorage_write(daemon, daemon_local->flags,
+ dlt_daemon_logstorage_write(daemon,
+ &daemon_local->flags,
storage_header,
storage_header_size,
data1,
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index 66f9ec8..cd0ee11 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -466,7 +466,7 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *
* to write to the device, DltDaemon will disconnect this device.
*
* @param daemon Pointer to Dlt Daemon structure
- * @param user_config User configurations for log file
+ * @param user_config DltDaemon configuration
* @param data1 message header buffer
* @param size1 message header buffer size
* @param data2 message extended header buffer
@@ -474,51 +474,55 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *
* @param data3 message data buffer
* @param size3 message data size
*/
-void dlt_daemon_logstorage_write(DltDaemon *daemon, DltDaemonFlags user_config,
- unsigned char *data1, int size1, unsigned char *data2, int size2,
- unsigned char *data3, int size3)
+void dlt_daemon_logstorage_write(DltDaemon *daemon,
+ DltDaemonFlags *user_config,
+ unsigned char *data1,
+ int size1,
+ unsigned char *data2,
+ int size2,
+ unsigned char *data3,
+ int size3)
{
int i = 0;
-
- /* data2 contains DltStandardHeader, DltStandardHeaderExtra and DltExtendedHeader. We are interested
- * in last one, because it contains apid, ctid and loglevel */
- DltExtendedHeader ext;
DltLogStorageUserConfig file_config;
- char apid[DLT_ID_SIZE] = {0};
- char ctid[DLT_ID_SIZE] = {0};
- int log_level = -1;
- if (daemon == NULL || user_config.offlineLogstorageMaxDevices <= 0
+ if (daemon == NULL || (user_config->offlineLogstorageMaxDevices <= 0)
|| data1 == NULL || data2 == NULL || data3 == NULL
|| ((unsigned int)size2 < (sizeof(DltStandardHeader) +
sizeof(DltStandardHeaderExtra) + sizeof(DltExtendedHeader))))
{
- dlt_log(LOG_DEBUG, "dlt_daemon_logstorage_write: message type is not log. Skip storing.\n");
+ dlt_log(LOG_INFO,
+ "dlt_daemon_logstorage_write: message type is not log. "
+ "Skip storing.\n");
return;
}
- memset(&ext, 0, sizeof(DltExtendedHeader));
- memcpy(&ext, data2 + sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra), sizeof(DltExtendedHeader));
-
- dlt_set_id(apid, ext.apid);
- dlt_set_id(ctid, ext.ctid);
- log_level = DLT_GET_MSIN_MTIN(ext.msin);
-
/* Copy user configuration */
- file_config.logfile_timestamp = user_config.offlineLogstorageTimestamp;
- file_config.logfile_delimiter = user_config.offlineLogstorageDelimiter;
- file_config.logfile_maxcounter = user_config.offlineLogstorageMaxCounter;
- file_config.logfile_counteridxlen = user_config.offlineLogstorageMaxCounterIdx;
+ file_config.logfile_timestamp = user_config->offlineLogstorageTimestamp;
+ file_config.logfile_delimiter = user_config->offlineLogstorageDelimiter;
+ file_config.logfile_maxcounter = user_config->offlineLogstorageMaxCounter;
+ file_config.logfile_counteridxlen =
+ user_config->offlineLogstorageMaxCounterIdx;
- for (i = 0; i < user_config.offlineLogstorageMaxDevices; i++)
+ for (i = 0; i < user_config->offlineLogstorageMaxDevices; i++)
{
- if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
+ if (daemon->storage_handle[i].config_status ==
+ DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
{
- if (dlt_logstorage_write(&(daemon->storage_handle[i]), file_config, apid, ctid,
- log_level, data1, size1, data2, size2, data3, size3) != 0)
+ if (dlt_logstorage_write(&(daemon->storage_handle[i]),
+ &file_config,
+ data1,
+ size1,
+ data2,
+ size2,
+ data3,
+ size3) != 0)
{
- dlt_log(LOG_ERR,"dlt_daemon_logstorage_write: dlt_logstorage_write failed. Disable storage device\n");
- /* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened, therefore remove logstorage device */
+ dlt_log(LOG_ERR,
+ "dlt_daemon_logstorage_write: failed. "
+ "Disable storage device\n");
+ /* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened,
+ * therefore remove logstorage device */
dlt_logstorage_device_disconnected(&(daemon->storage_handle[i]));
}
}
diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h
index cb7698a..148abd0 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.h
+++ b/src/daemon/dlt_daemon_offline_logstorage.h
@@ -103,7 +103,7 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int de
* to write to the device, DltDaemon will disconnect this device.
*
* @param daemon Pointer to Dlt Daemon structure
- * @param user_config User configurations for log file
+ * @param user_config DltDaemon configuration
* @param apid application id
* @param ctid context id
* @param log_level log level
@@ -112,9 +112,14 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int de
* @param data2 message data buffer
* @param size2 message data size
*/
-void dlt_daemon_logstorage_write(DltDaemon *daemon, DltDaemonFlags user_config, unsigned char *data1,
- int size1, unsigned char *data2, int size2,
- unsigned char *data3, int size3);
+void dlt_daemon_logstorage_write(DltDaemon *daemon,
+ DltDaemonFlags *user_config,
+ unsigned char *data1,
+ int size1,
+ unsigned char *data2,
+ int size2,
+ unsigned char *data3,
+ int size3);
/**
* dlt_daemon_logstorage_setup_internal_storage
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c
index d1efbb5..3e964bd 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage.c
@@ -350,6 +350,37 @@ int dlt_logstorage_set_sync_strategy(int *strategy, char *value)
}
/**
+ * dlt_logstorage_set_ecuid
+ *
+ * Evaluate if ECU idenfifier given in config file
+ *
+ * @param ecuid string to store the ecuid name
+ * @param value string given in config file
+ * @return 0 on success, -1 on error
+ */
+int dlt_logstorage_set_ecuid(char **ecuid, char *value)
+{
+ int len;
+
+ if (ecuid == NULL || value == NULL || value[0] == '\0')
+ {
+ return -1;
+ }
+
+ if (*ecuid != NULL)
+ {
+ free(*ecuid);
+ *ecuid = NULL;
+ }
+
+ len = strlen(value);
+ *ecuid = calloc((len+1), sizeof(char));
+ strncpy(*ecuid, value, len);
+
+ return 0;
+}
+
+/**
* dlt_logstorage_create_keys
*
* Create keys for hash table
@@ -562,6 +593,11 @@ void dlt_logstorage_free(DltLogStorage *handle)
free(handle->config_data[i].data.file_name);
+ if (handle->config_data[i].data.ecuid != NULL)
+ {
+ free(handle->config_data[i].data.ecuid);
+ }
+
if (handle->config_data[i].data.log != NULL)
{
fclose(handle->config_data[i].data.log);
@@ -672,6 +708,14 @@ int dlt_logstorage_prepare_table(DltLogStorage *handle, char *appid, char *ctxid
strcpy(p_node->key, keys+(idx * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN));
memcpy(&p_node->data, tmp_data, sizeof(DltLogStorageConfigData));
p_node->data.file_name = strdup(tmp_data->file_name);
+ if (tmp_data->ecuid != NULL)
+ {
+ p_node->data.ecuid = strdup(tmp_data->ecuid);
+ }
+ else
+ {
+ p_node->data.ecuid = NULL;
+ }
p_node->data.records = NULL;
p_node->data.log = NULL;
p_node->data.cache = NULL;
@@ -762,6 +806,14 @@ int dlt_logstorage_validate_filter_value(char *filter_key, char *filter_value,
return DLT_OFFLINE_LOGSTORAGE_SYNC_BEHAVIOR;
}
}
+ else if (strncmp(filter_key, "EcuID", strlen("EcuID")) == 0)
+ {
+ ret = dlt_logstorage_set_ecuid(&(tmp_data->ecuid), filter_value);
+ if (ret == 0)
+ {
+ return DLT_OFFLINE_LOGSTORAGE_ECUID;
+ }
+ }
else
{
/* Invalid filter key */
@@ -866,7 +918,8 @@ int dlt_logstorage_store_filters(DltLogStorage *handle, char *config_file_name)
"File",
"FileSize",
"NOFiles",
- "SyncBehavior"
+ "SyncBehavior",
+ "EcuID"
};
config_file = dlt_config_file_init(config_file_name);
@@ -892,7 +945,15 @@ int dlt_logstorage_store_filters(DltLogStorage *handle, char *config_file_name)
for (i = 0; i < num_filters; i++)
{
if (tmp_data.file_name != NULL)
+ {
free(tmp_data.file_name);
+ }
+
+ if (tmp_data.ecuid != NULL)
+ {
+ free(tmp_data.ecuid);
+ tmp_data.ecuid = NULL;
+ }
if (appid != NULL)
{
@@ -917,16 +978,25 @@ int dlt_logstorage_store_filters(DltLogStorage *handle, char *config_file_name)
/* Validate filter name */
ret = dlt_logstorage_validate_filter_name(filter_name);
if (ret !=0)
+ {
continue;
+ }
else
+ {
is_filter_set = DLT_OFFLINE_LOGSTORAGE_FILTER_PRESENT;
+ }
for (j = 0; j < num_filter_keys; j++)
{
/* Get filter value for filter keys */
ret = dlt_config_file_get_value(config_file, filter_name, filter_key[j], filter_value);
+
+ /* only return an error when the failure occurred on a mandatory
+ * value. */
if (ret != 0 &&
strncmp(filter_key[j], "SyncBehavior", strlen(filter_key[j]))
+ != 0 &&
+ strncmp(filter_key[j], "EcuID", strlen(filter_key[j]))
!= 0)
{
is_filter_set = DLT_OFFLINE_LOGSTORAGE_FILTER_UNINIT;
@@ -981,6 +1051,11 @@ int dlt_logstorage_store_filters(DltLogStorage *handle, char *config_file_name)
if (tmp_data.file_name != NULL)
free(tmp_data.file_name);
+ if (tmp_data.ecuid != NULL)
+ {
+ free(tmp_data.ecuid);
+ }
+
dlt_config_file_release(config_file);
return ret;
@@ -1159,10 +1234,16 @@ DltLogStorageConfigData **dlt_logstorage_get_config(DltLogStorage *handle, char
* @param appid application id
* @param ctxid context id
* @param log_level Log level of message
+ * @param ecuid EcuID given in the message
* @param num Number of found configurations
* @return list of filters received from hashmap or NULL
*/
-DltLogStorageConfigData **dlt_logstorage_filter(DltLogStorage *handle, char *appid, char *ctxid, int log_level, int *num)
+DltLogStorageConfigData **dlt_logstorage_filter(DltLogStorage *handle,
+ char *appid,
+ char *ctxid,
+ char *ecuid,
+ int log_level,
+ int *num)
{
DltLogStorageConfigData **config = NULL;
int i = 0;
@@ -1182,6 +1263,16 @@ DltLogStorageConfigData **dlt_logstorage_filter(DltLogStorage *handle, char *app
if (log_level > config[i]->log_level)
{
config[i] = NULL;
+ continue;
+ }
+
+ /* filter on ECU id only if EcuID is set */
+ if (config[i]->ecuid != NULL)
+ {
+ if (strncmp(ecuid, config[i]->ecuid, strlen(ecuid)) != 0)
+ {
+ config[i] = NULL;
+ }
}
}
@@ -1191,38 +1282,60 @@ DltLogStorageConfigData **dlt_logstorage_filter(DltLogStorage *handle, char *app
/**
* dlt_logstorage_write
*
- * Write a message to one or more configured log files, based on filter configuration.
+ * Write a message to one or more configured log files, based on filter
+ * configuration.
*
* @param handle DltLogStorage handle
- * @param file_config User configurations for log file
- * @param appid Application id of sender
- * @param ctxid Context id of sender
- * @param log_level log_level of message to store
+ * @param config User configurations for log file
* @param data1 Data buffer of message header
* @param size1 Size of message header buffer
* @param data2 Data buffer of message body
* @param size2 Size of message body
* @return 0 on success or write errors < max write errors, -1 on error
*/
-int dlt_logstorage_write(DltLogStorage *handle, DltLogStorageUserConfig file_config,
- char *appid, char *ctxid, int log_level,
- unsigned char *data1, int size1, unsigned char *data2,
- int size2, unsigned char *data3, int size3)
+int dlt_logstorage_write(DltLogStorage *handle,
+ DltLogStorageUserConfig *uconfig,
+ unsigned char *data1,
+ int size1,
+ unsigned char *data2,
+ int size2,
+ unsigned char *data3,
+ int size3)
{
DltLogStorageConfigData **config = NULL;
int i = 0;
int ret = 0;
int num = 0;
int err = 0;
-
- if (handle == NULL || handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED || handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
+ /* data2 contains DltStandardHeader, DltStandardHeaderExtra and
+ * DltExtendedHeader. We are interested in ecuid, apid, ctid and loglevel */
+ DltExtendedHeader *extendedHeader;
+ DltStandardHeaderExtra *extraHeader;
+ int log_level = -1;
+
+ if (handle == NULL || uconfig == NULL ||
+ data1 == NULL || data2 == NULL || data3 == NULL ||
+ handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED ||
+ handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
{
return 0;
}
+ extendedHeader = (DltExtendedHeader *)(data2 +
+ sizeof(DltStandardHeader) +
+ sizeof(DltStandardHeaderExtra));
+ extraHeader = (DltStandardHeaderExtra *)(data2 + sizeof(DltStandardHeader));
+
+ log_level = DLT_GET_MSIN_MTIN(extendedHeader->msin);
+
/* check if log message need to be stored in a certain device based on
* filter configuration */
- config = dlt_logstorage_filter(handle, appid, ctxid, log_level, &num);
+ config = dlt_logstorage_filter(handle,
+ extendedHeader->apid,
+ extendedHeader->ctid,
+ extraHeader->ecu,
+ log_level,
+ &num);
if (config != NULL)
{
@@ -1231,9 +1344,9 @@ int dlt_logstorage_write(DltLogStorage *handle, DltLogStorageUserConfig file_con
{
if(config[i] != NULL)
{
- /* prepare logfile (create and/or open)*/
+ /* prepare log file (create and/or open)*/
ret = config[i]->dlt_logstorage_prepare(config[i],
- &file_config,
+ uconfig,
handle->device_mount_point,
size1 + size2 + size3);
if (ret == 0) /* log data (write) */
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h
index 01427a1..ce12095 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage.h
@@ -81,6 +81,7 @@
DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + 1)
#define DLT_OFFLINE_LOGSTORAGE_FILTER_UNINIT 0
+#define DLT_OFFLINE_LOGSTORAGE_ECUID (1<<8)
#define DLT_OFFLINE_LOGSTORAGE_FILTER_PRESENT (1<<7)
#define DLT_OFFLINE_LOGSTORAGE_APP_INIT (1<<6)
#define DLT_OFFLINE_LOGSTORAGE_CTX_INIT (1<<5)
@@ -89,7 +90,7 @@
#define DLT_OFFLINE_LOGSTORAGE_SIZE_INIT (1<<2)
#define DLT_OFFLINE_LOGSTORAGE_SYNC_BEHAVIOR (1<<1)
#define DLT_OFFLINE_LOGSTORAGE_NUM_INIT 1
-/* Sync behavior is optional */
+/* Sync behavior and ECUid are optional */
#define DLT_OFFLINE_LOGSTORAGE_FILTER_INIT 0xFD
#define DLT_OFFLINE_LOGSTORAGE_FILTER_INITIALIZED(A) ((A) >= DLT_OFFLINE_LOGSTORAGE_FILTER_INIT)
@@ -107,7 +108,7 @@
#define DLT_OFFLINE_LOGSTORAGE_MIN(A, B) ((A) < (B) ? (A) : (B))
#define DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS 5
-#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM 7
+#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM 8
#define DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION "FILTER"
@@ -154,6 +155,7 @@ typedef struct DltLogStorageConfigData
unsigned int file_size; /* MAX File size of storage file configured for filter */
unsigned int num_files; /* MAX number of storage files configured for filters */
int sync; /* Sync strategy */
+ char *ecuid; /* ECU identifier */
/* callback function for filter configurations */
int (*dlt_logstorage_prepare)(DltLogStorageConfigData *config,
DltLogStorageUserConfig *file_config,
@@ -254,21 +256,23 @@ extern int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key);
/**
* dlt_logstorage_write
*
- * Write a message to one or more configured log files, based on filter configuration.
+ * Write a message to one or more configured log files, based on filter
+ * configuration.
*
* @param handle DltLogStorage handle
- * @param file_config User configurations for log file
- * @param appid Application id of sender
- * @param ctxid Context id of sender
- * @param log_level log_level of message to store
+ * @param uconfig User configurations for log file
* @param data1 Data buffer of message header
* @param size1 Size of message header buffer
* @param data2 Data buffer of message body
* @param size2 Size of message body
* @return 0 on success or write errors < max write errors, -1 on error
*/
-extern int dlt_logstorage_write(DltLogStorage *handle, DltLogStorageUserConfig file_config,
- char *appid, char *ctxid, int log_level,
- unsigned char *data1, int size1, unsigned char *data2,
- int size2, unsigned char *data3, int size3);
+extern int dlt_logstorage_write(DltLogStorage *handle,
+ DltLogStorageUserConfig *uconfig,
+ unsigned char *data1,
+ int size1,
+ unsigned char *data2,
+ int size2,
+ unsigned char *data3,
+ int size3);
#endif /* DLT_OFFLINE_LOGSTORAGE_H */
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
index 77823ee..43c4d68 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
@@ -68,6 +68,7 @@ void dlt_logstorage_log_file_name(char *log_file_name,
strncat(log_file_name, &file_config->logfile_delimiter, 1);
snprintf(file_index, 10, "%d",idx);
+
if (file_config->logfile_maxcounter != UINT_MAX)
{
/* Setup 0's to be appended in file index until max index len*/