tests: Rename stop-wifi.sh to stop.sh
[mech_eap.git] / tests / hwsim / stop.sh
1 #!/bin/sh
2
3 if pidof wpa_supplicant hostapd valgrind.bin hlr_auc_gw > /dev/null; then
4     RUNNING=yes
5 else
6     RUNNING=no
7 fi
8
9 sudo killall -q hostapd
10 sudo killall -q wpa_supplicant
11 for i in `pidof valgrind.bin`; do
12     if ps $i | grep -q -E "wpa_supplicant|hostapd"; then
13         sudo kill $i
14     fi
15 done
16 sudo killall -q wlantest
17 sudo killall -q tcpdump
18 if grep -q hwsim0 /proc/net/dev; then
19     sudo ifconfig hwsim0 down
20 fi
21
22 killall -q hlr_auc_gw
23
24 if [ "$RUNNING" = "yes" ]; then
25     # give some time for hostapd and wpa_supplicant to complete deinit
26     sleep 0.5
27     for i in `seq 1 5`; do
28         if pidof wpa_supplicant hostapd valgrind.bin hlr_auc_gw > /dev/null; then
29             echo "Waiting for processes to exit (1)"
30             sleep 1
31         else
32             break
33         fi
34     done
35 fi
36
37 if pidof wpa_supplicant hostapd hlr_auc_gw > /dev/null; then
38     echo "wpa_supplicant/hostapd/hlr_auc_gw did not exit - try to force them to die"
39     sudo killall -9 -q hostapd
40     sudo killall -9 -q wpa_supplicant
41     killall -9 -q hlr_auc_gw
42     for i in `seq 1 5`; do
43         if pidof wpa_supplicant hostapd hlr_auc_gw > /dev/null; then
44             echo "Waiting for processes to exit (2)"
45             sleep 1
46         else
47             break
48         fi
49     done
50 fi
51
52 for i in `pidof valgrind.bin`; do
53     if ps $i | grep -q -E "wpa_supplicant|hostapd"; then
54         echo "wpa_supplicant/hostapd(valgrind) did not exit - try to force it to die"
55         sudo kill -9 $i
56     fi
57 done
58
59 for i in /tmp/wpas-wlan0 /tmp/wpas-wlan1 /tmp/wpas-wlan2 /var/run/hostapd-global /tmp/hlr_auc_gw.sock /tmp/wpa_ctrl_* /tmp/eap_sim_db_*; do
60     if [ -e $i ]; then
61         echo "Waiting for ctrl_iface $i to disappear"
62         sleep 1
63         if [ -e $i ]; then
64             echo "Control interface file $i exists - remove it"
65             sudo rm $i
66         fi
67     fi
68 done
69
70 if grep -q mac80211_hwsim /proc/modules 2>/dev/null ; then
71     sudo rmmod mac80211_hwsim 
72     sudo rmmod mac80211
73     sudo rmmod cfg80211
74     # wait at the end to avoid issues starting something new immediately after
75     # this script returns
76     sleep 1
77 fi