1 | # rfkill tests
|
---|
2 | # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
|
---|
3 | #
|
---|
4 | # This software may be distributed under the terms of the BSD license.
|
---|
5 | # See README for more details.
|
---|
6 |
|
---|
7 | import logging
|
---|
8 | logger = logging.getLogger()
|
---|
9 | import subprocess
|
---|
10 | import time
|
---|
11 |
|
---|
12 | import hostapd
|
---|
13 | import hwsim_utils
|
---|
14 |
|
---|
15 | def get_rfkill_id(dev):
|
---|
16 | try:
|
---|
17 | cmd = subprocess.Popen(["rfkill", "list"], stdout=subprocess.PIPE)
|
---|
18 | except Exception, e:
|
---|
19 | logger.info("No rfkill available: " + str(e))
|
---|
20 | return None
|
---|
21 | res = cmd.stdout.read()
|
---|
22 | cmd.stdout.close()
|
---|
23 | phy = dev.get_driver_status_field("phyname")
|
---|
24 | matches = [ line for line in res.splitlines() if phy + ':' in line ]
|
---|
25 | if len(matches) != 1:
|
---|
26 | return None
|
---|
27 | return matches[0].split(':')[0]
|
---|
28 |
|
---|
29 | def test_rfkill_open(dev, apdev):
|
---|
30 | """rfkill block/unblock during open mode connection"""
|
---|
31 | id = get_rfkill_id(dev[0])
|
---|
32 | if id is None:
|
---|
33 | return "skip"
|
---|
34 |
|
---|
35 | hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
|
---|
36 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
|
---|
37 | try:
|
---|
38 | logger.info("rfkill block")
|
---|
39 | subprocess.call(['sudo', 'rfkill', 'block', id])
|
---|
40 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10)
|
---|
41 | if ev is None:
|
---|
42 | raise Exception("Missing disconnection event on rfkill block")
|
---|
43 |
|
---|
44 | logger.info("rfkill unblock")
|
---|
45 | subprocess.call(['sudo', 'rfkill', 'unblock', id])
|
---|
46 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
|
---|
47 | if ev is None:
|
---|
48 | raise Exception("Missing connection event on rfkill unblock")
|
---|
49 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
|
---|
50 | finally:
|
---|
51 | subprocess.call(['sudo', 'rfkill', 'unblock', id])
|
---|
52 |
|
---|
53 | def test_rfkill_wpa2_psk(dev, apdev):
|
---|
54 | """rfkill block/unblock during WPA2-PSK connection"""
|
---|
55 | id = get_rfkill_id(dev[0])
|
---|
56 | if id is None:
|
---|
57 | return "skip"
|
---|
58 |
|
---|
59 | ssid = "test-wpa2-psk"
|
---|
60 | passphrase = 'qwertyuiop'
|
---|
61 | params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
|
---|
62 | hapd = hostapd.add_ap(apdev[0]['ifname'], params)
|
---|
63 | dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
|
---|
64 | try:
|
---|
65 | logger.info("rfkill block")
|
---|
66 | subprocess.call(['sudo', 'rfkill', 'block', id])
|
---|
67 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10)
|
---|
68 | if ev is None:
|
---|
69 | raise Exception("Missing disconnection event on rfkill block")
|
---|
70 |
|
---|
71 | logger.info("rfkill unblock")
|
---|
72 | subprocess.call(['sudo', 'rfkill', 'unblock', id])
|
---|
73 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
|
---|
74 | if ev is None:
|
---|
75 | raise Exception("Missing connection event on rfkill unblock")
|
---|
76 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
|
---|
77 | finally:
|
---|
78 | subprocess.call(['sudo', 'rfkill', 'unblock', id])
|
---|
79 |
|
---|
80 | def test_rfkill_autogo(dev, apdev):
|
---|
81 | """rfkill block/unblock for autonomous P2P GO"""
|
---|
82 | id0 = get_rfkill_id(dev[0])
|
---|
83 | if id0 is None:
|
---|
84 | return "skip"
|
---|
85 | id1 = get_rfkill_id(dev[1])
|
---|
86 | if id1 is None:
|
---|
87 | return "skip"
|
---|
88 |
|
---|
89 | dev[0].p2p_start_go()
|
---|
90 | dev[1].request("SET p2p_no_group_iface 0")
|
---|
91 | dev[1].p2p_start_go()
|
---|
92 |
|
---|
93 | try:
|
---|
94 | logger.info("rfkill block 0")
|
---|
95 | subprocess.call(['sudo', 'rfkill', 'block', id0])
|
---|
96 | ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
|
---|
97 | if ev is None:
|
---|
98 | raise Exception("Group removal not reported")
|
---|
99 | if "reason=UNAVAILABLE" not in ev:
|
---|
100 | raise Exception("Unexpected group removal reason: " + ev)
|
---|
101 |
|
---|
102 | logger.info("rfkill block 1")
|
---|
103 | subprocess.call(['sudo', 'rfkill', 'block', id1])
|
---|
104 | ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
|
---|
105 | if ev is None:
|
---|
106 | raise Exception("Group removal not reported")
|
---|
107 | if "reason=UNAVAILABLE" not in ev:
|
---|
108 | raise Exception("Unexpected group removal reason: " + ev)
|
---|
109 |
|
---|
110 | logger.info("rfkill unblock 0")
|
---|
111 | subprocess.call(['sudo', 'rfkill', 'unblock', id0])
|
---|
112 | logger.info("rfkill unblock 1")
|
---|
113 | subprocess.call(['sudo', 'rfkill', 'unblock', id1])
|
---|
114 | time.sleep(1)
|
---|
115 | finally:
|
---|
116 | subprocess.call(['sudo', 'rfkill', 'unblock', id0])
|
---|
117 | subprocess.call(['sudo', 'rfkill', 'unblock', id1])
|
---|