mbed IP library over Ethernet

Dependencies:   Socket lwip-eth lwip-sys lwip

Dependents:   iot_gateway

Fork of EthernetInterface by mbed official

Committer:
donatien
Date:
Tue Jun 26 14:53:52 2012 +0000
Revision:
4:9a52c802be61
Parent:
3:f5776537f27f
Child:
14:cec293071eed
Documentation update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 3:f5776537f27f 1 /* EthernetInterface.h */
donatien 3:f5776537f27f 2 /* Copyright (C) 2012 mbed.org, MIT License
donatien 3:f5776537f27f 3 *
donatien 3:f5776537f27f 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 3:f5776537f27f 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
donatien 3:f5776537f27f 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
donatien 3:f5776537f27f 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
donatien 3:f5776537f27f 8 * furnished to do so, subject to the following conditions:
donatien 3:f5776537f27f 9 *
donatien 3:f5776537f27f 10 * The above copyright notice and this permission notice shall be included in all copies or
donatien 3:f5776537f27f 11 * substantial portions of the Software.
donatien 3:f5776537f27f 12 *
donatien 3:f5776537f27f 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 3:f5776537f27f 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 3:f5776537f27f 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 3:f5776537f27f 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 3:f5776537f27f 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 3:f5776537f27f 18 */
donatien 3:f5776537f27f 19
donatien 3:f5776537f27f 20 #ifndef ETHERNETINTERFACE_H_
donatien 3:f5776537f27f 21 #define ETHERNETINTERFACE_H_
donatien 3:f5776537f27f 22
donatien 3:f5776537f27f 23 #include "core/fwk.h"
donatien 3:f5776537f27f 24
donatien 3:f5776537f27f 25 #include "rtos.h"
donatien 3:f5776537f27f 26
donatien 3:f5776537f27f 27 #include "LwIPInterface.h"
donatien 3:f5776537f27f 28
donatien 3:f5776537f27f 29 #include "lwip/netif.h"
donatien 3:f5776537f27f 30
donatien 4:9a52c802be61 31 /** Interface using Ethernet to connect to an IP-based network
donatien 3:f5776537f27f 32 *
donatien 3:f5776537f27f 33 */
donatien 3:f5776537f27f 34 class EthernetInterface : public LwIPInterface
donatien 3:f5776537f27f 35 {
donatien 3:f5776537f27f 36 public:
donatien 4:9a52c802be61 37 /** Instantiate the Ethernet interface.
donatien 4:9a52c802be61 38 *
donatien 4:9a52c802be61 39 */
donatien 3:f5776537f27f 40 EthernetInterface();
donatien 3:f5776537f27f 41
donatien 4:9a52c802be61 42 /** Initialize the interface with DHCP.
donatien 4:9a52c802be61 43 * Initialize the interface and configure it to use DHCP (no connection at this point).
donatien 4:9a52c802be61 44 * \return 0 on success, a negative number on failure
donatien 4:9a52c802be61 45 */
donatien 3:f5776537f27f 46 int init(); //With DHCP
donatien 3:f5776537f27f 47
donatien 4:9a52c802be61 48 /** Initialize the interface with a static IP address.
donatien 4:9a52c802be61 49 * Initialize the interface and configure it with the following static configuration (no connection at this point).
donatien 4:9a52c802be61 50 * \param ip the IP address to use
donatien 4:9a52c802be61 51 * \param mask the IP address mask
donatien 4:9a52c802be61 52 * \param gateway the gateway to use
donatien 4:9a52c802be61 53 * \param dns1 the primary DNS server
donatien 4:9a52c802be61 54 * \param dns2 the secondary DNS server
donatien 4:9a52c802be61 55 * \return 0 on success, a negative number on failure
donatien 4:9a52c802be61 56 */
donatien 3:f5776537f27f 57 int init(const char* ip, const char* mask, const char* gateway, const char* dns1, const char* dns2); //No DHCP
donatien 3:f5776537f27f 58
donatien 4:9a52c802be61 59 /** Connect
donatien 4:9a52c802be61 60 * Bring the interface up, start DHCP if needed.
donatien 4:9a52c802be61 61 * \return 0 on success, a negative number on failure
donatien 4:9a52c802be61 62 */
donatien 3:f5776537f27f 63 virtual int connect();
donatien 4:9a52c802be61 64
donatien 4:9a52c802be61 65 /** Disconnect
donatien 4:9a52c802be61 66 * Bring the interface down
donatien 4:9a52c802be61 67 * \return 0 on success, a negative number on failure
donatien 4:9a52c802be61 68 */
donatien 3:f5776537f27f 69 virtual int disconnect();
donatien 3:f5776537f27f 70
donatien 3:f5776537f27f 71 private:
donatien 3:f5776537f27f 72 static void netifStatusCb(struct netif *netif);
donatien 3:f5776537f27f 73
donatien 3:f5776537f27f 74 static int32_t s_lpcNetifOff; //Offset between m_lpcNetif and this ... this might be quite kludgy but should work!
donatien 3:f5776537f27f 75
donatien 3:f5776537f27f 76 struct netif m_lpcNetif;
donatien 3:f5776537f27f 77 Semaphore m_netifStatusSphre;
donatien 3:f5776537f27f 78 bool m_useDHCP;
donatien 3:f5776537f27f 79 };
donatien 3:f5776537f27f 80
donatien 3:f5776537f27f 81 //As a helper, include TCPSocket.h & UDPSocket.h here
donatien 3:f5776537f27f 82 #include "TCPSocket.h"
donatien 3:f5776537f27f 83 #include "UDPSocket.h"
donatien 3:f5776537f27f 84
donatien 3:f5776537f27f 85 #endif /* ETHERNETINTERFACE_H_ */