Wednesday 19 October 2011

Wicd cannot connect to ad-hoc networks

In my Nokia (5800 Xpress music) phone I have a network sharing application called Joikuspot. Its purpose is to use your phone as a wireless access point offering your mobile data plan via wi-fi to other devices (such as my laptop with Arch Linux). The provided wlan network is in ad-hoc mode though and my Wicd client cannot connect to it. dmesg says: "Unable to find TIM Element in beacon". After some research I found this bug, some says that it is solved in the newest version of wicd but for me upgrading to 1.7.0 did not solve the issue.

Fortunately the ad-hoc network works fine with manual configuration. To bring down the wlan0 interface and restart it in ad-hoc mode without passphrase (as my phone app does not support protected networking) and obtaining an IP address with dhclient (dhcpcd might work as well) simply use this command:

ifconfig wlan0 down && iwconfig wlan0 mode Ad-Hoc && iwconfig wlan0 essid <ESSID_of_your_wlan> key off && ifconfig wlan0 up && dhclient wlan0

As a workaround for wicd I created a preconnect script (more about wicd scripting: here) that runs this command and does not let wicd to destroy my ad-hoc connection (because it wants to do it) until another connection is set manually in the wicd client. I used a loop that does not let the script end while a lock file exists. Choosing another connection in wicd deletes the lock file, the ad-hoc script ends and gives back the control to wicd.

The script lies under /etc/wicd/scripts/preconnect/ad-hoc.sh

#!/bin/bash

script="$(basename "$0")"
script_name="${script/.sh/}"

echo $1 $2 $3 $4 $5 >> "/var/log/wicd/${script_name}.log"

echo "Running ${script}" >"/var/log/wicd/${script_name}.log"
exec 2>>"/var/log/wicd/${script_name}.log"
exec 1>&2

connection_type="$1"
echo "Connection type: ${connection_type}"

if [ "${connection_type}" == "wired" ]; then
        profile="$3"
        echo "Profile: ${profile}"
elif [ "${connection_type}" == "wireless" ]; then
        essid="$2"
        bssid="$3"
        echo "ESSID: ${essid}"
        echo "BSSID: ${bssid}"
else
        echo "Unknown connection type: ${connection_type}" >&2
        exit
fi

rm /var/lock/wicd_adhoc.lock

case $2 in
*JoikuSpot*)
  # When I connect to my phone my ESSID contains JoikuSpot
     touch /var/lock/wicd_adhoc.lock
     ifconfig wlan0 down && iwconfig wlan0 mode Ad-Hoc && iwconfig wlan0 essid $2 key off && ifconfig wlan0 up && dhclient wlan0

     while [ -f /var/lock/wicd_adhoc.lock ]
     do
     sleep 2;
     done

esac


Waiting for the real bugfix in the newer releases of wicd!

No comments:

Post a Comment