generic_networkhandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. /** @file generic_networkhandler.h
  7. * @author Martin Melik Merkumians
  8. * @brief This file includes all platform-independent functions of the network handler to reduce code duplication
  9. *
  10. * @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
  11. */
  12. #ifndef GENERIC_NETWORKHANDLER_H_
  13. #define GENERIC_NETWORKHANDLER_H_
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #if !defined(HPMICRO) /** Not HPMICRO target */
  18. #include <errno.h>
  19. #else /** HPMICRO target (GCC), lwip has its own error code list */
  20. #include "lwip/errno.h"
  21. #endif /* HPMICRO target */
  22. #include "opener_api.h"
  23. #include "typedefs.h"
  24. #include "endianconv.h"
  25. #include "cipconnectionmanager.h"
  26. #include "networkhandler.h"
  27. #include "appcontype.h"
  28. #include "socket_timer.h"
  29. /*The port to be used per default for I/O messages on UDP.*/
  30. extern const uint16_t kOpenerEipIoUdpPort;
  31. extern const uint16_t kOpenerEthernetPort;
  32. extern SocketTimer g_timestamps[OPENER_NUMBER_OF_SUPPORTED_SESSIONS];
  33. /** @brief Ethernet/IP standard ports */
  34. #define kOpenerEthernetPort 44818 /** Port to be used per default for messages on TCP */
  35. #define kOpenerEipIoUdpPort 2222 /** Port to be used per default for I/O messages on UDP.*/
  36. //EipUint8 g_ethernet_communication_buffer[PC_OPENER_ETHERNET_BUFFER_SIZE]; /**< communication buffer */
  37. extern fd_set master_socket;
  38. extern fd_set read_socket;
  39. extern int highest_socket_handle; /**< temporary file descriptor for select() */
  40. /** @brief This variable holds the TCP socket the received to last explicit message.
  41. * It is needed for opening point to point connection to determine the peer's
  42. * address.
  43. */
  44. extern int g_current_active_tcp_socket;
  45. extern struct timeval g_time_value;
  46. extern MilliSeconds g_actual_time;
  47. extern MilliSeconds g_last_time;
  48. /** @brief Struct representing the current network status
  49. *
  50. */
  51. typedef struct {
  52. int tcp_listener; /**< TCP listener socket */
  53. int udp_unicast_listener; /**< UDP unicast listener socket */
  54. int udp_global_broadcast_listener; /**< UDP global network broadcast listener */
  55. int udp_io_messaging; /**< UDP IO messaging socket */
  56. CipUdint ip_address; /**< IP being valid during NetworkHandlerInitialize() */
  57. CipUdint network_mask; /**< network mask being valid during NetworkHandlerInitialize() */
  58. MilliSeconds elapsed_time;
  59. } NetworkStatus;
  60. extern NetworkStatus g_network_status; /**< Global variable holding the current network status */
  61. /** @brief The platform independent part of network handler initialization routine
  62. *
  63. * @return Returns the OpENer status after the initialization routine
  64. */
  65. EipStatus NetworkHandlerInitialize(void);
  66. void CloseUdpSocket(int socket_handle);
  67. void CloseTcpSocket(int socket_handle);
  68. EipStatus NetworkHandlerProcessCyclic(void);
  69. EipStatus NetworkHandlerFinish(void);
  70. /** @brief check if the given socket is set in the read set
  71. * @param socket The socket to check
  72. * @return true if socket is set
  73. */
  74. EipBool8 CheckSocketSet(int socket);
  75. /** @brief Returns the socket with the highest id
  76. * @param socket1 First socket
  77. * @param socket2 Second socket
  78. * @param socket3 Third socket
  79. * @param socket4 Fourth socket
  80. *
  81. * @return Highest socket id from the provided sockets
  82. */
  83. int GetMaxSocket(int socket1, int socket2, int socket3, int socket4);
  84. /** @brief Set the Qos the socket for implicit IO messaging
  85. *
  86. * @return 0 if successful, else the error code */
  87. int SetQos(CipUsint qos_for_socket);
  88. /** @brief Set the socket options for Multicast Producer
  89. *
  90. * @return 0 if successful, else the error code */
  91. int SetSocketOptionsMulticastProduce(void);
  92. /** @brief Get the peer address
  93. *
  94. * @return peer address if successful, else any address (0) */
  95. EipUint32 GetPeerAddress(void);
  96. #endif /* GENERIC_NETWORKHANDLER_H_ */