Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
feb52e0
shared-module/mdns: add a portable DNS-SD browser
tyeth Nov 23, 2026
759e281
docs: DNS-SD and Wi-Fi Aware research notes
tyeth Nov 23, 2026
df1672a
mdns: fix the shared browser on espressif
tyeth Nov 23, 2026
9446b6e
mdns: repeat the browse query; correct the unicast-reply comment
tyeth Nov 23, 2026
97da733
espressif: treat a select() that returns 0 as a spurious wakeup
tyeth Nov 23, 2026
54d696b
docs: ESP-IDF issue drafts for the two NAN defects, plus capture tooling
tyeth Nov 23, 2026
f97db22
docs: confirm the NAN map-0/map-1 structure is not an AP artefact
tyeth Nov 23, 2026
110a940
docs: run 7 established the data path; both asks now resolve
tyeth Nov 23, 2026
0d9dc53
docs: M2 is slot-anchored, not latency-bound — ask 1 rewritten
tyeth Nov 23, 2026
575923f
docs: withdraw the slot-anchoring argument; add the Schedule Request …
tyeth Nov 23, 2026
90a0ec9
docs: narrow issue 3's impact to idle data paths
tyeth Nov 23, 2026
23d4a7a
docs: issue 3 title and run count follow the narrowed impact
tyeth Nov 23, 2026
a28b03c
docs: no slot threshold exists; ask 1 becomes a reliability claim
tyeth Nov 23, 2026
070703f
docs: correct the setup success count and record the capture caveat
tyeth Nov 23, 2026
96bc8ac
docs: sniffer dropped frames from run 7 on; central claim survives on…
tyeth Nov 23, 2026
c1d485b
docs: runs 13-16 — app version ruled out, retry limit evidenced, tall…
tyeth Nov 23, 2026
b092ce0
docs: decode every M2 and NAF subtype from the raw captures
tyeth Nov 23, 2026
91e41ba
docs: correct the ESP's NAF subtype set in issue 3
tyeth Nov 23, 2026
dfcb21b
docs: withdraw the burst-length oracle; six clean runs change three c…
tyeth Nov 23, 2026
d093e30
docs: finish the clean-run rewrite and deduplicate the section
tyeth Nov 23, 2026
e2dde4b
docs: withdraw "the phone misses the ESP's ACKs"; verify the rest fro…
tyeth Nov 23, 2026
dc60907
docs: restructure issue 2 so it can actually be filed
tyeth Nov 23, 2026
76569f7
docs: state the ESP32 chip revision prominently in all three issues
tyeth Nov 23, 2026
2033727
docs: rescope ask 1 to the esp32 target; esp32s2 already does it right
tyeth Nov 24, 2026
af00b68
docs: scope the missing-radiotap-Rate note to runs 3-28
tyeth Nov 24, 2026
d4079ab
docs: the v3.1 run splits library from hardware; ask 1 reframed again
tyeth Nov 24, 2026
6e966fa
docs: reorder the timing-scatter suspects; drop the crystal hypothesis
tyeth Nov 24, 2026
552f17c
docs: split the rev-0 delay distribution; crystal scaling leads for t…
tyeth Nov 24, 2026
53c8721
docs: withdraw the timing ask; the rev-0 board was a faulty instrument
tyeth Nov 24, 2026
ad81c7f
docs: issue 1 localised to A3 filtering; issue 3 reproduced on curren…
tyeth Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions IDF-ISSUE-1-localise.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Subject: [PATCH] nan_usd: instrument the USD action-frame Rx path (diagnostic)

Diagnostic only; not a fix. Applies to cb73317.

- Logs every entry to esp_nan_de_rx_action() with A1/A2/A3 and the first six
body bytes, and which early-return gate failed, if any.
- Logs every remain-on-channel request with allow_broadcast and its return
code, and every WIFI_EVENT_ROC_DONE.
- With -DLOCALISE_TX_BCAST=1/2/3 (C define), esp_nan_de_tx() replaces the NAN
Network ID with ff:ff:ff:ff:ff:ff in A1 / A3 / both, for group-addressed
SDFs only. This is the experiment showing A3 decides delivery.

MSG_ERROR so the result does not depend on the configured log level.

diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_nan_usd.c b/components/wpa_supplicant/esp_supplicant/src/esp_nan_usd.c
index 30d54c8a8e..1ce5f5bcfd 100644
--- a/components/wpa_supplicant/esp_supplicant/src/esp_nan_usd.c
+++ b/components/wpa_supplicant/esp_supplicant/src/esp_nan_usd.c
@@ -127,6 +127,7 @@ static void nan_de_tx_event_handler(void *arg, esp_event_base_t event_base,
} else if (event_id == WIFI_EVENT_ROC_DONE) {
wifi_event_roc_done_t *evt = (wifi_event_roc_done_t *)event_data;
int freq = esp_nan_chan_to_freq(evt->channel);
+ wpa_printf(MSG_ERROR, "NAN-USD: ROC_DONE chan=%u", (unsigned)evt->channel);
if (freq == -1) {
wpa_printf(MSG_ERROR, "Invalid channel received from ROC done handler");
return;
@@ -144,8 +145,18 @@ int esp_nan_de_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t cha
struct ieee80211_hdr *rx_hdr = (struct ieee80211_hdr *)hdr;
struct nan_de *nan_de = NULL;
int freq;
+ static unsigned s_rx_count;
+
+ /* LOCALISE: log every entry, MSG_ERROR so it does not depend on log level. */
+ s_rx_count++;
+ wpa_printf(MSG_ERROR, "NAN-USD: rx_action #%u len=%u chan=%u A1=" MACSTR " A2=" MACSTR " A3=" MACSTR
+ " body=%02x %02x %02x%02x%02x %02x",
+ s_rx_count, (unsigned)len, (unsigned)channel, MAC2STR(rx_hdr->addr1), MAC2STR(rx_hdr->addr2),
+ MAC2STR(rx_hdr->addr3), len > 0 ? payload[0] : 0, len > 1 ? payload[1] : 0, len > 2 ? payload[2] : 0,
+ len > 3 ? payload[3] : 0, len > 4 ? payload[4] : 0, len > 5 ? payload[5] : 0);

if (len < 6) {
+ wpa_printf(MSG_ERROR, "NAN-USD: gate len<6");
/* Frame too short for NAN-SDF frame */
return ESP_FAIL;
}
@@ -169,6 +180,8 @@ int esp_nan_de_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t cha
/* Received a valid NAN Service Discovery Frame */
} else {
/* Frame is not a NAN SDF frame */
+ wpa_printf(MSG_ERROR, "NAN-USD: gate not-SDF cat=%u pa=%u oui=%06x type=%u",
+ category, public_action, (unsigned)oui_value, oui_type);
return ESP_FAIL;
}

@@ -179,8 +192,10 @@ int esp_nan_de_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t cha
}

if (!nan_usd_try_lock_active(&nan_de)) {
+ wpa_printf(MSG_ERROR, "NAN-USD: gate lock/inactive");
return ESP_FAIL;
}
+ wpa_printf(MSG_ERROR, "NAN-USD: -> nan_de_rx_sdf freq=%d", freq);
nan_de_rx_sdf(nan_de, rx_hdr->addr2, rx_hdr->addr3, freq, payload, len - 6);
NAN_USD_DATA_UNLOCK();
return ESP_OK;
@@ -204,6 +219,18 @@ static int esp_nan_de_tx(void *ctx, unsigned int freq, unsigned int wait_time,
req->wait_time_ms = wait_time;
memcpy(req->dest_mac, dst, ETH_ALEN);
memcpy(req->bssid, bssid, ETH_ALEN);
+#ifdef LOCALISE_TX_BCAST
+ /* LOCALISE experiment: replace the NAN Network ID 51:6f:9a:01:00:00 (multicast, not broadcast)
+ * with ff:ff:ff:ff:ff:ff. Bit 0 = A1 (dest), bit 1 = A3 (BSSID). Only group-addressed SDFs are touched. */
+ if (dst[0] & 1) {
+ if (LOCALISE_TX_BCAST & 1) {
+ memset(req->dest_mac, 0xff, ETH_ALEN);
+ }
+ if (LOCALISE_TX_BCAST & 2) {
+ memset(req->bssid, 0xff, ETH_ALEN);
+ }
+ }
+#endif
req->no_ack = false;
req->data_len = buf_len;
req->rx_cb = esp_nan_de_rx_action;
@@ -250,7 +277,11 @@ static int esp_nan_de_listen(void *ctx, unsigned int freq, unsigned int duration
req->done_cb = NULL;
req->allow_broadcast = true;

- if (esp_wifi_remain_on_channel(req) != ESP_OK) {
+ esp_err_t roc_err = esp_wifi_remain_on_channel(req);
+ /* LOCALISE: show every listen request the subscriber makes, and whether the library accepted it. */
+ wpa_printf(MSG_ERROR, "NAN-USD: ROC req chan=%d dur=%u allow_bcast=%d -> %d", channel, duration,
+ req->allow_broadcast, roc_err);
+ if (roc_err != ESP_OK) {
wpa_printf(MSG_ERROR, "ROC request failure");
os_free(req);
return ESP_FAIL;
177 changes: 177 additions & 0 deletions IDF-ISSUE-1-nan-usd-rx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# NAN-USD: group-addressed SDFs are dropped before the ROC Rx callback unless A3 is broadcast, so USD discovery never completes

**Status: draft, ready.** Measured on current silicon (ESP32 rev v3.1 and
ESP32-S2) with instrumented logging in the open-source receive path. The loss
is localised to below the supplicant, and the deciding address field is
identified.

## Summary

With `CONFIG_ESP_WIFI_NAN_USD_ENABLE=y`, a USD subscriber that is listening on
the right channel never has its ROC receive callback (`rx_cb`,
`esp_nan_de_rx_action()`) entered for the publisher's Service Discovery
Frames, so discovery never completes. Two ESP boards running the unmodified
`usd_publisher` / `usd_subscriber` examples never discover each other, in
either role assignment.

The frames are dropped because their **Address 3 (BSSID) is the NAN Network ID
`51:6f:9a:01:00:00`, not broadcast**. Changing only A3 to
`ff:ff:ff:ff:ff:ff` makes them arrive and discovery complete in under a
second. Changing only A1 does not.

This contradicts the documented behaviour of `wifi_roc_req_t.allow_broadcast`,
which the USD listen path sets to `true`:

> If set to true, broadcast/multicast action frames from any network
> (Address3/BSSID=ANY) will be received in the ROC Rx callback

## Environment

| | |
|---|---|
| ESP-IDF | `v6.1-dev-6107` (`cb73317`), `esp_wifi/lib` at `7cd4d7b2` |
| Targets | ESP32-U4WDH **rev v3.1** (40 MHz crystal) and ESP32-S2FNR2 rev v1.0 |
| Projects | `examples/wifi/wifi_aware/usd_publisher` and `usd_subscriber`, unchanged apart from logging |
| Config | `CONFIG_IDF_EXPERIMENTAL_FEATURES=y`, `CONFIG_ESP_WIFI_NAN_USD_ENABLE=y`, `CONFIG_ESP_WIFI_DEBUG_PRINT=y`, `esp_log_level_set("wpa", ESP_LOG_DEBUG)` |
| Mode | `WIFI_MODE_NULL`, no association, default channel 6 |
| Capture | a third ESP32 in promiscuous mode on channel 6, written to pcap |

An earlier round on an ESP32 rev v0.0 and an ESP32-S3 showed the same
outcome. Everything below is from the rev v3.1 and S2 boards.

## Instrumentation

All in open source, in `esp_supplicant/src/esp_nan_usd.c`, at `MSG_ERROR` so
the result does not depend on log level (patch attached as
`IDF-ISSUE-1-localise.patch`):

- the first line of `esp_nan_de_rx_action()` logs every entry with A1, A2, A3
and the first six body bytes, and each early-return gate logs which gate
failed;
- `esp_nan_de_listen()` logs every `esp_wifi_remain_on_channel()` request,
its `allow_broadcast` value and its return code;
- the `WIFI_EVENT_ROC_DONE` handler logs each completion.

## What was measured

**The subscriber is listening on the right channel the whole time.** In a 60 s
run it issued 56 consecutive ROC requests on channel 6, 1000 ms each,
`allow_broadcast=1`, every one returning `ESP_OK`, each followed by
`ROC_DONE`:

```
D (677) wpa: NAN: Assigned new subscribe handle 1 for ESP-USD-TEST
E (687) wpa: NAN-USD: ROC req chan=6 dur=1000 allow_bcast=1 -> 0
E (1687) wpa: NAN-USD: ROC_DONE chan=6
E (1687) wpa: NAN-USD: ROC req chan=6 dur=1000 allow_bcast=1 -> 0
...
```

**The publisher's SDFs are on the air, well-formed and strong.** In the same
60 s, the sniffer captured 134 USD publish SDFs from the publisher on channel
6 at about −10 dBm: Public Action, Vendor Specific, WFA OUI, OUI type `0x13`,
SDA and SDEA attributes, with A1 = A3 = `51:6f:9a:01:00:00`. Two other NAN
devices nearby added 164 more SDFs on channel 6, at −32 and −61 dBm.

**`rx_cb` is never entered.** Not once for any of those roughly 300 frames.
Because the entry log is the first statement in the callback, no gate in the
open-source path is involved. The frames are discarded below the supplicant.

The same holds with the roles swapped (ESP32 publishing, ESP32-S2
subscribing): 39 accepted ROC windows on channel 6, 87 publish SDFs on air,
zero callback entries, no discovery.

## The deciding experiment

The publisher was rebuilt so that `esp_nan_de_tx()` replaces the NAN Network
ID with `ff:ff:ff:ff:ff:ff` in A1, in A3, or in both, for group-addressed SDFs
only. Nothing else changed. ESP32-S2 publishing, ESP32 rev v3.1 subscribing:

| A1 (DA) | A3 (BSSID) | `rx_cb` entered | discovery |
|---|---|---|---|
| `51:6f:9a:01:00:00` | `51:6f:9a:01:00:00` | never (134 frames on air) | never |
| `ff:ff:ff:ff:ff:ff` | `51:6f:9a:01:00:00` | never (101 frames on air) | never |
| `51:6f:9a:01:00:00` | `ff:ff:ff:ff:ff:ff` | yes | 1.0 s after boot |
| `ff:ff:ff:ff:ff:ff` | `ff:ff:ff:ff:ff:ff` | yes | 0.9 s after boot |

With A3 broadcast, the first frame arrives and is processed normally:

```
E (867) wpa: NAN-USD: rx_action #1 len=24 chan=6 A1=ff:ff:ff:ff:ff:ff A2=7c:e8:b1:4a:11:14 A3=ff:ff:ff:ff:ff:ff body=04 09 506f9a 13
D (877) wpa: NAN: RX SDF from 7c:e8:b1:4a:11:14 freq=2437 len=18
I (897) wpa: NAN_USD DISCOVERY_RESULT - subscribe_id = 1 peer_publish_id = 1 peer_address = 7c:e8:b1:4a:11:14 service_protocol_type = 0
```

The reverse direction (ESP32 publishing with A3 broadcast, ESP32-S2
subscribing) also discovers at once: the subscriber matched before its USB
console attached, about a second after boot, and its unicast follow-ups to the
publisher are on air from the start of the capture. With the stock A3 it
never discovers.

**Unicast frames are not affected.** Follow-ups addressed to the receiver's
own MAC, with A3 still `51:6f:9a:01:00:00`, reach `rx_cb` normally; the
ESP32 publisher logged 20 such entries and 11 follow-up receptions. So the
filter applies to group-addressed frames whose A3 is not broadcast.

## Why ESP-to-ESP USD can never work as shipped

The supplicant itself transmits USD SDFs with A3 set to the NAN Network ID.
In `components/wpa_supplicant/src/common/nan_de.c`, `nan_de_tx_multicast()`:

```c
if (srv->is_p2p) {
network_id = p2p_network_id;
bssid = wildcard_bssid;
} else {
network_id = nan_network_id;
bssid = nan_network_id;
}
```

So every non-P2P USD publish or active subscribe an ESP sends carries an A3
that another ESP's receive path discards. Discovery between two ESPs cannot
complete, in either direction, whatever the timing or channel.

## Already ruled out

- **Channel.** Both ends on channel 6; `esp_nan_chan_to_freq(6)` = 2437. The
subscriber is on channel 6 for essentially the whole run (ROC log above).
- **The open-source gate chain.** The entry log precedes every gate and never
prints, so none of `len < 6`, category/action/OUI/type,
`esp_nan_chan_to_freq()` or `nan_usd_try_lock_active()` is involved.
- **Signal level.** The publisher was received by the sniffer at −10 to
−17 dBm, the other devices at −32 and −61 dBm; none reached `rx_cb`.
- **Transmit failure.** The frames are on air, and with A3 changed the same
frames are received.
- **Chip.** ESP32 rev v3.1 and ESP32-S2 behave identically, both directions.
- **`.type` / active vs passive.** The USD path ignores it:
`ESP_USD_SUBSCRIBE_DEFAULT_PARAMS()` hardcodes `.active = false` and
`ESP_USD_PUBLISH_DEFAULT_PARAMS()` hardcodes `.unsolicited = true,
.solicited = true`.

## Impact

NAN-USD discovery does not work between ESP devices on ESP-IDF today. It also
cannot receive standard USD SDFs from other implementations, since the Wi-Fi
Aware specification puts a non-broadcast value in A3 (the NAN Cluster ID in
v4.0; the comment in `nan_de.c` near the follow-up path discusses this). The
same filter also drops NAN-Sync SDFs, whose A3 is a Cluster ID such as
`50:6f:9a:01:db:dd`: none of those reached `rx_cb` either.

Since `ESP_WIFI_NAN_USD_ENABLE` depends only on `IDF_EXPERIMENTAL_FEATURES`
and not on `SOC_WIFI_NAN_SUPPORT`, USD is the only Wi-Fi Aware mode on parts
such as the ESP32-S3, and the only one that can run alongside a STA
association.

## Asks

1. **Make `allow_broadcast` behave as documented**: when set on a ROC
request, deliver group-addressed Public Action frames to `rx_cb` whatever
their A3, not only when A3 is broadcast.
2. Until then, consider whether `nan_de_tx_multicast()` should use the
wildcard BSSID for A3 on the non-P2P path, as it already does for P2P.
That alone makes ESP-to-ESP USD work (measured above), though it does not
fix reception from other implementations.
3. If the current filtering is intended, please correct the
`allow_broadcast` documentation, and say how a USD subscriber is meant to
receive SDFs whose A3 is the NAN Network ID or a Cluster ID.
Loading
Loading