Skip to content
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

WPS functionality added #1694

Merged
merged 11 commits into from
Jan 9, 2017
Merged

WPS functionality added #1694

merged 11 commits into from
Jan 9, 2017

Conversation

FrankX0
Copy link
Contributor

@FrankX0 FrankX0 commented Jan 1, 2017

Fixes #1556 .

  • This PR is for the dev branch rather than for master.
  • This PR is compliant with the other contributing guidelines as well (if not, please describe why).
  • I have thoroughly tested my contribution.
  • The code changes are reflected in the documentation at docs/en/*.

Although there seems to be some opposition against using WPS, I still think it is worthwhile making it available to whomever wants to use it.
Please bare in mind that my software/Github skills are somewhat limited.
Looking forward to your comments/acceptance.

static int ICACHE_FLASH_ATTR wps_start(lua_State* L)
{
// retrieve callback arg (optional)
if (wps_callback_ref != LUA_NOREF)
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to do the test -- you can unref LUA_NOREF

@@ -68,6 +68,7 @@
//#define LUA_USE_MODULES_UCG
//#define LUA_USE_MODULES_WEBSOCKET
#define LUA_USE_MODULES_WIFI
#define LUA_USE_MODULES_WPS
Copy link
Member

Choose a reason for hiding this comment

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

This should default to OFF

FrankX0 and others added 3 commits January 1, 2017 21:46
- both WiFi and Wi-Fi are valid but we seem to have opted for WiFi (although not 100% consistently)
- we don't use "Errors" sections
- we omit the "Examples" section if they'd be trivial
@@ -0,0 +1,63 @@
# WPS Module
Copy link
Member

Choose a reason for hiding this comment

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

A reference to this file needs to be added to /mkdocs.yaml.

@marcelstoer
Copy link
Member

The CI build fails with

section .text will not fit in region iram1_0_seg

Looks like the fix that @djphoenix provided in #1566 didn't last long.

Fix whitespace
@marcelstoer
Copy link
Member

I don't mind having this available as an off-by-default module. However, I think we should prominently mention the security concerns our WiFi module maintainer @dnc40085 raised a long time ago in the docs.

@FrankX0
Copy link
Contributor Author

FrankX0 commented Jan 1, 2017

I guess we can add a statement to the WPS module documentation:

Use with caution: there are (serious) security concerns about using WPS.

@FrankX0
Copy link
Contributor Author

FrankX0 commented Jan 3, 2017

@marcelstoer, @djphoenix: any ideas how to fix the CI build error?

@marcelstoer
Copy link
Member

I don't, not my area of expertise 😞

@djphoenix
Copy link
Contributor

djphoenix commented Jan 4, 2017

Rebased this PR on current dev and built all-modules + ssl configuration. Build succeeds for integer version but fails for float.

After temporary increase iram0 segment size I tried to link binary again and it succeeds, and so size of iram is 0x8045 (69 bytes overflow).

For dev branch iram size is 0x7d45 (difference with wps is 768 bytes).

And the winner is...
libwps.a is placed in irom at most. But size of all symbols in text section is...

$ gobjdump -h sdk/esp_iot_sdk_v2.0.0/lib/libwps.a | grep ' .text' | awk '{print $3}' | grep -v 00000000
0000000b
000000aa
00000094
00000082
00000068
000000aa
$ node
> 0xb + 0xaa + 0x94 + 0x82 + 0x68 + 0xaa
733

Very close to what we see...

The solution is patch LD script as I was originally propose - keep only main, pp, phy, net80211 and gcc libs of SDK in iram. But I cannot guarantee that wps will keep work in irom. Cannot test this solution myself because in my router WPS completely disabled for security reasons.

@FrankX0
Copy link
Contributor Author

FrankX0 commented Jan 7, 2017

@djphoenix: I am willing to test, but it's not clear how to modify the current dev LD script.

@djphoenix
Copy link
Contributor

In ld/nodemcu.ld file, near line 105:

+    *libmain.a:*(.literal .text)
+    *libnet80211.a:*(.literal .text)
+    *libphy.a:*(.literal .text)
+    *libpp.a:*(.literal .text)
+    *libgcc.a:*(.literal .text)
-    *sdk/esp_iot_sdk_*lib/lib*.a:*(.literal .text)

@FrankX0
Copy link
Contributor Author

FrankX0 commented Jan 7, 2017

Thanks @djphoenix: no problems compiling.
WPS functionality still works OK.
I tested using the physical button implementation, not through PIN.
This I have disabled (for what it is worth).

Keep only main, pp, phy, net80211 and gcc libs of SDK in iram, and
therefore wps in irom.
// Lua: wps.disable()
static int ICACHE_FLASH_ATTR wps_disable(lua_State* L)
{
wifi_wps_disable();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be error handler, as far as wps-related functions (in includes) returns bool as success/failure status.

if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION)
wps_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
else
return luaL_error (L, "Argument not a function");
Copy link
Contributor

Choose a reason for hiding this comment

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

With luaL_checkanyfunction no needed to manually raise an error.
And so safer way is check arguments before any internal state change.


wps_callback_ref = LUA_NOREF;

if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION)
Copy link
Contributor

Choose a reason for hiding this comment

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

luaL_checkanyfunction should be there

wps_callback_ref = LUA_NOREF;

if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION)
wps_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
Copy link
Contributor

Choose a reason for hiding this comment

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

There will be issue when more than one argument is passed, so call lua_pushvalue(L, 1) before luaL_ref

*libnet80211.a:*(.literal .text)
*libphy.a:*(.literal .text)
*libpp.a:*(.literal .text)
*libgcc.a:*(.literal .text)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this change is outside this PR's scope.
@marcelstoer @jmattsson should we move it in another issue/PR or keep there?

Copy link
Member

@marcelstoer marcelstoer Jan 8, 2017

Choose a reason for hiding this comment

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

I prefer a dedicated PR. Once it's merged we can restart the CI build here.

Copy link
Member

Choose a reason for hiding this comment

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

I'm really wary of this change altogether. As you already pointed out Yury, Espressif has put almost everything into irom0.text, except for what appears to be a few internal pieces. Presumably they had a really good reason for keeping those in IRAM. Maybe it would be worthwhile raising the large iram1_0_seg size with Espressif as a potential bug? If they respond, we'd know for certain whether it has to be kept in IRAM or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jmattsson Johny, as I reviewed, a lot of Espressif code is a mess. I think there was some internal Espressif's issues e.g. "radius of the developers hands curvature does not comply with the platform requirements" :)
Anyway for WPS we decide that it works when fully putted in irom. And for most places it right (with exceptions for interrupts-related stuff). I haven't see any of interrupt-related code here.

Copy link
Member

Choose a reason for hiding this comment

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

Hah! Well I can't argue too strongly here seeing as I've used the "I've reviewed and tested it, and it works" argument myself in regard to flash vs ram.

Could we perhaps leave a comment in the nodemcu.ld file indicating that we're specifically excluding ilbwps.a due to size constraints?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jmattsson I think we should move this discussion to #1710.
For @FrankX0 - just revert this part, we will fix this issue in other way.

Copy link
Member

Choose a reason for hiding this comment

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

For @FrankX0 - just revert this part, we will fix this issue in other way.

The cool thing is that GitHub allows us to do that yourselves right in the browser. You can't revert but you can resolve conflicts by editing code - which is just did.

@marcelstoer
Copy link
Member

I'll add the doc amendment we talked about at #1694 (comment) after merging.

Thanks Frank, Yury and Johny.

@marcelstoer marcelstoer merged commit 378e5eb into nodemcu:dev Jan 9, 2017
@marcelstoer marcelstoer added this to the 2.0.0 milestone Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants