Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Committer:
tsungta
Date:
Fri Mar 17 08:29:26 2017 +0000
Revision:
15:074fa2489b47
Parent:
10:7fc160bd0246
Child:
19:d47ed42a7e45
34:29ff90e; Fix bug of tcp/udp socket hang up issue when AP is reconnected;

Who changed what in which revision?

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