Skip to content

zephyr-cp/wifi: subscribe to NET_EVENT_WIFI_SCAN_RESULT - #11223

Open
mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:fix/zephyr-wifi-scan-result-event
Open

zephyr-cp/wifi: subscribe to NET_EVENT_WIFI_SCAN_RESULT#11223
mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:fix/zephyr-wifi-scan-result-event

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

Wi-Fi scanning on zephyr-cp returns zero networks on every board.

_event_handler in ports/zephyr-cp/common-hal/wifi/__init__.c has a NET_EVENT_WIFI_SCAN_RESULT case that queues each AP as it arrives, but that event is not in the mask passed to net_mgmt_init_event_callback. The case has never run, so nothing is ever queued and every scan comes back empty.

NET_EVENT_WIFI_RAW_SCAN_RESULT is in the mask, which is probably how this went unnoticed, but it is not a substitute. It carries raw beacon frames and only fires when CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS is enabled, which it is not by default.

Testing

Raspberry Pi Pico 2 W, in-tree board raspberrypi_rpi_pico2_w_zephyr, built from 069144c on Linux and flashed over SWD with pyOCD via a CMSIS-DAP Debug Probe.

import wifi
len([1 for n in wifi.radio.start_scanning_networks()])
build result
main 0
main + this patch 204

Same board, same probe, same script. The before run is this commit reverted and rebuilt, nothing else changed. Both returned promptly to the prompt.

Anyone with a Pico 2 W can reproduce this, no vendor hardware needed.

Notes

This is the root cause behind #11214, which I opened earlier and have closed. That one bounded the scan wait instead of fixing why no results arrive, and @tannewt was right to push back on it.

AI assistance was used to draft this change. I ran the hardware testing above myself and confirmed the before and after numbers on my own board.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One request to remove a PR-specific comment

Comment on lines +281 to +286
// SCAN_RESULT delivers the parsed per-AP entries. Without it the
// handler's NET_EVENT_WIFI_SCAN_RESULT case never runs and scans
// always return zero networks. RAW_SCAN_RESULT is not a substitute:
// it carries raw beacon frames and only fires when
// CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS is enabled, which it is not by
// default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for this. The addition is self explanatory.

Suggested change
// SCAN_RESULT delivers the parsed per-AP entries. Without it the
// handler's NET_EVENT_WIFI_SCAN_RESULT case never runs and scans
// always return zero networks. RAW_SCAN_RESULT is not a substitute:
// it carries raw beacon frames and only fires when
// CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS is enabled, which it is not by
// default.

The event handler has a NET_EVENT_WIFI_SCAN_RESULT case that queues each
AP as it arrives, but that event was never in the subscription mask, so
the case never ran and scans always returned zero networks.

RAW_SCAN_RESULT is in the mask but is not a substitute. It carries raw
beacon frames and only fires when CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS is
enabled, which it is not by default.

Measured on a Raspberry Pi Pico 2 W running raspberrypi_rpi_pico2_w_zephyr,
built from 069144c and flashed over SWD with pyOCD:

  len([1 for n in wifi.radio.start_scanning_networks()])

  before  0
  after   204

Same board, same probe, same script, with only this change reverted for
the before run.
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.

2 participants