Wykres commitów

29 Commity (master)

Autor SHA1 Wiadomość Data
iabdalkader 7753045a8f extmod: Add interface and security constants at WLAN class level.
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>
2024-03-28 12:52:28 +11:00
Felix Dörre 1c6012b0b5 extmod/modnetwork: Implement IPv6 API to set and get NIC configuration.
This commit implements a new <AbstractNIC>.ipconfig() function for the NIC
classes that use lwIP, to set and retrieve network configuration for a NIC.
Currently this method supports:
- ipconfig("addr4"): obtain a tuple (addr, netmask) of the currently
  configured ipv4 address
- ipconfig("addr6"): obtain a list of tuples (addr, state,
  prefered_lifetime, valid_lifetime) of all currently active ipv6
  addresses; this includes static, slaac and link-local addresses
- ipconfig("has_dhcp4"): whether ipv4 dhcp has supplied an address
- ipconfig("has_autoconf6"): if there is a valid, non-static ipv6 address
- ipconfig(addr4="1.2.3.4/24"): to set the ipv4 address and netmask
- ipconfig(addr6="2a01::2"): to set a static ipv6 address; note that this
  does not configure an interface route, as this does not seem supported by
  lwIP
- ipconfig(autoconf6=True): to enable ipv6 network configuration with slaac
- ipconfig(gw4="1.2.3.1"): to set the ipv4 gateway
- ipconfig(dhcp4=True): enable ipv4 dhcp; this sets ipv4 address, netmask,
  gateway and a dns server
- ipconfig(dhcp4=False): stops dhcp, releases the ip, and clears the
  configured ipv4 address.
- ipconfig(dhcp6=True): enable stateless dhcpv6 to obtain a dns server

There is also a new global configuration function network.ipconfig() that
supports the following:
- network.ipconfig(dns="2a01::2"): set the primary dns server (can be a
  ipv4 or ipv6 address)
- network.ipconfig(prefer=6): to prefer ipv6 addresses to be returned as
  dns responses (falling back to ipv4 if the host does not have an ipv6
  address); note that this does not flush the dns cache, so if a host is
  already in the dns cache with its v4 address, subsequent lookups will
  return that address even if prefer=6 is set

This interface replaces NIC.ifconfig() completely, and ifconfig() should be
marked as deprecated and removed in a future version.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-03-19 16:42:10 +11:00
Angus Gratton decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a.  The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.

This STATIC feature is rarely (if ever) used.  And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.

So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing.  For example, newcomers don't have
to learn what the STATIC macro is and why it exists.  Reading the code is
also less "loud" with a lowercase static.

One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.

Methodology for this commit was:

1) git ls-files | egrep '\.[ch]$' | \
   xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"

2) Do some manual cleanup in the diff by searching for the word STATIC in
   comments and changing those back.

3) "git-grep STATIC docs/", manually fixed those cases.

4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07 14:20:42 +11:00
Felix Dörre 628abf8f25 extmod/modlwip: Support IPv6.
With these changes IPv6 works on the rp2 port (and possibly others that use
the lwIP socket implementation).

Things that have been tested and work:
- Neighbour solicitation for v6 link local address.
- Ping of v6 link-local address.
- Receiving a SLAAC address via router advertisement.
- Ping a v6 address allocated via SLAAC.
- Perform an outgoing connection to a routed v6-address (via default
  gateway).
- Create a listening IPv6 wildcard socked bound to ::, and trying to access
  it via link-local, SLAAC, and IPv4 (to ensure the dual-stack binding
  works).

Things that could be improved:
- socket.socket().getaddrinfo only returns the v4 address.  It could also
  return v6 addresses (getaddrinfo is actively programmed to only return a
  single address, and this is the v4-address by default, with fallback to
  the v6 address if both are enabled).

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-02-16 11:46:40 +11:00
Angus Gratton df3948d3c2 extmod: Switch to use new event functions.
See previous commit for details of these functions.  As of this commit,
these still call the old hook macros on all ports.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:48:50 +11:00
Jim Mussared 65a3ce39a3 extmod/modnetwork: Forward if.config(hostname) to network.hostname.
This removes the duplicate code in cyw43, esp32, esp8266 that implements
the same logic as network.hostname.

Renames the `mod_network_hostname` (where we store the hostname value in
`.data`) to `mod_network_hostname_data` to make way for calling the shared
function `mod_network_hostname`.

And uses memcpy for mod_network_hostname_data, because the length of source
is already known and removes reliance on string data being null-terminated.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-04 12:39:51 +11:00
Jim Mussared b329fdcb73 extmod/modnetwork: Increase max hostname length to 32.
This changes from the previous limit of 15 characters.  Although DHCP and
mDNS allow for up to 63, ESP32 and ESP8266 only allow 32, so this seems
like a reasonable limit to enforce across all ports (and avoids wasting the
additional memory).

