Recommeded DHCP setup for HostAPD

Hi @aaronmc this might be easier with the clean up I did in our Bullseye images…

Grab the IoT version here: Debian 11.x (Bullseye) - Monthly Snapshots

Next we need to configure your wlan0 into host mode:

There are two files to look at under udev:

The first, creates the SoftAp0 interface, you’ll need to run:

udevadm info --attribute-walk /sys/class/net/wlan0  | grep DRIVERS

to grab the DRIVERS name… then try both “managed” or “__ap”…

/etc/udev/rules.d/81-add-SoftAp0-interface.rules

SUBSYSTEM=="net", ACTION=="add", KERNEL=="wlan[0-9]", DRIVERS=="wl18xx_driver" \
	RUN+="/sbin/iw dev %k interface add SoftAp0 type managed"
SUBSYSTEM=="net", ACTION=="add", KERNEL=="wlan[0-9]", DRIVERS=="brcmfmac" \
	RUN+="/sbin/iw dev %k interface add SoftAp0 type __ap"

Next add that same Driver to this udev rule that kicks off the hostapd.service:

and /etc/udev/rules.d/82-SoftAp0-start-hostpad.rules

SUBSYSTEM=="net", KERNEL=="SoftAp0", DRIVERS=="wl18xx_driver", TAG+="systemd", ENV{SYSTEMD_WANTS}="hostapd.service"
SUBSYSTEM=="net", KERNEL=="SoftAp0", DRIVERS=="brcmfmac", TAG+="systemd", ENV{SYSTEMD_WANTS}="hostapd.service"

Finally the default hostapd config:

/etc/hostapd/hostapd.conf

interface=SoftAp0

# a simply means 5GHz
# g simply means 2.4GHz band
hw_mode=g

# the channel to use
channel=1

# limit the frequencies used to those allowed in the country
#ieee80211d=1
# the country code
#country_code=US

# 802.11n support
ieee80211n=1
# QoS support, also required for full speed on 802.11n/ac/ax
wmm_enabled=1

ssid=BeagleBone-WXYZ

# 1=wpa, 2=wep, 3=both
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
wpa_passphrase=BeagleBone

macaddr_acl=0
ignore_broadcast_ssid=0

logger_syslog=-1
logger_syslog_level=2

Finally we configure SoftAp0’s dhcp server in systemd-networkd:

/etc/systemd/network/SoftAp0.network

[Match]
Name=SoftAp0

[Link]
RequiredForOnline=no

[Network]
DHCP=no
Address=192.168.8.1/24
DHCPServer=on

This all uses udev and systemctl, so run on events, and thus no random start scripts with wait’s and timeout’s… (like we did in older images…) Totally dynamic, so if you boot without the WiFI adapter, none of this will run, or cause wait states. :wink:

Regards,