Skip to content

Commit 0338f6c

Browse files
authored
Merge branch 'master' into i2c_slave_by_bjoham
2 parents 9e63df6 + 9bc8ea1 commit 0338f6c

39 files changed

+2670
-150
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ Boards manager link: `http://arduino.esp8266.com/stable/package_esp8266com_index
3030

3131
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.4.2/](https://arduino-esp8266.readthedocs.io/en/2.4.2/)
3232

33-
### Using git version
33+
### Using git version (basic instructions)
3434
[![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino)
3535

3636
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is at the [Arduino website](http://www.arduino.cc/en/main/software).
37-
- Go to Arduino application directory
37+
- Go to Arduino directory
3838
- For Mac OS X, it is `Arduino.app` showing as the Arduino icon.
3939
This location may be your `~/Downloads`, `~/Desktop` or even `/Applications`.
4040
```bash
4141
cd <application-directory>/Arduino.app/Contents/Java
4242
```
43+
- For Linux, it is ~/arduino by default.
44+
```bash
45+
cd ~arduino
46+
```
4347
- Clone this repository into hardware/esp8266com/esp8266 directory (or clone it elsewhere and create a symlink)
4448
```bash
4549
cd hardware

boards.txt

Lines changed: 348 additions & 0 deletions
Large diffs are not rendered by default.

doc/esp8266wifi/readme.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Soft Access Point
125125
~~~~~~~~~~~~~~~~~
126126

127127
An `access point (AP) <https://en.wikipedia.org/wiki/Wireless_access_point>`__ is a device that provides access to Wi-Fi network to other devices (stations)
128-
and connects them further to a wired network. ESP8266 can provide similar functionality except it does not have interface to a wired network. Such mode of operation is called soft access point (soft-AP). The maximum number of stations that can simultaneously be connected to the soft-AP can be set `from 1 to 8 <https://bbs.espressif.com/viewtopic.php?f=46&t=481&p=1832&hilit=max_connection#p1832>`__, but defaults to 4.
128+
and connects them further to a wired network. ESP8266 can provide similar functionality except it does not have interface to a wired network. Such mode of operation is called soft access point (soft-AP). The maximum number of stations that can simultaneously be connected to the soft-AP can be set `from 0 to 8 <https://bbs.espressif.com/viewtopic.php?f=46&t=481&p=1832&hilit=max_connection#p1832>`__, but defaults to 4.
129129

130130
.. figure:: pictures/esp8266-soft-access-point.png
131131
:alt: ESP8266 operating in the Soft Access Point mode
@@ -293,7 +293,7 @@ What's Inside?
293293

294294
If you like to analyze in detail what is inside of the ESP8266WiFi library, go directly to the `ESP8266WiFi <https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi/src>`__ folder of esp8266 / Arduino repository on the GitHub.
295295

296-
To make the analysis easier, rather than looking into individual header or source files, use one of free tools to automatically generate documentation. The class index in chapter `Class Description <class-description>`__ above has been prepared in no time using great `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`__, that is the de facto standard tool for generating documentation from annotated C++ sources.
296+
To make the analysis easier, rather than looking into individual header or source files, use one of free tools to automatically generate documentation. The class index in chapter `Class Description`_ above has been prepared in no time using great `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`__, that is the de facto standard tool for generating documentation from annotated C++ sources.
297297

298298
.. figure:: pictures/doxygen-esp8266wifi-documentation.png
299299
:alt: Example of documentation prepared by Doxygen

doc/esp8266wifi/soft-access-point-class.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Meaning of all parameters is as follows:
5454
- ``password`` - optional character string with a password. For WPA2-PSK network it should be at least 8 character long. If not specified, the access point will be open for anybody to connect.
5555
- ``channel`` - optional parameter to set Wi-Fi channel, from 1 to 13. Default channel = 1.
5656
- ``hidden`` - optional parameter, if set to ``true`` will hide SSID.
57-
- ``max_connection`` - optional parameter to set max simultaneous connected stations, `from 1 to 8 <https://bbs.espressif.com/viewtopic.php?f=46&t=481&p=1832&hilit=max_connection#p1832>`__. Defaults to 4. Once the max number has been reached, any other station that wants to connect will be forced to wait until an already connected station disconnects.
57+
- ``max_connection`` - optional parameter to set max simultaneous connected stations, `from 0 to 8 <https://bbs.espressif.com/viewtopic.php?f=46&t=481&p=1832&hilit=max_connection#p1832>`__. Defaults to 4. Once the max number has been reached, any other station that wants to connect will be forced to wait until an already connected station disconnects.
5858

5959
Function will return ``true`` or ``false`` depending on result of setting the soft-AP.
6060

@@ -141,7 +141,7 @@ Get the count of the stations that are connected to the soft-AP interface.
141141

