[HOWTO] Switching Dual WiFi-Bluetooth With a Hotkey

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
User avatar
MagicMint
Level 3
Level 3
Posts: 140
Joined: Fri May 31, 2013 1:29 pm

[HOWTO] Switching Dual WiFi-Bluetooth With a Hotkey

Post by MagicMint » Mon Apr 20, 2015 1:57 pm

This tutorial would be pointless, if the dedicated WiFi hotkey on my Asus Zenbook would work as intended. While the WiFi itself doesn’t pose any problems at all, its switch worked only halfway on Nadia, and it didn’t fall in love with Rebecca either :)

Kernel 3.13.0-37 doesn’t recognize the hotkey anymore, but as it turned out, this is a feature rather than a bug. Because the built-in Intel Centrino Advanced-N 6205 card is a dual band, combined WiFi-Bluetooth device with four possible states to choose from — which lets the kernel make random guesses at startup, login or wakeup :cry:

In short, it’s better to use a small script to make things more defined, which has the additional convenience of having a true control LED for the state of the WiFi hardware. The only drawback is that Bluetooth and WiFi are now tied together, which might be inefficient in battery mode, if you happen to use a Bluetooth mouse but no WLAN…

So install the following script as /usr/local/bin/wifi.sh, and make it executable:

Code: Select all

#!/bin/bash
# /usr/local/bin/wifi.sh	(MagicMint) O0108
# WiFi switch command for key binding
# (ɔ) GPL-2, see /usr/share/common-licenses/GPL-2

help_msg() {
	cat <<-EOF
	`awk  'FNR==3 {print gensub("# ", "", 1)}' "$0"`
	Usage: $0 [ --same ] | [ -h | --help ]
	EOF
}

case $1 in
	-h | --help )
		help_msg ;;

	--same )
		if LANG=C nmcli nm wifi | grep -q enabled; then
			rfkill unblock bluetooth
		else
			rfkill block bluetooth
		fi ;;

	*)	if LANG=C nmcli nm wifi | grep -q disabled; then
			nmcli nm wifi on
			rfkill unblock bluetooth
		else
			nmcli nm wifi off
			rfkill block bluetooth
		fi
	;;
esac
The command in itself just switches the state of the WiFi from on to off, or backwards. You should bind it to the key Super(=Windows)+F2 if the WiFi key is Fn+F2. (That is, add it to the Menu› Administration› System Settings› (Hardware›) Keyboard› Keyboard Shortcuts› Custom Shortcuts.)

With the option --same it keeps the state and does nothing else than to adjust the WiFi light. Thus, wifi.sh --same should be added to the Menu› Preferences› Startup Applications.

Additionally, the following script should be installed as /etc/pm/sleep.d/wifi-led.sh (and made also executable) in order to guarantee the same on resuming from sleep or hibernation:

Code: Select all

#!/bin/sh
# /etc/pm/sleep.d/wifi-led.sh	(MagicMint) O0112
# Restore power settings for wifi
# (ɔ) GPL-2, see /usr/share/common-licenses/GPL-2

case $1 in
	suspend|suspend_hybrid|hibernate)
	;;

	resume|thaw)
	if LANG=C nmcli nm wifi | grep -q disabled; then
		rfkill block bluetooth
	else
		rfkill unblock bluetooth
	fi;;
esac
Last edited by MagicMint on Thu Aug 06, 2015 10:56 am, edited 2 times in total.

JeremyB
Level 20
Level 20
Posts: 10324
Joined: Fri Feb 21, 2014 8:17 am

Re: Switching Dual WiFi-Bluetooth With a Hotkey

Post by JeremyB » Mon Apr 20, 2015 5:27 pm

Is asus_nb_wmi loaded

Code: Select all

lsmod | grep asus_nb

User avatar
MagicMint
Level 3
Level 3
Posts: 140
Joined: Fri May 31, 2013 1:29 pm

Re: Switching Dual WiFi-Bluetooth With a Hotkey

Post by MagicMint » Tue Apr 21, 2015 10:22 am

Yes, of course. Actually, for some reason it’s the only Fn key that doesn’t work — even Fn+A for the ambient light sensor does, although it has no key symbol assigned.

But as I’ve said, it doesn’t matter: I’d override it even if it worked because the state of the card is never that what you would expect :twisted: (it’s the same under Windows).

JeremyB
Level 20
Level 20
Posts: 10324
Joined: Fri Feb 21, 2014 8:17 am

Re: Switching Dual WiFi-Bluetooth With a Hotkey

Post by JeremyB » Tue Apr 21, 2015 1:09 pm

Have you tried changing the wapf parameter setting for asus_nb_wmi as it does affect rfkill?

Code: Select all

echo "options asus_nb_wmi wapf=1" | sudo tee /etc/modprobe.d/asus_nb_wmi.conf
Reboot and if no change replace 1 with another number, 0 is default and 0 - 4 are valid

User avatar
MagicMint
Level 3
Level 3
Posts: 140
Joined: Fri May 31, 2013 1:29 pm

Re: Switching Dual WiFi-Bluetooth With a Hotkey

Post by MagicMint » Wed Apr 22, 2015 12:30 pm

Nope. The wapf parameter has no effect, and as you can see above, rfkill as well as everything else is working. So it’s just the Fn+2 button that doesn’t work which I don’t care about :)

Post Reply

Return to “Tutorials”