Ad-Hoc Wireless connection fails on Ubuntu with NetworkManager on Atheros wireless device
Amain on December 14th, 2008
For some time now I experience problems with my Atherios Wireless NIC in combination with NetworkManager. For quite some time now, it’s possible for me to connect to a normal Wireless Access Point. Now I have an iPhone and want to use PDANet to connect a Laptop to the Internet using the iPhone 3G fast Internet capabilities. PDANet requires an Ad-Hoc wirless connection with the iPhone and works very similar to IP Masquarading(NAT).
With NetworkManager (which uses WPA supplicant) it’s not possible to do so. NetorkManager tries to connect to the selected Ad-Hoc network, but fails. Analizing logfiles, I concluded that this is because the mode change from “Managed” to “Ad-Hoc” does not work. WPA supplicant is instructed by NetworkManager to do so (using DBus communication).
Ubuntu 8.10 and 8.04 both have compiled WPA Supplicant with a limited set of drivers. 8.10 was compiled with:
- wext = Linux wireless extensions (generic)
- atmel = ATMEL AT76C5XXx (USB, PCMCIA)
- wired = wpa_supplicant wired Ethernet driver
NetworkManager instructs (at least for my card) to use the wext (Linux Wireless Extensions) driver to communicate with the hardware. Using iwconfig manualy (part wext) give an error:
root@jvz:~# iwconfig ath0 mode Managed
Error for wireless request “Set Mode” (8B06) :
SET failed on device ath0 ; Invalid argument
So it’s not strange for WPA Supplicant to fail to change the mode. ath_pci is the driver I’m using for my Atheros wireless card. See WifiDocs on ubuntu documentation for some more info on this driver.
Following the MadWifi UserDocs changing the mode of and MadWifi based card the following commands should be used:
wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode adhoc
Possible Solutions:
- Use ath5k new MadWifi driver, but I have tested it and the link stability was not good, but it works out of the box with NetworkManager
- Recompile WPA Supplicant to support the madwifi driver extensions and patch NetworkManager to use madfiwi instead of wext as commandline parameter for WPA Supplicant – not my favorite option!
- Create a sudo script which stops NetworkManager and issue the above madwifi wlanconfig command from the script and connect manualy
I choose to use the third option. Here is my adhoc.sh bash sudo script:
#!/bin/sh if [ "$1" != "sudo" ]; then { exec sudo "$0" sudo "$1" } fi function reload() { /etc/init.d/NetworkManager stop ifconfig ath0 down rmmod ath_pci modprobe ath_pci wlanconfig ath0 destroy wlanconfig ath0 create wlandev wifi0 wlanmode adhoc sleep 2 iwconfig ath0 key s:11111 iwconfig ath0 essid J3G iwconfig sleep 10 } function dhcp() { dhclient ath0 } function mail () { netstat -pan 2>/dev/null| grep ":25" | grep "tcpW" | grep LISTEN | grep ssh | awk '{print $7}' | sed 's!/ssh!!' | while read pid; do echo killing ssh: $pid sudo kill -9 $pid done echo -n "Starting SMTP tunnel...." ssh -N -f -L 25:mailserver:25 user@domain.tld echo "done" } function stop() { ifconfig ath0 down rmmod ath_pci modprobe ath_pci /etc/init.d/NetworkManager start } if [ "$2" == "mail" ]; then mail exit 0 elif [ "$2" == "all" ]; then reload dhcp mail elif [ "$2" == "dhcp" ]; then dhcp elif [ "$2" == "stop" ]; then stop else echo "usage: $0 all|dhcp|mail|stop" exit 1 fi
May 3rd, 2010 at 09:32
hi guys…
hi guysI would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well and i have start my own blog now, , thanks for your effort…