Skip to content

Commit e486887

Browse files
authored
optionally allow WPS (#4889)
1 parent e0b6242 commit e486887

File tree

7 files changed

+106
-10
lines changed

7 files changed

+106
-10
lines changed

cores/esp8266/core_esp8266_main.cpp

+49-1
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,59 @@ void init_done() {
156156
* Peripherals (except for SPI0 and UART0) are not initialized.
157157
* This function does not return.
158158
*/
159+
/*
160+
A bit of explanation for this entry point:
161+
162+
SYS is the SDK task/context used by the upperlying system to run its
163+
administrative tasks (at least WLAN and lwip's receive callbacks and
164+
Ticker). NONOS-SDK is designed to run user's non-threaded code in
165+
another specific task/context with its own stack in BSS.
166+
167+
Some clever fellows found that the SYS stack was a large and quite unused
168+
piece of ram that we could use for the user's stack instead of using user's
169+
main memory, thus saving around 4KB on ram/heap.
170+
171+
A problem arose later, which is that this stack can heavily be used by
172+
the SDK for some features. One of these features is WPS. We still don't
173+
know if other features are using this, or if this memory is going to be
174+
used in future SDK releases.
175+
176+
WPS beeing flawed by its poor security, or not beeing used by lots of
177+
users, it has been decided that we are still going to use that memory for
178+
user's stack and disable the use of WPS, with an option to revert that
179+
back at the user's discretion. This selection can be done with the
180+
global define NO_EXTRA_4K_HEAP. An option has been added to the board
181+
generator script.
182+
183+
References:
184+
https://github.com/esp8266/Arduino/pull/4553
185+
https://github.com/esp8266/Arduino/pull/4622
186+
https://github.com/esp8266/Arduino/issues/4779
187+
https://github.com/esp8266/Arduino/pull/4889
188+
189+
*/
190+
191+
#ifdef NO_EXTRA_4K_HEAP
192+
/* this is the default NONOS-SDK user's heap location */
193+
cont_t g_cont __attribute__ ((aligned (16)));
194+
#endif
195+
159196
extern "C" void ICACHE_RAM_ATTR app_entry(void)
160197
{
161-
/* Allocate continuation context on this stack, and save pointer to it. */
198+
#ifdef NO_EXTRA_4K_HEAP
199+
200+
/* this is the default NONOS-SDK user's heap location */
201+
g_pcont = &g_cont;
202+
203+
#else
204+
205+
/* Allocate continuation context on this SYS stack,
206+
and save pointer to it. */
162207
cont_t s_cont __attribute__((aligned(16)));
163208
g_pcont = &s_cont;
209+
210+
#endif
211+
164212
/* Call the entry point of the SDK code. */
165213
call_user_start();
166214
}

doc/faq/readme.rst

+16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ entering an issue report, please perform initial troubleshooting.
4040

4141
`Read more <a02-my-esp-crashes.rst>`__.
4242

43+
How can I get some extra KBs in flash ?
44+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45+
46+
Using ``*printf()`` with floats is enabled by default. Some KBs of flash can
47+
be saved by using the option ``--nofloat`` with the boards generator:
48+
49+
``./tools/boards.txt.py --nofloat --allgen``
50+
51+
Why can't I use WPS ?
52+
~~~~~~~~~~~~~~~~~~~~~
53+
54+
WPS is disabled by default, this offers an extra 4KB in ram/heap. To enable
55+
WPS (and lose 4KB of useable ram), use this boards generator option:
56+
57+
``./tools/boards.txt.py --allowWPS --allgen``
58+
4359
This Arduino library doesn't work on ESP. How do I make it work?
4460
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4561

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ int32_t ESP8266WiFiSTAClass::RSSI(void) {
571571
// -------------------------------------------------- STA remote configure -----------------------------------------------
572572
// -----------------------------------------------------------------------------------------------------------------------
573573

574+
#ifdef NO_EXTRA_4K_HEAP
575+
/* NO_EXTRA_4K_HEAP's description in cores/esp8266/core_esp8266_main.cpp */
576+
574577
void wifi_wps_status_cb(wps_cb_status status);
575578

576579
/**
@@ -650,7 +653,7 @@ void wifi_wps_status_cb(wps_cb_status status) {
650653
esp_schedule(); // resume the beginWPSConfig function
651654
}
652655

653-
656+
#endif // NO_EXTRA_4K_HEAP
654657

655658
bool ESP8266WiFiSTAClass::_smartConfigStarted = false;
656659
bool ESP8266WiFiSTAClass::_smartConfigDone = false;

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "ESP8266WiFiType.h"
2828
#include "ESP8266WiFiGeneric.h"
29+
#include "user_interface.h"
2930

3031

3132
class ESP8266WiFiSTAClass {
@@ -92,7 +93,13 @@ class ESP8266WiFiSTAClass {
9293

9394
public:
9495

96+
#ifdef NO_EXTRA_4K_HEAP
9597
bool beginWPSConfig(void);
98+
#else
99+
inline bool beginWPSConfig(void) __attribute__((always_inline)) {
100+
return WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool();
101+
}
102+
#endif
96103

97104
bool beginSmartConfig();
98105
bool stopSmartConfig();

platform.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ build.vtable_flags=-DVTABLES_IN_FLASH
2525

2626
build.float=-u _printf_float -u _scanf_float
2727
build.led=
28+
build.noextra4kheap=
2829

2930
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
3031
compiler.sdk.path={runtime.platform.path}/tools/sdk
3132
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
3233
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
3334

3435
compiler.c.cmd=xtensa-lx106-elf-gcc
35-
compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
36+
compiler.c.flags=-c {compiler.warning_flags} {build.noextra4kheap} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
3637

3738
compiler.S.cmd=xtensa-lx106-elf-gcc
3839
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
@@ -43,7 +44,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc
4344
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc
4445

4546
compiler.cpp.cmd=xtensa-lx106-elf-g++
46-
compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections
47+
compiler.cpp.flags=-c {compiler.warning_flags} {build.noextra4kheap} -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections
4748

4849
compiler.as.cmd=xtensa-lx106-elf-as
4950

tools/boards.txt.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,9 @@ def all_boards ():
12361236
if nofloat:
12371237
print id + '.build.float='
12381238

1239+
if noextra4kheap:
1240+
print id + '.build.noextra4kheap=-DNO_EXTRA_4K_HEAP'
1241+
12391242
print ''
12401243

12411244
if boardsgen:
@@ -1253,11 +1256,8 @@ def package ():
12531256

12541257
if packagegen:
12551258
pkgfname_read = pkgfname + '.orig'
1256-
# check if backup already exists
12571259
if os.path.isfile(pkgfname_read):
1258-
print "package file is in the way, please move it"
1259-
print " %s" % pkgfname_read
1260-
sys.exit(1)
1260+
os.remove(pkgfname_read)
12611261
os.rename(pkgfname, pkgfname_read)
12621262

12631263
# read package file
@@ -1333,6 +1333,8 @@ def usage (name,ret):
13331333
print " --speed s - change default serial speed"
13341334
print " --customspeed s - new serial speed for all boards"
13351335
print " --nofloat - disable float support in printf/scanf"
1336+
print " --noextra4kheap - disable extra 4k heap (will enable WPS)"
1337+
print " --allowWPS - synonym for --noextra4kheap"
13361338
print ""
13371339
print " mandatory option (at least one):"
13381340
print ""
@@ -1376,6 +1378,7 @@ def usage (name,ret):
13761378
led_default = 2
13771379
led_max = 16
13781380
nofloat = False
1381+
noextra4kheap = False
13791382
ldgen = False
13801383
ldshow = False
13811384
boardsgen = False
@@ -1391,6 +1394,7 @@ def usage (name,ret):
13911394
try:
13921395
opts, args = getopt.getopt(sys.argv[1:], "h",
13931396
[ "help", "lwip=", "led=", "speed=", "board=", "customspeed=", "nofloat",
1397+
"noextra4kheap", "allowWPS",
13941398
"ld", "ldgen", "boards", "boardsgen", "package", "packagegen", "doc", "docgen",
13951399
"allgen"] )
13961400
except getopt.GetoptError as err:
@@ -1434,6 +1438,9 @@ def usage (name,ret):
14341438
elif o in ("--nofloat"):
14351439
nofloat=True
14361440

1441+
elif o in ("--noextra4kheap", "--allowWPS"):
1442+
noextra4kheap=True
1443+
14371444
elif o in ("--ldshow"):
14381445
ldshow = True
14391446

tools/sdk/include/user_interface.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,27 @@ enum wps_cb_status {
575575
WPS_CB_ST_UNK,
576576
};
577577

578+
typedef void (*wps_st_cb_t)(int status);
579+
580+
#ifdef NO_EXTRA_4K_HEAP
581+
/* check cores/esp8266/core_esp8266_main.cpp for comments about this */
582+
578583
bool wifi_wps_enable(WPS_TYPE_t wps_type);
579584
bool wifi_wps_disable(void);
580585
bool wifi_wps_start(void);
581-
582-
typedef void (*wps_st_cb_t)(int status);
583586
bool wifi_set_wps_cb(wps_st_cb_t cb);
584587

588+
#else
589+
590+
bool WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool ();
591+
#define wifi_wps_enable(...) WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
592+
#define wifi_wps_disable() WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
593+
#define wifi_wps_start() WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
594+
#define wifi_set_wps_cb(...) WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
595+
596+
#endif
597+
598+
585599
typedef void (*freedom_outside_cb_t)(uint8 status);
586600
int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb);
587601
void wifi_unregister_send_pkt_freedom_cb(void);

0 commit comments

Comments
 (0)