34 #include <arpa/inet.h> 35 #include <sys/socket.h> 36 #include <netinet/in.h> 53 #ifndef DLT_UNIT_TESTS 74 struct sockaddr_in sa;
82 ret = inet_pton(AF_INET, value, &(sa.sin_addr));
91 dlt_log(LOG_ERR,
"Cannot copy passive node IP address string\n");
99 dlt_log(LOG_ERR,
"IP address is not valid\n");
121 tmp = (int) strtol(value,
NULL, 10);
124 if (tmp > IPPORT_RESERVED && tmp <= USHRT_MAX)
131 dlt_log(LOG_ERR,
"Port number is invalid\n");
151 con->
ecuid = strdup(value);
176 if (strncasecmp(value,
"OnStartup", strlen(
"OnStartup")) == 0)
180 else if (strncasecmp(value,
"OnDemand", strlen(
"OnDemand")) == 0)
186 dlt_log(LOG_ERR,
"Wrong connection trigger state given.\n");
258 if (strlen(value) == 0)
266 token = strtok_r(value,
",", &rest);
272 if (errno == EINVAL || errno == ERANGE)
276 "Control message ID is not an integer: %s\n", token);
285 "Control message ID is not valid: %s\n", token);
290 token = strtok_r(
NULL,
",", &rest);
325 .key =
"SendControl",
329 .key =
"SendSerialHeader",
334 #define DLT_GATEWAY_NUM_PROPERTIES_MAX GW_CONF_COUNT 384 while (i < gateway->num_connections)
421 dlt_log(LOG_CRIT,
"dlt_client_init() failed for gateway connection\n");
432 "dlt_client_set_server_ip() failed for gateway connection \n");
440 dlt_log(LOG_ERR,
"Gateway: DltClient initialization failed\n");
463 if (gateway ==
NULL || config_file == 0 || config_file[0] ==
'\0')
477 dlt_log(LOG_ERR,
"Invalid number of sections in configuration file\n");
487 dlt_log(LOG_CRIT,
"Memory allocation for gateway connections failed\n");
500 memset(&tmp, 0,
sizeof(tmp));
520 "Using default for %s.\n",
522 dlt_log(LOG_WARNING, local_str);
529 "Missing configuration for %s.\n",
531 dlt_log(LOG_WARNING, local_str);
542 "Configuration %s = %s is invalid.\n" 553 "%s configuration is invalid.\n" 564 dlt_log(LOG_ERR,
"Storing gateway connection data failed\n");
581 if (daemon_local ==
NULL)
597 dlt_log(LOG_ERR,
"Gateway initialization failed\n");
603 dlt_log(LOG_CRIT,
"Pointer to Gateway structure is NULL\n");
645 if (gateway ==
NULL || daemon_local ==
NULL)
655 dlt_log(LOG_CRIT,
"Cannot retrieve gateway connection details\n");
679 dlt_log(LOG_ERR,
"Gateway connection creation failed\n");
693 "Passive Node is not up. Connection failed.\n");
700 "Passive Node connection retry timed out. " 742 if (daemon ==
NULL || daemon_local ==
NULL || receiver ==
NULL)
752 dlt_log(LOG_ERR,
"Gateway structure is NULL\n");
767 dlt_log(LOG_ERR,
"Cannot associate fd to passive Node connection\n");
775 "Cannot initialize DLT message for passive node forwarding\n");
785 dlt_log(LOG_ERR,
"Cannot free DLT message\n");
789 dlt_log(LOG_WARNING,
"Connection to passive node lost\n");
793 dlt_log(LOG_WARNING,
"Try to reconnect.\n");
804 dlt_log(LOG_ERR,
"Remove passive node Connection failed\n");
811 (
unsigned char *)receiver->
buf,
816 DltStandardHeaderExtra *header = (DltStandardHeaderExtra *)
818 sizeof(DltStorageHeader) +
819 sizeof(DltStandardHeader));
822 if (strncmp(header->ecu, con->
ecuid, strlen(con->
ecuid)) == 0)
826 "Received ECUid (%s) similar to configured ECUid(%s). " 827 "Forwarding message (%s).\n",
837 sizeof(DltStorageHeader),
844 dlt_log(LOG_WARNING,
"Forward message to clients failed!\n");
851 "Received ECUid (%s) differs to configured ECUid(%s). " 852 "Discard this message.\n",
855 dlt_log(LOG_WARNING, local_str);
865 dlt_log(LOG_ERR,
"Remove passive node Connection failed\n");
869 "Disconnect from passive node due to invalid ECUid\n");
877 sizeof(DltStorageHeader) +
890 sizeof(DltStorageHeader)) == -1)
925 if ((daemon_local ==
NULL) || (daemon ==
NULL) || (receiver ==
NULL))
929 "%s: invalid parameters",
935 res = read(receiver->
fd, &expir,
sizeof(expir));
941 "%s: Fail to read timer (%s)\n", __func__, strerror(errno));
942 dlt_log(LOG_WARNING, local_str);
952 dlt_log(LOG_DEBUG,
"Gateway Timer\n");
987 dlt_log(LOG_WARNING,
"Unknown passive node identifier\n");
993 dlt_log(LOG_INFO,
"Passive node is not connected\n");
1006 dlt_log(LOG_ERR,
"Sending message to passive DLT Daemon failed\n");
1017 dlt_log(LOG_ERR,
"Sending message to passive DLT Daemon failed\n");
1025 dlt_log(LOG_ERR,
"Sending message to passive DLT Daemon failed\n");
1030 dlt_log(LOG_INFO,
"Control message forwarded\n");
1045 if (gateway ==
NULL || daemon_local ==
NULL || node_id ==
NULL)
1062 dlt_log(LOG_WARNING,
"Specified ECUid not found\n");
1066 if (connection_status == 1)
1081 dlt_log(LOG_ERR,
"Gateway connection creation failed\n");
1087 dlt_log(LOG_ERR,
"Could not connect to passive node\n");
1093 dlt_log(LOG_INFO,
"Passive node already connected\n");
1096 else if (connection_status == 0)
1105 "Remove passive node event handler connection failed\n");
1110 dlt_log(LOG_ERR,
"Could not cleanup DltClient structure\n");
1116 dlt_log(LOG_ERR,
"Unknown command (connection_status)\n");
1135 if (con ==
NULL || gateway ==
NULL || daemon_local ==
NULL)
1139 "%s: Invalid parameter given\n", __func__);
1140 dlt_log(LOG_WARNING, local_str);
1151 memset(&msg, 0,
sizeof(msg));
1157 "Initialization of message failed\n");
1158 dlt_log(LOG_WARNING, local_str);
1164 DltServiceGetLogInfoRequest *req;
1166 malloc(
sizeof(DltServiceGetLogInfoRequest));
1171 "Initialization of 'GetLogInfo' failed\n");
1172 dlt_log(LOG_WARNING, local_str);
1177 req = (DltServiceGetLogInfoRequest *)msg.
databuffer;
1189 DltServiceGetSoftwareVersion *req;
1192 malloc(
sizeof(DltServiceGetSoftwareVersion));
1197 "Initialization of 'GetSoftwareVersion' failed\n");
1198 dlt_log(LOG_WARNING, local_str);
1203 req = (DltServiceGetSoftwareVersion *)msg.
databuffer;
1213 "Unknown control message. Skip.\n");
1214 dlt_log(LOG_WARNING, local_str);
1232 #if (BYTE_ORDER==BIG_ENDIAN) 1252 sizeof(DltStorageHeader) +
1253 sizeof(DltStandardHeader) +
1265 sizeof(DltStandardHeader) +
1266 sizeof(DltExtendedHeader) +
1272 fprintf(stderr,
"Critical: Huge injection message discarded!\n");
1289 "Failed to forward message to passive node.\n");
1290 dlt_log(LOG_WARNING, local_str);
STATIC int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value)
int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
int dlt_receiver_receive_socket(DltReceiver *receiver)
#define DLT_GATEWAY_RECONNECT_MAX
#define PRINT_FUNCTION_VERBOSE(_verbose)
int dlt_config_file_get_section_name(const DltConfigFile *file, int num, char *name)
STATIC int dlt_gateway_check_control_messages(DltGatewayConnection *con, char *value)
int dlt_event_handler_unregister_connection(DltEventHandler *evhdl, DltDaemonLocal *daemon_local, int fd)
Unregisters a connection from the event handler and destroys it.
int8_t found_serialheader
DltStorageHeader * storageheader
int dlt_gateway_store_connection(DltGateway *gateway, DltGatewayConnection *tmp, int verbose)
int dlt_gateway_process_gateway_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
#define DLT_MSIN_CONTROL_REQUEST
int(* func)(DltGatewayConnection *con, char *value)
int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num)
#define DLT_HTYP_PROTOCOL_VERSION1
void dlt_set_id(char *id, const char *text)
STATIC int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value)
#define DLT_CONFIG_FILE_ENTRY_MAX_LEN
DltConfigFile * dlt_config_file_init(char *file_name)
int dlt_client_set_server_ip(DltClient *client, char *ipaddr)
int dlt_gateway_establish_connections(DltGateway *gateway, DltDaemonLocal *daemon_local, int verbose)
int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose)
#define DLT_MESSAGE_ERROR_OK
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
int dlt_gateway_process_on_demand_request(DltGateway *gateway, DltDaemonLocal *daemon_local, char *node_id, int connection_status, int verbose)
#define DLT_SERVICE_ID_SET_LOG_LEVEL
#define DLT_SERVICE_ID_GET_LOG_INFO
#define DLT_DAEMON_ERROR_OK
DltReturnValue dlt_log(int prio, char *s)
int control_msgs[DLT_GATEWAY_MAX_STARTUP_CTRL_MSG]
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
DltExtendedHeader * extendedheader
void dlt_gateway_send_control_message(DltGatewayConnection *con, DltGateway *gateway, DltDaemonLocal *daemon_local, int verbose)
int dlt_gateway_process_passive_node_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
connection_trigger trigger
STATIC int dlt_gateway_check_port(DltGatewayConnection *con, char *value)
STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT]
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
STATIC int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value)
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
DltReturnValue dlt_client_cleanup(DltClient *client, int verbose)
uint32_t dlt_uptime(void)
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
DltGatewayConnection * connections
int dlt_gateway_forward_control_message(DltGateway *gateway, DltDaemonLocal *daemon_local, DltMessage *msg, char *ecu, int verbose)
char gatewayConfigFile[DLT_DAEMON_FLAG_MAX]
int dlt_daemon_client_send(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, void *storage_header, int storage_header_size, void *data1, int size1, void *data2, int size2, int verbose)
const char dltSerialHeader[DLT_ID_SIZE]
DltReceiver * dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con, char *value)
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
#define DLT_DAEMON_SEND_TO_ALL
DltStandardHeaderExtra headerextra
int dlt_config_file_get_value(const DltConfigFile *file, const char *section, const char *key, char *value)
#define DLT_DAEMON_RCVBUFSIZESOCK
STATIC int dlt_gateway_check_param(DltGateway *gateway, DltGatewayConnection *con, DltGatewayConfType ctype, char *value)
int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose)
DltStandardHeader * standardheader
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
#define DLT_GATEWAY_MAX_STARTUP_CTRL_MSG
#define DLT_DAEMON_TCP_PORT
#define DLT_SERVICE_ID_LAST_ENTRY
#define DLT_DAEMON_TEXTBUFSIZE
#define DLT_SERVICE_ID_GET_SOFTWARE_VERSION
void dlt_config_file_release(DltConfigFile *file)
int dlt_connection_create(DltDaemonLocal *daemon_local, DltEventHandler *evh, int fd, int mask, DltConnectionType type)
Creates a connection and registers it to the DltEventHandler.
void dlt_gateway_deinit(DltGateway *gateway, int verbose)
STATIC int dlt_gateway_check_ip(DltGatewayConnection *con, char *value)