Wifi disconnected after resume 16.04 - Other solutions don't work

I am a new Ubuntu user and have so far really enjoyed it. However, I spent around 3 hours yesterday trying to get my wifi to resume after my laptop wakes from sleep mode (it works if i reboot). I have scoured message boards and all the links on google are purple 3 or 4 pages in for every search result on this matter. Therefore, I don't think this question will be a repeat.

I have

  • A Dell Inspiron 15
  • AMD A6-6310
  • Ubuntu A6-6310
  • My wireless card is labeled as (device) wlp3s0 (driver) ath9k

and I have tried the following:

I have put these into a config folder in /config.d

SUSPEND_MODULES="$SUSPEND_MODULES ath9k"

SUSPEND_MODULES="ath9k"

I have created executable files in /sleep.d such as:

 #!/bin/sh
#Tell Network Manager that resume was successful
case "$1" in
        thaw)
       /usr/bin/nmcli nm sleep false
      ;;
 esac

#!/bin/sh

case "${1}" in
 resume|thaw)
 nmcli r wifi off && nmcli r wifi on ;;
esac

and many other variants thereof.

Also, this restarts the NetworkManager but does not connect wifi again:

sudo service network-manager restart

There are a couple other things I have tried that I can't exactly remember with commands like nmcli d wifi on, or something. They didnt work.

Now, I may be wrong, but I think the problem might lie in this:

sudo nmcli nm sleep false

Now, my terminal does NOT recognize "nm" and says:

sudo nmcli nm sleep false

and when I pull up the menu for nmcli, nm is nowhere in the object list. I feel like this might be the key to the problem. So, is there anything that I haven't done that I should do and is there any way to "fix" the "nm" problem? Thanks in advance!


Solution 1:

EDIT: Driver misbehavior on returning from suspend is a problem I've run across several times with several network interfaces across several operating systems. The only thing I've found to be effective across all of these is to turn power management off for the WiFi card. After reviewing the adjustments I made to a system to resolve a similar problem I offer the following resolution.

First we will make a backup of existing default power management settings with:

sudo cp /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf.bak

Next we will edit the content to turn power management for WiFi off entirely. with gksu gedit /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf which contains the default value wifi.powersave = 3 which enables power saving on the WiFi device. Changing the content of this file to:

[connection]
wifi.powersave = 0

Completing the above and also renaming my interface to wlan0 resolved my issues under 16.04

Once that is done you'll need to reboot or issue the command sudo systemctl restart NetworkManager to restart Network Manager

Note: My card does not have an Atheros chip and is identified as follows:

*-network description: Wireless interface product: RT2561/RT61 802.11g PCI vendor: Ralink corp. physical id: 1 bus info: pci@0000:04:01.0 logical name: wlan0 version: 00 serial: 00:1a:ef:03:00:aa width: 32 bits clock: 33MHz capabilities: pm bus_master cap_list ethernet physical wireless

Alternatives that may work for others with a similar problem are:

Put the bash script below in your /etc/pm/sleep.d folder with a name like 99_wifiup.

NOTE: The 99_ is needed where the 99 is the highest number in the folder to ensure it runs last.

You'll need to insure that the script has execute permissions and you'll need superuser (sudo) permissions to write the file there. Once in place every time you come out of suspend it will run.

#!/bin/bash

case "$1" in
suspend | hibernate)
# executed on suspend
;;
resume | thaw)
# executed on resume
/usr/sbin/rfkill block all
/usr/sbin/rfkill unblock all
/sbin/iwlist wlan0 scan
;;
*)
;;
esac 

If that doesn't work it should be worth exploring modifying the script to issue the commands nmcli networking off on suspend and nmcli networking on on thaw.

If none of these solutions work for you and you notice other anomalies you may have a faulty WiFi adapter or perhaps this bug has been resurrected.

Sources:

Modified /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf and /etc/udev/rules.d/70-persistent-net.rules on one of my systems.

Mickeypop post #9 https://ubuntuforums.org/showthread.php?t=2321399

man nmcli

https://gist.github.com/jcberthon/ea8cfe278998968ba7c5a95344bc8b55

Solution 2:

I've found wifi power management often to be a bane of the linux experience. In my case, it was across various Intel and Broadcom adapters. Perhaps disabling it will resolve your issue. Here is how I do it (edit for your interface wlp3s0):

Create: /etc/network/if-up.d/wifi-powerman-off
Enable: chmod +x /etc/network/if-up.d/wifi-powerman-off

wifi-powerman-off:

#!/bin/sh
IWCONFIG=/sbin/iwconfig
WLAN_IFACE=<<interface name>>
if [ ! -x $IWCONFIG ]; then
    exit 1
fi
if [ "$IFACE" = $WLAN_IFACE ]; then
    $IWCONFIG $IFACE power off
fi

Here is the original Q & A reference:
How can I prevent iwconfig power management from being turned on?