Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.
Dependents: christmasLights device_server pop3demo device_server_udp ... more
if/eth/EthernetNetIf.h@0:8b387bed54c2, 2011-01-10 (annotated)
- Committer:
- hlipka
- Date:
- Mon Jan 10 21:03:11 2011 +0000
- Revision:
- 0:8b387bed54c2
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:8b387bed54c2 | 1 | |
hlipka | 0:8b387bed54c2 | 2 | /* |
hlipka | 0:8b387bed54c2 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
hlipka | 0:8b387bed54c2 | 4 | |
hlipka | 0:8b387bed54c2 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
hlipka | 0:8b387bed54c2 | 6 | of this software and associated documentation files (the "Software"), to deal |
hlipka | 0:8b387bed54c2 | 7 | in the Software without restriction, including without limitation the rights |
hlipka | 0:8b387bed54c2 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hlipka | 0:8b387bed54c2 | 9 | copies of the Software, and to permit persons to whom the Software is |
hlipka | 0:8b387bed54c2 | 10 | furnished to do so, subject to the following conditions: |
hlipka | 0:8b387bed54c2 | 11 | |
hlipka | 0:8b387bed54c2 | 12 | The above copyright notice and this permission notice shall be included in |
hlipka | 0:8b387bed54c2 | 13 | all copies or substantial portions of the Software. |
hlipka | 0:8b387bed54c2 | 14 | |
hlipka | 0:8b387bed54c2 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hlipka | 0:8b387bed54c2 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hlipka | 0:8b387bed54c2 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hlipka | 0:8b387bed54c2 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hlipka | 0:8b387bed54c2 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hlipka | 0:8b387bed54c2 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hlipka | 0:8b387bed54c2 | 21 | THE SOFTWARE. |
hlipka | 0:8b387bed54c2 | 22 | */ |
hlipka | 0:8b387bed54c2 | 23 | |
hlipka | 0:8b387bed54c2 | 24 | /** \file |
hlipka | 0:8b387bed54c2 | 25 | Ethernet network interface header file |
hlipka | 0:8b387bed54c2 | 26 | */ |
hlipka | 0:8b387bed54c2 | 27 | |
hlipka | 0:8b387bed54c2 | 28 | #ifndef ETHERNETNETIF_H |
hlipka | 0:8b387bed54c2 | 29 | #define ETHERNETNETIF_H |
hlipka | 0:8b387bed54c2 | 30 | |
hlipka | 0:8b387bed54c2 | 31 | struct netif; |
hlipka | 0:8b387bed54c2 | 32 | |
hlipka | 0:8b387bed54c2 | 33 | #include "mbed.h" |
hlipka | 0:8b387bed54c2 | 34 | |
hlipka | 0:8b387bed54c2 | 35 | #include "if/lwip/LwipNetIf.h" |
hlipka | 0:8b387bed54c2 | 36 | #include "lwip/dhcp.h" |
hlipka | 0:8b387bed54c2 | 37 | |
hlipka | 0:8b387bed54c2 | 38 | ///Ethernet network interface return codes |
hlipka | 0:8b387bed54c2 | 39 | enum EthernetErr |
hlipka | 0:8b387bed54c2 | 40 | { |
hlipka | 0:8b387bed54c2 | 41 | __ETH_MIN = -0xFFFF, |
hlipka | 0:8b387bed54c2 | 42 | ETH_TIMEOUT, ///<Timeout during setup |
hlipka | 0:8b387bed54c2 | 43 | ETH_OK = 0 ///<Success |
hlipka | 0:8b387bed54c2 | 44 | }; |
hlipka | 0:8b387bed54c2 | 45 | |
hlipka | 0:8b387bed54c2 | 46 | ///Ethernet network interface |
hlipka | 0:8b387bed54c2 | 47 | /** |
hlipka | 0:8b387bed54c2 | 48 | This class provides Ethernet connectivity to the stack |
hlipka | 0:8b387bed54c2 | 49 | */ |
hlipka | 0:8b387bed54c2 | 50 | class EthernetNetIf : public LwipNetIf |
hlipka | 0:8b387bed54c2 | 51 | { |
hlipka | 0:8b387bed54c2 | 52 | public: |
hlipka | 0:8b387bed54c2 | 53 | ///Instantiates the Interface and register it against the stack, DHCP will be used |
hlipka | 0:8b387bed54c2 | 54 | /** |
hlipka | 0:8b387bed54c2 | 55 | * An optional hostname can be specified which will be passed to the DHCP server. |
hlipka | 0:8b387bed54c2 | 56 | * Examples without and with hostname specified: |
hlipka | 0:8b387bed54c2 | 57 | * |
hlipka | 0:8b387bed54c2 | 58 | * @code |
hlipka | 0:8b387bed54c2 | 59 | * EthernetNetIf eth(); |
hlipka | 0:8b387bed54c2 | 60 | * @endcode |
hlipka | 0:8b387bed54c2 | 61 | * @code |
hlipka | 0:8b387bed54c2 | 62 | * EthernetNetIf eth("mbedSE"); |
hlipka | 0:8b387bed54c2 | 63 | * @endcode |
hlipka | 0:8b387bed54c2 | 64 | */ |
hlipka | 0:8b387bed54c2 | 65 | EthernetNetIf(const char* hostname = NULL); //W/ DHCP |
hlipka | 0:8b387bed54c2 | 66 | |
hlipka | 0:8b387bed54c2 | 67 | ///Instantiates the Interface and register it against the stack, DHCP will not be used |
hlipka | 0:8b387bed54c2 | 68 | /** |
hlipka | 0:8b387bed54c2 | 69 | IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address. |
hlipka | 0:8b387bed54c2 | 70 | */ |
hlipka | 0:8b387bed54c2 | 71 | EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP |
hlipka | 0:8b387bed54c2 | 72 | virtual ~EthernetNetIf(); |
hlipka | 0:8b387bed54c2 | 73 | |
hlipka | 0:8b387bed54c2 | 74 | ///Brings the interface up |
hlipka | 0:8b387bed54c2 | 75 | /** |
hlipka | 0:8b387bed54c2 | 76 | Uses DHCP if necessary |
hlipka | 0:8b387bed54c2 | 77 | @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s |
hlipka | 0:8b387bed54c2 | 78 | @return : ETH_OK on success or ETH_TIMEOUT on timeout |
hlipka | 0:8b387bed54c2 | 79 | */ |
hlipka | 0:8b387bed54c2 | 80 | EthernetErr setup(int timeout_ms = 15000); |
hlipka | 0:8b387bed54c2 | 81 | |
hlipka | 0:8b387bed54c2 | 82 | virtual void poll(); |
hlipka | 0:8b387bed54c2 | 83 | |
hlipka | 0:8b387bed54c2 | 84 | ///Returns an array containing the hardware address |
hlipka | 0:8b387bed54c2 | 85 | const char* getHwAddr() const; |
hlipka | 0:8b387bed54c2 | 86 | |
hlipka | 0:8b387bed54c2 | 87 | ///Returns a pointer to the hostname set in the constructor |
hlipka | 0:8b387bed54c2 | 88 | const char* getHostname() const; |
hlipka | 0:8b387bed54c2 | 89 | |
hlipka | 0:8b387bed54c2 | 90 | private: |
hlipka | 0:8b387bed54c2 | 91 | Timer m_ethArpTimer; |
hlipka | 0:8b387bed54c2 | 92 | Timer m_dhcpCoarseTimer; |
hlipka | 0:8b387bed54c2 | 93 | Timer m_dhcpFineTimer; |
hlipka | 0:8b387bed54c2 | 94 | Timer m_igmpTimer; |
hlipka | 0:8b387bed54c2 | 95 | |
hlipka | 0:8b387bed54c2 | 96 | bool m_useDhcp; |
hlipka | 0:8b387bed54c2 | 97 | |
hlipka | 0:8b387bed54c2 | 98 | netif* m_pNetIf; |
hlipka | 0:8b387bed54c2 | 99 | |
hlipka | 0:8b387bed54c2 | 100 | IpAddr m_netmask; |
hlipka | 0:8b387bed54c2 | 101 | IpAddr m_gateway; |
hlipka | 0:8b387bed54c2 | 102 | |
hlipka | 0:8b387bed54c2 | 103 | const char* m_hostname; |
hlipka | 0:8b387bed54c2 | 104 | dhcp* m_pDhcp; |
hlipka | 0:8b387bed54c2 | 105 | bool m_setup; |
hlipka | 0:8b387bed54c2 | 106 | }; |
hlipka | 0:8b387bed54c2 | 107 | |
hlipka | 0:8b387bed54c2 | 108 | #endif |
hlipka | 0:8b387bed54c2 | 109 |