Recommeded DHCP setup for HostAPD

I have a PocketBeagle-based system running the current “AM3358 Debian 10.3 2020-04-06 4GB SD IoT” image. I have HostAPD up and running on wlan0 on a USB Wifi adapter. I am looking to the best way to setup a DHCP server to run on wlan0 with minimal overhead. Most online references I find are pretty old. Here’s what I a looking for:

  • Keep usb0 and usb1 Ethernet gadgets as-is (I connect via wired USB in some cases)
  • Run wlan0 in HostAP mode (already working) with DHCP server (only needs to allow one device to connect)
  • No internet connection will be available on the Beagle or connected device

Is this possible to do with dnsmasq? Or would I need to install udhcpd or full-blown isc-dhcp-server?

Thanks!

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,

@RobertCNelson thanks for the detailed feedback. I originally started with the 2022-04–1 Debian 11.x Bullseye IOT Snapshot and had the everything working. However, it would not mount rootfs reliability (rootfs timeout message in the serial console) after the kernel booted across the ~20 boards I have. The release 2020-04-06 IOT seems to boot like clockwork across all boards.

EDIT: Also, I am booting from a SD card, so I tried multiple new cards (Sandisk Ultra, Samsung EVO, etc.) and found just swapping the image on the same card reproduced the rootfs mount problem.

So with 5.10.x-ti, TI switched to the generic SDHC layer, which is a little different then older OMAP/AM335x specific SDHC driver…

You can switch to the older v4.19.x kernel via:

sudo apt update
sudo apt install bbb.io-kernel-4.19-ti-am335x
sudo apt remove bbb.io-kernel-5.10-ti-am335x --purge
sudo reboot

and then you’ll have Bullseye with v4.19.x vs 5.10.x

Regards,

Ah, that maybe the issue.

I will try this, thanks!

@RobertCNelson Trying the Bullseye Monthly IOT am335x-debian-11.3-iot-armhf-2022-05-01-4gb.img.xz from your link, I get the following repeated boot error. Is there a known issue with this snapshot?

CCCCCCCCCCCCCCCC
U-Boot SPL 2022.04-g4237220b (Apr 08 2022 - 13:42:29 +0000)
Trying to boot from MMC1


U-Boot 2022.04-g4237220b (Apr 08 2022 - 13:42:29 +0000)

CPU  : AM335X-GP rev 2.1
Model: TI AM335x PocketBeagle
DRAM:  512 MiB
Reset Source: Power-on reset has occurred.
RTC 32KCLK Source: Internal.
Core:  146 devices, 12 uclasses, devicetree: separate
Could not initialize timer (err -19)

Could not initialize timer (err -19)

Could not initialize timer (err -19)

Could not initialize timer (err -19)

hi @aaronmc thanks for the report, that is strange… i’ll take a look at it…

Please test the prior version (2022-04-01 or 2022-03-02)…

https://rcn-ee.net/rootfs/bb.org/testing/

i don’t remember the exact date i moved to 2022.04

Regards,

Hey @RobertCNelson, the 2022-04-01 IOT Snapshot with the kernel rolled back to 4.19.x did indeed work! It boots reliably and was much easier to get the HostAPD with DHCP up and running as you recommended. I only have one outstanding issue, the kernel is kicking out a ton of this repeating message:

May 16 21:52:24 <HOSTNAME> kernel: configfs-gadget gadget: Wrong NDP SIGN
May 16 21:52:24 <HOSTNAME> kernel: configfs-gadget gadget: Wrong NDP SIGN
May 16 21:52:25 <HOSTNAME> kernel: configfs-gadget gadget: Wrong NDP SIGN
May 16 21:52:25 <HOSTNAME> kernel: configfs-gadget gadget: Wrong NDP SIGN
May 16 21:52:25 <HOSTNAME> kernel: configfs-gadget gadget: Wrong NDP SIGN
May 16 21:52:25 <HOSTNAME> kernel: configfs-gadget gadget: Wrong NDP SIGN

Note: I replaced my real hostname with <HOSTNAME>

It looks like this was an issue in the past. I am connected to a Windows 11 system.

My guess, one of these patches might have fixed it in the v4.19.x tree:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/drivers/usb/gadget/function/f_ncm.c?h=v4.19.243

Right now the 4.19.x-ti kernel is on patch level 94…

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/drivers/usb/gadget/function/f_ncm.c?h=v4.19.94

Regards,