Skip to content

esp8266/network_wlan: Allow bytes() objects as MAC address.#19282

Open
agatti wants to merge 1 commit into
micropython:masterfrom
agatti:esp8266-fix-macaddr
Open

esp8266/network_wlan: Allow bytes() objects as MAC address.#19282
agatti wants to merge 1 commit into
micropython:masterfrom
agatti:esp8266-fix-macaddr

Conversation

@agatti
Copy link
Copy Markdown
Contributor

@agatti agatti commented May 30, 2026

Summary

This PR fixes a crash occurring when setting the WLAN MAC address using a bytes() object containing the new MAC address bytes. This also fixes cases where the address is put in ROM or is an unaligned slice of a larger buffer.

The ESP8266's network stack seems to want the MAC address buffer being in a particular memory area and with a specific alignment, which cannot be always guaranteed. Luckily stack-allocated buffers do have the necessary requirements when it comes to location and alignment, so the MAC address is first copied into such a buffer and then that's passed to the network stack.

This fixes #11357.

Testing

The sample code fragments provided in #11357 were executed on a generic ESP8266 board, correctly setting the WLAN MAC address instead of crashing.

Trade-offs and Alternatives

This makes the firmware 76 bytes larger, which I believe is unavoidable in this case.

Generative AI

I did not use generative AI tools when creating this PR.

Comment thread ports/esp8266/network_wlan.c
This commit fixes a crash occurring when setting the WLAN MAC address
using a bytes() object containing the new MAC address bytes.  This also
fixes cases where the address is put in ROM or is an unaligned slice of
a larger buffer.

The ESP8266's network stack seems to want the MAC address buffer being
in a particular memory area and with a specific alignment, which cannot
be always guaranteed.  Luckily stack-allocated buffers do have the
necessary requirements when it comes to location and alignment, so the
MAC address is first copied into such a buffer and then that's passed to
the network stack.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@agatti agatti force-pushed the esp8266-fix-macaddr branch from 442abd0 to 4c02566 Compare May 31, 2026 12:33
Copy link
Copy Markdown
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

Thanks!

@octoprobe-bot
Copy link
Copy Markdown

octoprobe-bot commented Jun 1, 2026

Octoprobe PR report

Summary

Test Groups
run
Groups
skipped
Groups
retried
Tests
passed
Tests
skipped
Tests
xfailed
Tests
failed
RUN-FLASH_FORMAT 1 1
RUN-NATMODTESTS 1 3 38
RUN-PERFBENCH 2 36 10 2
RUN-TESTS_EXTMOD_HARDWARE_NATIVE 1 9
RUN-TESTS_EXTMOD_HARDWARE 1 1 8
RUN-TESTS_STANDARD_NATIVE 1 505 494 4 1
RUN-TESTS_STANDARD_VIA_MPY 1 845 158 1
RUN-TESTS_STANDARD 1 830 160 4
Total 9 2220 878 7 5

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.

Changing AP interface MAC address using bytes results in a crash, but bytearray works

3 participants