2016-10-03 08:42:28 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Dius Computing Pty Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* - Neither the name of the copyright holders nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @author Johny Mattsson <jmattsson@dius.com.au>
|
|
|
|
*/
|
|
|
|
#include "module.h"
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "lextra.h"
|
|
|
|
#include "wifi_common.h"
|
Initial support for ESP32-C6 and ESP32-H2, plus assorted fixes & improvements (#3646)
* Proof-of-concept multi-type console support via stdio
* Address crashes on linput's use of printf.
On an empty line input, a C3 with UART console would panic while attempting
to output the new Lua prompt. The backtrace shows a xQueueSemaphoreTake
with uxItemSize==0 as the panic cause, deep inside the uart driver, invoked
via vfs_uart and vfs_console layers, from printf.
Similarly, the printf for outputting a backspace/erase sequence would also
trigger a panic.
This workaround (of not mixing fflush() with printf) is likely merely hiding
a deeper issue, but it appears to be consistent. Plus, printf with no args
and a user-supplied format string is a no-no and should be fixed anyway.
* Work around IDF inconsistency with stdout buffering.
* Increase console task stack size.
Seems on Xtensa it ended up not being enough.
* Switch to single-byte console reads.
* Stop cheating and feed Lua from the right context.
* Work around IDF buffering stdout even when told not to, on ACM consoles.
* Initial build support for esp32c6.
Plus fixup of module selection for a variety of targets.
* Update github actions to node 20 versions.
* Update github build to deal with Lua 5.3 being default.
* Address fatal compiler warning.
Newer IDF toolchain is stricter, and we'd apparently failed to build test
the Lua-5.1 path for some time.
* Initial build support for esp32h2.
* Upgrade IDF to v5.1.3
* Fix left-over incorrect type in uzlib.
* Avoid null pointer crashes when debugging startup.
* Workaround for using wifi module on S2 with USB-CDC console.
---------
Co-authored-by: Jade Mattsson <github@frozenlogic.org>
2024-04-26 23:35:22 +02:00
|
|
|
#include "task/task.h"
|
2016-10-04 08:40:06 +02:00
|
|
|
|
|
|
|
static int wifi_getmode (lua_State *L)
|
|
|
|
{
|
|
|
|
wifi_mode_t mode;
|
|
|
|
esp_err_t err = esp_wifi_get_mode (&mode);
|
|
|
|
if (err != ESP_OK)
|
|
|
|
return luaL_error (L, "failed to get mode, code %d", err);
|
|
|
|
lua_pushinteger (L, mode);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-03 02:57:45 +01:00
|
|
|
static int wifi_getchannel (lua_State *L)
|
|
|
|
{
|
|
|
|
uint8_t primary;
|
|
|
|
wifi_second_chan_t secondary;
|
|
|
|
esp_err_t err = esp_wifi_get_channel (&primary, &secondary);
|
|
|
|
if (err != ESP_OK)
|
|
|
|
return luaL_error (L, "failed to get channel, code %d", err);
|
|
|
|
lua_pushinteger (L, primary);
|
|
|
|
lua_pushinteger (L, secondary);
|
|
|
|
return 2;
|
|
|
|
}
|
2016-10-04 08:40:06 +02:00
|
|
|
|
|
|
|
static int wifi_mode (lua_State *L)
|
2016-10-03 08:42:28 +02:00
|
|
|
{
|
|
|
|
int mode = luaL_checkinteger (L, 1);
|
|
|
|
bool save = luaL_optbool (L, 2, DEFAULT_SAVE);
|
|
|
|
SET_SAVE_MODE(save);
|
|
|
|
esp_err_t err;
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case WIFI_MODE_NULL:
|
|
|
|
case WIFI_MODE_STA:
|
|
|
|
case WIFI_MODE_AP:
|
|
|
|
case WIFI_MODE_APSTA:
|
|
|
|
return ((err = esp_wifi_set_mode (mode)) == ESP_OK) ?
|
|
|
|
0 : luaL_error (L, "failed to set mode, code %d", err);
|
|
|
|
default:
|
|
|
|
return luaL_error (L, "invalid wifi mode %d", mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wifi_start (lua_State *L)
|
|
|
|
{
|
|
|
|
esp_err_t err = esp_wifi_start ();
|
|
|
|
return (err == ESP_OK) ?
|
|
|
|
0 : luaL_error(L, "failed to start wifi, code %d", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-04 08:40:06 +02:00
|
|
|
static int wifi_stop (lua_State *L)
|
|
|
|
{
|
|
|
|
esp_err_t err = esp_wifi_stop ();
|
|
|
|
return (err == ESP_OK) ?
|
|
|
|
0 : luaL_error (L, "failed to stop wifi, code %d", err);
|
|
|
|
}
|
|
|
|
|
2016-12-10 05:25:57 +01:00
|
|
|
extern void wifi_ap_init (void);
|
|
|
|
extern void wifi_sta_init (void);
|
2016-10-03 08:42:28 +02:00
|
|
|
static int wifi_init (lua_State *L)
|
|
|
|
{
|
2016-12-10 05:25:57 +01:00
|
|
|
wifi_ap_init ();
|
2021-07-20 10:18:21 +02:00
|
|
|
wifi_sta_init ();
|
2016-10-04 08:40:06 +02:00
|
|
|
|
Initial support for ESP32-C6 and ESP32-H2, plus assorted fixes & improvements (#3646)
* Proof-of-concept multi-type console support via stdio
* Address crashes on linput's use of printf.
On an empty line input, a C3 with UART console would panic while attempting
to output the new Lua prompt. The backtrace shows a xQueueSemaphoreTake
with uxItemSize==0 as the panic cause, deep inside the uart driver, invoked
via vfs_uart and vfs_console layers, from printf.
Similarly, the printf for outputting a backspace/erase sequence would also
trigger a panic.
This workaround (of not mixing fflush() with printf) is likely merely hiding
a deeper issue, but it appears to be consistent. Plus, printf with no args
and a user-supplied format string is a no-no and should be fixed anyway.
* Work around IDF inconsistency with stdout buffering.
* Increase console task stack size.
Seems on Xtensa it ended up not being enough.
* Switch to single-byte console reads.
* Stop cheating and feed Lua from the right context.
* Work around IDF buffering stdout even when told not to, on ACM consoles.
* Initial build support for esp32c6.
Plus fixup of module selection for a variety of targets.
* Update github actions to node 20 versions.
* Update github build to deal with Lua 5.3 being default.
* Address fatal compiler warning.
Newer IDF toolchain is stricter, and we'd apparently failed to build test
the Lua-5.1 path for some time.
* Initial build support for esp32h2.
* Upgrade IDF to v5.1.3
* Fix left-over incorrect type in uzlib.
* Avoid null pointer crashes when debugging startup.
* Workaround for using wifi module on S2 with USB-CDC console.
---------
Co-authored-by: Jade Mattsson <github@frozenlogic.org>
2024-04-26 23:35:22 +02:00
|
|
|
#if defined(CONFIG_ESP_CONSOLE_USB_CDC)
|
2024-10-14 09:59:31 +02:00
|
|
|
// For some unknown reason, on an S2 with USB CDC console enabled, if we allow
|
|
|
|
// the esp_wifi_init() to run during initial startup, something Bad(tm)
|
|
|
|
// happens and the S2 fails to enumerate on the USB bus. However, if we defer
|
|
|
|
// it by half a second or so, everything works. This is an ugly workaround,
|
|
|
|
// but I'm out of ideas at this point.
|
|
|
|
vTaskDelay(CONFIG_NODEMCU_CMODULE_WIFI_STARTUP_DELAY / portTICK_PERIOD_MS);
|
Initial support for ESP32-C6 and ESP32-H2, plus assorted fixes & improvements (#3646)
* Proof-of-concept multi-type console support via stdio
* Address crashes on linput's use of printf.
On an empty line input, a C3 with UART console would panic while attempting
to output the new Lua prompt. The backtrace shows a xQueueSemaphoreTake
with uxItemSize==0 as the panic cause, deep inside the uart driver, invoked
via vfs_uart and vfs_console layers, from printf.
Similarly, the printf for outputting a backspace/erase sequence would also
trigger a panic.
This workaround (of not mixing fflush() with printf) is likely merely hiding
a deeper issue, but it appears to be consistent. Plus, printf with no args
and a user-supplied format string is a no-no and should be fixed anyway.
* Work around IDF inconsistency with stdout buffering.
* Increase console task stack size.
Seems on Xtensa it ended up not being enough.
* Switch to single-byte console reads.
* Stop cheating and feed Lua from the right context.
* Work around IDF buffering stdout even when told not to, on ACM consoles.
* Initial build support for esp32c6.
Plus fixup of module selection for a variety of targets.
* Update github actions to node 20 versions.
* Update github build to deal with Lua 5.3 being default.
* Address fatal compiler warning.
Newer IDF toolchain is stricter, and we'd apparently failed to build test
the Lua-5.1 path for some time.
* Initial build support for esp32h2.
* Upgrade IDF to v5.1.3
* Fix left-over incorrect type in uzlib.
* Avoid null pointer crashes when debugging startup.
* Workaround for using wifi module on S2 with USB-CDC console.
---------
Co-authored-by: Jade Mattsson <github@frozenlogic.org>
2024-04-26 23:35:22 +02:00
|
|
|
#endif
|
2024-10-14 09:59:31 +02:00
|
|
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
|
|
|
ESP_ERROR_CHECK(esp_wifi_init (&cfg));
|
|
|
|
|
Initial support for ESP32-C6 and ESP32-H2, plus assorted fixes & improvements (#3646)
* Proof-of-concept multi-type console support via stdio
* Address crashes on linput's use of printf.
On an empty line input, a C3 with UART console would panic while attempting
to output the new Lua prompt. The backtrace shows a xQueueSemaphoreTake
with uxItemSize==0 as the panic cause, deep inside the uart driver, invoked
via vfs_uart and vfs_console layers, from printf.
Similarly, the printf for outputting a backspace/erase sequence would also
trigger a panic.
This workaround (of not mixing fflush() with printf) is likely merely hiding
a deeper issue, but it appears to be consistent. Plus, printf with no args
and a user-supplied format string is a no-no and should be fixed anyway.
* Work around IDF inconsistency with stdout buffering.
* Increase console task stack size.
Seems on Xtensa it ended up not being enough.
* Switch to single-byte console reads.
* Stop cheating and feed Lua from the right context.
* Work around IDF buffering stdout even when told not to, on ACM consoles.
* Initial build support for esp32c6.
Plus fixup of module selection for a variety of targets.
* Update github actions to node 20 versions.
* Update github build to deal with Lua 5.3 being default.
* Address fatal compiler warning.
Newer IDF toolchain is stricter, and we'd apparently failed to build test
the Lua-5.1 path for some time.
* Initial build support for esp32h2.
* Upgrade IDF to v5.1.3
* Fix left-over incorrect type in uzlib.
* Avoid null pointer crashes when debugging startup.
* Workaround for using wifi module on S2 with USB-CDC console.
---------
Co-authored-by: Jade Mattsson <github@frozenlogic.org>
2024-04-26 23:35:22 +02:00
|
|
|
return 0;
|
2016-10-03 08:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-21 17:39:54 +02:00
|
|
|
extern LROT_TABLE(wifi_sta);
|
|
|
|
extern LROT_TABLE(wifi_ap);
|
2016-10-03 08:42:28 +02:00
|
|
|
|
2021-08-21 17:39:54 +02:00
|
|
|
LROT_BEGIN(wifi, NULL, 0)
|
2019-07-22 11:13:43 +02:00
|
|
|
LROT_FUNCENTRY( getchannel, wifi_getchannel )
|
|
|
|
LROT_FUNCENTRY( getmode, wifi_getmode )
|
|
|
|
LROT_FUNCENTRY( mode, wifi_mode )
|
|
|
|
LROT_FUNCENTRY( start, wifi_start )
|
|
|
|
LROT_FUNCENTRY( stop, wifi_stop )
|
2016-10-03 08:42:28 +02:00
|
|
|
|
2021-07-20 10:18:21 +02:00
|
|
|
LROT_TABENTRY ( sta, wifi_sta )
|
2019-07-22 11:13:43 +02:00
|
|
|
LROT_TABENTRY ( ap, wifi_ap )
|
2016-10-03 08:42:28 +02:00
|
|
|
|
|
|
|
|
2019-07-22 11:13:43 +02:00
|
|
|
LROT_NUMENTRY ( NULLMODE, WIFI_MODE_NULL )
|
|
|
|
LROT_NUMENTRY ( STATION, WIFI_MODE_STA )
|
|
|
|
LROT_NUMENTRY ( SOFTAP, WIFI_MODE_AP )
|
|
|
|
LROT_NUMENTRY ( STATIONAP, WIFI_MODE_APSTA )
|
2017-01-03 02:57:45 +01:00
|
|
|
|
2019-07-22 11:13:43 +02:00
|
|
|
LROT_NUMENTRY ( AUTH_OPEN, WIFI_AUTH_OPEN )
|
|
|
|
LROT_NUMENTRY ( AUTH_WEP, WIFI_AUTH_WEP )
|
|
|
|
LROT_NUMENTRY ( AUTH_WPA_PSK, WIFI_AUTH_WPA_PSK )
|
|
|
|
LROT_NUMENTRY ( AUTH_WPA2_PSK, WIFI_AUTH_WPA2_PSK )
|
|
|
|
LROT_NUMENTRY ( AUTH_WPA_WPA2_PSK, WIFI_AUTH_WPA_WPA2_PSK )
|
2021-07-28 11:09:19 +02:00
|
|
|
LROT_NUMENTRY ( AUTH_WPA2_ENTERPRISE, WIFI_AUTH_WPA2_ENTERPRISE )
|
|
|
|
LROT_NUMENTRY ( AUTH_WPA3_PSK, WIFI_AUTH_WPA3_PSK )
|
|
|
|
LROT_NUMENTRY ( AUTH_WPA2_WPA3_PSK, WIFI_AUTH_WPA2_WPA3_PSK )
|
|
|
|
LROT_NUMENTRY ( AUTH_WAPI_PSK, WIFI_AUTH_WAPI_PSK )
|
2017-01-03 02:57:45 +01:00
|
|
|
|
2022-12-21 04:50:27 +01:00
|
|
|
LROT_NUMENTRY ( SAE_PWE_UNSPECIFIED, WPA3_SAE_PWE_UNSPECIFIED )
|
|
|
|
LROT_NUMENTRY ( SAE_PWE_HUNT_AND_PECK, WPA3_SAE_PWE_HUNT_AND_PECK )
|
|
|
|
LROT_NUMENTRY ( SAE_PWE_HASH_TO_ELEMENT, WPA3_SAE_PWE_HASH_TO_ELEMENT )
|
|
|
|
LROT_NUMENTRY ( SAE_PWE_BOTH, WPA3_SAE_PWE_BOTH )
|
|
|
|
|
2019-07-22 11:13:43 +02:00
|
|
|
LROT_NUMENTRY ( STR_WIFI_SECOND_CHAN_NONE, WIFI_SECOND_CHAN_NONE )
|
|
|
|
LROT_NUMENTRY ( STR_WIFI_SECOND_CHAN_ABOVE, WIFI_SECOND_CHAN_ABOVE )
|
|
|
|
LROT_NUMENTRY ( STR_WIFI_SECOND_CHAN_BELOW, WIFI_SECOND_CHAN_BELOW )
|
|
|
|
LROT_END(wifi, NULL, 0)
|
2016-10-03 08:42:28 +02:00
|
|
|
|
2019-07-22 11:13:43 +02:00
|
|
|
NODEMCU_MODULE(WIFI, "wifi", wifi, wifi_init);
|