WIFI_API_20150524e
EthernetInterface/EthernetInterface.h@0:a2de37bf5f3d, 2015-06-09 (annotated)
- Committer:
- Marcomissyou
- Date:
- Tue Jun 09 06:04:13 2015 +0000
- Revision:
- 0:a2de37bf5f3d
update to WIFI_API_20150524e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Marcomissyou | 0:a2de37bf5f3d | 1 | /* EthernetInterface.h */ |
Marcomissyou | 0:a2de37bf5f3d | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
Marcomissyou | 0:a2de37bf5f3d | 3 | * |
Marcomissyou | 0:a2de37bf5f3d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Marcomissyou | 0:a2de37bf5f3d | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Marcomissyou | 0:a2de37bf5f3d | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Marcomissyou | 0:a2de37bf5f3d | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Marcomissyou | 0:a2de37bf5f3d | 8 | * furnished to do so, subject to the following conditions: |
Marcomissyou | 0:a2de37bf5f3d | 9 | * |
Marcomissyou | 0:a2de37bf5f3d | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
Marcomissyou | 0:a2de37bf5f3d | 11 | * substantial portions of the Software. |
Marcomissyou | 0:a2de37bf5f3d | 12 | * |
Marcomissyou | 0:a2de37bf5f3d | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Marcomissyou | 0:a2de37bf5f3d | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Marcomissyou | 0:a2de37bf5f3d | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Marcomissyou | 0:a2de37bf5f3d | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Marcomissyou | 0:a2de37bf5f3d | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Marcomissyou | 0:a2de37bf5f3d | 18 | */ |
Marcomissyou | 0:a2de37bf5f3d | 19 | |
Marcomissyou | 0:a2de37bf5f3d | 20 | #ifndef ETHERNETINTERFACE_H_ |
Marcomissyou | 0:a2de37bf5f3d | 21 | #define ETHERNETINTERFACE_H_ |
Marcomissyou | 0:a2de37bf5f3d | 22 | /*Tsungta |
Marcomissyou | 0:a2de37bf5f3d | 23 | #if !defined(TARGET_LPC1768) && !defined(TARGET_LPC4088) && !defined(TARGET_K64F) && !defined(TARGET_RZ_A1H) |
Marcomissyou | 0:a2de37bf5f3d | 24 | #error The Ethernet Interface library is not supported on this target |
Marcomissyou | 0:a2de37bf5f3d | 25 | #endif |
Marcomissyou | 0:a2de37bf5f3d | 26 | |
Marcomissyou | 0:a2de37bf5f3d | 27 | #include "rtos.h" |
Marcomissyou | 0:a2de37bf5f3d | 28 | #include "lwip/netif.h" |
Marcomissyou | 0:a2de37bf5f3d | 29 | */ |
Marcomissyou | 0:a2de37bf5f3d | 30 | /** Interface using Ethernet to connect to an IP-based network |
Marcomissyou | 0:a2de37bf5f3d | 31 | * |
Marcomissyou | 0:a2de37bf5f3d | 32 | */ |
Marcomissyou | 0:a2de37bf5f3d | 33 | class EthernetInterface { |
Marcomissyou | 0:a2de37bf5f3d | 34 | public: |
Marcomissyou | 0:a2de37bf5f3d | 35 | /** Initialize the interface with DHCP. |
Marcomissyou | 0:a2de37bf5f3d | 36 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
Marcomissyou | 0:a2de37bf5f3d | 37 | * \return 0 on success, a negative number on failure |
Marcomissyou | 0:a2de37bf5f3d | 38 | */ |
Marcomissyou | 0:a2de37bf5f3d | 39 | static int init(); //With DHCP |
Marcomissyou | 0:a2de37bf5f3d | 40 | |
Marcomissyou | 0:a2de37bf5f3d | 41 | /** Initialize the interface with a static IP address. |
Marcomissyou | 0:a2de37bf5f3d | 42 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
Marcomissyou | 0:a2de37bf5f3d | 43 | * \param ip the IP address to use |
Marcomissyou | 0:a2de37bf5f3d | 44 | * \param mask the IP address mask |
Marcomissyou | 0:a2de37bf5f3d | 45 | * \param gateway the gateway to use |
Marcomissyou | 0:a2de37bf5f3d | 46 | * \return 0 on success, a negative number on failure |
Marcomissyou | 0:a2de37bf5f3d | 47 | */ |
Marcomissyou | 0:a2de37bf5f3d | 48 | static int init(const char* ip, const char* mask, const char* gateway); |
Marcomissyou | 0:a2de37bf5f3d | 49 | |
Marcomissyou | 0:a2de37bf5f3d | 50 | /** Connect |
Marcomissyou | 0:a2de37bf5f3d | 51 | * Bring the interface up, start DHCP if needed. |
Marcomissyou | 0:a2de37bf5f3d | 52 | * \param timeout_ms timeout in ms (default: (15)s). |
Marcomissyou | 0:a2de37bf5f3d | 53 | * \return 0 on success, a negative number on failure |
Marcomissyou | 0:a2de37bf5f3d | 54 | */ |
Marcomissyou | 0:a2de37bf5f3d | 55 | static int connect(unsigned int timeout_ms=35000); |
Marcomissyou | 0:a2de37bf5f3d | 56 | |
Marcomissyou | 0:a2de37bf5f3d | 57 | /** Disconnect |
Marcomissyou | 0:a2de37bf5f3d | 58 | * Bring the interface down |
Marcomissyou | 0:a2de37bf5f3d | 59 | * \return 0 on success, a negative number on failure |
Marcomissyou | 0:a2de37bf5f3d | 60 | */ |
Marcomissyou | 0:a2de37bf5f3d | 61 | static int disconnect(); |
Marcomissyou | 0:a2de37bf5f3d | 62 | |
Marcomissyou | 0:a2de37bf5f3d | 63 | /** Get the MAC address of your Ethernet interface |
Marcomissyou | 0:a2de37bf5f3d | 64 | * \return a pointer to a string containing the MAC address |
Marcomissyou | 0:a2de37bf5f3d | 65 | */ |
Marcomissyou | 0:a2de37bf5f3d | 66 | static char* getMACAddress(); |
Marcomissyou | 0:a2de37bf5f3d | 67 | |
Marcomissyou | 0:a2de37bf5f3d | 68 | /** Get the IP address of your Ethernet interface |
Marcomissyou | 0:a2de37bf5f3d | 69 | * \return a pointer to a string containing the IP address |
Marcomissyou | 0:a2de37bf5f3d | 70 | */ |
Marcomissyou | 0:a2de37bf5f3d | 71 | static char* getIPAddress(); |
Marcomissyou | 0:a2de37bf5f3d | 72 | |
Marcomissyou | 0:a2de37bf5f3d | 73 | /** Get the Gateway address of your Ethernet interface |
Marcomissyou | 0:a2de37bf5f3d | 74 | * \return a pointer to a string containing the Gateway address |
Marcomissyou | 0:a2de37bf5f3d | 75 | */ |
Marcomissyou | 0:a2de37bf5f3d | 76 | static char* getGateway(); |
Marcomissyou | 0:a2de37bf5f3d | 77 | |
Marcomissyou | 0:a2de37bf5f3d | 78 | /** Get the Network mask of your Ethernet interface |
Marcomissyou | 0:a2de37bf5f3d | 79 | * \return a pointer to a string containing the Network mask |
Marcomissyou | 0:a2de37bf5f3d | 80 | */ |
Marcomissyou | 0:a2de37bf5f3d | 81 | static char* getNetworkMask(); |
Marcomissyou | 0:a2de37bf5f3d | 82 | }; |
Marcomissyou | 0:a2de37bf5f3d | 83 | |
Marcomissyou | 0:a2de37bf5f3d | 84 | #include "TCPSocketConnection.h" |
Marcomissyou | 0:a2de37bf5f3d | 85 | #include "TCPSocketServer.h" |
Marcomissyou | 0:a2de37bf5f3d | 86 | |
Marcomissyou | 0:a2de37bf5f3d | 87 | #include "Endpoint.h" |
Marcomissyou | 0:a2de37bf5f3d | 88 | #include "UDPSocket.h" |
Marcomissyou | 0:a2de37bf5f3d | 89 | |
Marcomissyou | 0:a2de37bf5f3d | 90 | // following are added by Tsungta |
Marcomissyou | 0:a2de37bf5f3d | 91 | #include "stdint.h" |
Marcomissyou | 0:a2de37bf5f3d | 92 | #include "string.h" |
Marcomissyou | 0:a2de37bf5f3d | 93 | typedef struct ip_addr ip_addr_t; |
Marcomissyou | 0:a2de37bf5f3d | 94 | struct ip_addr { |
Marcomissyou | 0:a2de37bf5f3d | 95 | uint32_t addr; |
Marcomissyou | 0:a2de37bf5f3d | 96 | }; |
Marcomissyou | 0:a2de37bf5f3d | 97 | |
Marcomissyou | 0:a2de37bf5f3d | 98 | #endif /* ETHERNETINTERFACE_H_ */ |