WIZNet W5500 with additional enhancements

Fork of WIZnetInterface by WIZnet

Committer:
Helmut Tschemernjak
Date:
Wed Oct 11 11:18:41 2017 +0200
Revision:
36:0ba2e8d5274a
Parent:
35:fe3028eda085
Child:
37:018436dccfcd
More DHCP cleanup, added precise DHCP packet construction
DHCP hostname support (added to the DHCP request) which
allows dynamic DNS updates and routers will show the client name.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Soohwan Kim 0:6f28332c466f 1 /* Copyright (C) 2012 mbed.org, MIT License
Soohwan Kim 0:6f28332c466f 2 *
Soohwan Kim 0:6f28332c466f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Soohwan Kim 0:6f28332c466f 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Soohwan Kim 0:6f28332c466f 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Soohwan Kim 0:6f28332c466f 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Soohwan Kim 0:6f28332c466f 7 * furnished to do so, subject to the following conditions:
Soohwan Kim 0:6f28332c466f 8 *
Soohwan Kim 0:6f28332c466f 9 * The above copyright notice and this permission notice shall be included in all copies or
Soohwan Kim 0:6f28332c466f 10 * substantial portions of the Software.
Soohwan Kim 0:6f28332c466f 11 *
Soohwan Kim 0:6f28332c466f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Soohwan Kim 0:6f28332c466f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Soohwan Kim 0:6f28332c466f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Soohwan Kim 0:6f28332c466f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Soohwan Kim 0:6f28332c466f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Soohwan Kim 0:6f28332c466f 17 */
Soohwan Kim 0:6f28332c466f 18
Soohwan Kim 0:6f28332c466f 19 #pragma once
Soohwan Kim 0:6f28332c466f 20 #include "eth_arch.h"
Soohwan Kim 0:6f28332c466f 21 /** Interface using Wiznet chip to connect to an IP-based network
Soohwan Kim 0:6f28332c466f 22 *
Soohwan Kim 0:6f28332c466f 23 */
Soohwan Kim 0:6f28332c466f 24 class EthernetInterface: public WIZnet_Chip {
Soohwan Kim 0:6f28332c466f 25 public:
Soohwan Kim 8:4c02de1dbf3a 26
embeddist 28:200e63e513a8 27 #if (not defined TARGET_WIZwiki_W7500) && (not defined TARGET_WIZwiki_W7500P) && (not defined TARGET_WIZwiki_W7500ECO)
hjjeon 26:d07c80e18b27 28
Soohwan Kim 8:4c02de1dbf3a 29 /**
Soohwan Kim 8:4c02de1dbf3a 30 * Constructor
Soohwan Kim 8:4c02de1dbf3a 31 *
Soohwan Kim 8:4c02de1dbf3a 32 * \param mosi mbed pin to use for SPI
Soohwan Kim 8:4c02de1dbf3a 33 * \param miso mbed pin to use for SPI
Soohwan Kim 8:4c02de1dbf3a 34 * \param sclk mbed pin to use for SPI
Soohwan Kim 8:4c02de1dbf3a 35 * \param cs chip select of the WIZnet_Chip
Soohwan Kim 8:4c02de1dbf3a 36 * \param reset reset pin of the WIZnet_Chip
Soohwan Kim 8:4c02de1dbf3a 37 */
embeddist 3:f8c6efc8bf83 38 EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset);
embeddist 3:f8c6efc8bf83 39 EthernetInterface(SPI* spi, PinName cs, PinName reset);
Helmut Tschemernjak 35:fe3028eda085 40 ~EthernetInterface();
embeddist 7:da6fcec0f3fe 41 #endif
Soohwan Kim 8:4c02de1dbf3a 42
Soohwan Kim 0:6f28332c466f 43 /** Initialize the interface with DHCP.
Soohwan Kim 0:6f28332c466f 44 * Initialize the interface and configure it to use DHCP (no connection at this point).
Soohwan Kim 0:6f28332c466f 45 * \return 0 on success, a negative number on failure
Soohwan Kim 0:6f28332c466f 46 */
kaizen 20:bda61525ac71 47 int init(); //With DHCP
Soohwan Kim 0:6f28332c466f 48 int init(uint8_t * mac); //With DHCP
Soohwan Kim 0:6f28332c466f 49
Soohwan Kim 0:6f28332c466f 50 /** Initialize the interface with a static IP address.
Soohwan Kim 0:6f28332c466f 51 * Initialize the interface and configure it with the following static configuration (no connection at this point).
Soohwan Kim 0:6f28332c466f 52 * \param ip the IP address to use
Soohwan Kim 0:6f28332c466f 53 * \param mask the IP address mask
Soohwan Kim 0:6f28332c466f 54 * \param gateway the gateway to use
Helmut Tschemernjak 34:7d44648ec5f2 55 * \param dnsServer the DNS server to use
Soohwan Kim 0:6f28332c466f 56 * \return 0 on success, a negative number on failure
Soohwan Kim 0:6f28332c466f 57 */
Helmut Tschemernjak 34:7d44648ec5f2 58 int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway, const char* dnsServer = NULL);
Soohwan Kim 0:6f28332c466f 59
Soohwan Kim 0:6f28332c466f 60 /** Connect
Soohwan Kim 0:6f28332c466f 61 * Bring the interface up, start DHCP if needed.
Soohwan Kim 0:6f28332c466f 62 * \return 0 on success, a negative number on failure
Soohwan Kim 0:6f28332c466f 63 */
Helmut Tschemernjak 36:0ba2e8d5274a 64 int connect(const char *hostname = NULL);
Soohwan Kim 0:6f28332c466f 65
Soohwan Kim 0:6f28332c466f 66 /** Disconnect
Soohwan Kim 0:6f28332c466f 67 * Bring the interface down
Soohwan Kim 0:6f28332c466f 68 * \return 0 on success, a negative number on failure
Soohwan Kim 0:6f28332c466f 69 */
Soohwan Kim 0:6f28332c466f 70 int disconnect();
Soohwan Kim 0:6f28332c466f 71
Soohwan Kim 0:6f28332c466f 72 /** Get IP address & MAC address
Soohwan Kim 0:6f28332c466f 73 *
Soohwan Kim 0:6f28332c466f 74 * @ returns ip address
Soohwan Kim 0:6f28332c466f 75 */
Soohwan Kim 0:6f28332c466f 76 char* getIPAddress();
Soohwan Kim 0:6f28332c466f 77 char* getNetworkMask();
Soohwan Kim 0:6f28332c466f 78 char* getGateway();
Helmut Tschemernjak 33:879cfe51e66e 79 char* getDNSServer();
Soohwan Kim 0:6f28332c466f 80 char* getMACAddress();
Helmut Tschemernjak 35:fe3028eda085 81 int getLeaseTime() { return leaseTime; };
Helmut Tschemernjak 35:fe3028eda085 82 int getLeaseStart() { return leaseStart; };
Helmut Tschemernjak 35:fe3028eda085 83 char *getDomainName(void) { return domainName; };
Soohwan Kim 0:6f28332c466f 84 int IPrenew(int timeout_ms = 15*1000);
Soohwan Kim 0:6f28332c466f 85
Soohwan Kim 0:6f28332c466f 86 private:
Soohwan Kim 0:6f28332c466f 87 char ip_string[20];
Soohwan Kim 0:6f28332c466f 88 char mask_string[20];
Soohwan Kim 0:6f28332c466f 89 char gw_string[20];
Helmut Tschemernjak 34:7d44648ec5f2 90 char dns_string[20];
Soohwan Kim 0:6f28332c466f 91 char mac_string[20];
Soohwan Kim 0:6f28332c466f 92 bool ip_set;
Helmut Tschemernjak 35:fe3028eda085 93 uint32_t leaseStart;
Helmut Tschemernjak 35:fe3028eda085 94 char *domainName;
Helmut Tschemernjak 36:0ba2e8d5274a 95 const char *_hostname;
Soohwan Kim 0:6f28332c466f 96 };
Soohwan Kim 0:6f28332c466f 97
Soohwan Kim 0:6f28332c466f 98 #include "TCPSocketConnection.h"
Soohwan Kim 0:6f28332c466f 99 #include "TCPSocketServer.h"
Soohwan Kim 0:6f28332c466f 100 #include "UDPSocket.h"