Skip to content

Fix Raspberry Pi 5 WiFi Support#41

Merged
mihai-chiorean merged 2 commits intomainfrom
edg-322-pi-5-wifi-not-working-with-connman-device-shows-as
Oct 10, 2025
Merged

Fix Raspberry Pi 5 WiFi Support#41
mihai-chiorean merged 2 commits intomainfrom
edg-322-pi-5-wifi-not-working-with-connman-device-shows-as

Conversation

@mihai-chiorean
Copy link
Member

@mihai-chiorean mihai-chiorean commented Oct 10, 2025

Fixes #EDG-322

Summary

This PR enables full WiFi functionality on Raspberry Pi 5 by upgrading to kernel 6.12 and implementing proper regulatory domain configuration and WiFi state persistence.

Problem

Raspberry Pi 5 WiFi was not working due to several issues:

  • WiFi device remained in DOWN/DORMANT state
  • connmanctl services only showed USB gadget, no WiFi networks
  • Regulatory domain stuck at country 99: DFS-UNSET for phy#0
  • brcmfmac driver loaded but produced no logs
  • WiFi state not persisting across reboots

Root Causes

  1. Kernel version - Running 6.6.x which has older brcmfmac drivers
  2. Regulatory domain - The brcmfmac driver requires an explicit regulatory hint via iw reg set to properly initialize the PHY
  3. State persistence - ConnMan WiFi enable/disable state wasn't persisting across reboots due to race conditions with systemd-rfkill

Solution

Kernel Upgrade (6.6 → 6.12)

  • Upgraded to kernel 6.12 to match Raspberry Pi OS (latest brcmfmac improvements)
  • Added PREFERRED_VERSION_linux-raspberrypi = "6.12.%" to local.conf template
  • Enables better WiFi driver support and regulatory domain handling

WiFi DISTRO_FEATURES

  • Added wifi to DISTRO_FEATURES in edgeos.conf
  • Ensures WiFi support is properly configured at distribution level

ConnMan CLI Tools

  • Added connman-client package for connmanctl command-line interface
  • Essential for WiFi management and troubleshooting

Regulatory Domain Configuration

  • udev rule (85-wifi-regdomain.rules) - Automatically runs iw reg set when phy0 appears
  • cfg80211.conf - Sets kernel module default regulatory domain as fallback
  • Provisioning-friendly - Country code stored in /etc/regdomain, easy to customize per deployment

WiFi State Persistence

  • Uses standard systemd-rfkill to persist WiFi enable/disable state
  • wifi-rfkill-migrate.service - One-time migration from ConnMan settings on first boot
  • wifi-nudge.service - Ensures wpa_supplicant properly registers with ConnMan when WiFi is enabled
  • rfkill state is the single source of truth, ConnMan reads and respects it

Architecture
udev → regulatory domain setting
systemd-rfkill → WiFi radio on/off persistence
ConnMan → network management

Boot Sequence

  1. brcmfmac driver loads → phy0 appears
  2. udev sets regulatory domain via iw reg set
  3. wlan0 interface appears and brought UP
  4. systemd-rfkill restores saved radio state
  5. wifi-rfkill-migrate runs (first boot only) to migrate ConnMan settings
  6. ConnMan starts and reads rfkill state
  7. wifi-nudge ensures wpa_supplicant registration if WiFi enabled

Testing

Verified on Raspberry Pi 5:

  • ✅ Kernel 6.12.25 running
  • ✅ WiFi firmware (BCM4345/6) loads successfully
  • ✅ wlan0 interface present
  • ✅ connmanctl enable wifi works correctly
  • ✅ WiFi networks scan successfully (9+ networks detected)
  • ✅ Regulatory domain sets properly
  • ✅ No interference with USB gadget networking

Usage

Enable WiFi:
connmanctl enable wifi
connmanctl scan wifi
connmanctl services

Set Country Code (optional):
echo "US" > /etc/regdomain
iw reg set US

Files Changed

  • meta-edgeos/conf/distro/edgeos.conf - Added wifi DISTRO_FEATURE
  • meta-edgeos/conf/local.conf.template - Kernel 6.12 upgrade
  • meta-edgeos/recipes-core/packagegroups/packagegroup-edgeos-base.bb - Added connman-client
  • meta-edgeos/recipes-core/packagegroups/packagegroup-edgeos-wifi.bb - Added comment about firmware
  • meta-edgeos/recipes-connectivity/connman/connman_%.bbappend - ConnMan configuration and services
  • docs/WIFI_CONFIGURATION.md - Complete WiFi configuration guide

References

  • Linear Issue: EDG-322
  • Raspberry Pi 5 uses CYW43455 WiFi chip (same as Pi 4)
  • Firmware provided automatically by meta-raspberrypi via MACHINE_EXTRA_RRECOMMENDS

This commit addresses WiFi issues on Raspberry Pi 5 by fixing:
1. Regulatory domain configuration (PHY-specific hint required)
2. WiFi state persistence across reboots (using systemd-rfkill)

**Problem:**
- brcmfmac driver keeps WiFi soft-blocked until regulatory domain is set
- ieee80211_regdom kernel parameter sets global default but PHY won't
  adopt it without userspace regulatory hint via 'iw reg set'
- WiFi state persistence had race conditions between ConnMan and
  hardware rfkill state on boot

**Solution:**

**Regulatory Domain (udev-based):**
- 85-wifi-regdomain.rules: Triggers when phy0 appears, reads country
  code from /etc/regdomain, runs 'iw reg set <COUNTRY>'
- cfg80211.conf: Sets global regulatory domain default as fallback
- Provisioning-friendly: Update /etc/regdomain and run 'iw reg set'

**State Persistence (systemd-rfkill):**
- Uses standard systemd-rfkill to persist WiFi enable/disable state
- wifi-rfkill-migrate.service: One-time migration from ConnMan settings
  to rfkill state (runs before ConnMan on first boot only)
- wifi-nudge.service: Ensures wpa_supplicant registers wlan0 with
  ConnMan when WiFi is enabled on boot
- rfkill is single source of truth, ConnMan synchronizes to match

**Architecture:**
- udev owns regulatory domain setting
- systemd-rfkill owns radio state persistence
- ConnMan owns network management
- No interference with USB gadget networking (ConnMan starts immediately)

**Boot Sequence:**
1. brcmfmac loads → phy0 appears (rfkill registered, default unblocked)
2. udev sets regulatory domain via iw reg set
3. wlan0 appears, brought UP by udev rule
4. systemd-rfkill restores saved rfkill state
5. wifi-rfkill-migrate (first boot only) sets initial state from ConnMan
6. ConnMan starts, reads rfkill state
7. wifi-nudge toggles WiFi if enabled (ensures wpa_supplicant registration)

Closes EDG-322
@mihai-chiorean mihai-chiorean changed the title Edg 322 pi 5 wifi not working with connman device shows as Fix Raspberry Pi 5 WiFi Support Oct 10, 2025
@mihai-chiorean mihai-chiorean marked this pull request as ready for review October 10, 2025 17:38
@mihai-chiorean mihai-chiorean merged commit cc88e1e into main Oct 10, 2025
3 checks passed
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