EthernetInterface.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* EthernetInterface.h */
  2. /* Copyright (C) 2012 mbed.org, MIT License
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  5. * and associated documentation files (the "Software"), to deal in the Software without restriction,
  6. * including without limitation the rights to use, copy, modify, merge, publish, distribute,
  7. * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in all copies or
  11. * substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  14. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  16. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. */
  19. #ifndef ETHERNETINTERFACE_H_
  20. #define ETHERNETINTERFACE_H_
  21. #if !defined(TARGET_LPC1768) && !defined(TARGET_LPC4088) && !defined(TARGET_LPC4088_DM) && !defined(TARGET_K64F) && !defined(TARGET_RZ_A1H) && !defined(TARGET_STM32F4)
  22. #error The Ethernet Interface library is not supported on this target
  23. #endif
  24. #include "rtos.h"
  25. #include "lwip/netif.h"
  26. /** Interface using Ethernet to connect to an IP-based network
  27. *
  28. */
  29. class EthernetInterface {
  30. public:
  31. /** Initialize the interface with DHCP.
  32. * Initialize the interface and configure it to use DHCP (no connection at this point).
  33. * \return 0 on success, a negative number on failure
  34. */
  35. static int init(); //With DHCP
  36. /** Initialize the interface with a static IP address.
  37. * Initialize the interface and configure it with the following static configuration (no connection at this point).
  38. * \param ip the IP address to use
  39. * \param mask the IP address mask
  40. * \param gateway the gateway to use
  41. * \return 0 on success, a negative number on failure
  42. */
  43. static int init(const char* ip, const char* mask, const char* gateway);
  44. /** Connect
  45. * Bring the interface up, start DHCP if needed.
  46. * \param timeout_ms timeout in ms (default: (15)s).
  47. * \return 0 on success, a negative number on failure
  48. */
  49. static int connect(unsigned int timeout_ms=15000);
  50. /** Disconnect
  51. * Bring the interface down
  52. * \return 0 on success, a negative number on failure
  53. */
  54. static int disconnect();
  55. /** Get the MAC address of your Ethernet interface
  56. * \return a pointer to a string containing the MAC address
  57. */
  58. static char* getMACAddress();
  59. /** Get the IP address of your Ethernet interface
  60. * \return a pointer to a string containing the IP address
  61. */
  62. static char* getIPAddress();
  63. /** Get the Gateway address of your Ethernet interface
  64. * \return a pointer to a string containing the Gateway address
  65. */
  66. static char* getGateway();
  67. /** Get the Network mask of your Ethernet interface
  68. * \return a pointer to a string containing the Network mask
  69. */
  70. static char* getNetworkMask();
  71. };
  72. #include "TCPSocketConnection.h"
  73. #include "TCPSocketServer.h"
  74. #include "Endpoint.h"
  75. #include "UDPSocket.h"
  76. #endif /* ETHERNETINTERFACE_H_ */