1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

optionally allow WPS (#4889)

This commit is contained in:
david gauchard 2018-07-06 16:45:25 +02:00 committed by GitHub
parent e0b6242e04
commit e486887f18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 10 deletions

View File

@ -156,11 +156,59 @@ void init_done() {
* Peripherals (except for SPI0 and UART0) are not initialized. * Peripherals (except for SPI0 and UART0) are not initialized.
* This function does not return. * 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) 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))); cont_t s_cont __attribute__((aligned(16)));
g_pcont = &s_cont; g_pcont = &s_cont;
#endif
/* Call the entry point of the SDK code. */ /* Call the entry point of the SDK code. */
call_user_start(); call_user_start();
} }

View File

@ -40,6 +40,22 @@ entering an issue report, please perform initial troubleshooting.
`Read more <a02-my-esp-crashes.rst>`__. `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? This Arduino library doesn't work on ESP. How do I make it work?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -571,6 +571,9 @@ int32_t ESP8266WiFiSTAClass::RSSI(void) {
// -------------------------------------------------- STA remote configure ----------------------------------------------- // -------------------------------------------------- STA remote configure -----------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------
#ifdef NO_EXTRA_4K_HEAP
/* NO_EXTRA_4K_HEAP's description in cores/esp8266/core_esp8266_main.cpp */
void wifi_wps_status_cb(wps_cb_status status); void wifi_wps_status_cb(wps_cb_status status);
/** /**
@ -650,7 +653,7 @@ void wifi_wps_status_cb(wps_cb_status status) {
esp_schedule(); // resume the beginWPSConfig function esp_schedule(); // resume the beginWPSConfig function
} }
#endif // NO_EXTRA_4K_HEAP
bool ESP8266WiFiSTAClass::_smartConfigStarted = false; bool ESP8266WiFiSTAClass::_smartConfigStarted = false;
bool ESP8266WiFiSTAClass::_smartConfigDone = false; bool ESP8266WiFiSTAClass::_smartConfigDone = false;

View File

@ -26,6 +26,7 @@
#include "ESP8266WiFiType.h" #include "ESP8266WiFiType.h"
#include "ESP8266WiFiGeneric.h" #include "ESP8266WiFiGeneric.h"
#include "user_interface.h"
class ESP8266WiFiSTAClass { class ESP8266WiFiSTAClass {
@ -92,7 +93,13 @@ class ESP8266WiFiSTAClass {
public: public:
#ifdef NO_EXTRA_4K_HEAP
bool beginWPSConfig(void); 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 beginSmartConfig();
bool stopSmartConfig(); bool stopSmartConfig();

View File

@ -25,6 +25,7 @@ build.vtable_flags=-DVTABLES_IN_FLASH
build.float=-u _printf_float -u _scanf_float build.float=-u _printf_float -u _scanf_float
build.led= build.led=
build.noextra4kheap=
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/ compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
compiler.sdk.path={runtime.platform.path}/tools/sdk compiler.sdk.path={runtime.platform.path}/tools/sdk
@ -32,7 +33,7 @@ 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.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.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.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
@ -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.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.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 compiler.as.cmd=xtensa-lx106-elf-as

View File

@ -1236,6 +1236,9 @@ def all_boards ():
if nofloat: if nofloat:
print id + '.build.float=' print id + '.build.float='
if noextra4kheap:
print id + '.build.noextra4kheap=-DNO_EXTRA_4K_HEAP'
print '' print ''
if boardsgen: if boardsgen:
@ -1253,11 +1256,8 @@ def package ():
if packagegen: if packagegen:
pkgfname_read = pkgfname + '.orig' pkgfname_read = pkgfname + '.orig'
# check if backup already exists
if os.path.isfile(pkgfname_read): if os.path.isfile(pkgfname_read):
print "package file is in the way, please move it" os.remove(pkgfname_read)
print " %s" % pkgfname_read
sys.exit(1)
os.rename(pkgfname, pkgfname_read) os.rename(pkgfname, pkgfname_read)
# read package file # read package file
@ -1333,6 +1333,8 @@ def usage (name,ret):
print " --speed s - change default serial speed" print " --speed s - change default serial speed"
print " --customspeed s - new serial speed for all boards" print " --customspeed s - new serial speed for all boards"
print " --nofloat - disable float support in printf/scanf" print " --nofloat - disable float support in printf/scanf"
print " --noextra4kheap - disable extra 4k heap (will enable WPS)"
print " --allowWPS - synonym for --noextra4kheap"
print "" print ""
print " mandatory option (at least one):" print " mandatory option (at least one):"
print "" print ""
@ -1376,6 +1378,7 @@ default_speed = '115'
led_default = 2 led_default = 2
led_max = 16 led_max = 16
nofloat = False nofloat = False
noextra4kheap = False
ldgen = False ldgen = False
ldshow = False ldshow = False
boardsgen = False boardsgen = False
@ -1391,6 +1394,7 @@ customspeeds = []
try: try:
opts, args = getopt.getopt(sys.argv[1:], "h", opts, args = getopt.getopt(sys.argv[1:], "h",
[ "help", "lwip=", "led=", "speed=", "board=", "customspeed=", "nofloat", [ "help", "lwip=", "led=", "speed=", "board=", "customspeed=", "nofloat",
"noextra4kheap", "allowWPS",
"ld", "ldgen", "boards", "boardsgen", "package", "packagegen", "doc", "docgen", "ld", "ldgen", "boards", "boardsgen", "package", "packagegen", "doc", "docgen",
"allgen"] ) "allgen"] )
except getopt.GetoptError as err: except getopt.GetoptError as err:
@ -1434,6 +1438,9 @@ for o, a in opts:
elif o in ("--nofloat"): elif o in ("--nofloat"):
nofloat=True nofloat=True
elif o in ("--noextra4kheap", "--allowWPS"):
noextra4kheap=True
elif o in ("--ldshow"): elif o in ("--ldshow"):
ldshow = True ldshow = True

View File

@ -575,13 +575,27 @@ enum wps_cb_status {
WPS_CB_ST_UNK, 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_enable(WPS_TYPE_t wps_type);
bool wifi_wps_disable(void); bool wifi_wps_disable(void);
bool wifi_wps_start(void); bool wifi_wps_start(void);
typedef void (*wps_st_cb_t)(int status);
bool wifi_set_wps_cb(wps_st_cb_t cb); 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); typedef void (*freedom_outside_cb_t)(uint8 status);
int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb); int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb);
void wifi_unregister_send_pkt_freedom_cb(void); void wifi_unregister_send_pkt_freedom_cb(void);