Access Point Mode on Raspberry Pi - cu-ecen-aeld/buildroot-assignments-base GitHub Wiki
This is a wiki page which describes, documents and also provides some learnings from my final project for ECEN5713 which involved the use of the onboard Wi-Fi adapter. This wiki page will specifically talk about the Wi-Fi adapter and the usage of it as an Access Point for various wireless applications
Motivation
While I was working on my course final project which was a Captive Wi-Fi Gateway, I decided to use the onboard Wi-Fi interface to host the SSID of my network. This requires quite a few changes in the buildroot make menu config. Other than the normal hostapd package, certain firmware packages also have to be enabled. I spent quite some time on figuring out these packages and am therefore documenting it so that one does not have to spend the same amount of time again.
Required Packages
In order to be able to meaningfully host a network via the Wi-Fi interface on the Raspberry Pi, you would need to use the hostapd package.
Without hostapd, the Pi would only have a Wi-Fi interface, but it would not behave as an access point. In my project, hostapd is what makes the project act like a router or gateway from the client device perspective.
Why hostapd was needed
The project required the Pi to:
- create a Wi-Fi SSID
- accept client associations
hostapd-related Buildroot settings
The relevant package selections included:
BR2_PACKAGE_HOSTAPD=yBR2_PACKAGE_HOSTAPD_DRIVER_HOSTAP=yBR2_PACKAGE_HOSTAPD_DRIVER_NL80211=yBR2_PACKAGE_HOSTAPD_ACS=y
The most important one for this project was the nl80211 driver support, because modern Linux wireless access point operation uses the kernel wireless stack through nl80211.
hostapd role in runtime
At runtime, hostapd is started by the custom init script and uses the project’s hostapd.conf file to:
- bind to
wlan0 - advertise the configured SSID
- apply the configured security mode
- bring up the guest network
This is one of the core pieces that makes the full gateway architecture possible.
Raspberry Pi Wi-Fi Firmware
The onboard Raspberry Pi 4 Wi-Fi uses a Broadcom chipset and requires the correct firmware and kernel driver support.
Why firmware was important
Even with the kernel and hostapd present, the Wi-Fi AP would not work unless the Broadcom firmware blob for the SDIO Wi-Fi device was also included in the image.
That firmware is loaded by the kernel driver and is essential for the wireless device to initialize properly.
Firmware-related Buildroot settings
The important package selections were:
BR2_PACKAGE_BRCMFMAC_SDIO_FIRMWARE_RPI=yBR2_PACKAGE_BRCMFMAC_SDIO_FIRMWARE_RPI_WIFI=yBR2_PACKAGE_RPI_FIRMWARE=yBR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y
Why this mattered in the project
One of the most important early challenges in the project was getting the onboard Broadcom Wi-Fi to work reliably with hostapd.
The success of the access point, captive portal, and guest device flow all depended on:
- the correct Raspberry Pi firmware package
- the Broadcom Wi-Fi firmware package
- the
brcmfmackernel driver - the
hostapdpackage with proper wireless driver support
Once these were all aligned, the Pi was able to act as the guest Wi-Fi gateway.
Getting wlan0 to show up
After making the buildroot image with all the packages I have mentioned above, when I tested to see if wlan0 interface is connected, linux could not find it. It is very important to do modprobe on the terminal (if having an init script, have this as one of the first commands before starting hostapd so that the wlan0 interface is detected by the system).
Command
modprobe brcmfmac
Example Usage
Here are some scripts that I have made which can be used in your image to test and understand the wlan0 interface quickly.
This is the custom init script which you can reference in your buildroot image. The script loads and realizes the wlan0 interface. Script: https://github.com/cu-ecen-aeld/final-project-pranavshastry16/blob/main/S99wlan_setup.sh
This behavior is implemented in the custom init script:
board/raspberrypi4/overlays/rootfs_overlay_build05/etc/init.d/S99wlan_setup.sh
The access point configuration is provided by:
board/raspberrypi4/overlays/rootfs_overlay_build05/etc/hostapd.conf
To modify the wlan SSID settings, you will need to play around with the hostapd.conf file where you will see fields such as SSID=.... etc.
Kernel and Driver Relationship
The Linux kernel was built for Raspberry Pi 4 using the BCM2711 defconfig.
Important configuration points included:
- Raspberry Pi 4 kernel target
- device tree support for BCM2711
- support for the onboard wireless hardware
- integration with Raspberry Pi firmware
At runtime, the Wi-Fi side depends on the brcmfmac driver. In the project, the startup process explicitly loads that driver before bringing up the AP stack.
So the chain is:
- Buildroot includes kernel + firmware
- kernel provides
brcmfmac - firmware enables the Broadcom Wi-Fi device
hostapdconfigures that device as an AP
Other Networking Packages Selected in Buildroot
While hostapd and firmware were essential for Wi-Fi bring-up, several other Buildroot package selections were required to complete the gateway.
dnsmasq
Used for:
- DHCP leases
- DNS service to guest clients
- probe-domain handling for captive portal behavior
iptables
Used for:
- NAT
- client authorization and deauthorization
- captive portal redirection logic
- allow/block enforcement
iproute2
Used for:
- interface configuration
- static IP routing
- route management
iw
Used for:
- inspecting connected Wi-Fi stations
- online/offline device detection
lighttpd
Used for:
- captive portal web server
- admin portal web server
- CGI execution
dropbear
Used for:
- lightweight SSH access to the target for debugging and testing
Author Note
If you would like to see a demo implementation of hostapd from an application use case perspective, please feel free to visit my final project where I have used all of the above mentioned packages and integrated it into one single gateway. My project also features DHCP linked with the wlan0 interface so you can have a user device successfully obtain an IP address and connect to the network as well.
Embedded Linux based Wi-Fi Captive Gateway - Final Project : https://github.com/cu-ecen-aeld/final-project-pranavshastry16
Quick link to view the demo video of my project which explains the gateway : https://drive.google.com/file/d/1KbEnH9M319t7DJrfrMjbSj4TdqALYMBG/view?usp=sharing