diff options
author | Christoph Lipka <clipka@de.adit-jv.com> | 2018-12-20 14:58:19 +0100 |
---|---|---|
committer | Christoph Lipka <clipka@de.adit-jv.com> | 2018-12-21 10:23:41 +0100 |
commit | dca8ab254aa0a687c32009079d85e4d8f960b213 (patch) | |
tree | e63b6a552fd9f61873892110a56a89ef354864cd /src/gateway | |
parent | 0d0c74640c8b792db37cb9f884f89f7561ea551f (diff) | |
download | DLT-daemon-dca8ab254aa0a687c32009079d85e4d8f960b213.tar.gz |
Code beautification using uncrustify
Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
Diffstat (limited to 'src/gateway')
-rw-r--r-- | src/gateway/dlt_gateway.c | 687 | ||||
-rw-r--r-- | src/gateway/dlt_gateway_internal.h | 10 |
2 files changed, 260 insertions, 437 deletions
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c index 2bc535e..6b7a629 100644 --- a/src/gateway/dlt_gateway.c +++ b/src/gateway/dlt_gateway.c @@ -61,8 +61,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, char * struct sockaddr_in sa; int ret = DLT_RETURN_ERROR; - if ((con == NULL) || (value == NULL)) - { + if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -70,20 +69,17 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, char * ret = inet_pton(AF_INET, value, &(sa.sin_addr)); /* valid IP address */ - if (ret != 0) - { + if (ret != 0) { con->ip_address = strdup(value); - if (con->ip_address == NULL) - { + if (con->ip_address == NULL) { dlt_log(LOG_ERR, "Cannot copy passive node IP address string\n"); return DLT_RETURN_ERROR; } return DLT_RETURN_OK; } - else - { + else { dlt_log(LOG_ERR, "IP address is not valid\n"); } @@ -98,26 +94,23 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, char * * @return Value from DltReturnValue enum */ DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, - char *value) + char *value) { int tmp = -1; - if ((con == NULL) || (value == NULL)) - { + if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - tmp = (int) strtol(value, NULL, 10); + 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 DLT_RETURN_OK; } - else - { + else { dlt_log(LOG_ERR, "Port number is invalid\n"); } @@ -132,10 +125,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, * @return Value from DltReturnValue enum */ DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, - char *value) + char *value) { - if ((con == NULL) || (value == NULL)) - { + if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -143,9 +135,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, con->ecuid = strdup(value); if (con->ecuid == NULL) - { return DLT_RETURN_ERROR; - } return DLT_RETURN_OK; } @@ -160,22 +150,19 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection *con, char *value) { - if ((con == NULL) || (value == NULL)) - { + if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if (strncasecmp(value, "OnStartup", strlen("OnStartup")) == 0) - { + if (strncasecmp(value, "OnStartup", strlen("OnStartup")) == 0) { con->trigger = DLT_GATEWAY_ON_STARTUP; } else if (strncasecmp(value, "OnDemand", strlen("OnDemand")) == 0) { con->trigger = DLT_GATEWAY_ON_DEMAND; } - else - { + else { dlt_log(LOG_ERR, "Wrong connection trigger state given.\n"); con->trigger = DLT_GATEWAY_UNDEFINED; return DLT_RETURN_ERROR; @@ -192,20 +179,17 @@ DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection * @return Value from DltReturnValue enum */ DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection *con, - char *value) + char *value) { - if ((con == NULL) || (value == NULL)) - { + if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - con->timeout = (int) strtol(value, NULL, 10); + con->timeout = (int)strtol(value, NULL, 10); if (con->timeout > 0) - { return DLT_RETURN_OK; - } return DLT_RETURN_ERROR; } @@ -218,15 +202,14 @@ DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection *con, * @return Value from DltReturnValue enum */ DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection *con, - char *value) + char *value) { - if ((con == NULL) || (value == NULL)) - { + if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - con->send_serial = !!((int) strtol(value, NULL, 10)); + con->send_serial = !!((int)strtol(value, NULL, 10)); return DLT_RETURN_OK; } @@ -239,29 +222,24 @@ DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection *co */ DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnection *con) { - if (con == NULL) - { + if (con == NULL) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if (con->p_control_msgs == NULL) - { + if (con->p_control_msgs == NULL) { con->p_control_msgs = calloc(1, sizeof(DltPassiveControlMessage)); - if (!con->p_control_msgs) - { + if (!con->p_control_msgs) { dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; } } - else - { + else { con->p_control_msgs->next = calloc(1, sizeof(DltPassiveControlMessage)); - if (!con->p_control_msgs->next) - { + if (!con->p_control_msgs->next) { dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; @@ -288,24 +266,19 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio char *rest = NULL; DltPassiveControlMessage *head = NULL; - if ((con == NULL) || (value == 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; - } /* set on startup control msg id and interval*/ token = strtok_r(value, ",", &rest); - while (token != NULL) - { - if (dlt_gateway_allocate_control_messages(con) != DLT_RETURN_OK) - { + while (token != NULL) { + if (dlt_gateway_allocate_control_messages(con) != DLT_RETURN_OK) { dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; @@ -318,12 +291,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio con->p_control_msgs->interval = -1; if (head == NULL) - { head = con->p_control_msgs; - } - if ((errno == EINVAL) || (errno == ERANGE)) - { + if ((errno == EINVAL) || (errno == ERANGE)) { dlt_vlog(LOG_ERR, "Control message ID is not an integer: %s\n", token); @@ -356,23 +326,20 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio * @return Value from DltReturnValue enum */ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( - DltGatewayConnection *con, - char *value) + DltGatewayConnection *con, + char *value) { char *token = NULL; char *rest = NULL; DltPassiveControlMessage *head = NULL; - if ((con == NULL) || (value == 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; @@ -380,35 +347,31 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( /* set periodic control msg id and interval*/ token = strtok_r(value, ",", &rest); - while (token != NULL) - { + 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)) - { + 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) - { + 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; } @@ -416,24 +379,19 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( } /* if the id is not added yet, p_control_msgs supposed to be NULL */ - if (con->p_control_msgs == 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) - { + 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) != DLT_RETURN_OK) - { + if (dlt_gateway_allocate_control_messages(con) != DLT_RETURN_OK) { dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; @@ -444,23 +402,19 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( 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)) - { + if ((errno == EINVAL) || (errno == ERANGE)) { dlt_vlog(LOG_ERR, "Control message ID is not an integer: %s\n", p_token); @@ -490,40 +444,47 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( * Caution: after changing entries here, * dlt_gateway_check_param needs to be updated as well * */ -DLT_STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT] = -{ +DLT_STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT] = { [GW_CONF_IP_ADDRESS] = { .key = "IPaddress", .func = dlt_gateway_check_ip, - .is_opt = 0 }, + .is_opt = 0 + }, [GW_CONF_PORT] = { .key = "Port", .func = dlt_gateway_check_port, - .is_opt = 1 }, + .is_opt = 1 + }, [GW_CONF_ECUID] = { .key = "EcuID", .func = dlt_gateway_check_ecu, - .is_opt = 0 }, + .is_opt = 0 + }, [GW_CONF_CONNECT] = { .key = "Connect", .func = dlt_gateway_check_connect_trigger, - .is_opt = 1 }, + .is_opt = 1 + }, [GW_CONF_TIMEOUT] = { .key = "Timeout", .func = dlt_gateway_check_timeout, - .is_opt = 0 }, + .is_opt = 0 + }, [GW_CONF_SEND_CONTROL] = { .key = "SendControl", .func = dlt_gateway_check_control_messages, - .is_opt = 1 }, + .is_opt = 1 + }, [GW_CONF_SEND_PERIODIC_CONTROL] = { .key = "SendPeriodicControl", .func = dlt_gateway_check_periodic_control_messages, - .is_opt = 1 }, + .is_opt = 1 + }, [GW_CONF_SEND_SERIAL_HEADER] = { .key = "SendSerialHeader", .func = dlt_gateway_check_send_serial, - .is_opt = 1 } + .is_opt = 1 + } }; #define DLT_GATEWAY_NUM_PROPERTIES_MAX GW_CONF_COUNT @@ -542,8 +503,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_param(DltGateway *gateway, DltGatewayConfType ctype, char *value) { - if ((gateway == NULL) || (con == NULL) || (value == NULL)) - { + if ((gateway == NULL) || (con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -570,27 +530,21 @@ int dlt_gateway_store_connection(DltGateway *gateway, PRINT_FUNCTION_VERBOSE(verbose); - if ((gateway == NULL) || (tmp == NULL)) - { + if ((gateway == NULL) || (tmp == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } /* find next free entry in connection array */ - while (i < gateway->num_connections) - { + while (i < gateway->num_connections) { if (gateway->connections[i].status == DLT_GATEWAY_UNINITIALIZED) - { break; - } i++; } if (&(gateway->connections[i]) == NULL) - { return DLT_RETURN_ERROR; - } /* store values */ gateway->connections[i].ip_address = strdup(tmp->ip_address); @@ -609,8 +563,7 @@ int dlt_gateway_store_connection(DltGateway *gateway, if (dlt_client_init_port(&gateway->connections[i].client, gateway->connections[i].port, - verbose) != 0) - { + verbose) != 0) { free(gateway->connections[i].ip_address); gateway->connections[i].ip_address = NULL; free(gateway->connections[i].ecuid); @@ -622,9 +575,8 @@ int dlt_gateway_store_connection(DltGateway *gateway, } /* setup DltClient Structure */ - if(dlt_client_set_server_ip(&gateway->connections[i].client, - gateway->connections[i].ip_address) == -1) - { + if (dlt_client_set_server_ip(&gateway->connections[i].client, + gateway->connections[i].ip_address) == -1) { dlt_log(LOG_ERR, "dlt_client_set_server_ip() failed for gateway connection \n"); return DLT_RETURN_ERROR; @@ -649,8 +601,7 @@ 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')) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -661,8 +612,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) /* get number of entries and allocate memory to store information */ ret = dlt_config_file_get_num_sections(file, &gateway->num_connections); - if (ret != 0) - { + if (ret != 0) { dlt_config_file_release(file); dlt_log(LOG_ERR, "Invalid number of sections in configuration file\n"); return DLT_RETURN_ERROR; @@ -671,20 +621,18 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) gateway->connections = calloc(sizeof(DltGatewayConnection), gateway->num_connections); - if (gateway->connections == NULL) - { + if (gateway->connections == NULL) { dlt_config_file_release(file); dlt_log(LOG_CRIT, "Memory allocation for gateway connections failed\n"); return DLT_RETURN_ERROR; } - for (i = 0; i < gateway->num_connections; i++) - { + for (i = 0; i < gateway->num_connections; i++) { DltGatewayConnection tmp; int invalid = 0; DltGatewayConfType j = 0; - char section[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {'\0'}; - char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {'\0'}; + char section[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; + char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; memset(&tmp, 0, sizeof(tmp)); @@ -694,15 +642,13 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) ret = dlt_config_file_get_section_name(file, i, section); - for (j = 0; j < GW_CONF_COUNT; j++) - { + for (j = 0; j < GW_CONF_COUNT; j++) { ret = dlt_config_file_get_value(file, section, configuration_entries[j].key, value); - if ((ret != 0) && configuration_entries[j].is_opt) - { + if ((ret != 0) && configuration_entries[j].is_opt) { /* Use default values for this key */ dlt_vlog(LOG_WARNING, "Using default for %s.\n", @@ -722,29 +668,23 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) ret = dlt_gateway_check_param(gateway, &tmp, j, value); if (ret != 0) - { dlt_vlog(LOG_ERR, "Configuration %s = %s is invalid.\n" "Using default.\n", configuration_entries[j].key, value); - } } - if (invalid) - { + if (invalid) { dlt_vlog(LOG_ERR, "%s configuration is invalid.\n" "Ignoring.\n", section); } - else - { + else { ret = dlt_gateway_store_connection(gateway, &tmp, verbose); if (ret != 0) - { dlt_log(LOG_ERR, "Storing gateway connection data failed\n"); - } } /* strdup used inside some get_value function */ @@ -762,29 +702,25 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - if (daemon_local == NULL) - { + if (daemon_local == NULL) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } DltGateway *gateway = &daemon_local->pGateway; - if (gateway != NULL) - { + if (gateway != NULL) { /* Get default value from daemon_local */ gateway->send_serial = daemon_local->flags.lflag; if (dlt_gateway_configure(gateway, daemon_local->flags.gatewayConfigFile, - verbose) != 0) - { + verbose) != 0) { dlt_log(LOG_ERR, "Gateway initialization failed\n"); return DLT_RETURN_ERROR; } } - else - { + else { dlt_log(LOG_CRIT, "Pointer to Gateway structure is NULL\n"); return DLT_RETURN_ERROR; } @@ -800,24 +736,22 @@ void dlt_gateway_deinit(DltGateway *gateway, int verbose) DltPassiveControlMessage *msg; int i = 0; - if (gateway == NULL) - { + if (gateway == NULL) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return; } PRINT_FUNCTION_VERBOSE(verbose); - for (i = 0; i < gateway->num_connections; i++) - { + for (i = 0; i < gateway->num_connections; i++) { 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) - { + + while (c->p_control_msgs != NULL) { msg = c->p_control_msgs->next; free(c->p_control_msgs); c->p_control_msgs = msg; @@ -837,14 +771,13 @@ void dlt_gateway_deinit(DltGateway *gateway, int verbose) * @return 0 on success, -1 otherwise */ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, - DltGatewayConnection *con, - int verbose) + DltGatewayConnection *con, + int verbose) { DltPassiveControlMessage *control_msg = NULL; int sendtime = 1; - if ((daemon_local == NULL) || (con == NULL)) - { + if ((daemon_local == NULL) || (con == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -860,8 +793,7 @@ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, &daemon_local->pEvent, con->client.sock, POLLIN, - DLT_CONNECTION_GATEWAY) != 0) - { + DLT_CONNECTION_GATEWAY) != 0) { dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } @@ -869,27 +801,22 @@ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, /* immediately send configured control messages */ control_msg = con->p_control_msgs; - while (control_msg != NULL) - { + while (control_msg != NULL) { if ((control_msg->type == CONTROL_MESSAGE_ON_STARTUP) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) - { + (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; } @@ -909,46 +836,39 @@ int dlt_gateway_establish_connections(DltGateway *gateway, PRINT_FUNCTION_VERBOSE(verbose); - if ((gateway == NULL) || (daemon_local == NULL)) - { + if ((gateway == NULL) || (daemon_local == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - for (i = 0; i < gateway->num_connections; i++) - { + for (i = 0; i < gateway->num_connections; i++) { DltGatewayConnection *con = &(gateway->connections[i]); DltPassiveControlMessage *control_msg = NULL; - if (con == NULL) - { + if (con == NULL) { dlt_log(LOG_CRIT, "Cannot retrieve gateway connection details\n"); return DLT_RETURN_ERROR; } if ((con->status != DLT_GATEWAY_CONNECTED) && (con->trigger != DLT_GATEWAY_ON_DEMAND) && - (con->trigger != DLT_GATEWAY_DISABLED)) - { + (con->trigger != DLT_GATEWAY_DISABLED)) { ret = dlt_client_connect(&con->client, verbose); - if (ret == 0) - { + if (ret == 0) { /* setup dlt connection and add to poll event loop here */ - if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK) - { + if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK) { dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } } - else - { + else { dlt_log(LOG_DEBUG, "Passive Node is not up. Connection failed.\n"); con->timeout_cnt++; - if (con->timeout_cnt > con->timeout) - { + + if (con->timeout_cnt > con->timeout) { con->trigger = DLT_GATEWAY_DISABLED; dlt_log(LOG_WARNING, "Passive Node connection retry timed out. " @@ -961,11 +881,10 @@ int dlt_gateway_establish_connections(DltGateway *gateway, { /* setup dlt connection and add to poll event loop here */ if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - con->client.sock, - POLLIN, - DLT_CONNECTION_GATEWAY) != 0) - { + &daemon_local->pEvent, + con->client.sock, + POLLIN, + DLT_CONNECTION_GATEWAY) != 0) { dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } @@ -973,32 +892,25 @@ int dlt_gateway_establish_connections(DltGateway *gateway, /* immediately send periodic configured control messages */ control_msg = con->p_control_msgs; - while (control_msg != NULL) - { + while (control_msg != NULL) { if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) - { + (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; - } } } @@ -1009,19 +921,16 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd) { int i = 0; - if (gateway == NULL) - { + if (gateway == NULL) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return NULL; } - for (i = 0; i < gateway->num_connections; i++) - { + for (i = 0; i < gateway->num_connections; i++) { DltGatewayConnection *c = &gateway->connections[i]; - if (c->status == DLT_GATEWAY_CONNECTED && c->client.sock == fd) - { + + if ((c->status == DLT_GATEWAY_CONNECTED) && (c->client.sock == fd)) return &c->client.receiver; - } } return NULL; @@ -1043,7 +952,7 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, int req, int verbose) { - char resp_text[DLT_RECEIVE_BUFSIZE] = {'\0'}; + char resp_text[DLT_RECEIVE_BUFSIZE] = { '\0' }; DltServiceGetLogInfoResponse *resp = NULL; AppIDsType app; ContextIDsInfoType con; @@ -1052,30 +961,24 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); - if ((msg == NULL) || (msg->databuffer == NULL)) - { + 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) - { + if (req == CONTROL_MESSAGE_REQUESTED) { /* clear application list */ - if (dlt_daemon_applications_clear(daemon, ecu, verbose) == DLT_RETURN_ERROR) - { + 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) - { + if (dlt_daemon_contexts_clear(daemon, ecu, verbose) == DLT_RETURN_ERROR) { dlt_log(LOG_ERR, "Cannot clear contexts list\n"); return DLT_RETURN_ERROR; } @@ -1085,49 +988,43 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, if (dlt_message_payload(msg, resp_text, DLT_RECEIVE_BUFSIZE, - DLT_OUTPUT_ASCII, 0) != DLT_RETURN_OK) - { + 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)); + resp = (DltServiceGetLogInfoResponse *)calloc(1, sizeof(DltServiceGetLogInfoResponse)); - if (resp == NULL) - { + 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) - { + 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) - { + 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++) - { + 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) - { + app.app_id, + 0, + app.app_description, + -1, + ecu, + verbose) == 0) { dlt_vlog(LOG_WARNING, "%s: dlt_daemon_application_add failed\n", __func__); @@ -1135,22 +1032,20 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, return DLT_RETURN_ERROR; } - for (j = 0; j < app.count_context_ids; j++) - { + 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) - { + 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__, @@ -1177,38 +1072,35 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, * @return 0 on success, -1 otherwise */ DLT_STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *ecu, - DltMessage *msg, - int verbose) + 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)) - { + 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) - { + sizeof(DltServiceGetDefaultLogLevelResponse)) < 0) { dlt_log(LOG_ERR, "Received data incomplete.\n"); return DLT_RETURN_ERROR; } /* prepare pointer to message request */ - resp = (DltServiceGetDefaultLogLevelResponse *) (msg->databuffer); + resp = (DltServiceGetDefaultLogLevelResponse *)(msg->databuffer); con = dlt_gateway_get_connection(&daemon_local->pGateway, ecu, verbose); - if (con == NULL) - { + if (con == NULL) { dlt_vlog(LOG_ERR, "No information about passive ECU: %s\n", ecu); @@ -1229,48 +1121,43 @@ DLT_STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon, * @return 0 on success, -1 otherwise */ DLT_STATIC int dlt_gateway_control_service_logstorage(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) + DltDaemonLocal *daemon_local, + int verbose) { unsigned int connection_type = 0; int i = 0; - if (daemon_local->flags.offlineLogstorageMaxDevices <= 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++) - { + 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; } DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) + DltDaemonLocal *daemon_local, + DltReceiver *receiver, + int verbose) { int i = 0; DltGateway *gateway = NULL; DltGatewayConnection *con = NULL; - DltMessage msg = {0}; + DltMessage msg = { 0 }; - if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) - { + if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -1278,63 +1165,56 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); gateway = &daemon_local->pGateway; - if (gateway == NULL) - { + + if (gateway == NULL) { dlt_log(LOG_ERR, "Gateway structure is NULL\n"); return DLT_RETURN_ERROR; } for (i = 0; i < gateway->num_connections; i++) - { - if (gateway->connections[i].client.sock == receiver->fd) - { + if (gateway->connections[i].client.sock == receiver->fd) { con = &gateway->connections[i]; break; } - } - if (con == NULL) - { + + + if (con == NULL) { dlt_log(LOG_ERR, "Cannot associate fd to passive Node connection\n"); return DLT_RETURN_ERROR; } /* now the corresponding passive node connection is available */ - if (dlt_message_init(&msg, verbose) == -1) - { + if (dlt_message_init(&msg, verbose) == -1) { dlt_log(LOG_ERR, "Cannot initialize DLT message for passive node forwarding\n"); return DLT_RETURN_ERROR; } /* nearly copy and paste of dlt_client_main_loop function */ - if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0) - { + if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0) { /* No more data to be received */ - if (dlt_message_free(&msg, verbose) < 0) - { + if (dlt_message_free(&msg, verbose) < 0) { dlt_log(LOG_ERR, "Cannot free DLT message\n"); return DLT_RETURN_ERROR; } dlt_log(LOG_WARNING, "Connection to passive node lost\n"); - if (con->reconnect_cnt < DLT_GATEWAY_RECONNECT_MAX) - { + if (con->reconnect_cnt < DLT_GATEWAY_RECONNECT_MAX) { dlt_log(LOG_WARNING, "Try to reconnect.\n"); con->reconnect_cnt += 1; con->timeout_cnt = 0; } - else - { + else { con->status = DLT_GATEWAY_DISCONNECTED; + if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, - daemon_local, - receiver->fd) != 0) - { + daemon_local, + receiver->fd) != 0) dlt_log(LOG_ERR, "Remove passive node Connection failed\n"); - } } + return DLT_RETURN_OK; } @@ -1342,16 +1222,14 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, (unsigned char *)receiver->buf, receiver->bytesRcvd, 0, - verbose) == DLT_MESSAGE_ERROR_OK) - { + verbose) == DLT_MESSAGE_ERROR_OK) { DltStandardHeaderExtra *header = (DltStandardHeaderExtra *) - (msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader)); + (msg.headerbuffer + + sizeof(DltStorageHeader) + + sizeof(DltStandardHeader)); /* only forward messages if the received ECUid is the expected one */ - if (strncmp(header->ecu, con->ecuid, strlen(con->ecuid)) == 0) - { + if (strncmp(header->ecu, con->ecuid, strlen(con->ecuid)) == 0) { uint32_t id; uint32_t id_tmp; DltPassiveControlMessage *control_msg = con->p_control_msgs; @@ -1363,24 +1241,19 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, con->ecuid, msg.databuffer); - id_tmp = *((uint32_t*)(msg.databuffer)); + 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 (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, @@ -1391,6 +1264,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, control_msg->req = CONTROL_MESSAGE_NOT_REQUESTED; break; } + control_msg = control_msg->next; } } @@ -1402,95 +1276,79 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, 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) - { + msg.headerextra.ecu) == DLT_RETURN_ERROR) { dlt_vlog(LOG_ERR, "%s: Can't set storage header\n", __func__); return DLT_RETURN_ERROR; } if (dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - msg.headerbuffer, - sizeof(DltStorageHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - msg.headersize - sizeof(DltStorageHeader), - msg.databuffer, - msg.datasize, - verbose) != DLT_DAEMON_ERROR_OK) - { + daemon, + daemon_local, + msg.headerbuffer, + sizeof(DltStorageHeader), + msg.headerbuffer + sizeof(DltStorageHeader), + msg.headersize - sizeof(DltStorageHeader), + msg.databuffer, + msg.datasize, + verbose) != DLT_DAEMON_ERROR_OK) dlt_log(LOG_WARNING, "Forward message to clients failed!\n"); - } } - else /* otherwise remove this connection and do not connect again */ - { + else { /* otherwise remove this connection and do not connect again */ dlt_vlog(LOG_WARNING, "Received ECUid (%s) differs to configured ECUid(%s). " "Discard this message.\n", header->ecu, con->ecuid); - /* disconnect from passive node */ + /* 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) + 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"); } - if (msg.found_serialheader) - { + if (msg.found_serialheader) { if (dlt_receiver_remove(receiver, msg.headersize + msg.datasize - sizeof(DltStorageHeader) + - sizeof(dltSerialHeader)) == -1) - { - /* Return value ignored */ - dlt_message_free(&msg,verbose); - return DLT_RETURN_ERROR; - } - } - else - { - if (dlt_receiver_remove(receiver, - msg.headersize + - msg.datasize - - sizeof(DltStorageHeader)) == -1) - { + sizeof(dltSerialHeader)) == -1) { /* Return value ignored */ - dlt_message_free(&msg,verbose); + dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; } } + else if (dlt_receiver_remove(receiver, + msg.headersize + + msg.datasize - + sizeof(DltStorageHeader)) == -1) { + /* Return value ignored */ + dlt_message_free(&msg, verbose); + return DLT_RETURN_ERROR; + } } - if (dlt_receiver_move_to_begin(receiver) == -1) - { + if (dlt_receiver_move_to_begin(receiver) == -1) { /* Return value ignored */ dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; } if (dlt_message_free(&msg, verbose) == -1) - { return DLT_RETURN_ERROR; - } return DLT_RETURN_OK; } @@ -1505,8 +1363,7 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL)) - { + if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL)) { dlt_vlog(LOG_ERR, "%s: invalid parameters\n", __func__); @@ -1515,15 +1372,13 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon, res = read(receiver->fd, &expir, sizeof(expir)); - if(res < 0) - { + if (res < 0) 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 */ - } + * let's go on sending notification */ /* try to connect to passive nodes */ dlt_gateway_establish_connections(&daemon_local->pGateway, @@ -1549,69 +1404,62 @@ int dlt_gateway_forward_control_message(DltGateway *gateway, PRINT_FUNCTION_VERBOSE(verbose); - if (gateway == NULL || daemon_local == NULL || msg == NULL || ecu == NULL) - { + if ((gateway == NULL) || (daemon_local == NULL) || (msg == NULL) || (ecu == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } for (i = 0; i < gateway->num_connections; i++) - { if (strncmp(gateway->connections[i].ecuid, ecu, - strlen(gateway->connections[i].ecuid)) == 0) - { + strlen(gateway->connections[i].ecuid)) == 0) { con = &gateway->connections[i]; break; } - } - if (con == NULL) - { + + + if (con == NULL) { dlt_log(LOG_WARNING, "Unknown passive node identifier\n"); return DLT_RETURN_ERROR; } - if (con->status != DLT_GATEWAY_CONNECTED) - { + if (con->status != DLT_GATEWAY_CONNECTED) { dlt_log(LOG_INFO, "Passive node is not connected\n"); return DLT_RETURN_ERROR; } - if (con->send_serial) /* send serial header */ - { + if (con->send_serial) { /* send serial header */ ret = send(con->client.sock, (void *)dltSerialHeader, sizeof(dltSerialHeader), 0); - if (ret == -1) - { + if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); return DLT_RETURN_ERROR; } } ret = send(con->client.sock, - msg->headerbuffer + sizeof(DltStorageHeader), - msg->headersize - sizeof(DltStorageHeader), - 0); - if (ret == -1) - { + msg->headerbuffer + sizeof(DltStorageHeader), + msg->headersize - sizeof(DltStorageHeader), + 0); + + if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); return DLT_RETURN_ERROR; } - else - { + else { ret = send(con->client.sock, msg->databuffer, msg->datasize, 0); - if (ret == -1) - { + + if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); return DLT_RETURN_ERROR; } } - id_tmp = *((uint32_t*)(msg->databuffer)); + id_tmp = *((uint32_t *)(msg->databuffer)); id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); dlt_vlog(LOG_INFO, @@ -1631,49 +1479,41 @@ 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)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } /* find connection by ECU id */ for (i = 0; i < gateway->num_connections; i++) - { - if (strncmp(node_id, gateway->connections->ecuid, DLT_ID_SIZE) == 0) - { + if (strncmp(node_id, gateway->connections->ecuid, DLT_ID_SIZE) == 0) { con = &gateway->connections[i]; break; } - } - if (con == NULL) - { + + + if (con == NULL) { dlt_log(LOG_WARNING, "Specified ECUid not found\n"); return DLT_RETURN_ERROR; } - if (connection_status == 1) /* try to connect */ - { - if (con->status != DLT_GATEWAY_CONNECTED) - { - if (dlt_client_connect(&con->client, verbose) == 0) - { + if (connection_status == 1) { /* try to connect */ + + if (con->status != DLT_GATEWAY_CONNECTED) { + if (dlt_client_connect(&con->client, verbose) == 0) { /* setup dlt connection and add to poll event loop here */ - if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK) - { + if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK) { dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } } - else - { + else { dlt_log(LOG_ERR, "Could not connect to passive node\n"); return DLT_RETURN_ERROR; } } - else - { + else { dlt_log(LOG_INFO, "Passive node already connected\n"); } } @@ -1682,16 +1522,14 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway, con->status = DLT_GATEWAY_DISCONNECTED; con->trigger = DLT_GATEWAY_ON_DEMAND; + if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, - daemon_local, - con->client.sock) != 0) - { + daemon_local, + con->client.sock) != 0) dlt_log(LOG_ERR, "Remove passive node event handler connection failed\n"); - } } - else - { + else { dlt_log(LOG_ERR, "Unknown command (connection_status)\n"); return DLT_RETURN_ERROR; } @@ -1708,8 +1546,7 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, PRINT_FUNCTION_VERBOSE(verbose); - if (con == NULL) - { + if (con == NULL) { dlt_vlog(LOG_WARNING, "%s: Invalid parameter given\n", __func__); @@ -1718,45 +1555,34 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, /* no (more) control message to be send */ if (control_msg->id == 0) - { return DLT_RETURN_ERROR; - } /* 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->type != CONTROL_MESSAGE_ON_DEMAND) && (con->sendtime_cnt > 0)) { if (control_msg->interval <= 0) - { return DLT_RETURN_ERROR; - } if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) - { + (control_msg->type == CONTROL_MESSAGE_BOTH)) { if ((con->sendtime_cnt - 1) % control_msg->interval != 0) - { return DLT_RETURN_ERROR; - } } } - if (con->send_serial) /* send serial header */ - { + if (con->send_serial) { /* send serial header */ ret = send(con->client.sock, (void *)dltSerialHeader, sizeof(dltSerialHeader), 0); - if (ret == -1) - { + if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); return DLT_RETURN_ERROR; } } - switch(control_msg->id) - { + switch (control_msg->id) { case DLT_SERVICE_ID_GET_LOG_INFO: return dlt_client_get_log_info(&con->client); break; @@ -1767,15 +1593,15 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, return dlt_client_get_software_version(&con->client); break; case DLT_SERVICE_ID_SET_LOG_LEVEL: - if (data == NULL) - { + + if (data == NULL) { 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; } - DltServiceSetLogLevel *req = (DltServiceSetLogLevel *) data; + DltServiceSetLogLevel *req = (DltServiceSetLogLevel *)data; return dlt_client_send_log_level(&con->client, req->apid, req->ctid, @@ -1799,19 +1625,16 @@ DltGatewayConnection *dlt_gateway_get_connection(DltGateway *gateway, PRINT_FUNCTION_VERBOSE(verbose); - if ((gateway == NULL) || (ecu == NULL)) - { + if ((gateway == NULL) || (ecu == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); return con; } - for (i = 0; i < gateway->num_connections; i++) - { + for (i = 0; i < gateway->num_connections; i++) { con = &gateway->connections[i]; + if (strncmp(con->ecuid, ecu, DLT_ID_SIZE) == 0) - { return con; - } } dlt_vlog(LOG_ERR, "%s: No connection found\n", ecu); diff --git a/src/gateway/dlt_gateway_internal.h b/src/gateway/dlt_gateway_internal.h index c0f9241..a473f11 100644 --- a/src/gateway/dlt_gateway_internal.h +++ b/src/gateway/dlt_gateway_internal.h @@ -59,22 +59,22 @@ #define DLT_GATEWAY_INTERNAL_H_ DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, - char *value); + char *value); DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, - char *value); + char *value); DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, - char *value); + char *value); DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection *con, char *value); DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection *con, - char *value); + char *value); DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection *con, - char *value); + char *value); DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnection *con); |