Ubuntu – (Yet another) Wifi issue after suspend in Ubuntu 16.04

16.04driversnetwork-managernetworkingsuspend

I'm posting here as having troubles with the wifi after suspend.

I recently bought a new pcie wifi card (TP-LINK TL-WN881N), and it all works great. Unfortunately, it seems things turn bad when I put my computer to sleep, as the wifi doesn't work properly after waking up.

In face, the problem is weird. It does connect to the wifi network, connection is showed in nm-applet, connection seems alright in ifconfig, routes are fine, but it seems the drivers gets in a buggy mode where I cannot even ping (or reach in anyway) my gateway or any other location.

I tried different fixes, like the one here Wifi doesn't work after suspend after 16.04 upgrade or here Wireless networking not working after resume in Ubuntu 14.04 and none of them worked.
The weirdest thing is, if I try to manually restart the network-manager service, things don't get solved and instead I even get troubles listing the wifi networks. A reboot seems like the only way to solve the problem so far.

Here are some details about my card and driver:

$sudo lshw -class network
  *-network               
       description: Wireless interface
       product: RTL8192EE PCIe Wireless Network Adapter
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: wlp2s0
       version: 00
       serial: 30:b4:9e:72:08:78
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=rtl8192ee driverversion=4.10.0-32-generic firmware=N/A ip=192.168.2.2 latency=0 link=yes multicast=yes wireless=IEEE 802.11
       resources: irq:127 ioport:d000(size=256) memory:f7100000-f7103fff

Thanks!

edit:

Solved! Thanks @WinEunuuchs2Unix, it seems that by applying a similar method than the one described here WiFi signal icon switches to Ethernet icon (up down arrows) after Suspend?, I managed to solve the problem.

The conditions were not exactly the same, and I had to adapt the solution. Basically, restarting network-manager doesn't fix the problem, but unloading the reloading the kernel module worked!
So here is how I adapted the script:

#!/bin/sh                                                                                     

# NAME: /lib/systemd/system-sleep/wifi-reset                                                  
# DESC: Resets Realtek WiFi after a long suspend.                                             
# DATE: Aug 25, 2017. Modified Aug 25, 2017.                                                  

MYNAME=$0                                                                                     

DRIVER=rtl8192ee                                                                              

restart_wifi() {                                                                              
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'                                              
    /sbin/modprobe -v -r $DRIVER # This removes the driver                                    
    /sbin/modprobe -v $DRIVER   # This starts the driver                                      
    #systemctl restart NetworkManager.service # network manager restart disabled as not needed
    /usr/bin/logger $MYNAME 'restart_wifi END'                                                
}                                                                                             

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'                                                     
case "${1}/${2}" in                                                                           
    hibernate|suspend|pre*)                                                                   
    ;;                                                                                        
    resume|thaw|post*)                                                                        
        restart_wifi;;                                                                        
esac                                                                                          

It works perfectly now 🙂

Thanks guys!

Best Answer

Solved! Thanks @WinEunuuchs2Unix, it seems that by applying a similar method than the one described here WiFi signal icon switches to Ethernet icon (up down arrows) after Suspend?, I managed to solve the problem.

The conditions were not exactly the same, and I had to adapt the solution. Basically, restarting network-manager doesn't fix the problem, but unloading the reloading the kernel module worked! So here is how I adapted the script:

#!/bin/sh                                                                                     

# NAME: /lib/systemd/system-sleep/wifi-reset                                                  
# DESC: Resets Realtek WiFi after a long suspend.                                             
# DATE: Aug 25, 2017. Modified Aug 25, 2017.                                                  

MYNAME=$0                                                                                     

DRIVER=rtl8192ee                                                                              

restart_wifi() {                                                                              
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'                                              
    /sbin/modprobe -v -r $DRIVER # This removes the driver                                    
    /sbin/modprobe -v $DRIVER   # This starts the driver                                      
    #systemctl restart NetworkManager.service # network manager restart disabled as not needed
    /usr/bin/logger $MYNAME 'restart_wifi END'                                                
}                                                                                             

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'                                                     
case "${1}/${2}" in                                                                           
    hibernate|suspend|pre*)                                                                   
    ;;                                                                                        
    resume|thaw|post*)                                                                        
        restart_wifi;;                                                                        
esac                                                                                          

It works perfectly now :)

Thanks guys!

Related Question