Skip to content

Claude/circuitpython dns sd wifi aware 7137cd - #45

Draft
tyeth wants to merge 30 commits into
mainfrom
claude/circuitpython-dns-sd-wifi-aware-7137cd
Draft

tyeth wants to merge 30 commits into
mainfrom
claude/circuitpython-dns-sd-wifi-aware-7137cd

Conversation

@tyeth

@tyeth tyeth commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

tyeth and others added 30 commits November 23, 2026 20:04
Adds a socketpool-based DNS-SD (RFC 6762/6763) browser in shared-module so
ports with an IP stack but no native mDNS library can implement `mdns.Server`
without a per-port responder. Selected with CIRCUITPY_MDNS_SHARED=1, which
filters common-hal/mdns out of the build and compiles the shared-module
sources in its place; shared-bindings/mdns/*.h pick the matching struct
definitions.

This is a browser only. `find()` works; `advertise_service()` raises
NotImplementedError, except on the web-workflow path where it stays silent so
the supervisor's own call is not a hard error. The supervisor path also must
not raise or allocate: `mdns_server_find()` wraps the call in nlr_push(), and
the receive buffer is static rather than GC-allocated.

Browser.c is a separate translation unit from Server.c on purpose. A port that
already has a native responder but no browser can add Browser.c alone to its
sources and call shared_module_mdns_find() from its own common-hal find(),
without dragging in a second set of common_hal_mdns_server_* definitions.

Parsing details worth noting: PTR matches check both the service-type and
protocol labels, SRV matches validate the whole owner name so two services on
one host cannot overwrite each other, A records are ignored for entries with no
hostname yet, and entries still missing a port get a follow-up SRV query at the
halfway point of the timeout for responders that do not send the full set
unprompted. The receive loop yields with mp_hal_delay_ms(1) when no packet is
pending instead of spinning.

Built and verified for raspberrypi (Pico W) both ways: with
CIRCUITPY_MDNS_SHARED=1 and with the port's existing common-hal/mdns, the
latter producing no shared-module/mdns objects and no size change.

zephyr-cp emits the flag from its builder when the port has no common-hal/mdns
of its own; that path is not yet exercised on hardware.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Working notes for tyeth/deepsleep_espnow_wifi_and_ble_env_collector#18: what
it would take to add DNS-SD and Wi-Fi Aware (NAN) to CircuitPython across
backends, and what the hardware actually does today.

Measured on rpi-hil006 against CircuitPython's pinned ESP-IDF v6.1-dev-6096:

- NAN-Sync works end to end. Cluster at 3.35 s from boot, service match
  4.40 s, IPv6 NDP datapath 4.93 s, then ICMPv6 over that datapath at 2 ms
  RTT with no loss. It is an exclusive radio mode (wifi:mode : NAN) and the
  NMI MAC is randomised at every start, so the peer's link-local address
  changes on every wake.

- NAN-USD transmits correctly but never discovers. Localised with a
  promiscuous capture running alongside the subscribe: the subscriber's own
  NIC counted 407 NAN service discovery frames while nan_de_rx_sdf() was
  never entered, with a positive control proving the logging was live. The
  frames reach the radio and are not handed to the discovery engine. This is
  upstream, not misconfiguration, and is reproducible without any NAN code.

- USD does coexist with STA, on the associated AP's channel. Pinned to the
  AP's channel both boards held association for the whole run; pinned
  elsewhere the link dies at ~36 s with no STA_DISCONNECTED event and a stale
  IP left in esp_netif. Hence the API rule that USD must default to the AP's
  channel.

SOC_WIFI_NAN_SUPPORT gates only ESP_WIFI_NAN_SYNC_ENABLE; USD depends only on
IDF_EXPERIMENTAL_FEATURES. The notes no longer describe either as a
demonstrated silicon requirement, since the gated chip list skips a generation
and returns, and CircuitPython already runs two TSF domains on one radio via
WIFI_MODE_APSTA.

Conclusion recorded in the notes: do the DNS-SD browser first, since it serves
every port and risks nothing, and build any wifiaware module on Sync rather
than USD. Open items are listed in section 14.5 — chiefly that the browser has
not yet met a real responder, and that phone interop needs secured NDP and
pairing, both untested.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Zero the browser's stack socketpool and socket before use. On espressif,
socketpool_socket() leaves ssl_socket and connected unset, and
socketpool_socket_close() treats a non-NULL ssl_socket as an SSL socket to
close, so stack garbage there crashed find() intermittently (LoadProhibited
in common_hal_ssl_sslsocket_close).

Add a no-op mdns_server_deinit_singleton(). espressif's
common_hal_wifi_radio_set_enabled() calls it unconditionally, so builds
with CIRCUITPY_MDNS_SHARED=1 failed to link without it. The browser keeps
no state between find() calls, so there is nothing to tear down.

Tested on a Lolin S2 Mini (60 find() calls across a hard reset and three
soft reloads, no crash) and a SparkFun ESP32 Thing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Multicast on Wi-Fi gets no link-layer retries, so a single PTR query or a
reply to it is easily lost. Repeat the query at 1 s, 3 s, 7 s, ... for as
long as the timeout allows (RFC 6762 Section 5.2 spacing). Responders answer
again and get_entry() merges the duplicates by instance name.

The header comment said responders may multicast their answer instead.
For a query from a port other than 5353, RFC 6762 Section 6.7 requires a
unicast reply to that port, which is what every responder tested did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
socket_select_task asserted that select() with no timeout returns at least
one ready socket. lwIP checks the sockets again after it wakes, so it
returns 0 when the main task has already read the datagram that woke it.
The shared mDNS browser does exactly that with its system socket, and
DEBUG=1 builds stopped at the assert (Socket.c:111). Release builds compile
the assert out and loop, so wait again explicitly instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Working drafts for two ESP-IDF reports arising from the Wi-Fi Aware
investigation. Neither is filed.

IDF-ISSUE-1-nan-usd-rx.md — NAN-USD discovery never completes:
nan_de_rx_sdf() is never called although the subscriber's own radio counts
407 NAN SDFs in 60 s. The open-source receive path in esp_nan_usd.c should
pass every one of those frames, so the leading hypothesis is that the NAN
Network ID 51:6f:9a:01:00:00 — multicast but not broadcast — is absent from
the hardware receive filter. That is a hypothesis, not a measurement.
IDF-ISSUE-1-localise.patch is the one-line diagnostic that would settle it,
also pushed as tyeth/esp-idf branch nan-usd-rx-localise at the cb73317 pin.

IDF-ISSUE-2-nan-ndp-availability.md — the data path with an Android peer
never completes. This one separates two distinct failures. Runs 3 and 4 have
a probable cause: of six ESP unicast transmission events, the two first sent
at +4.2 and +9.2 ms into the Discovery Window were delivered and the four
first sent at +13.1 ms or later failed, with the same boundary on and off the
AP. Runs 5 and 6 are unexplained — 88 of 123 publish SDFs in run 5 landed at
or before +10 ms with no firmware match at all.

Four earlier explanations were proposed and discarded along the way
(Potential-only availability, a 5 GHz-only offer, the negotiation having
succeeded, and a simple DW-end deadline). That history is kept in the draft
rather than tidied away, because each was discarded on evidence that
constrains the remaining hypotheses.

nan-pcap-parse.py reads the radiotap/802.11 captures without tshark and
exposes the retry bit, which is what the delivery analysis rests on: the
monitor was configured with WIFI_PROMIS_FILTER_MASK_MGMT and recorded no ACK
frames at all.

Capture, decode and three substantive corrections came from the bench session
running the hardware.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Ask 2 in the NDP draft rests on the two-map Availability structure of an NDP
Request captured only while the phone was associated to an AP. Decoding the
attributes out of the captures with nan-pcap-parse.py settles most of that
concern.

The phone's map-0 SDF entry is byte-identical on-AP and off-AP, and the map-1
entries appear in both conditions. The op class is decisive: class 128 with
channel bitmap 0x0020 is the 80 MHz block centred on 155, channels 149-161,
which contains 149, the NAN 5 GHz discovery channel. The phone's AP was on
channel 64, in the block centred on 58, which would be bit 1. So map 1 is the
phone's own NAN 5 GHz availability and not its AP. An earlier reading of
those entries as matching the AP channel was wrong.

The AP does change the content: the 5 GHz potential time bitmap is 00f000ff
on-AP and fff0ffff off-AP.

The caveat that matters is recorded too. All of this is from SDFs, and the
SDF map-0 entry is Potential with slots 03000000 while the on-AP NDP Request
map-0 was Conditional with ffffffff — the phone upgrades its offer when it
actually requests a data path. No off-AP NDP Request has ever been captured,
because off-AP discovery never completes.

Also corrects the count: the parse failure appears in runs 2 and 3, not run 3
alone. Both on-AP, both with the ESP as responder, zero off-AP observations.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An IPv6 data path came up between the Note 9 and the ESP32. The draft is no
longer "NAN does not work with Android"; it is two specific defects and one
unexplained discovery failure.

Ask 2 is settled and downgraded. "Avail: missing a conditional or committed
entry" was logged in run 7 as well, and the NDP confirmed anyway, so the
error never prevented anything and the open worry that it might corrupt the
ESP's schedule state is answered. It is an error-level log line for a
non-error.

Ask 1 is sharpened and an earlier reading here is corrected. With ACK frames
captured directly rather than inferred from the retry bit, the boundary is
the real 16.384 ms Discovery Window end, not the ~10-13 ms early termination
this document previously proposed: +15 ms acknowledged, +16 and +17 ms not.
The mechanism is latency, not policy — the ESP takes about 16 ms to turn an
NDP Request into an M2, which lands the response on the window edge and makes
setup close to a coin flip.

The within-run control did not happen: IDF refused a second publish of the
same service name, so run 7 was solicited-only and the off-AP discovery
question is untouched by it.

New and uninvestigated: the link dropped about 20 s after confirmation, with
the phone reporting eventDataPathTerminated and the ESP logging nothing.
Either an idle data path is reclaimed, or the ESP's all-slots channel-6 NDL
commitment cannot be honoured by a phone that is also serving an AP. The test
app now sends a keepalive every 2 s to separate the two.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The previous revision blamed the NDP Response timing on processing latency,
the ESP taking about 16 ms to turn M1 into M2. The capture refutes that.

Run 3's two M2 bursts both start at +15.927 ms relative to the phone's SDF —
the identical intra-window position, to the microsecond, separated by 524.252
ms or 0.9999 Discovery Window periods. Processing latency cannot reproduce a
sub-millisecond offset a full period later. The ESP schedules M2 against the
slot grid, aiming at 0.97 of a slot: the slot-0/slot-1 boundary less about
460 microseconds.

That matches the ESP's own NDL, which places the NDC in slot 1 (ndc=[1,1],
crb1=[2,31]). Before the NDP is confirmed the peer's slot 1 is only
conditional, so a response aimed there has no guaranteed listener. It looks
like an off-by-one, slot+1 rather than end-of-slot-0, though a deliberate
last-moment policy with no margin is indistinguishable from outside the
blob. The remedy is the same.

Ask 1 now states it precisely: transmit the NDP Response, and any NAF to a
peer with no confirmed NDL, early in slot 0 and never at or after the slot
boundary, keeping retries inside slot 0. Measured starts as a fraction of a
slot: 0.25, 0.56 and 0.85-0.90 acknowledged; 0.93-1.05 and 0.97 not.

The slot-grid reading came from the bench session, prompted by Tyeth asking
whether this was an off-by-one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…defect

Two corrections and one new issue.

Withdrawn: the argument that M2 must be slot-anchored rather than
latency-bound because run 3's two bursts started at the identical offset.
Run 3's coincidence does not generalise — the successful retries in runs 7
and 8 started at 0.85-0.90 and 0.569 slots, nowhere near the first attempt.
Only the first attempt is consistent across runs, at 0.98, 0.93 and 1.03
slots after the request, and because the phone always sends its request at
DW+0 those first attempts cannot separate 16 ms of processing latency from
slot-grid scheduling. Off-by-one is a hypothesis again, and ask 1 is restated
so that it does not depend on which it is.

New, IDF-ISSUE-3-nan-schedule-request.md: after the data path is established
the phone sends a unicast NAF Schedule Request (subtype 10), the ESP ACKs it
at the link layer, never sends a Schedule Response, and the phone tears the
data path down. Reproduced in run 7 on-AP and run 8 off-AP.

The mechanism is in the binary. nan_rx_naf in ieee80211_nan_datapath.o
references exactly five parse handlers, subtypes 5 to 9, and the object
contains no parse, construct or send function for subtypes 10 to 13. The
"Unknown NAN Action subtype - %d" string it carries lives in
.rodata_wlog_error.144, so it is error level; since the ESP reportedly logged
nothing, either that line was not captured or the frame never reaches the
dispatcher despite being acknowledged. Either way the handlers do not exist.

This is the most likely cause of the teardown previously recorded in issue 2
as cause unknown.

Also recorded: run 8 established an off-AP data path via a solicited unicast
publish in 1.25 s, so the runs 5/6 discovery failure was specific to the
unsolicited group-addressed publish.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Run 9 ran the data path with a keepalive probe every 2 s and it stayed up for
the full 100 s capture — no teardown, no eventDataPathTerminated — against
the roughly 20 s teardown seen on idle links in runs 7 and 8.

Traffic also changes the peer's behaviour: Schedule Requests arrived about 6 s
apart on an idle link and about 30-36 s apart with traffic, and the phone
tolerated them going unanswered for at least 100 s.

So the teardown needs both conditions, an idle link and an unanswered
Schedule Request, and the write-up now states that as an observed correlation
rather than as cause. Whether a compliant Schedule Response would by itself
prevent the idle teardown cannot be known without a peer that answers one.

The part that does not change: there is no code to answer a Schedule Request,
so the ESP cannot participate in schedule renegotiation at all.

The logging question is also settled as far as it can be from outside. There
are zero occurrences of "Unknown NAN Action subtype" across runs 2, 3, 7, 8
and 9, while error-level wifi: lines such as the Avail message print in the
same logs, and run 9 captured 100 s of silence after NDP confirm while three
Schedule Requests arrived. Worded as "no log emitted although error-level
logs are visible", since a path into nan_rx_naf that skips the log cannot be
ruled out from here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The title claimed the peer tears the data path down; run 9 showed that only
happens on idle links, so it now says so. The observation section covered two
runs and there are three, the third being the keepalive run where the ESP
likewise never answered but the link survived.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Runs 10 and 11 both failed to establish a data path, with retries at
0.81-0.91 and 0.76 slots — positions where earlier runs succeeded.
Acknowledged retries at 0.57 and 0.85-0.90 sit inside the range of
unacknowledged ones at 0.76 to 0.91, so the ranges overlap and the "late
equals lost" boundary this document carried is not supportable. Every
enumerated accepted/rejected position list is removed.

Before accepting that, the anchor was checked, since every offset here is
measured from the phone's SDF rather than a true timebase. In run 3 the
phone's SDF falls within 1.31 ms of a beacon at Discovery Window start,
median 0.00 and standard deviation 0.40 ms over 593 windows. The proxy is
sound, the measurements are not drifting, and the erratic outcomes are real.

What survives is stronger for being simpler: the first NDP Response goes out
about 16 ms after the request in every run measured, 0.93 to 1.03 slots, and
the first attempt has never been acknowledged in any run. Setup succeeds only
when a retry happens to be heard — 3 runs in 5 with the solicited publisher.
The ask is now about that unreliability rather than about a position
threshold.

Two things constrain what remains. In run 10 the ESP failed to acknowledge
the phone's M1 seven times in one window before accepting it in the next, so
intermittent in-window deafness is not one-sided. And runs 10 and 11 carried
a confound: an Android ANR dialog may have taken the test app out of the
foreground.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The success rate was stated as 3 runs in 5; run 12 makes it 3 in 6 — runs 7,
8 and 9 succeeded, runs 10, 11 and 12 failed.

It is also not AP-driven, which an earlier reading of mine suggested in
passing. Runs 8 and 9 succeeded off-AP, so off-AP is 2 of 5 and on-AP 1 of 1
for the solicited build. Drift or a plain low success rate remains the
working explanation.

Run 12 also sharpens the point that no position threshold exists: its retry
at 0.575 slots failed where run 8 succeeded at 0.569.

Added the caveat that the monitor drops frames — run 12's window-0 M2 burst
is absent from the capture although the ESP's logs imply it was sent — so
absence from a capture is never read as absence from the air, and the ESP's
own NDP TX Confirm logging is treated as authoritative for acknowledgement.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… retry bits

The monitor began recording ACK frames from run 7, which overflowed its
24-entry queue with neighbouring-BSS traffic. Drops per run: run 3 zero,
run 7 55, run 8 84, run 9 1761, run 10 141, run 11 8, run 12 1203. Run 3 is
the only fully reliable capture, and for every other run a missing frame or
ACK is not evidence of non-transmission, burst sizes are lower bounds, and
per-frame acknowledgement columns are unsafe.

That would sink the central claim if it depended on seeing ACKs. It does not.
The 802.11 retry bit is carried in the transmitted frames themselves and no
amount of ACK loss touches it. In run 3, the drop-free capture, the bursts
decode as 011 for the follow-up the phone confirmed receiving, and 01111
twice for the two M2 bursts that failed. Frames 2..n carry the retry bit, so
attempts 1..n-1 were unacknowledged by the ESP's own MAC; a burst stopping
below the limit was acked on its last frame, and a burst running to five
exhausted the limit.

Dropped entries can only hide frames, so "five frames seen" is reliable
evidence of failure while "one frame seen" is not evidence of success. The
window-0 M2 burst is five frames in runs 3, 7, 8, 9, 10 and 11, so all six
went unacknowledged — including the three runs that later succeeded. Run 12's
window-0 burst is simply missing, which its 1203 drops explain.

This also resolves a logging ambiguity: successful runs emit no "NDP TX
Confirm ... transmission failed" for a window-0 burst that the retry bits
show did fail, so that line is logged only when the NDP finally gives up.
Absence of it is not evidence a burst succeeded.

Drop counters and the diagnosis of their cause come from the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…y 4/10

The A/B block settles the app-version question empirically as well as by
reasoning: two builds differing only by the probe guard went 0 of 2 and 1 of
2. Solicited-publisher setup is now 4 successes in 10 runs, off-AP 3 of 9 and
on-AP 1 of 1.

Ask 1's first-M2 figure is widened. It is not constant at about one slot;
runs 13 and 16 started at 1.17-1.22, so the measured range is 0.93 to 1.22
slots after the request. Always at or past the window end, and never
acknowledged on the first attempt in any run.

The "five frames means the retry limit was exhausted" step was an unstated
assumption and is now argued. Runs 3 to 6 all predate ACK capture and so are
drop-free, not just run 3, which gives a clean comparison: every failing NDP
burst runs to exactly five across two frame types and two runs, at about
0.99 ms per frame, while the follow-up path in run 4 ran to 21 frames at
about 0.45 ms per frame. Five is specific to the NDP path rather than a
universal ceiling. Not proof — the limit lives in the Wi-Fi libraries — but
better than coincidence.

Issue 3 gains run 16, which answers the question the duplicate-keepalive bug
had invalidated: a single keepalive series every 2 s keeps the data path up
to the end of a 55 s capture.

Run data and the drop-counter diagnosis come from the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Analysis from the pcaps for runs 8 to 16 rather than from relayed summaries.
NAN Action Frames use OUI type 0x18 with the subtype in the next byte; the
Service Discovery Frame uses 0x13 and carries attributes directly, which is
what an earlier pass of mine misread.

Issue 3 gains the strongest evidence yet. Counting NAF subtypes by sender
across all ten captures, the phone sends M1, NDP-Term, Schedule Request and
Schedule Update Notification, while the ESP sends M2 and nothing else in any
run. Subtype 0x0b, Schedule Response, appears zero times anywhere. Schedule
Requests appear only in the three runs that established a data path, and run
9's 17 frames against three logical requests suggests the phone retries each
about five or six times before giving up.

Issue 2 gains the full M2 burst table. Six independently captured
first-window bursts are exactly five frames, never four or six, which
supports the retry limit of five far better than the earlier inference; the
three short first bursts are all from runs with heavy capture loss. Every
fully captured first burst exhausts its attempts, so the first M2 is never
acknowledged in any run. Success tracks the second burst being acknowledged
on its first frame, but position still does not predict it: run 11 failed at
0.740 where run 9 succeeded at 0.724, and run 13 failed at 0.548 where run 8
succeeded at 0.581.

Also recorded: the phone retransmits its own M1 when the ESP fails to
acknowledge it, 8 frames in run 10 and 3 in run 9 against 1 elsewhere, so the
ESP's receive side misses in-window frames too. That is uncharacterised.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The draft said the ESP transmits exactly one NAF subtype ever, M2. That was
true only of the subset examined — runs 3 and 8 to 16, where the ESP was
always the NDP responder — and overstated what the captures show.

Run 4, where the ESP ran as subscriber and initiated, has it sending M1 six
times, and run 7 has it sending one NDP Termination. Verified for run 4 from
the capture, which was in hand and simply missing from the earlier tally;
run 7 is from the bench session. Runs 5 and 6b contain no NAFs at all, since
discovery never completed.

The accurate statement is stronger anyway: the ESP sends only NDP setup and
teardown frames, subtypes 5, 6 and 9, and never anything in 0x0a to 0x0d.
That is exactly the set the binary has handlers for — nan_rx_naf parses 5 to
9, and the object carries construct and send functions for the same range —
so the on-air behaviour and the binary agree precisely about what this
implementation can do.

Schedule Response still appears zero times in any capture while the phone
sends Schedule Requests repeatedly, which is the point the section exists to
make.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…laims

Runs 17-22 used a rebuilt sniffer with zero drops in every run, which
refutes an argument this document carried and sharpens two others.

Withdrawn: that a five-frame burst means the retry limit was exhausted and
the frame went unacknowledged, while a shorter burst was acknowledged on its
last frame. Run 22's second window is five frames with the fifth
acknowledged, and run 18's first window is two frames with no acknowledgement
and no success, both in zero-drop captures. Burst length is not an outcome
oracle. It was a reasonable inference when loss made it the only signal
immune to the drops, and it is wrong. ACK-by-RA is now the oracle.

Corrected: "the first window never succeeds". Run 21's retry at 0.972 slots
was acknowledged and the data path came up without a second window, so the
ESP can close the exchange inside the window the request arrived in. What
survives is narrower — the first transmission attempt has never been
acknowledged in any of sixteen runs, including run 21.

Corrected: the first-window M2 offset. It is not fixed near one slot but
spans 0.92 to 2.12 slots, with runs 17 and 22 landing past slot 1 entirely.
The earlier 0.93-1.22 figure came from too few runs.

New and uncharacterised: in runs 18, 20 and 22 the ESP acknowledged the
phone's M1 and the phone retransmitted anyway. A station is necessarily
receiving during the SIFS after its own transmission, so the phone did not
receive or decode the ESP's ACK — which is not a "not listening at that
instant" effect and suggests a different model for the missed M2s and
follow-ups seen throughout.

New defect candidate: run 19 failed with no M2 on the air at all despite zero
capture drops, while the ESP logged building it twice. It transmitted unicast
SDF retries to the phone instead. Single observation, needs repeats.

Setup is now 9 successes in 16 runs.

All run data from the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The previous commit, dfcb21b, has a message describing changes that were
not in it. Two of three edits failed on an assertion while the commit went
ahead regardless, so it landed the ask 1 rewrite alone and left the document
carrying the refuted claims its message said had been removed, plus a
duplicated "capture caveat" heading from an earlier slice edit. This commit
finishes the job and removes the duplicate.

Now actually present: the burst-length oracle is withdrawn, with run 22's
five-frame burst whose fifth frame was acknowledged and run 18's two-frame
burst with no acknowledgement and no success, both from zero-drop captures.
The runs 8-16 table keeps only what survives — position does not predict
outcome — and the stale "retry limit of five is well supported" and "first M2
is never acknowledged in any run" paragraphs are gone.

Added: the clean runs 17-22 table; run 21 acknowledging inside the request's
own window, which refutes "the first window never succeeds"; the first-window
offset range widened to 0.92-2.12 slots; the observation that the phone
retransmits M1 after the ESP has acknowledged it, which cannot be a wake-state
effect since a station receives during the SIFS after its own transmission;
and run 19, where no M2 reached the air at all despite zero drops while the
ESP logged building it twice and sent unicast SDF retries instead.

Setup is 9 successes in 16 runs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…m the pcaps

Decoded runs 17-22 directly rather than working from summaries, matching each
ACK to the frame it immediately follows.

Withdrawn: that the phone fails to receive the ESP's acknowledgements. It
rests on a single instance — run 18's second window, where M1 #10 was
acknowledged and the phone sent #11 about 180 microseconds later. In runs 20
and 22 the phone stopped transmitting the moment it was acknowledged, which
is correct. One extra frame at 180 us is better explained as a retry already
queued in hardware than as a reception failure, so the model built on it is
not supported.

The other half holds and is kept: the ESP misses M1 repeatedly. Run 18's
first window has seven M1 transmissions with no ESP acknowledgement at all,
run 20's first goes unacknowledged, run 22's first three do.

Confirmed directly, no longer by inference: the first M2 transmission attempt
is unacknowledged in all five clean runs that transmitted one. In run 21 the
opening frame at 0.946 slots is followed 617 us later by its own retry, and
the retry at 0.984 is what gets acknowledged.

A methodological note is included because it caused the error. An ACK is the
frame immediately following the one it acknowledges; matching any ACK to the
transmitter within a 1 ms window credits one ACK to two frames of a burst,
which initially made run 21's first attempt look acknowledged.

Table offsets re-derived from the captures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The draft had grown to 644 lines and twenty-odd sections, most of it a
chronological record of theories raised and withdrawn. It was complete but
unreadable, and no upstream maintainer would get through it.

Reorganised around the three asks, each with the evidence that supports it
and nothing else: the first M2 transmission never being acknowledged, with
the zero-drop run table; the error-level log that fires on successful runs;
and the ACCEPTED status reported after the parse returned 262.

The seven discarded explanations are compressed into an appendix, kept
rather than deleted because each was dropped on evidence that constrains
what remains — Potential-only availability, the 5 GHz exclusion, the
negotiation having succeeded, the Discovery Window deadline, slot-anchored
scheduling, burst length as an oracle, and the phone missing ACKs.

Three observations are now explicitly separated as not part of any ask,
because they rest on too little: the ESP missing M1 up to seven times in a
row, run 19 building an M2 it never transmitted, and off-AP discovery
failing with an unsolicited publish while a solicited one works.

The method note is promoted to the top, since the ACK matching rule is what
the whole evidence base depends on.

No evidence removed; nothing changed but structure and the removal of
superseded narrative.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The ESP under test is a SparkFun ESP32 Thing with an ESP32-D0WDQ6 revision
v0.0 (ECO0), 26 MHz crystal — first silicon. Espressif will reasonably ask
whether that accounts for timing or receive anomalies before treating them
as firmware defects, so it belongs next to the environment table in every
report rather than buried.

Two things worth saying alongside it, both checked against this IDF. Rev
v0.0 is still supported: CONFIG_ESP32_REV_MIN defaults to ESP32_REV_MIN_0,
so the build boots on it by design rather than by accident. And esp_wifi,
esp_phy and esp_coex contain no revision-conditional code at all — the only
rev-0 workaround anywhere in IDF is the brownout interrupt. The Wi-Fi stack
does not branch on chip revision, so a software-side cause would not be
revision-specific.

That does not exclude an analogue or RF difference in first silicon, which
cannot be assessed from here, and reproduction on current silicon remains
the right thing to do.

Raised by the bench session, which is arranging a run on an ESP32-S2 for a
second chip family on the same phone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The hardware swap we agreed to follow wherever it led has landed, and it
moves ask 1 rather than reinforcing it.

An ESP32-S2 as solicited publisher established the data path in 6 of 6 runs
against the same phone, same IDF, same application config, where the ESP32
manages 9 of 16. The mechanism differs: the S2 logs one M2 construction,
puts no M2 on the air in the request's own Discovery Window, and sends a
single M2 in the next window at 0.47-0.57 slots, first attempt, acknowledged.
The ESP32 builds M2 twice, transmits at 0.92-2.12 slots in the request's own
window where it is never acknowledged, and depends on a retry.

So the behaviour ask 1 was requesting already exists in the esp32s2 Wi-Fi
library. The ask is now "adopt the esp32s2 behaviour on esp32", with a
working reference implementation beside it, which is a far better report
than the one it replaces. libnet80211.a is per-target, so this is either the
esp32 library or rev-0 silicon; a current-revision ESP32 would separate them.

Ask 2 strengthens: the S2 logs "Avail: missing a conditional or committed
entry" in all six of its successful runs, so the spurious error spans both
targets.

The M1 receive misses gain a candidate explanation that is not NAN-specific.
Verified from the capture metadata, the phone sends NAFs at bg:48M around
-38 dBm while the ESP answers at bg:6M; and a rev-0 ESP32 used as sniffer
heard the 6 Mbps reference at 93-97% of an S2 sniffer's rate but the phone's
48 Mbps frames at about 5/s against 7.6/s, missing M1 entirely in three
runs. Recorded with the caveat that promiscuous reception may not represent
station reception.

Also noted for anyone re-analysing the pcaps: the radiotap headers carry
only Channel and signal strength, with no Rate field. Rates come from the
sniffer's text output.

Runs and the swap from the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The sniffer now emits the radiotap Rate field for non-HT frames and MCS for
HT frames alongside Channel and signal strength, so captures taken from here
on are self-contained. Only runs 3-28 keep their rates solely in the
sniff.txt output, and for those the capture and its text log have to travel
together.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An ESP32-U4WDH rev v3.1 running the identical esp32 nan_publisher_sol
binary established the data path 6 of 6, where the rev-0 board manages 9 of
16. That settles the question the previous revision left open: it is not the
esp32 Wi-Fi library.

The reframing the result forces. The esp32 library answers inside the
Discovery Window the request arrived in, and on v3.1 that works — M2 at
0.884-0.892 slots, 14.48-14.61 ms into a 16.384 ms slot, 1.77 ms of margin,
acknowledged first try every time, with a spread across six runs of 0.13 ms.
The rev-0 board running the same binary spreads over 19.7 ms, 150 times
wider, and its best case at 0.92 slots is later than v3.1's worst at 0.892.

So the defect is a strategy with almost no margin rather than a wrong one,
and the ask becomes: adopt the esp32s2 approach, which defers M2 to the next
window and sends it early, and therefore does not depend on how fast the
chip turns a request around. Failing that, give the same-window path enough
margin for the slowest silicon the build supports, which is still rev v0.0.

Two things kept honest. The rev-0 board differs from the v3.1 board in
crystal (26 MHz with XTAL_FREQ_AUTO, versus 40 MHz) and flash (external
versus embedded) as well as revision, so "rev 0" means "this rev-0 board";
of the three the crystal is the one most worth suspecting for a timing
defect, and that is untested. And it is still not a position cutoff, since a
rev-0 retry at 0.984 was acknowledged where first attempts at 0.92 were not.

Ask 2 now holds on three targets. The M1 receive misses also vanish on v3.1
with no phone retransmissions at all, which fits the rev-0 board's weak
48 Mbps OFDM reception rather than anything in the code.

Runs and the board swap from the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
I had suggested the 26 MHz crystal as the likeliest cause of the timing
scatter. That does not survive scrutiny and is demoted to third.

A crystal frequency error produces ppm-scale drift, which NAN TSF
synchronisation corrects continuously, and a mis-set XTAL_FREQ generally
breaks RF outright rather than adding jitter. A 19.7 ms spread in when M2 is
handed to the MAC has the signature of execution latency instead: task
preemption, interrupt latency, or flash-cache misses while constructing M2
from code or rodata not held in IRAM — on a board whose flash is external,
against one with embedded flash.

Suspects for the timing scatter are now ordered: execution latency on the
rev-0 board first, revision-specific RF or MAC behaviour second, the crystal
last. The 48 Mbps receive weakness keeps RF or silicon as its leading
suspect, since that is a different kind of failure.

I looked for a documented IDF erratum to support the cache explanation.
ESP32_ECO3_CACHE_LOCK_FIX is the obvious candidate and does not apply — it
depends on !ESP_SYSTEM_SINGLE_CORE_MODE && SPIRAM and neither board has
PSRAM. The draft now says explicitly that the ordering is reasoning from the
shape of the measurements rather than a citation.

Reasoning from the bench session; the Kconfig check is mine.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…he floor

Treating the rev-0 first-M2 delays as one population hid the structure.
Split, they are a tight cluster at 15.089-15.305 ms (sd 0.08, as tight as
v3.1's 0.051) and a separate tail from 15.77 to 33.06 ms.

That changes the diagnosis. The v3.1 guard before the end of slot 0 is
1.841 ms, within 2 us of 1.8 TU, so it is a designed constant rather than
whatever latency allows. The rev-0 cluster's guard is 1.167 ms, a ratio of
0.634 against 26/40 = 0.650 — predicting 15.188 ms where 15.217 was
measured, a 29 us miss. 25/40 fits equally well and cannot be separated; a
factor of one half is about 5 sd out.

So the floor is consistent with a crystal-derived scaling error and the tail
is execution latency, and the earlier ordering that put the crystal last is
revised accordingly, per phenomenon rather than overall.

One correction to the mechanism as proposed: a guard specified in ticks for
40 MHz but counted at 26 MHz would run longer and transmit earlier, the
opposite of what is seen. The fit requires a guard converted to ticks with
the real 26 MHz crystal and then consumed against a 40 MHz timebase.

A blob search for it came up empty and that is recorded. Neither
libnet80211.a nor libpp.a references any crystal or clock frequency helper
among their 1453 and 447 undefined symbols; no literal 40000000, 26000000,
73728 or 1843200 appears; the NAN datapath literal pool holds nothing of
guard-time magnitude, only log line numbers; hal_tsf.o has no literals at
all. The only clock-dependent external called is ROM's ets_delay_us. The
hypothesis therefore cannot be confirmed or refuted from the blob.

The decisive test is a rev v3.x board with a 26 MHz crystal, which should
land at about 15.19 ms if the crystal is the cause.

Distribution split and the scaling idea from Tyeth and the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The evidence for the NDP Response timing ask came entirely from one board,
and that board turns out to have a bidirectional RF fault.

Measured per board: the rev-0 Thing needs 9.81 transmissions per unicast
frame against 1.00 on an ESP32 rev v3.1 and 1.01 on an ESP32-S2. At 0-4 ms
into the Discovery Window, where the peer is certainly listening, the
phone acknowledges only 44 of 388 of the Thing's first transmissions — 11%,
against 275 of 278, or 99%, for v3.1. The same board received the phone's
48 Mbps OFDM poorly when used as a sniffer. The phone simply cannot decode
most of what that board transmits, so the M2 failures cannot be attributed
to transmit timing and the ask is withdrawn rather than reworded.

On current silicon the data path comes up in 16 of 16 runs: 6 ESP32-S2
solicited, 6 v3.1 solicited, 4 v3.1 unsolicited.

Three previously fenced observations are reattributed to that board, with
zero occurrences on v3.1 or S2: the ESP missing M1 up to seven times, run
19's constructed-but-unsent M2, and off-AP discovery failing with an
unsolicited publish. The last is positively refuted — v3.1 discovered in
0.55-0.76 s in 4 of 4 runs with about 114 group-addressed SDFs each, so the
phone does not ignore group-addressed SDFs off-AP.

What survives is two small defects, both reproducing on all three targets:
the error-level Avail log that fires on successful runs, and ACCEPTED being
reported after the parse returned 262. They are now asks 1 and 2.

The 26/40 guard-scaling fit is kept as a curiosity about that board rather
than an ESP-IDF ask, with the observation that a clock fault scaling a guard
by 26/40 would also produce carrier frequency offset, and carrier offset
degrades OFDM decode in both directions — so one faulty clock path may
explain the timing floor and the RF loss together.

Runs 35-38 and the per-board retry and ACK analysis from the bench session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…t silicon

Issue 1 (NAN-USD RX) is no longer a hypothesis. On an ESP32 rev v3.1 and an
ESP32-S2, with entry logging in esp_nan_de_rx_action() and on every ROC
request, the subscriber holds channel 6 continuously (56 accepted 1 s ROCs,
allow_broadcast=1) while 134 publish SDFs go past, and rx_cb is entered zero
times. Rewriting only A3 of the publisher's group SDFs to ff:ff:ff:ff:ff:ff
makes them arrive and discovery complete in about a second; rewriting only
A1 does not. Unicast frames with the same A3 are delivered. This contradicts
the allow_broadcast documentation, and since nan_de_tx_multicast() sends
A3 = NAN Network ID, ESP-to-ESP USD cannot work as shipped. The patch now
carries the full instrumentation and the A1/A3 experiment.

Issue 3 (Schedule Request) reproduced on the ESP32 rev v3.1: four idle runs,
two with the phone on an AP and two without, each with two MAC-ACKed Schedule
Requests at +12 s and +18 s, no response, and a HAL teardown at 21 s. Across
runs 23-42 on current silicon the phone sent 23 Schedule Requests, all ACKed,
none answered. The esp32s2, esp32c5 and esp32c61 libraries lack schedule
handlers too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant