automotive-dlt
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <limits.h>
#include <errno.h>
#include "dlt_gateway.h"
#include "dlt_config_file_parser.h"
#include "dlt_common.h"
#include "dlt-daemon_cfg.h"
#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_client.h"
Go to the source code of this file.
Data Structures | |
struct | DltGatewayConf |
Macros | |
#define | DLT_GATEWAY_NUM_PROPERTIES_MAX GW_CONF_COUNT |
Enumerations | |
enum | DltGatewayConfType { 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 } |
Variables | |
STATIC DltGatewayConf | configuration_entries [GW_CONF_COUNT] |
Definition in file dlt_gateway.c.
#define DLT_GATEWAY_NUM_PROPERTIES_MAX GW_CONF_COUNT |
Definition at line 334 of file dlt_gateway.c.
enum DltGatewayConfType |
Enumerator | |
---|---|
GW_CONF_IP_ADDRESS | |
GW_CONF_PORT | |
GW_CONF_ECUID | |
GW_CONF_CONNECT | |
GW_CONF_TIMEOUT | |
GW_CONF_SEND_CONTROL | |
GW_CONF_SEND_SERIAL_HEADER | |
GW_CONF_COUNT |
Definition at line 54 of file dlt_gateway.c.
STATIC int dlt_gateway_check_connect_trigger | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check connection trigger
con | DltGatewayConnection to be updated |
value | string to be tested |
Definition at line 168 of file dlt_gateway.c.
References DLT_GATEWAY_ON_DEMAND, DLT_GATEWAY_ON_STARTUP, DLT_GATEWAY_UNDEFINED, dlt_log(), NULL, and DltGatewayConnection::trigger.
STATIC int dlt_gateway_check_control_messages | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check the specified control messages identifier
con | DltGatewayConnection to be updated |
value | string to be tested |
Definition at line 244 of file dlt_gateway.c.
References DltGatewayConnection::control_msgs, DLT_DAEMON_TEXTBUFSIZE, DLT_GATEWAY_MAX_STARTUP_CTRL_MSG, dlt_log(), DLT_SERVICE_ID_LAST_ENTRY, DLT_SERVICE_ID_SET_LOG_LEVEL, and NULL.
STATIC int dlt_gateway_check_ecu | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check ECU name
con | DltGatewayConnection to be updated |
value | string to be used as ECU identifier |
Definition at line 144 of file dlt_gateway.c.
References DltGatewayConnection::ecuid, and NULL.
STATIC int dlt_gateway_check_ip | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check if given string is a valid IP address
con | DltGatewayConnection to be updated |
value | string to be tested |
Definition at line 72 of file dlt_gateway.c.
References dlt_log(), DltGatewayConnection::ip_address, and NULL.
STATIC int dlt_gateway_check_param | ( | DltGateway * | gateway, |
DltGatewayConnection * | con, | ||
DltGatewayConfType | ctype, | ||
char * | value | ||
) |
Check if gateway connection configuration parameter is valid.
g | DltGateway |
c | DltGatewayConnection |
key | DltGatwayConnection property |
value | specified property value from configuration file |
Definition at line 345 of file dlt_gateway.c.
References configuration_entries, DltGatewayConf::func, GW_CONF_COUNT, and NULL.
Referenced by dlt_gateway_configure().
STATIC int dlt_gateway_check_port | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check port number
con | DltGatewayConnection to be updated |
value | string to be tested |
Definition at line 112 of file dlt_gateway.c.
References dlt_log(), NULL, and DltGatewayConnection::port.
STATIC int dlt_gateway_check_send_serial | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check the value for SendSerialHeader
con | DltGatewayConnection to be updated |
value | string to be tested |
Definition at line 225 of file dlt_gateway.c.
References NULL, and DltGatewayConnection::send_serial.
STATIC int dlt_gateway_check_timeout | ( | DltGatewayConnection * | con, |
char * | value | ||
) |
Check connection timeout value
con | DltGatewayConnection to be updated |
value | string to be tested |
Definition at line 201 of file dlt_gateway.c.
References NULL, and DltGatewayConnection::timeout.
int dlt_gateway_configure | ( | DltGateway * | gateway, |
char * | config_file, | ||
int | verbose | ||
) |
Read configuration file and initialize connection data structures
gateway | DltGateway |
config_file | Gateway configuration |
verbose | verbose flag |
Definition at line 455 of file dlt_gateway.c.
References configuration_entries, DltGateway::connections, DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_get_num_sections(), dlt_config_file_get_section_name(), dlt_config_file_get_value(), dlt_config_file_init(), dlt_config_file_release(), DLT_DAEMON_TCP_PORT, DLT_DAEMON_TEXTBUFSIZE, dlt_gateway_check_param(), dlt_gateway_store_connection(), dlt_log(), DltGatewayConnection::ecuid, GW_CONF_COUNT, DltGatewayConnection::ip_address, NULL, DltGateway::num_connections, DltGatewayConnection::port, PRINT_FUNCTION_VERBOSE, DltGatewayConnection::send_serial, and DltGateway::send_serial.
Referenced by dlt_gateway_init().
void dlt_gateway_deinit | ( | DltGateway * | g, |
int | verbose | ||
) |
De-initialize the gateway. All internal data will be freed.
g | DltGateway pointer |
verbose | verbose flag |
Definition at line 613 of file dlt_gateway.c.
References DltGatewayConnection::client, DltGateway::connections, dlt_client_cleanup(), DltGatewayConnection::ecuid, DltGatewayConnection::ip_address, NULL, DltGateway::num_connections, and PRINT_FUNCTION_VERBOSE.
int dlt_gateway_establish_connections | ( | DltGateway * | g, |
DltDaemonLocal * | daemon_local, | ||
int | verbose | ||
) |
Establish all connections to passive nodes that are configured to be started on daemon startup and add this connections to the main event loop.
TODO: This function is called during gateway initialization and in main loop whenever the epoll returns. This may need to be improved.
g | DltGateway |
daemon_local | DltDaemonLocal |
verbose | verbose flag |
Definition at line 636 of file dlt_gateway.c.
References DltGatewayConnection::client, DltGateway::connections, dlt_client_connect(), dlt_connection_create(), DLT_CONNECTION_GATEWAY, DLT_GATEWAY_CONNECTED, DLT_GATEWAY_DISABLED, DLT_GATEWAY_ON_DEMAND, dlt_gateway_send_control_message(), dlt_log(), NULL, DltGateway::num_connections, DltDaemonLocal::pEvent, PRINT_FUNCTION_VERBOSE, DltGatewayConnection::reconnect_cnt, DltClient::sock, DltGatewayConnection::status, DltGatewayConnection::timeout, DltGatewayConnection::timeout_cnt, and DltGatewayConnection::trigger.
Referenced by dlt_gateway_init(), and dlt_gateway_process_gateway_timer().
int dlt_gateway_forward_control_message | ( | DltGateway * | g, |
DltDaemonLocal * | daemon_local, | ||
DltMessage * | msg, | ||
char * | ecu, | ||
int | verbose | ||
) |
Forward control messages to the specified passive node DLT Daemon.
g | DltGateway |
daemon_local | DltDaemonLocal |
msg | DltMessage |
ecu | Identifier of the passive node |
verbose | verbose flag |
Definition at line 957 of file dlt_gateway.c.
References DltGatewayConnection::client, DltGateway::connections, sDltMessage::databuffer, sDltMessage::datasize, DLT_GATEWAY_CONNECTED, dlt_log(), dltSerialHeader, DltGatewayConnection::ecuid, sDltMessage::headerbuffer, sDltMessage::headersize, NULL, DltGateway::num_connections, PRINT_FUNCTION_VERBOSE, DltGatewayConnection::send_serial, DltClient::sock, and DltGatewayConnection::status.
Referenced by dlt_daemon_client_process_control(), and dlt_gateway_send_control_message().
DltReceiver* dlt_gateway_get_connection_receiver | ( | DltGateway * | g, |
int | fd | ||
) |
Return the receiver for a given file descriptor
g | DltGateway |
fd | file descriptor |
Definition at line 710 of file dlt_gateway.c.
References DltGatewayConnection::client, DltGateway::connections, DLT_GATEWAY_CONNECTED, NULL, DltGateway::num_connections, DltClient::receiver, DltClient::sock, and DltGatewayConnection::status.
Referenced by dlt_connection_get_receiver().
int dlt_gateway_init | ( | DltDaemonLocal * | daemon_local, |
int | verbose | ||
) |
Initialize the gateway to passive nodes
TODO: Make path to configuration file configurable
daemon_local | pointer to DltDaemonLocal |
verbose | verbose flag |
Definition at line 577 of file dlt_gateway.c.
References dlt_gateway_configure(), dlt_gateway_establish_connections(), dlt_log(), DltDaemonLocal::flags, DltDaemonFlags::gatewayConfigFile, DltDaemonFlags::lflag, NULL, DltDaemonLocal::pGateway, PRINT_FUNCTION_VERBOSE, and DltGateway::send_serial.
Referenced by main().
int dlt_gateway_process_gateway_timer | ( | DltDaemon * | daemon, |
DltDaemonLocal * | daemon_local, | ||
DltReceiver * | rec, | ||
int | verbose | ||
) |
Process gateway timer
daemon | DltDaemon |
daemon_loocal | DltDaemonLocal |
verbose | verbose flag |
Definition at line 914 of file dlt_gateway.c.
References DLT_DAEMON_TEXTBUFSIZE, dlt_gateway_establish_connections(), dlt_log(), DltReceiver::fd, NULL, DltDaemonLocal::pGateway, and PRINT_FUNCTION_VERBOSE.
Referenced by dlt_connection_get_callback().
int dlt_gateway_process_on_demand_request | ( | DltGateway * | g, |
DltDaemonLocal * | daemon_local, | ||
char * | node_id, | ||
int | connection_status, | ||
int | verbose | ||
) |
Process on demand connect/disconnect of passive nodes
g | DltGateway |
node_id | Passive Node identifier |
connection_status | Connection status |
Definition at line 1034 of file dlt_gateway.c.
References DltGatewayConnection::client, DltGateway::connections, dlt_client_cleanup(), dlt_client_connect(), dlt_connection_create(), DLT_CONNECTION_GATEWAY, dlt_event_handler_unregister_connection(), DLT_GATEWAY_CONNECTED, DLT_GATEWAY_DISCONNECTED, DLT_ID_SIZE, dlt_log(), DltGatewayConnection::ecuid, NULL, DltGateway::num_connections, DltDaemonLocal::pEvent, PRINT_FUNCTION_VERBOSE, DltClient::sock, and DltGatewayConnection::status.
Referenced by dlt_daemon_control_passive_node_connect().
int dlt_gateway_process_passive_node_messages | ( | DltDaemon * | daemon, |
DltDaemonLocal * | daemon_local, | ||
DltReceiver * | recv, | ||
int | verbose | ||
) |
Process incoming messages from passive nodes
daemon | DltDaemon |
daemon_local | DltDaemonLocal |
recv | DltReceiver structure |
verbose | verbose flag |
Definition at line 731 of file dlt_gateway.c.
References DltReceiver::buf, DltReceiver::bytesRcvd, DltGatewayConnection::client, DltGateway::connections, sDltMessage::databuffer, sDltMessage::datasize, dlt_daemon_client_send(), DLT_DAEMON_ERROR_OK, DLT_DAEMON_SEND_TO_ALL, DLT_DAEMON_TEXTBUFSIZE, dlt_event_handler_unregister_connection(), DLT_GATEWAY_DISABLED, DLT_GATEWAY_DISCONNECTED, DLT_GATEWAY_RECONNECT_MAX, dlt_log(), DLT_MESSAGE_ERROR_OK, dlt_message_free(), dlt_message_init(), dlt_message_read(), dlt_receiver_move_to_begin(), dlt_receiver_receive_socket(), dlt_receiver_remove(), dltSerialHeader, DltGatewayConnection::ecuid, DltReceiver::fd, sDltMessage::found_serialheader, sDltMessage::headerbuffer, sDltMessage::headersize, NULL, DltGateway::num_connections, DltDaemonLocal::pEvent, DltDaemonLocal::pGateway, PRINT_FUNCTION_VERBOSE, DltGatewayConnection::reconnect_cnt, DltClient::sock, DltGatewayConnection::status, DltGatewayConnection::timeout_cnt, and DltGatewayConnection::trigger.
Referenced by dlt_connection_get_callback().
void dlt_gateway_send_control_message | ( | DltGatewayConnection * | con, |
DltGateway * | g, | ||
DltDaemonLocal * | daemon_local, | ||
int | verbose | ||
) |
Send control message to passive node.
con | DltGatewayConnection |
g | DltGateway |
daemon_local | DltDaemonLocal |
verbose | verbose flag |
Definition at line 1123 of file dlt_gateway.c.
References DltGatewayConnection::control_msgs, sDltMessage::databuffer, sDltMessage::databuffersize, sDltMessage::datasize, DLT_DAEMON_TEXTBUFSIZE, dlt_gateway_forward_control_message(), DLT_GATEWAY_MAX_STARTUP_CTRL_MSG, DLT_HTOBE_16, DLT_HTYP_MSBF, DLT_HTYP_PROTOCOL_VERSION1, DLT_HTYP_UEH, DLT_HTYP_WEID, DLT_HTYP_WTMS, dlt_log(), dlt_message_free(), dlt_message_init(), dlt_message_set_extraparameters(), DLT_MSIN_CONTROL_REQUEST, DLT_RETURN_ERROR, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, dlt_set_id(), dlt_set_storageheader(), DLT_STANDARD_HEADER_EXTRA_SIZE, dlt_uptime(), DltGatewayConnection::ecuid, sDltMessage::extendedheader, sDltMessage::headerbuffer, sDltMessage::headerextra, sDltMessage::headersize, NULL, PRINT_FUNCTION_VERBOSE, sDltMessage::standardheader, and sDltMessage::storageheader.
Referenced by dlt_gateway_establish_connections().
int dlt_gateway_store_connection | ( | DltGateway * | gateway, |
DltGatewayConnection * | tmp, | ||
int | verbose | ||
) |
Store gateway connection in internal data structure
g | DltGatway |
tmp | DltGatewayConnection |
verbose | verbose flag |
Definition at line 369 of file dlt_gateway.c.
References DltGatewayConnection::client, DltGateway::connections, DltGatewayConnection::control_msgs, dlt_client_init_port(), dlt_client_set_server_ip(), DLT_DAEMON_RCVBUFSIZESOCK, DLT_GATEWAY_INITIALIZED, DLT_GATEWAY_UNINITIALIZED, dlt_log(), dlt_receiver_init(), DltGatewayConnection::ecuid, DltGatewayConnection::handle, DltGatewayConnection::ip_address, NULL, DltGatewayConnection::port, PRINT_FUNCTION_VERBOSE, DltClient::receiver, DltGatewayConnection::send_serial, DltClient::sock, DltGatewayConnection::sock_domain, DltGatewayConnection::sock_protocol, DltGatewayConnection::sock_type, DltGatewayConnection::status, DltGatewayConnection::timeout, and DltGatewayConnection::trigger.
Referenced by dlt_gateway_configure().
STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT] |
Expected entries for a passive node configuration Caution: after changing entries here, dlt_gateway_check_param needs to be updated as well
Definition at line 302 of file dlt_gateway.c.
Referenced by dlt_gateway_check_param(), and dlt_gateway_configure().