GNOME Bugzilla – Bug 513488
Option to disable wifi when wired network is detected
Last modified: 2014-04-28 22:06:52 UTC
Hello, Having an option to disable wifi when a wired network is detected and reactivating it after unplugging would be useful, in order to save battery on laptops. Moreover, this is probably a really easy to implement feature, for someone who knows NM code. Regards, Nicolas
Sounds pretty sane, confirming.
Still valid in 9.x.
Still valid in 9.x. From bug 679275: Roan Kattouw [reporter] 2012-07-27 00:23:09 UTC Is this a new feature? I can see how trying to autoconnect to wifi even when eth is already up would be consistent with supporting multiple connections, so if those two things were introduced at the same time, that makes sense. It would still be nice to have a config option to limit autoconnect to 1 interface though (with eth preferred over wifi, as in previous versions of NM).
*** Bug 679275 has been marked as a duplicate of this bug. ***
(In reply to comment #4) > *** Bug 679275 has been marked as a duplicate of this bug. *** What I raised on that bug is subtly different: instead of disabling the wifi hardware to save power (which would also be nice), I want NetworkManager to stop trying to autoconnect to wifi networks (and prompting me for their passwords) when I have a live connection on a wired network. Obviously disabling the wifi hardware entirely would also accomplish that :)
It seems so related to me that I'll keep it in one bug report, if you don't object.
(In reply to comment #6) > It seems so related to me that I'll keep it in one bug report, if you don't > object. Sure, no problem. Just pointing out that my request is a subset of the original reporter's request.
How do I vote +1? +1 anyways, I'd like to see this feature implemented.
Created attachment 223570 [details] [review] Patch for disabling wifi connection(s) when wired connection is available This is not meant to compile. Just for feedback on the approach. Don't laugh. Still missing is a (global) config option that enables this "powersave"/single-connection mode.
A counter-proposal here would involve using dispatcher scripts to do this. Thus, when an ethernet connection was up, the dispatcher script would call 'nmcli nm wifi off' or such, and when all ethernet connections went down, it could call 'nmcli nm wifi on'. We'd need to: 1) enhance the dispatcher to put the device type into the script environment, which currently is not the case. That would involve passing the value of the hash key NMD_DEVICE_PROPS_TYPE into construct_basic_items() in callouts/nm-dispatcher-utils.c and putting that into the script environment. 2) create a dispatcher script that checks the device type and rfkills wifi when any ethernet connection starts; if the device type isn't present, the script can call 'nmcli -t --fields type,state dev' which returns output liek this: 802-11-wireless:connected 802-3-ethernet:unavailable and if any 802-3-ethernet device is "connected" then rfkill wifi using 'nmcli nm wifi off'. 3) when any interface gets disconnected, run the same 'nmcli -t --fields type,state dev' and if all 802-3-ethernet devices are unmanaged, unavailable, or disconnected, then unkill wifi using 'nmcli nm wifi on"
Created attachment 223572 [details] [review] Patch that disables wifi when wired connection is available Second one, which just disables/enables wifi completely by recommendation from dcbw on irc. Will follow Comment 10 now.
For 3, really, we just want to grep the nmcli output and look for "802-3-ethernet:connected" || "802-3-ethernet:connecting" and if neither of those are found, unkill wifi.
Here it is, the dispatcher script you need in all its glory /etc/NetworkManager/dispatcher.d/wifi-xor-wired #!/bin/bash # Author: Johannes Buchner (C) 2012 # Disables wifi when wired connection is available # Enables wifi when wired connection is lost if nmcli -t --fields type,state dev | grep -E "802-3-ethernet:connected" -q then # ethernet is available, so we can drop the wifi nmcli nm wifi off && echo "disabled wifi" elif nmcli -t --fields type,state dev | # no ethernet, wifi please help us grep -E "802-3-ethernet:(disconnected|unavailable)" -q then nmcli nm wifi on && echo "enabled wifi" fi
Created attachment 275137 [details] [review] 0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch Updated 0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch following Johannes' suggestions.
Comment on attachment 275137 [details] [review] 0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch >+# (C) 2012 Johannes Buchner <buchner.johannes@gmx.at> >+# (C) 2012 - 2014 Red Hat, Inc. IANAL, but I was told at one point that "(C)" is technically legally meaningless, because it is not literally a circled C. So, "Copyright" is preferred. >+ #with older nmcli, use nmcli nm wifi off This will only be shipping with newer nmcli, so I don't think we need those comments.
Fixed up for your comments and pushed to git master.