How to setup Wireless Access Point on Raspberry Pi running FreeBSD

Usually we connect the Raspberry Pi to the existing network.
But there are situations when we need to setup wireless access point.
This is for example, when the Raspberry Pi works as server for accepting data from different devices in a location without a network.
Here is an description how to setup a Wireless Access Point on the Raspberry Pi running FreeBSD 10.


We can use chapter from the official FreeBSD Handbook, but it isn’t complete.

Setup an adapter

First, we need an WiFi adapter which support hostap mode.
We should see HOSTAP in the list of the adaptor’s capabilities:

# ifconfig wlan0 create wlandev ath0
# ifconfig wlan0 list caps
drivercaps=6f85edc1<STA,FF,TURBOP,IBSS,HOSTAP,AHDEMO,TXPMGT,SHSLOT,SHPREAMBLE,MONITOR,MBSS,WPA1,WPA2,BURST,WME,WDS,BGSCAN,TXFRAG>
cryptocaps=1f<WEP,TKIP,AES,AES_CCM,TKIPMIC>

Adafruit says that the adapter from its shop support this mode.
Unfortunately, it does not support this mode in the FreeBSD.

AP01

In the FreeBSD Manual Pages I found three chipsets for USB WiFi adapters which support HostAP mode.
This are rum(4), run(4) and ural(4) adapters.
Each manual page has a list of adapters from different manufacturers.

I found in one local store D-Link DWA-140 rev B1.
I inserted it into my Raspberry Pi, booted it with the last FreeBSD 10 stable snapshot and checked ifconfig:

AP03

We don’t see any WiFi adapters, only Loopback and wired Ethernet.
Let’s load kernel modules for our adapter by hand:

# kldload /boot/kernel/if_run.ko
# kldload /boot/kernel/runfw.ko

AP04

We got our adapter.
Now we need to create a wlan pseudo-device from our adapter:

# ifconfig wlan0 create wlandev run0

And we got an message that we need to load wlan_amrr module. Let’s load it:

# kldload /boot/kernel/wlan_amrr.ko

AP05

Let’s check its capabilities:

# ifconfig wlan0 list caps

AP06

My adapter supports HostAP mode!
Now we need to recreate a wlan pseudo-device to put it in HostAP mode.

# ifconfig wlan0 destroy
# ifconfig wlan0 create wlandev run0 wlanmode hostap
# ifconfig wlan0 inet 192.168.1.1 netmask 255.255.255.0 ssid pibsd mode 11g channel 1

I setup ip address 192.168.1.1 with netmask 255.255.255.0 for wlan0 pseudo-device.
This means that devices connected to this adapter should has ip address in the network 192.168.1.0/24
I use "pibsd" as SSID, mode 11g and channel 1.

AP07

We have configured our Wireless Access Point.
It doesn't use any authentication and doesn't provide ip addresses to clients but it can accept connections now.

I have checked our new wireless network on my smartphone.

AP28

It sees the "pibsd" network. And this network is "open".
To work with this network we need to setup ip address for our client.
Here is an example for Windows machine:

AP08

AP09

AP10

Our Windows client is connected to our Access Point.

To make our settings permanent we need to load kernel modules and to setup wlan at startup.

We need to add next strings to /boot/loader.conf for D-Link DWA-140:

if_run_load="YES"
runfw_load="YES"
wlan_amrr_load="YES"

AP11

We need to add next strings to /etc/rc.conf to setup wlan:

wlans_run0="wlan0"
create_args_wlan0="wlanmode hostap"
ifconfig_wlan0="inet 192.168.1.1 netmask 255.255.255.0 ssid pibsd mode 11g channel 3"

AP12

I have changed channel from 1 to 3 for permanent usage.

After reboot we can see that our adapter works in HostAP mode:

AP13

Authentication

It is a good idea to have an authentication for our new Access Point.
I use WPA-PSK as "good enough" authentication method.

We need to setup and use hostapd(8) daemon for client authentication and key management on the AP with WPA.

The configuration is done in /etc/hostapd.conf:

interface=wlan0
debug=1
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
ssid=pibsd
wpa=1
wpa_passphrase=mysecretpassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP TKIP

AP17

Here we use interface wlan0, SSID "pibsd", "mysecretpassphrase" as WPA passphrase and WPA-PSK as key management protocol.

After that we can start hostapd(8) daemon.

AP18

And connect to AP with WPA authentication method:

AP19

We can check which clients are connected to our AP:

# ifconfig wlan0 list sta

AP20

To make our settings permanent we need to add next string to /etc/rc.conf:

hostapd_enable="YES"

AP16

DHCP

Complete Wireless Access Point should provide ip addresses for its clients.
It should have DHCP service.
Internet Systems Consortium provide DHCP software.
There is this software in FreeBSD ports.

First, we need to compile and install isc-dhcp-server:

AP15

Second, we need to create a configuration file for our DHCP server.
This is file /usr/local/etc/dhcpd.conf
It's enough to have a simple configuration.
I have network 192.168.1.0/24.
DHCP server will provide ip addresses from 192.168.1.10 to 192.168.1.250.
And our AP with ip address 192.168.1.1 will be a default router for our clients.

AP24

To start the DHCP server at boot time we to add next strings to /etc/rc.conf:

dhcpd_enable="YES"
dhcpd_flags="-q"
dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_ifaces="wlan0"
dhcpd_withumask="022"
dhcpd_chuser_enable="YES"
dhcpd_withuser="dhcpd"
dhcpd_withgroup="dhcpd"
dhcpd_chroot_enable="YES"
dhcpd_devfs_enable="YES"
dhcpd_rootdir="/var/db/dhcpd"

AP23

After reboot we can connect clients to our new and complete Wireless Access Point.

Windows machine connected to AP:

AP22

To connect FreeBSD machine we need to prepare correct /etc/wpa_supplicant.conf file:

AP26

Here is the result:

AP27

This is second Raspberry Pi with FreeBSD as client connected to first Raspberry Pi with FreeBSD as server.
Yes, I have two Raspberry Pi 🙂

Advertisements

2 thoughts on “How to setup Wireless Access Point on Raspberry Pi running FreeBSD

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s