]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_discovery.py
1 # P2P device discovery test cases
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
11 from wpasupplicant
import WpaSupplicant
13 def test_discovery(dev
):
14 """P2P device discovery and provision discovery"""
15 addr0
= dev
[0].p2p_dev_addr()
16 addr1
= dev
[1].p2p_dev_addr()
17 logger
.info("Start device discovery")
18 dev
[0].p2p_find(social
=True)
19 if not dev
[1].discover_peer(addr0
):
20 raise Exception("Device discovery timed out")
21 if not dev
[0].discover_peer(addr1
):
22 raise Exception("Device discovery timed out")
24 logger
.info("Test provision discovery for display")
25 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " display")
26 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=15)
28 raise Exception("Provision discovery timed out (display/dev1)")
30 raise Exception("Dev0 not in provision discovery event")
31 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN",
32 "P2P-PROV-DISC-FAILURE"], timeout
=15)
34 raise Exception("Provision discovery timed out (display/dev0)")
35 if "P2P-PROV-DISC-FAILURE" in ev0
:
36 raise Exception("Provision discovery failed (display/dev0)")
38 raise Exception("Dev1 not in provision discovery event")
40 logger
.info("Test provision discovery for keypad")
41 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " keypad")
42 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=15)
44 raise Exception("Provision discovery timed out (keypad/dev1)")
46 raise Exception("Dev0 not in provision discovery event")
47 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN",
48 "P2P-PROV-DISC-FAILURE"],
51 raise Exception("Provision discovery timed out (keypad/dev0)")
52 if "P2P-PROV-DISC-FAILURE" in ev0
:
53 raise Exception("Provision discovery failed (keypad/dev0)")
55 raise Exception("Dev1 not in provision discovery event")
57 logger
.info("Test provision discovery for push button")
58 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " pbc")
59 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout
=15)
61 raise Exception("Provision discovery timed out (pbc/dev1)")
63 raise Exception("Dev0 not in provision discovery event")
64 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP",
65 "P2P-PROV-DISC-FAILURE"],
68 raise Exception("Provision discovery timed out (pbc/dev0)")
69 if "P2P-PROV-DISC-FAILURE" in ev0
:
70 raise Exception("Provision discovery failed (pbc/dev0)")
72 raise Exception("Dev1 not in provision discovery event")
77 def test_discovery_pd_retries(dev
):
78 """P2P device discovery and provision discovery retries"""
79 addr0
= dev
[0].p2p_dev_addr()
80 addr1
= dev
[1].p2p_dev_addr()
82 if not dev
[0].discover_peer(addr1
):
83 raise Exception("Device discovery timed out")
84 dev
[1].p2p_stop_find()
85 dev
[0].p2p_stop_find()
86 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " display")
87 ev
= dev
[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout
=60)
89 raise Exception("No PD failure reported")
91 def test_discovery_group_client(dev
):
92 """P2P device discovery for a client in a group"""
93 logger
.info("Start autonomous GO " + dev
[0].ifname
)
94 res
= dev
[0].p2p_start_go(freq
="2422")
95 logger
.debug("res: " + str(res
))
96 logger
.info("Connect a client to the GO")
97 pin
= dev
[1].wps_read_pin()
98 dev
[0].p2p_go_authorize_client(pin
)
99 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
100 logger
.info("Client connected")
101 hwsim_utils
.test_connectivity_p2p(dev
[0], dev
[1])
102 logger
.info("Try to discover a P2P client in a group")
103 if not dev
[2].discover_peer(dev
[1].p2p_dev_addr(), social
=False):
104 raise Exception("Could not discover group client")
106 # This is not really perfect, but something to get a bit more testing
107 # coverage.. For proper discoverability mechanism validation, the P2P
108 # client would need to go to sleep to avoid acknowledging the GO Negotiation
109 # Request frame. Offchannel Listen mode operation on the P2P Client with
110 # mac80211_hwsim is apparently not enough to avoid the acknowledgement on
111 # the operating channel, so need to disconnect from the group which removes
112 # the GO-to-P2P Client part of the discoverability exchange in practice.
114 pin
= dev
[2].wps_read_pin()
115 # make group client non-responsive on operating channel
116 dev
[1].dump_monitor()
117 dev
[1].group_request("DISCONNECT")
118 ev
= dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
120 raise Exception("Timeout on waiting disconnection")
121 dev
[2].request("P2P_CONNECT {} {} display".format(dev
[1].p2p_dev_addr(),
123 ev
= dev
[1].wait_event(["P2P-GO-NEG-REQUEST"], timeout
=2)
125 raise Exception("Unexpected frame RX on P2P client")
126 # make group client available on operating channe
127 dev
[1].request("REASSOCIATE")
128 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED", "P2P-GO-NEG-REQUEST"])
130 raise Exception("Timeout on reconnection to group")
131 if "P2P-GO-NEG-REQUEST" not in ev
:
132 ev
= dev
[1].wait_event(["P2P-GO-NEG-REQUEST"])
134 raise Exception("Timeout on waiting for GO Negotiation Request")
136 def test_discovery_dev_type(dev
):
137 """P2P device discovery with Device Type filter"""
138 dev
[1].request("SET sec_device_type 1-0050F204-2")
140 dev
[0].p2p_find(social
=True, dev_type
="5-0050F204-1")
141 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
143 raise Exception("Unexpected P2P device found")
144 dev
[0].p2p_find(social
=True, dev_type
="1-0050F204-2")
145 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=2)
147 raise Exception("P2P device not found")
149 def test_discovery_dev_type_go(dev
):
150 """P2P device discovery with Device Type filter on GO"""
151 addr1
= dev
[1].p2p_dev_addr()
152 dev
[1].request("SET sec_device_type 1-0050F204-2")
153 res
= dev
[0].p2p_start_go(freq
="2412")
154 pin
= dev
[1].wps_read_pin()
155 dev
[0].p2p_go_authorize_client(pin
)
156 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
158 dev
[2].p2p_find(social
=True, dev_type
="5-0050F204-1")
159 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
161 raise Exception("Unexpected P2P device found")
162 dev
[2].p2p_find(social
=True, dev_type
="1-0050F204-2")
163 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND ' + addr1
], timeout
=2)
165 raise Exception("P2P device not found")
167 def test_discovery_dev_id(dev
):
168 """P2P device discovery with Device ID filter"""
169 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
170 wpas
.interface_add("wlan5")
171 wpas
.request("P2P_LISTEN 1")
172 status
= wpas
.global_request("STATUS")
173 if "p2p_state=LISTEN_ONLY" not in status
:
174 raise Exception("Unexpected status: " + status
)
175 addr1
= dev
[1].p2p_dev_addr()
177 dev
[0].p2p_find(social
=True, dev_id
="02:03:04:05:06:07")
178 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
180 raise Exception("Unexpected P2P device found")
181 dev
[0].p2p_find(social
=True, dev_id
=addr1
)
182 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=2)
184 raise Exception("P2P device not found")
186 raise Exception("Unexpected P2P peer found")
187 status
= wpas
.global_request("STATUS")
188 for i
in range(0, 2):
189 if "p2p_state=IDLE" in status
:
192 status
= wpas
.global_request("STATUS")
193 if "p2p_state=IDLE" not in status
:
194 raise Exception("Unexpected status: " + status
)
196 def test_discovery_dev_id_go(dev
):
197 """P2P device discovery with Device ID filter on GO"""
198 addr1
= dev
[1].p2p_dev_addr()
199 res
= dev
[0].p2p_start_go(freq
="2412")
200 pin
= dev
[1].wps_read_pin()
201 dev
[0].p2p_go_authorize_client(pin
)
202 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
204 dev
[2].p2p_find(social
=True, dev_id
="02:03:04:05:06:07")
205 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
207 raise Exception("Unexpected P2P device found")
208 dev
[2].p2p_find(social
=True, dev_id
=addr1
)
209 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND ' + addr1
], timeout
=2)
211 raise Exception("P2P device not found")
213 def test_discovery_social_plus_one(dev
):
214 """P2P device discovery with social-plus-one"""
215 logger
.info("Start autonomous GO " + dev
[0].ifname
)
216 dev
[1].p2p_find(social
=True)
217 dev
[0].p2p_find(progressive
=True)
218 logger
.info("Wait for initial progressive find phases")
219 dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
220 dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
221 go
= dev
[2].p2p_dev_addr()
222 dev
[2].p2p_start_go(freq
="2422")
223 logger
.info("Verify whether the GO on non-social channel can be found")
224 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
226 raise Exception("Peer not found")
228 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
230 raise Exception("Peer not found")
231 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
233 raise Exception("Peer not found")
234 dev
[0].p2p_stop_find()
235 dev
[1].p2p_stop_find()
236 if not dev
[0].peer_known(go
):
237 raise Exception("GO not found in progressive scan")
238 if dev
[1].peer_known(go
):
239 raise Exception("GO found in social-only scan")