WiFi configuration in FreeBSD (including WPA/WPA2)

Ok, once you have your drivers installed for your WiFi in FreeBSD, you’re ready to setup your WiFi.  I’m using an NDIS driver (see my post on Project Evil for more info) – so my wireless device is called ndis0.

I’m going to assume that you are using WPA/WPA2 and DHCP (the most common setup for WiFi) in this document.

To configure your wireless interface, add the following lines into /etc/rc.conf:

wlans_ndis0=”wlan0″
ifconfig_wlan0=”WPA DHCP”

Now we need to configure the WPA/WPA2 settings.  I will assume we have 2 wireless networks for this – “wifi1″ and “wifi2″ which have the WPA/WPA2 keys of “one” and “two” respectively.  We will prefer to connect to “wifi1″ when possible.

To setup WPA/WPA, edit (or create) the file /etc/wpa_supplicant.conf and add the following:

network={
priority=1
ssid=”wifi1″
psk=”one”
}

network={
priority=2
ssid=”wifi2″
psk=”two”
}

Next time you restart your computer, you will have a ‘wlan0′ interface which will attempt to connect to the listed networks (in order of priority).  You can confirm it is associated with ifconfig wlan0 – in my case, i get:

wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether xx:xx:xx:xx:xx:xx
inet 172.31.0.100 netmask 0xffffff00 broadcast 172.31.0.255
media: IEEE 802.11 Wireless Ethernet autoselect mode 11g
status: associated
ssid wlan1 channel 7 (2442 Mhz 11g) bssid yy:yy:yy:yy:yy:yy
country US authmode WPA2/802.11i privacy OFF txpower 0 bmiss 7
mcastrate 0.5 mgmtrate 0.5 scanvalid 60 protmode CTS roaming MANUAL
bintval 0

Now, although it says “11g”, it actually achieves 802.11n speeds so you can ignore this.

14 thoughts on “WiFi configuration in FreeBSD (including WPA/WPA2)

  1. Donald_McCormack

    Can I have a combination of WPA and none authenticated setups in the same BSD machine.

    At home I use WPA2, but most public use open, eg starbusks. How can I set them both so I can switch between them?

  2. dan Post author

    you can have multiple network blocks in your wpa_supplicant.conf file – check out the man page for it for some examples of different types of authentication supported. You can also set the priority of networks in case you may be in a location where you have more than one defined network.

  3. JJ

    I appreciate the instructions for this and Project Evil. They will hopefully allow me to use a B-Link card based on the RaLink RT3062 chip (rt2860 code).

    However, when I boot with the wpa_supplicant.conf file in /etc/, the kernel panics with a double fault. If I remove it, the system starts and the ifconfig wlan0 looks proper except the status is not displayed and during startup NIS complains that it cannot find /compat/ndis/rt2860.bin and /compat/ndis/rate.bin. When I run #wpa_supplicant -i wlan0 -c /root/wpa_supplicant.conf nothing changes until I run #ifconfig wlan0 list scan at which time the kernel panics.

    Any suggestions?

  4. dan Post author

    Some drivers require extra firmware files that are uploaded to the chip when the driver loads. It sounds like this is one of those. When you build the driver, it asks you if there are any firmware files – you may have to give it the list of the .bin files from the driver.
    I’ve never had a card that needed firmware files (under NDIS) so I can’t confirm if it works or not.

  5. JJ

    I installed Windows on a second drive of the computer. With the card installed and operating neither of the two files are present. However, in the Linux driver package, there is a file rt2860.bin.
    Is the Linux driver compatible with FreeBSD?

  6. JJ

    Do I need to enable Linux compatibility mode?
    From your “Installing Gnome …” blog:
    edit /boot/loader.conf – add the following lines:
    linux_load=”YES”
    linprocfs_load=”YES”
    This will load the linux compatibility layer, and linux procfs compatibility modules

  7. dan Post author

    you shouldn’t need to as the file should be a firmware file for the wifi adapter (rather than a driver or program for the OS) – so it should be OS neutral.

  8. JJ

    OK – now it only complains about rate.bin missing. I can start & stop wpa_supplicant but nothing happens until a scan is initiated. It still generates a kernel panic as soon as the first scan is initiated.

    BTW – does wpa_supplicant always throw the message about ntoskrnl dummy called when it starts?

    Also, is there some way to use Linux drivers directly?

  9. dan Post author

    hmm just been looking through the source code… have you tried the if_ural driver? (if_ural_load=”YES” in /boot/loader.conf) it claims on freebsd 8.2 to support a load of rt2860 chipset devices.

  10. JJ

    Dan – the ural driver appears to support usb only – my card is pci. I tried using the ural load and the card is not recognized. (If it’s important, I am on 8.2 prerelease 2/14/2011.)

    I was using the driver CD that came with the card. RaLink has posted an updated driver for the RT3062. Using the new .ko module generated with it, I no longer get the kernel panic. And, when I run wpa_supplicant, the ndis0 interface status changes to “associated” although there is no change to the wlan0 interface despite the network block in the wpa_supplicant.conf. (The ndis0 status changes back to “no carrier” when wpa_supplicant is terminated.)

    Do you have any suggestion for what to do next?

  11. dan Post author

    Usually that is a sign that your security keys may not be correct in wpa_supplicant.conf – other than that, i’m not sure.

  12. JJ

    No luck. I even tried with an open network to eliminate potential key problems. I’m shelving the project and returning the card.

    Thanks for the help anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>