-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Networking: Add network constants to WLAN classes. #14015
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
Conversation
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14015 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 161 161
Lines 21200 21200
=======================================
Hits 20860 20860
Misses 340 340 ☔ View full report in Codecov by Sentry. |
a0ee4ea
to
1c617cf
Compare
59a005b
to
a1a45c0
Compare
I just noticed that esp8266 and esp32 have these constants named We'll need to make the cyw43 (and nina, esp-hosted) drivers match that. |
We've had those for a few years now, and there's many scripts out there that use them, if we must use the prefix // Network is not secured.
{ MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(NINA_SEC_OPEN) },
// Security type WEP (40 or 104).
{ MP_ROM_QSTR(MP_QSTR_WEP), MP_ROM_INT(NINA_SEC_WEP) },
// Network secured with WPA/WPA2 personal(PSK).
{ MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(NINA_SEC_WPA_PSK) }, |
You can keep the existing constants in the nina/esp-hosted But adding new ones, they should go in |
That would still break the networking scripts that have been using those constants, because the same scripts run on CYW43, Nina and ESP hosted. |
But cyw43 doesn't currently have any constants, so those scripts don't work on cyw43 at the moment. Is it possible to update the networking scripts to use |
That true, this PR is to make CYW43 compatible with the existing networking scripts by adding the missing constants. If we add different constants, existing scripts won't run and we'll need to change every other interface to match. Right now Nina, ESP hosted use those constants, and one more driver that's not in MicroPython (a WINC1500 very similar to Nina driver in structure).
I will have to change 3 network interfaces and some examples but it will still break user code. |
How will it break user code if the old constants are left as they are? You could also update the network scripts to try |
Do the network scripts currently work on |
The networking scripts expect those constants to be in Note if we add constants
No they don't but we don't support any ESP boards. |
Just discussing this with @jimmo and we may actually want to go the other way: move everything out of Also then need to move things like |
The main justification for the above is the way constants work elsewhere, e.g. |
There's one more issue with |
machine groups many modules, each one has its own constants, that aren't shared with any other module. |
It happens to me regularly that I type WLAN.STA_IF, because I expect it there. Just to remember that it's network.STA_IF, which seem not to be natural. So maybe there can be a period where both variants exist. |
If all constants are moved to one module, regardless of what that module is, instead of being split between |
a1a45c0
to
d6687ab
Compare
Note that stm32 and mimxrt already have
Similarly for |
It's true some drivers will not support all modes, and constants have different values, but that's not a big problem we can use an enum and map to the actual value in drivers and fail if security mode is not supported. I've pushed a change to move the constants to WLAN, they have to be duplicated in every driver. Note I used |
I think we should put the constants on the class. It keeps the constants grouped together where they belong and with the class that they are used for. There aren't going to be that many cases where there are common constants, eg WLAN and ETH have pretty much nothing in common.
Yes, I agree, the constants should start with
Yes... I think we should also move those constants to their class. And while we are moving them, we can rename them to Of course we would retain the old constants for backwards compatibility (eg until MicroPython 2.0). |
extmod/network_ninaw10.c
Outdated
// Network secured with WPA/WPA2 personal(PSK). | ||
{ MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(NINA_SEC_WPA_PSK) }, | ||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(NINA_SEC_WPA_PSK) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this mixed mode? SEC_WPA_WPA2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When starting the AP mode, it looks like only WEP is supported (in our driver, nina_start_ap
only supports the open and WEP constants).
But the command we send to the Nina doesn't actually specify the mode. Our driver and the Arduino driver use the same command (0x19, which they call SET_AP_PASSPHRASE_CMD
and document as WPA, and we call NINA_CMD_START_AP_WEP
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our driver and the Arduino driver use the same command
No we use different commands: https://github.com/micropython/micropython/blob/master/drivers/ninaw10/nina_wifi_drv.c#L402
It's seems that WPA is also supported in AP mode, in the firmware, but there's no command to actually connect use it. Maybe I will push a firmware update later to fix it.
Is this mixed mode?
SEC_WPA_WPA2
.
@dpgeorge The security mode is not set in station mode, it seems to connect to all modes, except for deprecated/unsecure ones like WEP.
Does this also mean that we should keep both |
d6687ab
to
7ad1518
Compare
b2fe570
to
fb7a597
Compare
Updated. I've kept the existing constants to maintain backwards compatibility. As for esp ports, the constants in |
fb7a597
to
08a6b3e
Compare
The default CYW43 WiFi AP settings were missing the security mode, leaving the AP in open mode by default. That's changed by this commit to use WPA/WPA2 by default. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Other constants such as `machine.Pin.OUT` are defined on the class that uses them, rather than at the module level. This commit makes that the case for WLAN network interfaces, adding IF_xxx and SEC_xxx constants. The SEC_xxx constants are named as such to match the `security` keyword that they are used with. And the IF_xxx constants have IF as a prefix so they are grouped together as names. This scheme of putting constants on the class means that only the available features (eg security configurations) are made available as constants. It also means that different network interfaces (eg WLAN vs LAN) can keep their own specific constants within their class, such as PHY_xxx for LAN. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Following the same change to extmod network interfaces. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Following the same change to extmod network interfaces. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
08a6b3e
to
e8dd519
Compare
Documentation, folks! As far as I can tell these are not documented anywhere. I'm happy to add documentation but it's not clear to me what is port-specific and what is general... This is a real example: I was trying to create a simple, secured AP on ESP32 recently and couldn't figure out the appropriate configuration. Old forum posts with now-obsolete items make things worse - so I think we need to add a little more to the docs. |
When ports register network interfaces they either uses network.LAN or network.WAN, with the exception of things like |
No description provided.