Skip to content

optionally allow WPS #4889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,59 @@ void init_done() {
* Peripherals (except for SPI0 and UART0) are not initialized.
* This function does not return.
*/
/*
A bit of explanation for this entry point:

SYS is the SDK task/context used by the upperlying system to run its
administrative tasks (at least WLAN and lwip's receive callbacks and
Ticker). NONOS-SDK is designed to run user's non-threaded code in
another specific task/context with its own stack in BSS.

Some clever fellows found that the SYS stack was a large and quite unused
piece of ram that we could use for the user's stack instead of using user's
main memory, thus saving around 4KB on ram/heap.

A problem arose later, which is that this stack can heavily be used by
the SDK for some features. One of these features is WPS. We still don't
know if other features are using this, or if this memory is going to be
used in future SDK releases.

WPS beeing flawed by its poor security, or not beeing used by lots of
users, it has been decided that we are still going to use that memory for
user's stack and disable the use of WPS, with an option to revert that
back at the user's discretion. This selection can be done with the
global define NO_EXTRA_4K_HEAP. An option has been added to the board
generator script.

References:
https://github.com/esp8266/Arduino/pull/4553
https://github.com/esp8266/Arduino/pull/4622
https://github.com/esp8266/Arduino/issues/4779
https://github.com/esp8266/Arduino/pull/4889

*/

#ifdef NO_EXTRA_4K_HEAP
/* this is the default NONOS-SDK user's heap location */
cont_t g_cont __attribute__ ((aligned (16)));
#endif

extern "C" void ICACHE_RAM_ATTR app_entry(void)
{
/* Allocate continuation context on this stack, and save pointer to it. */
#ifdef NO_EXTRA_4K_HEAP

/* this is the default NONOS-SDK user's heap location */
g_pcont = &g_cont;

#else

/* Allocate continuation context on this SYS stack,
and save pointer to it. */
cont_t s_cont __attribute__((aligned(16)));
g_pcont = &s_cont;

#endif

/* Call the entry point of the SDK code. */
call_user_start();
}
Expand Down
16 changes: 16 additions & 0 deletions doc/faq/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ entering an issue report, please perform initial troubleshooting.

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

How can I get some extra KBs in flash ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using ``*printf()`` with floats is enabled by default. Some KBs of flash can
be saved by using the option ``--nofloat`` with the boards generator:

``./tools/boards.txt.py --nofloat --allgen``

Why can't I use WPS ?
~~~~~~~~~~~~~~~~~~~~~

WPS is disabled by default, this offers an extra 4KB in ram/heap. To enable
WPS (and lose 4KB of useable ram), use this boards generator option:

``./tools/boards.txt.py --allowWPS --allgen``

This Arduino library doesn't work on ESP. How do I make it work?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 4 additions & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ int32_t ESP8266WiFiSTAClass::RSSI(void) {
// -------------------------------------------------- STA remote configure -----------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------

#ifdef NO_EXTRA_4K_HEAP
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a descriptive comment about what the #define means, or at least reference the issue.

/* NO_EXTRA_4K_HEAP's description in cores/esp8266/core_esp8266_main.cpp */

void wifi_wps_status_cb(wps_cb_status status);

