How can I control switching between wireless APs on Linux?

Because the walls of my house are thick and tend to attenuate wireless signals badly, I have two access points in different parts of my house, configured on the same SSID with the same settings. Both work well in general. However, in a similar way to that observed by this user, I find that moving my laptop from one room to another doesn't cause it to switch access points quickly enough; either its rescanning is too infrequent, or the threshold of signal quality is too low, or both. This leads to an irritatingly long period where the network won't respond.

Can I control this at all on Linux? (which is what my laptop runs - more specifically, I have CrunchBang, a Debian variant, if it matters). I'd like to be able to alter that signal threshold and/or rescan period if possible to make it more aggressive at switching.


Solution 1:

It takes a while for the network manager to decide that the connection is not coming back and only then will it try to reconnect. I find wicd to be more "responsive" than NetworkManager - I'd consider switching to that.

You could also run a background script that polls the signal strength and forces a disconnect if the signal falls beyond a certain level. Once disconnected your network manager will normally connect to a network with stronger signal.

Example script using iw(1) from the iw package:

#!/bin/bash
IFACE="wlan0"
LIMIT="-75"
while true; do
        signal=$(iw $IFACE link | grep signal | awk '{print $2}')
        [ $signal ] && [ $signal -lt $LIMIT ] && iw $IFACE disconnect
        echo $signal
        sleep 1
done

Solution 2:

Roaming between access points is managed by wpa_supplicant, so to switch to a particular access point without dropping the connection for longer than needed, use wpa_cli roam. For example:

rav@fred:~$ sudo wpa_cli -i wlp58s0 scan_results 
bssid / frequency / signal level / flags / ssid
60:45:cb:94:d1:50   2447    -47 [WPA2-PSK-CCMP][ESS]    NextDoorBut1
cc:e1:d5:7c:af:a8   2417    -75 [WPA2-PSK-CCMP][WPS][ESS]   NextDoorBut1
10:6f:3f:4c:54:83   2427    -70 [WPA2-PSK-CCMP][ESS]    NextDoorBut1

rav@fred:~$ sudo wpa_cli -i wlp58s0 roam 60:45:cb:94:d1:50
OK

This only works for switching between APs on the same SSID, of course - and it requires you to do a bit of prior research to figure out the BSSID for each AP.