Committer:
donde
Date:
Tue Jun 05 00:06:50 2012 +0000
Revision:
0:005eb30e83da

        

Who changed what in which revision?

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