View Single Post
Posts: 61 | Thanked: 64 times | Joined on Oct 2007 @ EU
#46
Workaround with UI (by using maemo-pan application) for solving this problem:

Tested on 2008HE. Installed packages: xterm, gainroot, wireless-tools.

1. Install maemo-pan. This will create Bluetooth-PAN dummy connection that will be used to connect to your home wlan from UI.
2. Edit /usr/lib/maemo-pan/pan-control file and replace the whole file with the below code.
3. Edit MY_NETWORK with your network name. This should be the name of the wireless network that you want to use and is already configured in Connections.
4. Edit MY_ESSID with your wireless SSID.

Maybe someone knows an algorithm to convert list of intergers returned from wlan_ssid to string (see line 25 from script)? In this case it could be set automatically in the script.

Note: Tested only WEP security. WPA security will not work, I guess the implementation is more complex to make it work with iwconfig.

Code:
#! /bin/sh

# Script for controlling the WLAN connection.

# exit codes:
#   0: OK
#   1: you are not root
#   2: connection failed


# are we root?
if [ `id -u` != 0 ]; then
    echo "Only root may run $0."
    exit 1
fi

COMMAND=$1
USER=user

# set network name for wlan as saved in Connections
# only WEP, WPA preshared and NONE security
MY_NETWORK="HOME_WLAN"
MY_ESSID="HOME_WLAN"

# MY_ESSID=`su - $USER -c "gconftool-2 -g /system/osso/connectivity/IAP/${MY_NETWORK}/wlan_ssid"`

infoprint() {
    local msg=$1
    su - $USER -c "dbus-send --session --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint \"string:$*\""
}

bnep_start() {
    infoprint "Connecting to $MY_NETWORK ..."
		ifconfig wlan0 up
		MY_SECURITY=`su - $USER -c "gconftool-2 -g /system/osso/connectivity/IAP/${MY_NETWORK}/wlan_security"`
		case $MY_SECURITY in
				WEP)
	  	  		MY_KEY=`su - $USER -c "gconftool-2 -g /system/osso/connectivity/IAP/${MY_NETWORK}/wlan_wepkey1"`
						iwconfig wlan0 enc $MY_KEY mode managed essid $MY_ESSID
				;;
				WPA_PSK)
    				MY_KEY=`su - $USER -c "gconftool-2 -g /system/osso/connectivity/IAP/${MY_NETWORK}/EAP_wpa_preshared_passphrase"`
						iwconfig wlan0 enc s:$MY_KEY mode managed essid $MY_ESSID
				;;
				NONE)
						iwconfig wlan0 mode managed essid $MY_ESSID
				;;
		esac
		udhcpc -i wlan0 -n
		MY_IP=`ifconfig wlan0 | grep inet`
    infoprint "Connected with $MY_IP"
}


bnep_stop() {
    infoprint "Disconnecting from $MY_NETWORK ..."
		ifconfig wlan0 down
		udhcpc -i wlan0 -n
		ifconfig wlan0 up
}


case $COMMAND in
    connect)
        bnep_start
        ;;
    disconnect)
        bnep_stop
        ;;
esac

Last edited by yrannadx; 2010-04-30 at 08:36. Reason: Refine the script
 

The Following User Says Thank You to yrannadx For This Useful Post: