Skip to content

Commit fef1169

Browse files
committed
Merge remote-tracking branch 'amcewen/wifly_integration' into new-extension
2 parents 01e8531 + 4fc9deb commit fef1169

File tree

30 files changed

+164
-272
lines changed

30 files changed

+164
-272
lines changed

Dhcp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,19 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
271271
case routersOnSubnet :
272272
opt_len = _dhcpUdpSocket.read();
273273
_dhcpUdpSocket.read(_dhcpGatewayIp, 4);
274+
for (int i = 0; i < opt_len-4; i++)
275+
{
276+
_dhcpUdpSocket.read();
277+
}
274278
break;
275279

276280
case dns :
277281
opt_len = _dhcpUdpSocket.read();
278282
_dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
283+
for (int i = 0; i < opt_len-4; i++)
284+
{
285+
_dhcpUdpSocket.read();
286+
}
279287
break;
280288

281289
case dhcpServerIdentifier :

Dhcp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#ifndef Dhcp_h
55
#define Dhcp_h
66

7-
#include "Udp.h"
7+
#include "EthernetUdp.h"
88

99
/* DHCP state machine. */
1010
#define STATE_DHCP_START 0
@@ -139,7 +139,7 @@ class DhcpClass {
139139
uint8_t _dhcpGatewayIp[4];
140140
uint8_t _dhcpDhcpServerIp[4];
141141
uint8_t _dhcpDnsServerIp[4];
142-
UDP _dhcpUdpSocket;
142+
EthernetUDP _dhcpUdpSocket;
143143

144144
void presend_DHCP();
145145
void send_DHCP_MESSAGE(uint8_t, uint16_t);

Dns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Released under Apache License, version 2.0
44

55
#include "w5100.h"
6-
#include "Udp.h"
6+
#include "EthernetUdp.h"
77
#include "util.h"
88

99
#include "Dns.h"

Dns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef DNSClient_h
66
#define DNSClient_h
77

8-
#include <Udp.h>
8+
#include <EthernetUdp.h>
99

1010
class DNSClient
1111
{
@@ -35,7 +35,7 @@ class DNSClient
3535

3636
IPAddress iDNSServer;
3737
uint16_t iRequestId;
38-
UDP iUdp;
38+
EthernetUDP iUdp;
3939
};
4040

4141
#endif

Ethernet.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,37 @@ int EthernetClass::begin(uint8_t *mac_address)
3333
}
3434

3535
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
36+
{
37+
// Assume the DNS server will be the machine on the same network as the local IP
38+
// but with last octet being '1'
39+
IPAddress dns_server = local_ip;
40+
dns_server[3] = 1;
41+
begin(mac_address, local_ip, dns_server);
42+
}
43+
44+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
3645
{
3746
// Assume the gateway will be the machine on the same network as the local IP
3847
// but with last octet being '1'
3948
IPAddress gateway = local_ip;
4049
gateway[3] = 1;
41-
begin(mac_address, local_ip, gateway);
50+
begin(mac_address, local_ip, dns_server, gateway);
4251
}
4352

44-
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway)
53+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
4554
{
4655
IPAddress subnet(255, 255, 255, 0);
47-
begin(mac_address, local_ip, gateway, subnet);
56+
begin(mac_address, local_ip, dns_server, gateway, subnet);
4857
}
4958

50-
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress gateway, IPAddress subnet)
59+
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
5160
{
5261
W5100.init();
5362
W5100.setMACAddress(mac);
5463
W5100.setIPAddress(local_ip._address);
5564
W5100.setGatewayIp(gateway._address);
5665
W5100.setSubnetMask(subnet._address);
66+
_dnsServerAddress = dns_server;
5767
}
5868

5969
IPAddress EthernetClass::localIP()

Ethernet.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <inttypes.h>
55
//#include "w5100.h"
66
#include "IPAddress.h"
7-
#include "Client.h"
8-
#include "Server.h"
7+
#include "EthernetClient.h"
8+
#include "EthernetServer.h"
99

1010
#define MAX_SOCK_NUM 4
1111

@@ -20,16 +20,17 @@ class EthernetClass {
2020
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
2121
int begin(uint8_t *mac_address);
2222
void begin(uint8_t *mac_address, IPAddress local_ip);
23-
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway);
24-
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway, IPAddress subnet);
23+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
24+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
25+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
2526

2627
IPAddress localIP();
2728
IPAddress subnetMask();
2829
IPAddress gatewayIP();
2930
IPAddress dnsServerIP();
3031

31-
friend class Client;
32-
friend class Server;
32+
friend class EthernetClient;
33+
friend class EthernetServer;
3334
};
3435

3536
extern EthernetClass Ethernet;