142142
Stations connected to soft-AP = 2
143143

144-
Note: the maximum number of stations that may be connected to ESP8266 soft-AP is 4 by default. This can be changed from 1 to 8 via the ``max_connection`` argument of the softAP method.
144+
Note: the maximum number of stations that may be connected to ESP8266 soft-AP is 4 by default. This can be changed from 0 to 8 via the ``max_connection`` argument of the softAP method.
145145

146146
softAPdisconnect
147147
^^^^^^^^^^^^^^^^

libraries/DNSServer/keywords.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#######################################
2+
# Syntax Coloring Map For DNSServer
3+
#######################################
4+
5+
#######################################
6+
# Library (KEYWORD3)
7+
#######################################
8+
9+
DNSServer KEYWORD3 RESERVED_WORD
10+
11+
#######################################
12+
# Datatypes (KEYWORD1)
13+
#######################################
14+
15+
DNSReplyCode KEYWORD1 DATA_TYPE
16+
DNSHeader KEYWORD1 DATA_TYPE
17+
DNSServer KEYWORD1 DATA_TYPE
18+
19+
#######################################
20+
# Methods and Functions (KEYWORD2)
21+
#######################################
22+
23+
processNextRequest KEYWORD2
24+
setErrorReplyCode KEYWORD2
25+
setTTL KEYWORD2
26+
start KEYWORD2
27+
stop KEYWORD2
28+
29+
#######################################
30+
# Constants (LITERAL1)
31+
#######################################
32+
33+
DNS_QR_QUERY LITERAL1 RESERVED_WORD_2
34+
DNS_QR_RESPONSE LITERAL1 RESERVED_WORD_2
35+
DNS_OPCODE_QUERY LITERAL1 RESERVED_WORD_2
36+
MAX_DNSNAME_LENGTH LITERAL1 RESERVED_WORD_2
37+
NoError LITERAL1 RESERVED_WORD_2
38+
FormError LITERAL1 RESERVED_WORD_2
39+
ServerFailure LITERAL1 RESERVED_WORD_2
40+
NonExistentDomain LITERAL1 RESERVED_WORD_2
41+
NotImplemented LITERAL1 RESERVED_WORD_2
42+
Refused LITERAL1 RESERVED_WORD_2
43+
YXDomain LITERAL1 RESERVED_WORD_2
44+
YXRRSet LITERAL1 RESERVED_WORD_2
45+
NXRRSet LITERAL1 RESERVED_WORD_2

libraries/DNSServer/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DNSServer
2-
version=1.1.0
2+
version=1.1.1
33
author=Kristijan Novoselić
44
maintainer=Kristijan Novoselić, <kristijan.novoselic@gmail.com>
55
sentence=A simple DNS server for ESP8266.

libraries/DNSServer/src/DNSServer.cpp

Lines changed: 85 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bool DNSServer::start(const uint16_t &port, const String &domainName,
1313
const IPAddress &resolvedIP)
1414
{
1515
_port = port;
16-
_buffer = NULL;
16+
1717
_domainName = domainName;
1818
_resolvedIP[0] = resolvedIP[0];
1919
_resolvedIP[1] = resolvedIP[1];
@@ -36,8 +36,6 @@ void DNSServer::setTTL(const uint32_t &ttl)
3636
void DNSServer::stop()
3737
{
3838
_udp.stop();
39-
free(_buffer);
40-
_buffer = NULL;
4139
}
4240

4341
void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName)
@@ -48,82 +46,106 @@ void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName)
4846

4947
void DNSServer::processNextRequest()
5048
{
51-
_currentPacketSize = _udp.parsePacket();
52-
if (_currentPacketSize)
49+
size_t packetSize = _udp.parsePacket();
50+
51+
if (packetSize >= sizeof(DNSHeader))
5352
{
54-
if (_buffer != NULL) free(_buffer);
55-
_buffer = (unsigned char*)malloc(_currentPacketSize * sizeof(char));
56-
if (_buffer == NULL) return;
57-
_udp.read(_buffer, _currentPacketSize);
58-
_dnsHeader = (DNSHeader*) _buffer;
59-
60-
if (_dnsHeader->QR == DNS_QR_QUERY &&
61-
_dnsHeader->OPCode == DNS_OPCODE_QUERY &&
62-
requestIncludesOnlyOneQuestion() &&
63-
(_domainName == "*" || getDomainNameWithoutWwwPrefix() == _domainName)
53+
uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(packetSize));
54+
if (buffer == NULL) return;
55+
56+
_udp.read(buffer, packetSize);
57+
58+
DNSHeader* dnsHeader = reinterpret_cast<DNSHeader*>(buffer);
59+
60+
if (dnsHeader->QR == DNS_QR_QUERY &&
61+
dnsHeader->OPCode == DNS_OPCODE_QUERY &&
62+
requestIncludesOnlyOneQuestion(dnsHeader) &&
63+
(_domainName == "*" || getDomainNameWithoutWwwPrefix(buffer, packetSize) == _domainName)
6464
)
6565
{
66-
replyWithIP();
66+
replyWithIP(buffer, packetSize);
6767
}
68-
else if (_dnsHeader->QR == DNS_QR_QUERY)
68+
else if (dnsHeader->QR == DNS_QR_QUERY)
6969
{
70-
replyWithCustomCode();
70+
replyWithCustomCode(buffer, packetSize);
7171
}
7272

73-
free(_buffer);
74-
_buffer = NULL;
73+
free(buffer);
7574
}
7675
}
7776

