OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
generic_networkhandler.c File Reference

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"
Include dependency graph for generic_networkhandler.c:

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_
 

Detailed Description

This file includes all platform-independent functions of the network handler to reduce code duplication.

Author
Martin Melik Merkumians The generic network handler delegates platform-dependent tasks to the platform network handler
Martin Melik Merkumians
Attention
This file should only be used for implementing port-specific network handlers and is not intended to grant other parts of the OpENer access to the network layer

Definition in file generic_networkhandler.c.

Macro Definition Documentation

#define MAX_NO_OF_TCP_SOCKETS   10

Definition at line 28 of file generic_networkhandler.c.

Referenced by NetworkHandlerInitialize().

Function Documentation

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

EipBool8 CheckSocketSet ( int  socket)

check if the given socket is set in the read set

Parameters
socketThe socket to check
Returns
true if socket is set

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

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

void CloseUdpSocket ( int  socket_handle)

Definition at line 257 of file generic_networkhandler.c.

References CloseSocket().

Referenced by CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(), and CloseConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

int GetMaxSocket ( int  socket1,
int  socket2,
int  socket3,
int  socket4 
)

Returns the socket with the highest id.

Parameters
socket1First socket
socket2Second socket
socket3Third socket
socket4Fourth socket
Returns
Highest socket id from the provided sockets

Definition at line 1008 of file generic_networkhandler.c.

Referenced by NetworkHandlerInitialize().

Here is the caller graph for this function:

EipStatus HandleDataOnTcpSocket ( int  socket)

Handles data on an established TCP connection, processed connection is given by socket.

Parameters
socketThe socket to be processed
Returns
kEipStatusOk on success, or kEipStatusError on failure

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus NetworkHandlerInitialize ( void  )

Initializes the network handler, shall be implemented by a port-specific networkhandler.

The platform independent part of network handler initialization routine.

Returns
EipStatus, if initialization failed EipError is returned

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

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