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

Address several ESP32 network driver issues #1137

Open
wants to merge 3 commits into
base: release-0.6
Choose a base branch
from

Conversation

UncleGrumpy
Copy link
Collaborator

@UncleGrumpy UncleGrumpy commented Apr 23, 2024

These changes close the following issues for the ESP32 network driver:

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

#ifdef CONFIG_AVM_ENABLE_NETWORK_PORT_DRIVER

REGISTER_PORT_DRIVER(network, network_driver_init, NULL, network_driver_create_port)
REGISTER_PORT_DRIVER(network, network_driver_init, network_driver_stop, network_driver_create_port)
Copy link
Collaborator

Choose a reason for hiding this comment

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

network_driver_stop will not be called when calling network:stop/0. It gets called during tests (when GlobalContext is destoryed and recreated).
So this change sounds correct, but it doesn't do what you are saying.

@UncleGrumpy UncleGrumpy marked this pull request as draft April 28, 2024 18:44
@UncleGrumpy UncleGrumpy force-pushed the esp32_network_issues branch 4 times, most recently from 908bd03 to 40b8959 Compare May 1, 2024 02:40
@UncleGrumpy
Copy link
Collaborator Author

Thank you for the explanation of the REGISTER_PORT_DRIVER destroy_cb in the Telegram chat, this did not work as advertised! I was also several missing steps, so even when the VM exited and the destroy_cb would execute this code, netif and IP callbacks would still be triggered.

These problems have all been fixed, and the driver shuts down and exits cleanly. There is still one ESP-IDF message (in some builds, depending on the IDF version) in the console logs that is being reported as an error:

E (8246) wifi:NAN WiFi stop

I looked into this and it is actually a known ESP-IDF issue, that will be changed to an information message in a future update. See espressif/esp-idf#12473.

@UncleGrumpy UncleGrumpy marked this pull request as ready for review May 1, 2024 03:03
@UncleGrumpy UncleGrumpy changed the title Address several ESP32 network issues Address several ESP32 network driver issues May 1, 2024
Removes several possible uses of free() on memory that had been previously free'd. This would
happen under specific error conditions in the `start_network` function in network_driver.c
that `network:start/1` uses to configure and start the network.

Signed-off-by: Winford <winford@object.stream>
…SP32

Adds a destroy callback to the ESP32 network driver to completely stop the
driver and free all network resources when network:stop/0 is used.  Previosly
the driver was not being stopped internally and resources were not freed when
the gen_server was stopped, causing instability, and possible crashes when
event callbacks were triggered, but there was no process alive to handle them.

Closes atomvm#643

Signed-off-by: Winford <winford@object.stream>
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants