automotive-dlt
dlt_gateway.c File Reference
#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"
Include dependency graph for dlt_gateway.c:

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
}
 

Functions

STATIC int dlt_gateway_check_ip (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_port (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_ecu (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_connect_trigger (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_timeout (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_send_serial (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_control_messages (DltGatewayConnection *con, char *value)
 
STATIC int dlt_gateway_check_param (DltGateway *gateway, DltGatewayConnection *con, DltGatewayConfType ctype, char *value)
 
int dlt_gateway_store_connection (DltGateway *gateway, DltGatewayConnection *tmp, int verbose)
 
int dlt_gateway_configure (DltGateway *gateway, char *config_file, int verbose)
 
int dlt_gateway_init (DltDaemonLocal *daemon_local, int verbose)
 
void dlt_gateway_deinit (DltGateway *gateway, int verbose)
 
int dlt_gateway_establish_connections (DltGateway *gateway, DltDaemonLocal *daemon_local, int verbose)
 
DltReceiverdlt_gateway_get_connection_receiver (DltGateway *gateway, int fd)
 
int dlt_gateway_process_passive_node_messages (DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
 
int dlt_gateway_process_gateway_timer (DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
 
int dlt_gateway_forward_control_message (DltGateway *gateway, DltDaemonLocal *daemon_local, DltMessage *msg, char *ecu, int verbose)
 
int dlt_gateway_process_on_demand_request (DltGateway *gateway, DltDaemonLocal *daemon_local, char *node_id, int connection_status, int verbose)
 
void dlt_gateway_send_control_message (DltGatewayConnection *con, DltGateway *gateway, DltDaemonLocal *daemon_local, int verbose)
 

Variables

STATIC DltGatewayConf configuration_entries [GW_CONF_COUNT]
 

Detailed Description

Author
Christoph Lipka clipk.nosp@m.a@jp.nosp@m..adit.nosp@m.-jv..nosp@m.com

Definition in file dlt_gateway.c.

Macro Definition Documentation

#define DLT_GATEWAY_NUM_PROPERTIES_MAX   GW_CONF_COUNT

Definition at line 334 of file dlt_gateway.c.

Enumeration Type Documentation

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.

Function Documentation

STATIC int dlt_gateway_check_connect_trigger ( DltGatewayConnection con,
char *  value 
)

Check connection trigger

Parameters
conDltGatewayConnection to be updated
valuestring to be tested
Returns
0 on success, -1 otherwise

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

Parameters
conDltGatewayConnection to be updated
valuestring to be tested
Returns
0 on success, -1 otherwise

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

Parameters
conDltGatewayConnection to be updated
valuestring to be used as ECU identifier
Returns
0 on success, -1 otherwise

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

Parameters
conDltGatewayConnection to be updated
valuestring to be tested
Returns
0 on success, -1 otherwise

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.

Parameters
gDltGateway
cDltGatewayConnection
keyDltGatwayConnection property
valuespecified property value from configuration file
Returns
0 on success, -1 otherwise

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

Parameters
conDltGatewayConnection to be updated
valuestring to be tested
Returns
0 on success, -1 otherwise

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

Parameters
conDltGatewayConnection to be updated
valuestring to be tested
Returns
0 on success, -1 otherwise

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

Parameters
conDltGatewayConnection to be updated
valuestring to be tested
Returns
0 on success, -1 otherwise

Definition at line 201 of file dlt_gateway.c.

References NULL, and DltGatewayConnection::timeout.

void dlt_gateway_deinit ( DltGateway g,
int  verbose 
)

De-initialize the gateway. All internal data will be freed.

Parameters
gDltGateway pointer
verboseverbose 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.

Parameters
gDltGateway
daemon_localDltDaemonLocal
verboseverbose flag
Returns
0 on success, -1 on error

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 
)
DltReceiver* dlt_gateway_get_connection_receiver ( DltGateway g,
int  fd 
)

Return the receiver for a given file descriptor

Parameters
gDltGateway
fdfile descriptor
Returns
Pointer to DltReceiver on success, NULL otherwise

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

Parameters
daemon_localpointer to DltDaemonLocal
verboseverbose flag
Returns
0 on success, -1 on error

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

Parameters
daemonDltDaemon
daemon_loocalDltDaemonLocal
verboseverbose flag
Returns
0 on success, -1 otherwise

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 
)

Variable Documentation

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().