/**
Expand Down Expand Up @@ -650,7 +653,7 @@ void wifi_wps_status_cb(wps_cb_status status) {
esp_schedule(); // resume the beginWPSConfig function
}


#endif // NO_EXTRA_4K_HEAP

bool ESP8266WiFiSTAClass::_smartConfigStarted = false;
bool ESP8266WiFiSTAClass::_smartConfigDone = false;
Expand Down
7 changes: 7 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "ESP8266WiFiType.h"
#include "ESP8266WiFiGeneric.h"
#include "user_interface.h"


class ESP8266WiFiSTAClass {
Expand Down Expand Up @@ -92,7 +93,13 @@ class ESP8266WiFiSTAClass {

public:

#ifdef NO_EXTRA_4K_HEAP
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a descriptive comment about what the #define means, or at least reference the issue.

bool beginWPSConfig(void);
#else
inline bool beginWPSConfig(void) __attribute__((always_inline)) {
return WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool();
}
#endif

bool beginSmartConfig();
bool stopSmartConfig();
Expand Down
5 changes: 3 additions & 2 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ build.vtable_flags=-DVTABLES_IN_FLASH

build.float=-u _printf_float -u _scanf_float
build.led=
build.noextra4kheap=

compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
compiler.sdk.path={runtime.platform.path}/tools/sdk
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
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"

compiler.c.cmd=xtensa-lx106-elf-gcc
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
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

compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
Expand All @@ -43,7 +44,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc
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

compiler.cpp.cmd=xtensa-lx106-elf-g++
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
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

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

Expand Down
15 changes: 11 additions & 4 deletions tools/boards.txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,9 @@ def all_boards ():
if nofloat:
print id + '.build.float='

if noextra4kheap:
print id + '.build.noextra4kheap=-DNO_EXTRA_4K_HEAP'

print ''

if boardsgen:
Expand All @@ -1253,11 +1256,8 @@ def package ():

if packagegen:
pkgfname_read = pkgfname + '.orig'
# check if backup already exists
if os.path.isfile(pkgfname_read):
print "package file is in the way, please move it"
print " %s" % pkgfname_read
sys.exit(1)
os.remove(pkgfname_read)
os.rename(pkgfname, pkgfname_read)

# read package file
Expand Down Expand Up @@ -1333,6 +1333,8 @@ def usage (name,ret):
print " --speed s - change default serial speed"
print " --customspeed s - new serial speed for all boards"
print " --nofloat - disable float support in printf/scanf"
print " --noextra4kheap - disable extra 4k heap (will enable WPS)"
print " --allowWPS - synonym for --noextra4kheap"
print ""
print " mandatory option (at least one):"
print ""
Expand Down Expand Up @@ -1376,6 +1378,7 @@ def usage (name,ret):
led_default = 2
led_max = 16
nofloat = False
noextra4kheap = False
ldgen = False
ldshow = False
boardsgen = False
Expand All @@ -1391,6 +1394,7 @@ def usage (name,ret):
try:
opts, args = getopt.getopt(sys.argv[1:], "h",
[ "help", "lwip=", "led=", "speed=", "board=", "customspeed=", "nofloat",
"noextra4kheap", "allowWPS",
"ld", "ldgen", "boards", "boardsgen", "package", "packagegen", "doc", "docgen",
"allgen"] )
except getopt.GetoptError as err:
Expand Down Expand Up @@ -1434,6 +1438,9 @@ def usage (name,ret):
elif o in ("--nofloat"):
nofloat=True

elif o in ("--noextra4kheap", "--allowWPS"):
noextra4kheap=True

elif o in ("--ldshow"):
ldshow = True

Expand Down
18 changes: 16 additions & 2 deletions tools/sdk/include/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,27 @@ enum wps_cb_status {
WPS_CB_ST_UNK,
};

typedef void (*wps_st_cb_t)(int status);

#ifdef NO_EXTRA_4K_HEAP
/* check cores/esp8266/core_esp8266_main.cpp for comments about this */

bool wifi_wps_enable(WPS_TYPE_t wps_type);
bool wifi_wps_disable(void);
bool wifi_wps_start(void);

typedef void (*wps_st_cb_t)(int status);
bool wifi_set_wps_cb(wps_st_cb_t cb);

#else

bool WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool ();
#define wifi_wps_enable(...) WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
#define wifi_wps_disable() WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
#define wifi_wps_start() WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()
#define wifi_set_wps_cb(...) WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool()

#endif


typedef void (*freedom_outside_cb_t)(uint8 status);
int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb);
void wifi_unregister_send_pkt_freedom_cb(void);
Expand Down