forked from John-Vision/Intel-7260-Wifi-Fix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixwifi-force
103 lines (81 loc) · 4.62 KB
/
fixwifi-force
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
#############################################################################################################
# #
# This script requires "ifconfig" to be installed. If not installed, then do so now! #
# sudo apt install net-tools #
# The interface name is set below as "wlp3s0". If yours is different seach through and replace with yours. #
# #
#############################################################################################################
# You need to know the designations for your wifi interface.
# You can find these out by running: sudo lshw -C network
# Look through the output, and replace the information between the quotes, as necessary, in the following settings.
# product
wirelessPCI=$(lspci |grep "Wireless 7260")
# logical name
interface="wlp3s0"
# Intel voodoo. The setting below is known to work with the Wireless 7260. If we knew what this value should be
# for other Intel chipsets, this script should work for them as well. Maybe it's the same for multiple chipsets?
voodoo="0x50.B=0x40"
# Don't change anything below this line.
###########################################################################################################
# If this script works, then do "sudo crontab -e" and # add the following, without the initial hash (#) in each line.
#* * * * * /home/kflynn/.fixwifi
#* * * * * sleep 20; /home/kflynn/.fixwifi
#* * * * * sleep 40; /home/kflynn/.fixwifi
###########################################################################################################
#---------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------
# If we got to this point then we have detected a problem with wifi (wifiOK=false).
# The rest of this script will get it back up and running!
# Figure out what pci slot Linux has assigned the Network controller: Intel Corporation Wireless 7260
pci=$(echo ${wirelessPCI} | awk '{ print $1 }')
devicePath="/sys/bus/pci/devices/0000:$pci/remove"
# Not the best solution as this script can hang.
# But since if this script fails the ONLY way to revive the wifi anyway is a reboot...
# Feel free to improve the script if you have the scriptfu ninja skills to do so.
while true; do
# Tell Linux to remove the wifi card from the PCI device list only if it exists in the first place.
if [ -f $devicePath ]; then
echo '----removing device'
echo 1 | sudo tee $devicePath > /dev/null
sleep 1
fi
# Reprobe the driver modules in case we have removed them in a failed attempt to wake the network card.
echo '----reprobing drivers'
sudo modprobe iwlmvm
sudo modprobe iwlwifi
# Try to have Linux bring the network card back online as a PCI device.
echo '----pci rescan'
echo 1 | sudo tee /sys/bus/pci/rescan > /dev/null
sleep 1
# Check if Linux managed to bring the network card back online as a PCI device.
if [ -f $devicePath ]; then
echo '----device is back'
# Looks like we are back in business.
# So we try to set the PCI slot with some voodoo I don't understand that the Intel devs told me to try.
# https://bugzilla.kernel.org/show_bug.cgi?id=191601
sudo setpci -s $pci $voodoo
sleep 1
wifiId=$(rfkill list |grep Wireless |awk -F: '{ print $1 }')
echo "----rfkill unblock wireless device: $wifiId"
sudo rfkill unblock $wifiId
sleep 1
# Bring the wireless network interface up.
sudo ifconfig $interface up
# Did the wifi interface actually go live?
exitCode=$?
echo "----device UP status $exitCode"
if [ $exitCode -eq 0 ];then
# This should be the default for wireless devices as it is well documented that enabling power management causes problems.
sudo iwconfig $interface power off
# The exit code will be the exit code of our attempt at turning power management off for the interface.
break
fi
else
# The restart attempt failed, so we need to remove the the wifi driver modules and loop back in another attempt to revive the wifi.
echo "----WIFI RESTART FAILED - ATTEMPTING AGAIN"
sudo modprobe -r iwlmvm
sudo modprobe -r iwlwifi
fi
done
echo "DONE - WIFI SHOULD RESTART NOW."