78-
bool DNSServer::requestIncludesOnlyOneQuestion()
77+
bool DNSServer::requestIncludesOnlyOneQuestion(const DNSHeader* dnsHeader)
7978
{
80-
return ntohs(_dnsHeader->QDCount) == 1 &&
81-
_dnsHeader->ANCount == 0 &&
82-
_dnsHeader->NSCount == 0 &&
83-
_dnsHeader->ARCount == 0;
79+
return ntohs(dnsHeader->QDCount) == 1 &&
80+
dnsHeader->ANCount == 0 &&
81+
dnsHeader->NSCount == 0 &&
82+
dnsHeader->ARCount == 0;
8483
}
8584

86-
String DNSServer::getDomainNameWithoutWwwPrefix()
85+
String DNSServer::getDomainNameWithoutWwwPrefix(const uint8_t* buffer, size_t packetSize)
8786
{
88-
String parsedDomainName = "";
89-
if (_buffer == NULL) return parsedDomainName;
90-
unsigned char *start = _buffer + 12;
91-
if (*start == 0)
92-
{
93-
return parsedDomainName;
94-
}
95-
int pos = 0;
96-
while(true)
87+
String parsedDomainName;
88+
89+
const uint8_t* pos = buffer + sizeof(DNSHeader);
90+
const uint8_t* end = buffer + packetSize;
91+
92+
// to minimize reallocations due to concats below
93+
// we reserve enough space that a median or average domain
94+
// name size cold be easily contained without a reallocation
95+
// - max size would be 253, in 2013, average is 11 and max was 42
96+
//
97+
parsedDomainName.reserve(32);
98+
99+
uint8_t labelLength = *pos;
100+
101+
while (true)
97102
{
98-
unsigned char labelLength = *(start + pos);
99-
for(int i = 0; i < labelLength; i++)
103+
if (labelLength == 0)
104+
{
105+
// no more labels
106+
downcaseAndRemoveWwwPrefix(parsedDomainName);
107+
return parsedDomainName;
108+
}
109+
110+
// append next label
111+
for (int i = 0; i < labelLength && pos < end; i++)
100112
{
101113
pos++;
102-
parsedDomainName += (char)*(start + pos);
114+
parsedDomainName += static_cast<char>(*pos);
103115
}
104-
pos++;
105-
if (*(start + pos) == 0)
116+
117+
if (pos >= end)
106118
{
107-
downcaseAndRemoveWwwPrefix(parsedDomainName);
108-
return parsedDomainName;
119+
// malformed packet, return an empty domain name
120+
parsedDomainName = "";
121+
return parsedDomainName;
109122
}
110123
else
111124
{
112-
parsedDomainName += ".";
125+
// next label
126+
pos++;
127+
labelLength = *pos;
128+
129+
// if there is another label, add delimiter
130+
if (labelLength != 0)
131+
{
132+
parsedDomainName += ".";
133+
}
113134
}
114135
}
115136
}
116137

117-
void DNSServer::replyWithIP()
138+
void DNSServer::replyWithIP(uint8_t* buffer, size_t packetSize)
118139
{
119-
if (_buffer == NULL) return;
120-
_dnsHeader->QR = DNS_QR_RESPONSE;
121-
_dnsHeader->ANCount = _dnsHeader->QDCount;
122-
_dnsHeader->QDCount = _dnsHeader->QDCount;
123-
//_dnsHeader->RA = 1;
140+
DNSHeader* dnsHeader = reinterpret_cast<DNSHeader*>(buffer);
141+
142+
dnsHeader->QR = DNS_QR_RESPONSE;
143+
dnsHeader->ANCount = dnsHeader->QDCount;
144+
dnsHeader->QDCount = dnsHeader->QDCount;
145+
//dnsHeader->RA = 1;
124146

125147
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
126-
_udp.write(_buffer, _currentPacketSize);
148+
_udp.write(buffer, packetSize);
127149

128150
_udp.write((uint8_t)192); // answer name is a pointer
129151
_udp.write((uint8_t)12); // pointer to offset at 0x00c
@@ -142,22 +164,26 @@ void DNSServer::replyWithIP()
142164
_udp.write(_resolvedIP, sizeof(_resolvedIP));
143165
_udp.endPacket();
144166

145-
146-
147167
#ifdef DEBUG_ESP_DNS
148168
DEBUG_ESP_PORT.printf("DNS responds: %s for %s\n",
149-
IPAddress(_resolvedIP).toString().c_str(), getDomainNameWithoutWwwPrefix().c_str() );
169+
IPAddress(_resolvedIP).toString().c_str(), getDomainNameWithoutWwwPrefix(buffer, packetSize).c_str() );
150170
#endif
151171
}
152172

