OpENer - Open Source EtherNet/IP(TM) I/O Target Stack
2.1
|
This file includes all platform-independent functions of the network handler to reduce code duplication. More...
#include <assert.h>
#include <stdbool.h>
#include "generic_networkhandler.h"
#include "typedefs.h"
#include "trace.h"
#include "opener_error.h"
#include "encap.h"
#include "ciptcpipinterface.h"
#include "opener_user_conf.h"
#include "cipqos.h"
#include "udp_protocol.h"
Go to the source code of this file.
Macros | |
#define | MAX_NO_OF_TCP_SOCKETS 10 |
Functions | |
void | CheckAndHandleConsumingUdpSockets (void) |
check if on one of the UDP consuming sockets data has been received and if yes handle it correctly More... | |
void | CheckAndHandleTcpListenerSocket (void) |
handle any connection request coming in the TCP server socket. More... | |
void | CheckAndHandleUdpGlobalBroadcastSocket (void) |
Checks and handles incoming messages via UDP broadcast. More... | |
void | CheckAndHandleUdpUnicastSocket (void) |
Checks and processes request received via the UDP unicast socket, currently the implementation is port-specific. More... | |
void | CheckEncapsulationInactivity (int socket_handle) |
EipBool8 | CheckSocketSet (int socket) |
check if the given socket is set in the read set More... | |
void | CloseSocket (const int socket_handle) |
Close the given socket and clean up the stack. More... | |
void | CloseTcpSocket (int socket_handle) |
void | CloseUdpSocket (int socket_handle) |
int | CreateUdpSocket (UdpCommuncationDirection communication_direction, struct sockaddr_in *socket_data, CipUsint qos_for_socket) |
create a new UDP socket for the connection manager More... | |
int | GetMaxSocket (int socket1, int socket2, int socket3, int socket4) |
Returns the socket with the highest id. More... | |
EipStatus | HandleDataOnTcpSocket (int socket) |
Handles data on an established TCP connection, processed connection is given by socket. More... | |
EipStatus | NetworkHandlerFinish (void) |
EipStatus | NetworkHandlerInitialize (void) |
Initializes the network handler, shall be implemented by a port-specific networkhandler. More... | |
EipStatus | NetworkHandlerProcessOnce (void) |
void | RemoveSocketTimerFromList (const int socket_handle) |
EipStatus | SendUdpData (struct sockaddr_in *address, int socket_handle, EipUint8 *data, EipUint16 data_length) |
Create a producing or consuming UDP socket. More... | |
Variables | |
CipTcpIpNetworkInterfaceConfiguration | interface_configuration_ |
This file includes all platform-independent functions of the network handler to reduce code duplication.
Definition in file generic_networkhandler.c.
#define MAX_NO_OF_TCP_SOCKETS 10 |
Definition at line 28 of file generic_networkhandler.c.
Referenced by NetworkHandlerInitialize().
void CheckAndHandleConsumingUdpSockets | ( | void | ) |
check if on one of the UDP consuming sockets data has been received and if yes handle it correctly
Definition at line 934 of file generic_networkhandler.c.
References CheckSocketSet(), cip_connection_object::connection_close_function, connection_list, doubly_linked_list_node::data, DoublyLinkedList::first, FreeErrorMessage(), GetErrorMessage(), GetSocketErrorNumber(), HandleReceivedConnectedData(), kUdpCommuncationDirectionConsuming, doubly_linked_list_node::next, OPENER_SOCKET_WOULD_BLOCK, OPENER_TRACE_ERR, OPENER_TRACE_INFO, PC_OPENER_ETHERNET_BUFFER_SIZE, and cip_connection_object::socket.
Referenced by NetworkHandlerProcessOnce().
void CheckAndHandleTcpListenerSocket | ( | void | ) |
handle any connection request coming in the TCP server socket.
Definition at line 292 of file generic_networkhandler.c.
References CheckSocketSet(), FreeErrorMessage(), g_network_status, g_timestamps, GetErrorMessage(), GetPriorityForSocket(), GetSocketErrorNumber(), highest_socket_handle, master_socket, OPENER_ASSERT, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, OPENER_TRACE_ERR, OPENER_TRACE_INFO, OPENER_TRACE_STATE, SetQosOnSocket(), SocketTimerArrayGetEmptySocketTimer(), and NetworkStatus::tcp_listener.
Referenced by NetworkHandlerProcessOnce().
void CheckAndHandleUdpGlobalBroadcastSocket | ( | void | ) |
Checks and handles incoming messages via UDP broadcast.
Definition at line 426 of file generic_networkhandler.c.
References CheckSocketSet(), FreeErrorMessage(), g_network_status, GetErrorMessage(), GetSocketErrorNumber(), HandleReceivedExplictUdpData(), InitializeENIPMessage(), enip_message::message_buffer, OPENER_TRACE_ERR, OPENER_TRACE_INFO, OPENER_TRACE_STATE, PC_OPENER_ETHERNET_BUFFER_SIZE, NetworkStatus::udp_global_broadcast_listener, and enip_message::used_message_length.
Referenced by NetworkHandlerProcessOnce().
void CheckAndHandleUdpUnicastSocket | ( | void | ) |
Checks and processes request received via the UDP unicast socket, currently the implementation is port-specific.
Definition at line 492 of file generic_networkhandler.c.
References CheckSocketSet(), FreeErrorMessage(), g_network_status, GetErrorMessage(), GetSocketErrorNumber(), HandleReceivedExplictUdpData(), InitializeENIPMessage(), enip_message::message_buffer, OPENER_TRACE_ERR, OPENER_TRACE_INFO, OPENER_TRACE_STATE, PC_OPENER_ETHERNET_BUFFER_SIZE, NetworkStatus::udp_unicast_listener, and enip_message::used_message_length.
Referenced by NetworkHandlerProcessOnce().
void CheckEncapsulationInactivity | ( | int | socket_handle | ) |
Definition at line 1027 of file generic_networkhandler.c.
References CloseClass3ConnectionBasedOnSession(), CloseTcpSocket(), g_actual_time, g_encapsulation_inactivity_timeout, g_timestamps, GetSessionFromSocket(), OPENER_NUMBER_OF_SUPPORTED_SESSIONS, RemoveSession(), SocketTimerArrayGetSocketTimer(), and SocketTimerGetLastUpdate().
Referenced by NetworkHandlerProcessOnce().
EipBool8 CheckSocketSet | ( | int | socket | ) |
check if the given socket is set in the read set
socket | The socket to check |
Definition at line 278 of file generic_networkhandler.c.
References master_socket, OPENER_TRACE_INFO, and read_socket.
Referenced by CheckAndHandleConsumingUdpSockets(), CheckAndHandleTcpListenerSocket(), CheckAndHandleUdpGlobalBroadcastSocket(), CheckAndHandleUdpUnicastSocket(), and NetworkHandlerProcessOnce().
void CloseTcpSocket | ( | int | socket_handle | ) |
Definition at line 261 of file generic_networkhandler.c.
References CloseSocket(), and RemoveSocketTimerFromList().
Referenced by CheckEncapsulationInactivity(), CloseSession(), CloseSessionBySessionHandle(), EncapsulationShutDown(), HandleReceivedUnregisterSessionCommand(), and NetworkHandlerProcessOnce().
void CloseUdpSocket | ( | int | socket_handle | ) |
Definition at line 257 of file generic_networkhandler.c.
References CloseSocket().
Referenced by CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(), and CloseConnection().
int GetMaxSocket | ( | int | socket1, |
int | socket2, | ||
int | socket3, | ||
int | socket4 | ||
) |
Returns the socket with the highest id.
socket1 | First socket |
socket2 | Second socket |
socket3 | Third socket |
socket4 | Fourth socket |
Definition at line 1008 of file generic_networkhandler.c.
Referenced by NetworkHandlerInitialize().
EipStatus HandleDataOnTcpSocket | ( | int | socket | ) |
Handles data on an established TCP connection, processed connection is given by socket.
socket | The socket to be processed |
Definition at line 607 of file generic_networkhandler.c.
References ENCAPSULATION_HEADER_LENGTH, FreeErrorMessage(), g_actual_time, g_current_active_tcp_socket, g_timestamps, GetErrorMessage(), GetIntFromMessage(), GetSocketErrorNumber(), HandleReceivedExplictTcpData(), InitializeENIPMessage(), kEipStatusError, kEipStatusOk, enip_message::message_buffer, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, OPENER_SOCKET_WOULD_BLOCK, OPENER_TRACE_ERR, OPENER_TRACE_INFO, OPENER_TRACE_WARN, PC_OPENER_ETHERNET_BUFFER_SIZE, RemoveSession(), RemoveSocketTimerFromList(), SocketTimerArrayGetSocketTimer(), SocketTimerSetLastUpdate(), and enip_message::used_message_length.
Referenced by NetworkHandlerProcessOnce().
EipStatus NetworkHandlerFinish | ( | void | ) |
Definition at line 419 of file generic_networkhandler.c.
References CloseSocket(), g_network_status, kEipStatusOk, NetworkStatus::tcp_listener, NetworkStatus::udp_global_broadcast_listener, and NetworkStatus::udp_unicast_listener.
Referenced by main().
EipStatus NetworkHandlerInitialize | ( | void | ) |
Initializes the network handler, shall be implemented by a port-specific networkhandler.
The platform independent part of network handler initialization routine.
Definition at line 67 of file generic_networkhandler.c.
References NetworkStatus::elapsed_time, FreeErrorMessage(), g_last_time, g_network_status, g_timestamps, GetErrorMessage(), GetMaxSocket(), GetMilliSeconds(), GetSocketErrorNumber(), highest_socket_handle, kEipStatusError, kEipStatusOk, master_socket, MAX_NO_OF_TCP_SOCKETS, NetworkHandlerInitializePlatform(), OPENER_NUMBER_OF_SUPPORTED_SESSIONS, OPENER_TRACE_ERR, read_socket, SetSocketToNonBlocking(), cip_connection_object::socket, SocketTimerArrayInitialize(), NetworkStatus::tcp_listener, NetworkStatus::udp_global_broadcast_listener, and NetworkStatus::udp_unicast_listener.
Referenced by main().
EipStatus NetworkHandlerProcessOnce | ( | void | ) |
Definition at line 347 of file generic_networkhandler.c.
References CheckAndHandleConsumingUdpSockets(), CheckAndHandleTcpListenerSocket(), CheckAndHandleUdpGlobalBroadcastSocket(), CheckAndHandleUdpUnicastSocket(), CheckEncapsulationInactivity(), CheckSocketSet(), CloseTcpSocket(), NetworkStatus::elapsed_time, FreeErrorMessage(), g_actual_time, g_last_time, g_network_status, g_time_value, GetErrorMessage(), GetMilliSeconds(), GetSocketErrorNumber(), HandleDataOnTcpSocket(), highest_socket_handle, kEipStatusError, kEipStatusOk, ManageConnections(), master_socket, OPENER_TRACE_ERR, read_socket, and RemoveSession().
Referenced by executeEventLoop(), and main().
void RemoveSocketTimerFromList | ( | const int | socket_handle | ) |
Definition at line 266 of file generic_networkhandler.c.
References g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, SocketTimerArrayGetSocketTimer(), and SocketTimerClear().
Referenced by CloseTcpSocket(), and HandleDataOnTcpSocket().
CipTcpIpNetworkInterfaceConfiguration interface_configuration_ |
#5 IP, network mask, gateway, name server 1 & 2, domain name
Definition at line 30 of file ciptcpipinterface.c.
Referenced by ConfigureDomainName(), ConfigureIpMacAddress(), and ConfigureNetworkInterface().