Client.cpp renamed to EthernetClient.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ extern "C" {
88
#include "Arduino.h"
99

1010
#include "Ethernet.h"
11-
#include "Client.h"
12-
#include "Server.h"
11+
#include "EthernetClient.h"
12+
#include "EthernetServer.h"
1313
#include "Dns.h"
1414

15-
uint16_t Client::_srcport = 1024;
15+
uint16_t EthernetClient::_srcport = 1024;
1616

17-
Client::Client() : _sock(MAX_SOCK_NUM) {
17+
EthernetClient::EthernetClient() : _sock(MAX_SOCK_NUM) {
1818
}
1919

20-
Client::Client(uint8_t sock) : _sock(sock) {
20+
EthernetClient::EthernetClient(uint8_t sock) : _sock(sock) {
2121
}
2222

23-
int Client::connect(const char* host, uint16_t port) {
23+
int EthernetClient::connect(const char* host, uint16_t port) {
2424
// Look up the host first
2525
int ret = 0;
2626
DNSClient dns;
@@ -35,7 +35,7 @@ int Client::connect(const char* host, uint16_t port) {
3535
}
3636
}
3737

38-
int Client::connect(IPAddress ip, uint16_t port) {
38+
int EthernetClient::connect(IPAddress ip, uint16_t port) {
3939
if (_sock != MAX_SOCK_NUM)
4040
return 0;
4141

@@ -54,7 +54,7 @@ int Client::connect(IPAddress ip, uint16_t port) {
5454
if (_srcport == 0) _srcport = 1024;
5555
socket(_sock, SnMR::TCP, _srcport, 0);
5656

57-
if (!::connect(_sock, ip.raw_address(), port)) {
57+
if (!::connect(_sock, rawIPAddress(ip), port)) {
5858
_sock = MAX_SOCK_NUM;
5959
return 0;
6060
}
@@ -70,15 +70,15 @@ int Client::connect(IPAddress ip, uint16_t port) {
7070
return 1;
7171
}
7272

73-
size_t Client::write(uint8_t b) {
73+
size_t EthernetClient::write(uint8_t b) {
7474
return write(&b, 1);
7575
}
7676

77-
size_t Client::write(const char *str) {
77+
size_t EthernetClient::write(const char *str) {
7878
return write((const uint8_t *) str, strlen(str));
7979
}
8080

81-
size_t Client::write(const uint8_t *buf, size_t size) {
81+
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
8282
if (_sock == MAX_SOCK_NUM) {
8383
setWriteError();
8484
return 0;
@@ -90,13 +90,13 @@ size_t Client::write(const uint8_t *buf, size_t size) {
9090
return size;
9191
}
9292

93-
int Client::available() {
93+
int EthernetClient::available() {
9494
if (_sock != MAX_SOCK_NUM)
9595
return W5100.getRXReceivedSize(_sock);
9696
return 0;
9797
}
9898

99-
int Client::read() {
99+
int EthernetClient::read() {
100100
uint8_t b;
101101
if ( recv(_sock, &b, 1) > 0 )
102102
{
@@ -110,11 +110,11 @@ int Client::read() {
110110
}
111111
}
112112

113-
int Client::read(uint8_t *buf, size_t size) {
113+
int EthernetClient::read(uint8_t *buf, size_t size) {
114114
return recv(_sock, buf, size);
115115
}
116116

117-
int Client::peek() {
117+
int EthernetClient::peek() {
118118
uint8_t b;
119119
// Unlike recv, peek doesn't check to see if there's any data available, so we must
120120
if (!available())
@@ -123,12 +123,12 @@ int Client::peek() {
123123
return b;
124124
}
125125

126-
void Client::flush() {
126+
void EthernetClient::flush() {
127127
while (available())
128128
read();
129129
}
130130

131-
void Client::stop() {
131+
void EthernetClient::stop() {
132132
if (_sock == MAX_SOCK_NUM)
133133
return;
134134

@@ -148,22 +148,22 @@ void Client::stop() {
148148
_sock = MAX_SOCK_NUM;
149149
}
150150

151-
uint8_t Client::connected() {
151+
uint8_t EthernetClient::connected() {
152152
if (_sock == MAX_SOCK_NUM) return 0;
153153

154154
uint8_t s = status();
155155
return !(s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::FIN_WAIT ||
156156
(s == SnSR::CLOSE_WAIT && !available()));
157157
}
158158

159-
uint8_t Client::status() {
159+
uint8_t EthernetClient::status() {
160160
if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
161161
return W5100.readSnSR(_sock);
162162
}
163163

164164
// the next function allows us to use the client returned by
165-
// Server::available() as the condition in an if-statement.
165+
// EthernetServer::available() as the condition in an if-statement.
166166

167-
Client::operator bool() {
167+
EthernetClient::operator bool() {
168168
return _sock != MAX_SOCK_NUM;
169169
}

Client.h renamed to EthernetClient.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
#ifndef client_h
2-
#define client_h
1+
#ifndef ethernetclient_h
2+
#define ethernetclient_h
33
#include "Arduino.h"
44
#include "Print.h"
5+
#include "Client.h"
6+
#include "IPAddress.h"
57

6-
class Client : public Stream {
8+
class EthernetClient : public Client {
79

810
public:
9-
Client();
10-
Client(uint8_t sock);
11+
EthernetClient();
12+
EthernetClient(uint8_t sock);
1113

1214
uint8_t status();
13-
int connect(IPAddress ip, uint16_t port);
14-
int connect(const char *host, uint16_t port);
15+
virtual int connect(IPAddress ip, uint16_t port);
16+
virtual int connect(const char *host, uint16_t port);
1517
virtual size_t write(uint8_t);
1618
virtual size_t write(const char *str);
1719
virtual size_t write(const uint8_t *buf, size_t size);
@@ -20,11 +22,11 @@ class Client : public Stream {
2022
virtual int read(uint8_t *buf, size_t size);
2123
virtual int peek();
2224
virtual void flush();
23-
void stop();
24-
uint8_t connected();
25-
operator bool();
25+
virtual void stop();
26+
virtual uint8_t connected();
27+
virtual operator bool();
2628

27-
friend class Server;
29+
friend class EthernetServer;
2830

2931
private:
3032
static uint16_t _srcport;

0 commit comments

Comments
 (0)