Also clarifies that `MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN` does not include
the null terminator (which was unclear before).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-04 12:39:23 +11:00
Damien George a31e3de400 extmod/network_cyw43: Add power management constants.
And allow querying the current power management mode.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-08 11:56:31 +10:00
Oliver Joos f34af3e42e extmod/network_cyw43: Add support to get STA RSSI using status() method.
This enables the use of WLAN(0).status('rssi') to get current RSSI of the
AP that the STA is connected to.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-04 22:07:00 +10:00
Oliver Joos 11b5ee0d7c extmod/network_cyw43: Fix setting hostname using config() method.
This bug is probably a typo. args[0] is the cyw43 object itself.
While the value of a kwargs is in e->value.
2023-04-04 15:55:04 +10:00
Damien George 36ae5d3e87 extmod/network_cyw43: Use CYW43_CHANNEL_NONE for default arg in connect.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-01 01:28:17 +11:00
Jim Mussared bad0098a49 stm32: Update to use the open-source lib version of cyw43-driver.
This removes the previous WiFi driver from drivers/cyw43 (but leaves behind
the BT driver), and makes the stm32 port (i.e. PYBD and Portenta) use the
new "lib/cyw43-driver" open-source driver already in use by the rp2 port.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:27:12 +11:00
Jim Mussared a377302623 extmod/modnetwork: Add network.hostname() and network.country().
This provides a standard interface to setting the global networking config
for all interfaces and interface types.

For ports that already use either a static hostname (mimxrt, rp2) they will
now use the configured value. The default is configured by the port
(or optionally the board).

For interfaces that previously supported .config(hostname), this is still
supported but now implemented using the global network.hostname.

Similarly, pyb.country and rp2.country are now deprecated, but the methods
still exist (and forward to network.hostname).

Because ESP32/ESP8266 do not use extmod/modnetwork.c they are not affected
by this commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:26:17 +11:00
Damien George 699477d12d extmod/network_cyw43: Fix handling of networks with open security.
Prior to this commit, the default security=-1 would be passed directly
through to the cyw43 driver to auto-detect the security type, but that
driver did not correctly handle the case of open security.

The cyw43 driver has now been changed to no longer support auto-detection,
rather it is up to the caller to always select the security type.  The
defaults are now implemented in the Python bindings and are:
- if no key is given then it selects open security
- if a key is given then it selects WPA2_MIXED_PSK

Calling `wlan.connect(<ssid>)` will now connect to an open network, on
both rp2 and stm32 ports.  The form `wlan.connect(<ssid>, <key>)` will
connect to a WPA2 network.

Fixes issue #9016.

Signed-off-by: Damien George <damien@micropython.org>
2022-12-20 16:06:40 +11:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
iabdalkader 9dfabcd6d3 extmod/network_cyw43: Add hostname config option. 2022-08-06 00:30:57 +10:00
Damien George d660a0c3d1 extmod/network_cyw43: Add "security" config option to get/set auth mode.
Signed-off-by: Damien George <damien@micropython.org>
2022-07-05 11:05:13 +10:00
Damien George 7dd818052e extmod/network_cyw43: Support new cyw43-driver.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 14:10:58 +10:00
iabdalkader c502cf73e0 extmod/network_cyw43: Rename WLAN keyword args to ssid/security/key.
Rename WLAN keyword args to scan(), connect() and config() to be more
consistent across ports and WLAN drivers.  This change is backwards
compatible and will support obsolete keyword args, except for positional
"essid" which is now deprecated in favor of "ssid".

The changed argument names are
- "essid" changed to "ssid"
- "auth" or "authmode" changed to "security"
- "password" changed to "key"

Addresses issue #8083.
2022-06-17 21:43:25 +10:00
Damien George a34d43b2b7 extmod/network_cyw43: Make consistent use of STA and AP constants.
The network.STA_IF and network.AP_IF constants are now independent to the
CYW43_ITF_STA and CYW43_ITF_AP constants.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-15 01:37:27 +10:00
Damien George 30691ed2a1 drivers/cyw43: Make wifi join fail if interface is not active.
Otherwise the Python network object continues to report that it is
attempting to connect.

Also make the return error code consistent with wifi scan.

Signed-off-by: Damien George <damien@micropython.org>
2021-08-31 13:00:11 +10:00
stijn 84fa3312cf all: Format code to add space after C++-style comment start.
Note: the uncrustify configuration is explicitly set to 'add' instead of
'force' in order not to alter the comments which use extra spaces after //
as a means of indenting text for clarity.
2020-04-23 11:24:25 +10:00
Jim Mussared def76fe4d9 all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George 09376f0e47 py: Introduce MP_ROM_NONE macro for ROM to refer to None object.
This helps to prevent mistakes, and allows easily changing the ROM value of
None if needed.
2019-12-27 22:51:17 +11:00
Damien George c13f9f209d all: Convert nlr_raise(mp_obj_new_exception_msg(x)) to mp_raise_msg(x).
This helper function was added a while ago and these are the remaining
cases to convert, to save a bit of code size.
2019-11-05 11:35:45 +11:00
Damien George cf1c131f73 extmod: Add network-level class binding to cyw43 driver. 2019-06-03 16:47:35 +10:00