153-
void DNSServer::replyWithCustomCode()
173+
void DNSServer::replyWithCustomCode(uint8_t* buffer, size_t packetSize)
154174
{
155-
if (_buffer == NULL) return;
156-
_dnsHeader->QR = DNS_QR_RESPONSE;
157-
_dnsHeader->RCode = (unsigned char)_errorReplyCode;
158-
_dnsHeader->QDCount = 0;
175+
if (packetSize < sizeof(DNSHeader))
176+
{
177+
return;
178+
}
179+
180+
DNSHeader* dnsHeader = reinterpret_cast<DNSHeader*>(buffer);
181+
182+
dnsHeader->QR = DNS_QR_RESPONSE;
183+
dnsHeader->RCode = (unsigned char)_errorReplyCode;
184+
dnsHeader->QDCount = 0;
159185

160186
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
161-
_udp.write(_buffer, sizeof(DNSHeader));
187+
_udp.write(buffer, sizeof(DNSHeader));
162188
_udp.endPacket();
163189
}

libraries/DNSServer/src/DNSServer.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define DNS_QR_RESPONSE 1
77
#define DNS_OPCODE_QUERY 0
88

9+
#define MAX_DNSNAME_LENGTH 253
10+
911
enum class DNSReplyCode
1012
{
1113
NoError = 0,
@@ -40,6 +42,9 @@ class DNSServer
4042
{
4143
public:
4244
DNSServer();
45+
~DNSServer() {
46+
stop();
47+
};
4348
void processNextRequest();
4449
void setErrorReplyCode(const DNSReplyCode &replyCode);
4550
void setTTL(const uint32_t &ttl);
@@ -56,16 +61,13 @@ class DNSServer
5661
uint16_t _port;
5762
String _domainName;
5863
unsigned char _resolvedIP[4];
59-
int _currentPacketSize;
60-
unsigned char* _buffer;
61-
DNSHeader* _dnsHeader;
6264
uint32_t _ttl;
6365
DNSReplyCode _errorReplyCode;
6466

6567
void downcaseAndRemoveWwwPrefix(String &domainName);
66-
String getDomainNameWithoutWwwPrefix();
67-
bool requestIncludesOnlyOneQuestion();
68-
void replyWithIP();
69-
void replyWithCustomCode();
68+
String getDomainNameWithoutWwwPrefix(const uint8_t* buffer, size_t packetSize);
69+
bool requestIncludesOnlyOneQuestion(const DNSHeader* dnsHeader);
70+
void replyWithIP(uint8_t* buffer, size_t packetSize);
71+
void replyWithCustomCode(uint8_t* buffer, size_t packetSize);
7072
};
7173
#endif

libraries/ESP8266AVRISP/keywords.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#######################################
2+
# Syntax Coloring Map For ESP8266AVRISP
3+
#######################################
4+
5+
#######################################
6+
# Library (KEYWORD3)
7+
#######################################
8+
9+
ESP8266AVRISP KEYWORD3 RESERVED_WORD
10+
11+
#######################################
12+
# Datatypes (KEYWORD1)
13+
#######################################
14+
15+
AVRISPState_t KEYWORD1 DATA_TYPE
16+
AVRISP_parameter_t KEYWORD1 DATA_TYPE
17+
ESP8266AVRISP KEYWORD1 DATA_TYPE
18+
19+
#######################################
20+
# Methods and Functions (KEYWORD2)
21+
#######################################
22+
23+
begin KEYWORD2
24+
setSpiFrequency KEYWORD2
25+
setReset KEYWORD2
26+
update KEYWORD2
27+
serve KEYWORD2
28+
29+
#######################################
30+
# Constants (LITERAL1)
31+
#######################################
32+
33+
AVRISP_STATE_IDLE LITERAL1 RESERVED_WORD_2
34+
AVRISP_STATE_PENDING LITERAL1 RESERVED_WORD_2
35+
AVRISP_STATE_ACTIVE LITERAL1 RESERVED_WORD_2

0 commit comments

Comments
 (0)