EthernetNetIf

Dependents:   XBee_WiFi_EA_LPC4088

Committer:
hmike
Date:
Wed Nov 19 12:00:42 2014 +0000
Revision:
0:62580107d20c
EthernetNetIf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hmike 0:62580107d20c 1
hmike 0:62580107d20c 2 /*
hmike 0:62580107d20c 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hmike 0:62580107d20c 4
hmike 0:62580107d20c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hmike 0:62580107d20c 6 of this software and associated documentation files (the "Software"), to deal
hmike 0:62580107d20c 7 in the Software without restriction, including without limitation the rights
hmike 0:62580107d20c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hmike 0:62580107d20c 9 copies of the Software, and to permit persons to whom the Software is
hmike 0:62580107d20c 10 furnished to do so, subject to the following conditions:
hmike 0:62580107d20c 11
hmike 0:62580107d20c 12 The above copyright notice and this permission notice shall be included in
hmike 0:62580107d20c 13 all copies or substantial portions of the Software.
hmike 0:62580107d20c 14
hmike 0:62580107d20c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hmike 0:62580107d20c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hmike 0:62580107d20c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hmike 0:62580107d20c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hmike 0:62580107d20c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hmike 0:62580107d20c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hmike 0:62580107d20c 21 THE SOFTWARE.
hmike 0:62580107d20c 22 */
hmike 0:62580107d20c 23
hmike 0:62580107d20c 24 /** \file
hmike 0:62580107d20c 25 Ethernet network interface header file
hmike 0:62580107d20c 26 */
hmike 0:62580107d20c 27
hmike 0:62580107d20c 28 #ifndef ETHERNETNETIF_H
hmike 0:62580107d20c 29 #define ETHERNETNETIF_H
hmike 0:62580107d20c 30
hmike 0:62580107d20c 31 struct netif;
hmike 0:62580107d20c 32
hmike 0:62580107d20c 33 #include "mbed.h"
hmike 0:62580107d20c 34
hmike 0:62580107d20c 35 #include "if/lwip/LwipNetIf.h"
hmike 0:62580107d20c 36
hmike 0:62580107d20c 37 ///Ethernet network interface return codes
hmike 0:62580107d20c 38 enum EthernetErr
hmike 0:62580107d20c 39 {
hmike 0:62580107d20c 40 __ETH_MIN = -0xFFFF,
hmike 0:62580107d20c 41 ETH_TIMEOUT, ///<Timeout during setup
hmike 0:62580107d20c 42 ETH_OK = 0 ///<Success
hmike 0:62580107d20c 43 };
hmike 0:62580107d20c 44
hmike 0:62580107d20c 45 ///Ethernet network interface
hmike 0:62580107d20c 46 /**
hmike 0:62580107d20c 47 This class provides Ethernet connectivity to the stack
hmike 0:62580107d20c 48 */
hmike 0:62580107d20c 49 class EthernetNetIf : public LwipNetIf
hmike 0:62580107d20c 50 {
hmike 0:62580107d20c 51 public:
hmike 0:62580107d20c 52 ///Instantiates the Interface and register it against the stack, DHCP will be used
hmike 0:62580107d20c 53 EthernetNetIf(); //W/ DHCP
hmike 0:62580107d20c 54
hmike 0:62580107d20c 55 ///Instantiates the Interface and register it against the stack, DHCP will not be used
hmike 0:62580107d20c 56 /**
hmike 0:62580107d20c 57 IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address.
hmike 0:62580107d20c 58 */
hmike 0:62580107d20c 59 EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP
hmike 0:62580107d20c 60 virtual ~EthernetNetIf();
hmike 0:62580107d20c 61
hmike 0:62580107d20c 62 ///Brings the interface up
hmike 0:62580107d20c 63 /**
hmike 0:62580107d20c 64 Uses DHCP if necessary
hmike 0:62580107d20c 65 @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s
hmike 0:62580107d20c 66 @return : ETH_OK on success or ETH_TIMEOUT on timeout
hmike 0:62580107d20c 67 */
hmike 0:62580107d20c 68 EthernetErr setup(int timeout_ms = 15000);
hmike 0:62580107d20c 69
hmike 0:62580107d20c 70 virtual void poll();
hmike 0:62580107d20c 71
hmike 0:62580107d20c 72 private:
hmike 0:62580107d20c 73 Timer m_ethArpTimer;
hmike 0:62580107d20c 74 Timer m_dhcpCoarseTimer;
hmike 0:62580107d20c 75 Timer m_dhcpFineTimer;
hmike 0:62580107d20c 76 Timer m_igmpTimer;
hmike 0:62580107d20c 77
hmike 0:62580107d20c 78 bool m_useDhcp;
hmike 0:62580107d20c 79
hmike 0:62580107d20c 80 netif* m_pNetIf;
hmike 0:62580107d20c 81
hmike 0:62580107d20c 82 IpAddr m_netmask;
hmike 0:62580107d20c 83 IpAddr m_gateway;
hmike 0:62580107d20c 84
hmike 0:62580107d20c 85 const char* m_hostname;
hmike 0:62580107d20c 86
hmike 0:62580107d20c 87 };
hmike 0:62580107d20c 88
hmike 0:62580107d20c 89 #endif
hmike 0:62580107d20c 90