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