mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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