Committer:
donde
Date:
Tue Jun 05 01:27:57 2012 +0000
Revision:
0:f26903b63415

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donde 0:f26903b63415 1 00001
donde 0:f26903b63415 2 00002 /*
donde 0:f26903b63415 3 00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
donde 0:f26903b63415 4 00004
donde 0:f26903b63415 5 00005 Permission is hereby granted, free of charge, to any person obtaining a copy
donde 0:f26903b63415 6 00006 of this software and associated documentation files (the "Software"), to deal
donde 0:f26903b63415 7 00007 in the Software without restriction, including without limitation the rights
donde 0:f26903b63415 8 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donde 0:f26903b63415 9 00009 copies of the Software, and to permit persons to whom the Software is
donde 0:f26903b63415 10 00010 furnished to do so, subject to the following conditions:
donde 0:f26903b63415 11 00011
donde 0:f26903b63415 12 00012 The above copyright notice and this permission notice shall be included in
donde 0:f26903b63415 13 00013 all copies or substantial portions of the Software.
donde 0:f26903b63415 14 00014
donde 0:f26903b63415 15 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donde 0:f26903b63415 16 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donde 0:f26903b63415 17 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donde 0:f26903b63415 18 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donde 0:f26903b63415 19 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donde 0:f26903b63415 20 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donde 0:f26903b63415 21 00021 THE SOFTWARE.
donde 0:f26903b63415 22 00022 */
donde 0:f26903b63415 23 00023
donde 0:f26903b63415 24 00024 /** \file
donde 0:f26903b63415 25 00025 Ethernet network interface header file
donde 0:f26903b63415 26 00026 */
donde 0:f26903b63415 27 00027
donde 0:f26903b63415 28 00028 #ifndef ETHERNETNETIF_H
donde 0:f26903b63415 29 00029 #define ETHERNETNETIF_H
donde 0:f26903b63415 30 00030
donde 0:f26903b63415 31 00031 struct netif;
donde 0:f26903b63415 32 00032
donde 0:f26903b63415 33 00033 #include "mbed.h"
donde 0:f26903b63415 34 00034
donde 0:f26903b63415 35 00035 #include "if/lwip/LwipNetIf.h"
donde 0:f26903b63415 36 00036 #include "lwip/dhcp.h"
donde 0:f26903b63415 37 00037
donde 0:f26903b63415 38 00038 ///Ethernet network interface return codes
donde 0:f26903b63415 39 00039 enum EthernetErr
donde 0:f26903b63415 40 00040 {
donde 0:f26903b63415 41 00041 __ETH_MIN = -0xFFFF,
donde 0:f26903b63415 42 00042 ETH_TIMEOUT, ///<Timeout during setup
donde 0:f26903b63415 43 00043 ETH_OK = 0 ///<Success
donde 0:f26903b63415 44 00044 };
donde 0:f26903b63415 45 00045
donde 0:f26903b63415 46 00046 ///Ethernet network interface
donde 0:f26903b63415 47 00047 /**
donde 0:f26903b63415 48 00048 This class provides Ethernet connectivity to the stack
donde 0:f26903b63415 49 00049 */
donde 0:f26903b63415 50 00050 class EthernetNetIf : public LwipNetIf
donde 0:f26903b63415 51 00051 {
donde 0:f26903b63415 52 00052 public:
donde 0:f26903b63415 53 00053 ///Instantiates the Interface and register it against the stack, DHCP will be used
donde 0:f26903b63415 54 00054 /**
donde 0:f26903b63415 55 00055 * An optional hostname can be specified which will be passed to the DHCP server.
donde 0:f26903b63415 56 00056 * Examples without and with hostname specified:
donde 0:f26903b63415 57 00057 *
donde 0:f26903b63415 58 00058 * @code
donde 0:f26903b63415 59 00059 * EthernetNetIf eth();
donde 0:f26903b63415 60 00060 * @endcode
donde 0:f26903b63415 61 00061 * @code
donde 0:f26903b63415 62 00062 * EthernetNetIf eth("mbedSE");
donde 0:f26903b63415 63 00063 * @endcode
donde 0:f26903b63415 64 00064 */
donde 0:f26903b63415 65 00065 EthernetNetIf(const char* hostname = NULL); //W/ DHCP
donde 0:f26903b63415 66 00066
donde 0:f26903b63415 67 00067 ///Instantiates the Interface and register it against the stack, DHCP will not be used
donde 0:f26903b63415 68 00068 /**
donde 0:f26903b63415 69 00069 IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address.
donde 0:f26903b63415 70 00070 */
donde 0:f26903b63415 71 00071 EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP
donde 0:f26903b63415 72 00072 virtual ~EthernetNetIf();
donde 0:f26903b63415 73 00073
donde 0:f26903b63415 74 00074 ///Brings the interface up
donde 0:f26903b63415 75 00075 /**
donde 0:f26903b63415 76 00076 Uses DHCP if necessary
donde 0:f26903b63415 77 00077 @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s
donde 0:f26903b63415 78 00078 @return : ETH_OK on success or ETH_TIMEOUT on timeout
donde 0:f26903b63415 79 00079 */
donde 0:f26903b63415 80 00080 EthernetErr setup(int timeout_ms = 15000);
donde 0:f26903b63415 81 00081
donde 0:f26903b63415 82 00082 virtual void poll();
donde 0:f26903b63415 83 00083
donde 0:f26903b63415 84 00084 ///Returns an array containing the hardware address
donde 0:f26903b63415 85 00085 const char* getHwAddr() const;
donde 0:f26903b63415 86 00086
donde 0:f26903b63415 87 00087 private:
donde 0:f26903b63415 88 00088 Timer m_ethArpTimer;
donde 0:f26903b63415 89 00089 Timer m_dhcpCoarseTimer;
donde 0:f26903b63415 90 00090 Timer m_dhcpFineTimer;
donde 0:f26903b63415 91 00091 Timer m_igmpTimer;
donde 0:f26903b63415 92 00092
donde 0:f26903b63415 93 00093 bool m_useDhcp;
donde 0:f26903b63415 94 00094
donde 0:f26903b63415 95 00095 netif* m_pNetIf;
donde 0:f26903b63415 96 00096
donde 0:f26903b63415 97 00097 IpAddr m_netmask;
donde 0:f26903b63415 98 00098 IpAddr m_gateway;
donde 0:f26903b63415 99 00099
donde 0:f26903b63415 100 00100 const char* m_hostname;
donde 0:f26903b63415 101 00101 dhcp* m_pDhcp;
donde 0:f26903b63415 102 00102 bool m_setup;
donde 0:f26903b63415 103 00103 };
donde 0:f26903b63415 104 00104
donde 0:f26903b63415 105 00105 #endif
donde 0:f26903b63415 106 00106