From 8cc536bb7fe87f626a43cfb3261fc72ae8a7ad59 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 21 Oct 2022 13:20:16 +0300 Subject: [PATCH 01/12] PicoW start_ap() --- ports/raspberrypi/common-hal/wifi/Radio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index 3e95ae5cd1..f05215a131 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -168,7 +168,10 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { } void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) { - mp_raise_NotImplementedError(NULL); + if (!common_hal_wifi_radio_get_enabled(self)) { + mp_raise_RuntimeError(translate("wifi is not enabled")); + } + cyw43_arch_enable_ap_mode((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK); bindings_cyw43_wifi_enforce_pm(); } From 7a50beb67e92ba326177540a00e12081aeedfa54 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 22 Oct 2022 11:58:44 +0300 Subject: [PATCH 02/12] PicoW more ap work --- ports/raspberrypi/common-hal/wifi/Radio.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index f05215a131..9c2dea85c7 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -171,12 +171,17 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("wifi is not enabled")); } + // Is there a better way? + common_hal_wifi_radio_stop_station(self); + cyw43_arch_enable_ap_mode((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK); + // TODO: Implement authmode check like in espressif bindings_cyw43_wifi_enforce_pm(); } void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) { - mp_raise_NotImplementedError(NULL); + common_hal_wifi_radio_stop_station(self); + // I mean, since it already does both.. } wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) { @@ -188,8 +193,12 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t uint64_t start = port_get_raw_ticks(NULL); uint64_t deadline = start + timeout_ms; + // disconnect + common_hal_wifi_radio_stop_station(self); + // connect cyw43_arch_wifi_connect_async((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK); + // TODO: Implement authmode check like in espressif while (port_get_raw_ticks(NULL) < deadline) { RUN_BACKGROUND_TASKS; From 8fdb2df0bf4ff6759e1b1ca5c8511f2531ece1f2 Mon Sep 17 00:00:00 2001 From: paul-1 <6473457+paul-1@users.noreply.github.com> Date: Sat, 29 Oct 2022 10:22:58 -0400 Subject: [PATCH 03/12] picow: enable dhcpserver for apmode. --- ports/raspberrypi/Makefile | 4 +++- shared/netutils/dhcpserver.c | 2 +- shared/netutils/netutils.h | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 5095c4c1f8..d7373642b3 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -65,7 +65,7 @@ INC_CYW43 := \ -isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \ -isystem sdk/src/rp2_common/pico_lwip/include/ \ -CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DIGNORE_GPIO23 -DIGNORE_GPIO24 -DCYW43_LOGIC_DEBUG=0 +CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DIGNORE_GPIO23 -DIGNORE_GPIO24 -DCYW43_LOGIC_DEBUG=0 -DCYW43_NETUTILS=1 SRC_SDK_CYW43 := \ src/common/pico_sync/sem.c \ src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \ @@ -76,6 +76,8 @@ SRC_SDK_CYW43 := \ SRC_LWIP := \ shared/netutils/netutils.c \ + shared/netutils/trace.c \ + shared/netutils/dhcpserver.c \ $(wildcard lib/lwip/src/core/*.c) \ $(wildcard lib/lwip/src/core/ipv4/*.c) \ lib/lwip/src/netif/ethernet.c \ diff --git a/shared/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c index 9db42b3fd9..a61501c93c 100644 --- a/shared/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -33,7 +33,7 @@ #include "py/mperrno.h" #include "py/mphal.h" -#if MICROPY_PY_LWIP +#if LWIP_UDP #include "shared/netutils/dhcpserver.h" #include "lwip/udp.h" diff --git a/shared/netutils/netutils.h b/shared/netutils/netutils.h index b23a78e5b8..3bb9212800 100644 --- a/shared/netutils/netutils.h +++ b/shared/netutils/netutils.h @@ -33,6 +33,8 @@ #define NETUTILS_TRACE_PAYLOAD (0x0002) #define NETUTILS_TRACE_NEWLINE (0x0004) +#include "py/runtime.h" + typedef enum _netutils_endian_t { NETUTILS_LITTLE, NETUTILS_BIG, From 851c2cd8cb691587e53b874752e92ee14a04ae6c Mon Sep 17 00:00:00 2001 From: paul-1 <6473457+paul-1@users.noreply.github.com> Date: Sat, 29 Oct 2022 15:20:10 -0400 Subject: [PATCH 04/12] picow: Add channel setting when starting AP --- ports/raspberrypi/common-hal/wifi/Radio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index 9c2dea85c7..1c92aaea87 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -174,6 +174,10 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ // Is there a better way? common_hal_wifi_radio_stop_station(self); + // Channel can only be changed after inital powerup and config of ap. + // Defaults to 1 if not set or invalid (i.e. 13) + cyw43_wifi_ap_set_channel(&cyw43_state, (const uint32_t)channel); + cyw43_arch_enable_ap_mode((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK); // TODO: Implement authmode check like in espressif bindings_cyw43_wifi_enforce_pm(); From 11f1174658dbbfae9f8b257feda894befa774113 Mon Sep 17 00:00:00 2001 From: paul-1 <6473457+paul-1@users.noreply.github.com> Date: Sat, 29 Oct 2022 15:30:57 -0400 Subject: [PATCH 05/12] picow: Change init to use country code routine.....place holder for future improvements to allow country code setting. --- ports/raspberrypi/supervisor/port.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 781d2b11d2..be7afcac86 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -140,7 +140,9 @@ safe_mode_t port_init(void) { never_reset_pin_number(24); never_reset_pin_number(25); never_reset_pin_number(29); - if (cyw43_arch_init()) { + // Change this as a placeholder as to how to init with country code. + // Default country code is CYW43_COUNTRY_WORLDWIDE) + if (cyw43_arch_init_with_country(PICO_CYW43_ARCH_DEFAULT_COUNTRY_CODE)) { serial_write("WiFi init failed\n"); } else { cyw_ever_init = true; From b8cd6c093fa25ba650a79a64ce83491607f80691 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 17 Nov 2022 21:47:39 +0200 Subject: [PATCH 06/12] picow-ap progress --- locale/circuitpython.pot | 18 ++++++++-- ports/raspberrypi/common-hal/wifi/Radio.c | 40 ++++++++++++++++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 044900bd30..2d759d8cbe 100755 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -106,7 +106,7 @@ msgstr "" msgid "%q in use" msgstr "" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "" @@ -171,7 +171,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -397,6 +397,10 @@ msgstr "" msgid "ADC2 is being used by WiFi" msgstr "" +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "AP cannot be stopped." +msgstr "" + #: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c #, c-format msgid "Address must be %d bytes long" @@ -478,10 +482,18 @@ msgstr "" msgid "Already advertising." msgstr "" +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "Already connected to station." +msgstr "" + #: ports/atmel-samd/common-hal/canio/Listener.c msgid "Already have all-matches listener" msgstr "" +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "Already in access point mode." +msgstr "" + #: ports/espressif/common-hal/coproc/__init__.c #: shared-module/memorymonitor/AllocationAlarm.c #: shared-module/memorymonitor/AllocationSize.c @@ -3153,7 +3165,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index b70543a43c..ea0cde78bc 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -155,12 +155,11 @@ void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) { } void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { + + // This is wrong This is fine. cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); - // This is wrong, but without this call the state of ITF_STA is still - // reported as CYW43_LINK_JOIN (by wifi_link_status) and CYW43_LINK_UP - // (by tcpip_link_status). Until AP support is added, we can ignore the - // problem. cyw43_wifi_leave(&cyw43_state, CYW43_ITF_AP); + bindings_cyw43_wifi_enforce_pm(); } @@ -168,21 +167,41 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("wifi is not enabled")); } - // Is there a better way? - common_hal_wifi_radio_stop_station(self); + + if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_STA) != CYW43_LINK_DOWN) { + mp_raise_RuntimeError(translate("Already connected to station.")); + } + + common_hal_wifi_radio_stop_ap(self); // Channel can only be changed after inital powerup and config of ap. // Defaults to 1 if not set or invalid (i.e. 13) cyw43_wifi_ap_set_channel(&cyw43_state, (const uint32_t)channel); cyw43_arch_enable_ap_mode((const char *)ssid, (const char *)password, CYW43_AUTH_WPA2_AES_PSK); + // TODO: Implement authmode check like in espressif bindings_cyw43_wifi_enforce_pm(); } void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) { - common_hal_wifi_radio_stop_station(self); - // I mean, since it already does both.. + if (!common_hal_wifi_radio_get_enabled(self)) { + mp_raise_RuntimeError(translate("wifi is not enabled")); + } + + if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_AP) != CYW43_LINK_DOWN) { + mp_raise_NotImplementedError(translate("AP cannot be stopped.")); + } + + /* + * AP cannot be disconnected. cyw43_wifi_leave is broken. + * This code snippet should work, but doesn't. + * + * cyw43_wifi_leave(&cyw43_state, CYW43_ITF_AP); + * cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); + * + * bindings_cyw43_wifi_enforce_pm(); + */ } wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) { @@ -190,6 +209,11 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t mp_raise_RuntimeError(translate("wifi is not enabled")); } + if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_AP) != CYW43_LINK_DOWN) { + mp_raise_RuntimeError(translate("Already in access point mode.")); + } + + size_t timeout_ms = timeout <= 0 ? 8000 : (size_t)MICROPY_FLOAT_C_FUN(ceil)(timeout * 1000); uint64_t start = port_get_raw_ticks(NULL); uint64_t deadline = start + timeout_ms; From 88bd9ef6b8207b9835d60e5c590faa04e46d4895 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 18 Nov 2022 22:51:05 +0200 Subject: [PATCH 07/12] just change the ap error --- locale/circuitpython.pot | 8 ++++---- ports/raspberrypi/common-hal/wifi/Radio.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 2d759d8cbe..c91b425ef5 100755 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -397,10 +397,6 @@ msgstr "" msgid "ADC2 is being used by WiFi" msgstr "" -#: ports/raspberrypi/common-hal/wifi/Radio.c -msgid "AP cannot be stopped." -msgstr "" - #: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c #, c-format msgid "Address must be %d bytes long" @@ -1979,6 +1975,10 @@ msgstr "" msgid "Stereo right must be on PWM channel B" msgstr "" +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "Stopping AP is not supported." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c msgid "Supply at least one UART pin" msgstr "" diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index ea0cde78bc..a3a8f8ec12 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -190,7 +190,7 @@ void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) { } if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_AP) != CYW43_LINK_DOWN) { - mp_raise_NotImplementedError(translate("AP cannot be stopped.")); + mp_raise_NotImplementedError(translate("Stopping AP is not supported.")); } /* From b40facd0b42ecfaffc5f9fb084a49b050a3bf6a2 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Tue, 22 Nov 2022 01:00:34 +0200 Subject: [PATCH 08/12] Error msg changes --- locale/circuitpython.pot | 20 ++++++++++++-------- ports/raspberrypi/common-hal/wifi/Radio.c | 10 +++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index c91b425ef5..2af9257feb 100755 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -478,18 +478,10 @@ msgstr "" msgid "Already advertising." msgstr "" -#: ports/raspberrypi/common-hal/wifi/Radio.c -msgid "Already connected to station." -msgstr "" - #: ports/atmel-samd/common-hal/canio/Listener.c msgid "Already have all-matches listener" msgstr "" -#: ports/raspberrypi/common-hal/wifi/Radio.c -msgid "Already in access point mode." -msgstr "" - #: ports/espressif/common-hal/coproc/__init__.c #: shared-module/memorymonitor/AllocationAlarm.c #: shared-module/memorymonitor/AllocationSize.c @@ -2363,6 +2355,18 @@ msgstr "" msgid "Wi-Fi: " msgstr "" +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "Wifi is in access point mode." +msgstr "" + +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "Wifi is in station mode." +msgstr "" + +#: ports/raspberrypi/common-hal/wifi/Radio.c +msgid "Wifi is not enabled" +msgstr "" + #: main.c msgid "Woken up by alarm.\n" msgstr "" diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index a3a8f8ec12..55b9fc7b95 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -134,7 +134,7 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self, u mp_raise_RuntimeError(translate("Already scanning for wifi networks")); } if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); + mp_raise_RuntimeError(translate("Wifi is not enabled")); } wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t); scan->base.type = &wifi_scannednetworks_type; @@ -165,11 +165,11 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) { if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); + mp_raise_RuntimeError(translate("Wifi is not enabled")); } if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_STA) != CYW43_LINK_DOWN) { - mp_raise_RuntimeError(translate("Already connected to station.")); + mp_raise_RuntimeError(translate("Wifi is in station mode.")); } common_hal_wifi_radio_stop_ap(self); @@ -206,11 +206,11 @@ void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) { wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) { if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); + mp_raise_RuntimeError(translate("Wifi is not enabled")); } if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_AP) != CYW43_LINK_DOWN) { - mp_raise_RuntimeError(translate("Already in access point mode.")); + mp_raise_RuntimeError(translate("Wifi is in access point mode.")); } From 44d5326d4cbc21d93649b7221ee7c8444e6e8f1b Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 30 Nov 2022 19:36:00 +0200 Subject: [PATCH 09/12] fix picow-ap --- ports/raspberrypi/common-hal/wifi/Radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index fcedcb2ce2..0459841b47 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -162,7 +162,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { bindings_cyw43_wifi_enforce_pm(); } -void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) { +void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint32_t authmodes, uint8_t max_connections) { if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("Wifi is not enabled")); } From f8070d2141500e7f21021297e773b2f6fff1f6ab Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 30 Nov 2022 21:51:50 +0200 Subject: [PATCH 10/12] Change comment, and logic on dhcpserver --- ports/raspberrypi/common-hal/wifi/Radio.c | 5 ++++- shared/netutils/dhcpserver.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index 0459841b47..313363dd32 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -155,8 +155,11 @@ void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) { void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { - // This is wrong This is fine. cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); + // This is wrong, but without this call the state of ITF_STA is still + // reported as CYW43_LINK_JOIN (by wifi_link_status) and CYW43_LINK_UP + // (by tcpip_link_status). However since ap disconnection isn't working + // either, this is not an issue. cyw43_wifi_leave(&cyw43_state, CYW43_ITF_AP); bindings_cyw43_wifi_enforce_pm(); diff --git a/shared/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c index a61501c93c..d396a2ba56 100644 --- a/shared/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -265,9 +265,9 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, d->lease[yi].expiry = (mp_hal_ticks_ms() + DEFAULT_LEASE_TIME_S * 1000) >> 16; dhcp_msg.yiaddr[3] = DHCPS_BASE_IP + yi; opt_write_u8(&opt, DHCP_OPT_MSG_TYPE, DHCPACK); - printf("DHCPS: client connected: MAC=%02x:%02x:%02x:%02x:%02x:%02x IP=%u.%u.%u.%u\n", + LWIP_DEBUGF(DHCP_DEBUG, ("DHCPS: client connected: MAC=%02x:%02x:%02x:%02x:%02x:%02x IP=%u.%u.%u.%u\n", dhcp_msg.chaddr[0], dhcp_msg.chaddr[1], dhcp_msg.chaddr[2], dhcp_msg.chaddr[3], dhcp_msg.chaddr[4], dhcp_msg.chaddr[5], - dhcp_msg.yiaddr[0], dhcp_msg.yiaddr[1], dhcp_msg.yiaddr[2], dhcp_msg.yiaddr[3]); + dhcp_msg.yiaddr[0], dhcp_msg.yiaddr[1], dhcp_msg.yiaddr[2], dhcp_msg.yiaddr[3])); break; } From 0738d50834afc46f75a94c52910a0d0672b4124f Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 30 Nov 2022 22:24:21 +0200 Subject: [PATCH 11/12] debug_dhcp to follow general debug --- ports/raspberrypi/lwip_inc/lwipopts.h | 1 - shared/netutils/dhcpserver.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/lwip_inc/lwipopts.h b/ports/raspberrypi/lwip_inc/lwipopts.h index 6d116e89b6..64b8cffff3 100644 --- a/ports/raspberrypi/lwip_inc/lwipopts.h +++ b/ports/raspberrypi/lwip_inc/lwipopts.h @@ -95,7 +95,6 @@ #define TCPIP_DEBUG LWIP_DBG_OFF #define PPP_DEBUG LWIP_DBG_OFF #define SLIP_DEBUG LWIP_DBG_OFF -#define DHCP_DEBUG LWIP_DBG_OFF #define MDNS_DEBUG LWIP_DBG_OFF #define LWIP_TIMEVAL_PRIVATE 0 diff --git a/shared/netutils/dhcpserver.h b/shared/netutils/dhcpserver.h index 2349d2ea42..45ceaf9a87 100644 --- a/shared/netutils/dhcpserver.h +++ b/shared/netutils/dhcpserver.h @@ -31,6 +31,10 @@ #define DHCPS_BASE_IP (16) #define DHCPS_MAX_IP (8) +#ifndef DHCP_DEBUG +#define DHCP_DEBUG LWIP_DBG_ON +#endif + typedef struct _dhcp_server_lease_t { uint8_t mac[6]; uint16_t expiry; From 3fb4fd81e9afd4a129b86a1247816fc07f3b98c7 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 30 Nov 2022 22:44:18 +0200 Subject: [PATCH 12/12] Revert "debug_dhcp to follow general debug" --- ports/raspberrypi/lwip_inc/lwipopts.h | 1 + shared/netutils/dhcpserver.h | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/ports/raspberrypi/lwip_inc/lwipopts.h b/ports/raspberrypi/lwip_inc/lwipopts.h index 64b8cffff3..6d116e89b6 100644 --- a/ports/raspberrypi/lwip_inc/lwipopts.h +++ b/ports/raspberrypi/lwip_inc/lwipopts.h @@ -95,6 +95,7 @@ #define TCPIP_DEBUG LWIP_DBG_OFF #define PPP_DEBUG LWIP_DBG_OFF #define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF #define MDNS_DEBUG LWIP_DBG_OFF #define LWIP_TIMEVAL_PRIVATE 0 diff --git a/shared/netutils/dhcpserver.h b/shared/netutils/dhcpserver.h index 45ceaf9a87..2349d2ea42 100644 --- a/shared/netutils/dhcpserver.h +++ b/shared/netutils/dhcpserver.h @@ -31,10 +31,6 @@ #define DHCPS_BASE_IP (16) #define DHCPS_MAX_IP (8) -#ifndef DHCP_DEBUG -#define DHCP_DEBUG LWIP_DBG_ON -#endif - typedef struct _dhcp_server_lease_t { uint8_t mac[6]; uint16_t expiry;