Monday, March 29, 2010

Converting WiFi Adapter into 802.11g Access Point (WPA2-PSK) on FreeBSD

I originally had an ASUS WL500g Premium running on DD-WRT (released back in 2006), configured as Access Point with DHCP forwarding enabled. This allowed my laptops and iPhone at home to connect to this AP and automatically connect to the internet through BSD gateway.

I bricked this WiFi router when I did a software upgrade. At the same time, I also have two other WiFi routers at home - NetGear WNR2000 and TP-Link TL-WR740N. Both cannot be configured as WiFi Ethernet Bridge, nor have DHCP forwarding options. Also, there's no DD-WRT support.

I do not wish to add another layer of NAT for my home network, so I purchased the most economical WiFi Adapter I could find and convert it into a WiFi access point. The Adapter is TP-Link TL-WN851N (onboard PCI), running on Atheros 9280 chipset.


Configuring WiFi Access Point
From memory, the necessary kernel options for Atheros driver are already present in GENERIC file by default, so probably no further work was required... there is a chapter in FreeBSD handbook on "Wireless Network" for reference. http://www.freebsd.org/doc/handbook/network-wireless.html


Afterwards, I installed the hardware, startup BSD and the WiFi adapter was correctly recognized as "ath0":
ath0: (Atheros 9280) mem 0xfc500000-0xfc50ffff irq 5 at device 4.0 on pci5
ath0: [ITHREAD]
ath0: AR9280 mac 128.2 RF5133 phy 13.0

Then I proceeded to configure it. It was when I noted the system wouldn't allow me to provision any parameters using "ifconfig ath0". Did some research online and noted in FreeBSD 8.0, a virtual device (wlan0) has to be created prior to provisioning any WiFi configuration... which is different from previous BSD releases [http://forums.freebsd.org/showthread.php?t=11978].

Here is how I created my pseudo wireless device, wlan0. I also needed to set the option "wlanmode hostap" for it to be created as access point:
# ifconfig wlan0 create wlandev ath0 wlanmode hostap

Setting the AP to be WPA-PSK mode requires hostapd. There is an rc.d script to start this. My configuration file "/etc/hostapd.conf" is as follows:
interface=wlan0
debug=1
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=(your-ssid)
country_code=AU
hw_mode=g # I tried setting this to 802.11n, but encountered some error.
channel=0
basic_rates=60 120 240
wpa=1
wpa_passphrase=(wifi-passphrase)
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP

Finally, set IP interface on wlan0 and update DHCP daemon, along with other services to listen on this interface.

To startup this service when system boots, add the following to "/etc/rc.conf" file
wlans_ath0="wlan0"
create_args_wlan0="wlanmode hostap"
hostapd_enable="YES"
ifconfig_wlan0="inet 192.168.2.1 netmask 255.255.255.0 up" # Gateway

So this is how to set your WiFi adapter to become a Wireless Access Point.


After Thoughts - Usage Notes
Having used this for awhile, I must admit it is not as stable as having a dedicated Wireless router. The wireless connection would drop occassionally while "dmesg" kept displaying the message "ath0: stuck beacon; resetting (bmiss count 4)".

I found this wikipage dedicated to the stuck beacon issue. [http://madwifi-project.org/wiki/StuckBeacon]. While I have not resolved the root cause, the issue has been mitigated through running the sysctl variable: net.wlan.0.bmiss_max: 2 -> 10

Here with my setup today... 












[Jan 2012] An additional note: this wireless setting supports WPA authentication, but not WPA2 authentication. 



No comments:

Post a Comment