]>
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()
12 def test_discovery(dev
):
13 """P2P device discovery and provision discovery"""
14 addr0
= dev
[0].p2p_dev_addr()
15 addr1
= dev
[1].p2p_dev_addr()
16 logger
.info("Start device discovery")
17 dev
[0].p2p_find(social
=True)
18 if not dev
[1].discover_peer(addr0
):
19 raise Exception("Device discovery timed out")
20 if not dev
[0].discover_peer(addr1
):
21 raise Exception("Device discovery timed out")
23 logger
.info("Test provision discovery for display")
24 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " display")
25 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=15)
27 raise Exception("Provision discovery timed out (display/dev1)")
29 raise Exception("Dev0 not in provision discovery event")
30 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN",
31 "P2P-PROV-DISC-FAILURE"], timeout
=15)
33 raise Exception("Provision discovery timed out (display/dev0)")
34 if "P2P-PROV-DISC-FAILURE" in ev0
:
35 raise Exception("Provision discovery failed (display/dev0)")
37 raise Exception("Dev1 not in provision discovery event")
39 logger
.info("Test provision discovery for keypad")
40 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " keypad")
41 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=15)
43 raise Exception("Provision discovery timed out (keypad/dev1)")
45 raise Exception("Dev0 not in provision discovery event")
46 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN",
47 "P2P-PROV-DISC-FAILURE"],
50 raise Exception("Provision discovery timed out (keypad/dev0)")
51 if "P2P-PROV-DISC-FAILURE" in ev0
:
52 raise Exception("Provision discovery failed (keypad/dev0)")
54 raise Exception("Dev1 not in provision discovery event")
56 logger
.info("Test provision discovery for push button")
57 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " pbc")
58 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout
=15)
60 raise Exception("Provision discovery timed out (pbc/dev1)")
62 raise Exception("Dev0 not in provision discovery event")
63 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP",
64 "P2P-PROV-DISC-FAILURE"],
67 raise Exception("Provision discovery timed out (pbc/dev0)")
68 if "P2P-PROV-DISC-FAILURE" in ev0
:
69 raise Exception("Provision discovery failed (pbc/dev0)")
71 raise Exception("Dev1 not in provision discovery event")
76 def test_discovery_group_client(dev
):
77 """P2P device discovery for a client in a group"""
78 logger
.info("Start autonomous GO " + dev
[0].ifname
)
79 res
= dev
[0].p2p_start_go(freq
="2422")
80 logger
.debug("res: " + str(res
))
81 logger
.info("Connect a client to the GO")
82 pin
= dev
[1].wps_read_pin()
83 dev
[0].p2p_go_authorize_client(pin
)
84 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
85 logger
.info("Client connected")
86 hwsim_utils
.test_connectivity_p2p(dev
[0], dev
[1])
87 logger
.info("Try to discover a P2P client in a group")
88 if not dev
[2].discover_peer(dev
[1].p2p_dev_addr(), social
=False):
89 raise Exception("Could not discover group client")
91 # This is not really perfect, but something to get a bit more testing
92 # coverage.. For proper discoverability mechanism validation, the P2P
93 # client would need to go to sleep to avoid acknowledging the GO Negotiation
94 # Request frame. Offchannel Listen mode operation on the P2P Client with
95 # mac80211_hwsim is apparently not enough to avoid the acknowledgement on
96 # the operating channel, so need to disconnect from the group which removes
97 # the GO-to-P2P Client part of the discoverability exchange in practice.
99 pin
= dev
[2].wps_read_pin()
100 # make group client non-responsive on operating channel
101 dev
[1].dump_monitor()
102 dev
[1].group_request("DISCONNECT")
103 ev
= dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
105 raise Exception("Timeout on waiting disconnection")
106 dev
[2].request("P2P_CONNECT {} {} display".format(dev
[1].p2p_dev_addr(),
108 ev
= dev
[1].wait_event(["P2P-GO-NEG-REQUEST"], timeout
=2)
110 raise Exception("Unexpected frame RX on P2P client")
111 # make group client available on operating channe
112 dev
[1].request("REASSOCIATE")
113 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED", "P2P-GO-NEG-REQUEST"])
115 raise Exception("Timeout on reconnection to group")
116 if "P2P-GO-NEG-REQUEST" not in ev
:
117 ev
= dev
[1].wait_event(["P2P-GO-NEG-REQUEST"])
119 raise Exception("Timeout on waiting for GO Negotiation Request")
121 def test_discovery_dev_type(dev
):
122 """P2P device discovery with Device Type filter"""
123 dev
[1].request("SET sec_device_type 1-0050F204-2")
125 dev
[0].p2p_find(social
=True, dev_type
="5-0050F204-1")
126 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
128 raise Exception("Unexpected P2P device found")
129 dev
[0].p2p_find(social
=True, dev_type
="1-0050F204-2")
130 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=2)
132 raise Exception("P2P device not found")
134 def test_discovery_dev_type_go(dev
):
135 """P2P device discovery with Device Type filter on GO"""
136 addr1
= dev
[1].p2p_dev_addr()
137 dev
[1].request("SET sec_device_type 1-0050F204-2")
138 res
= dev
[0].p2p_start_go(freq
="2412")
139 pin
= dev
[1].wps_read_pin()
140 dev
[0].p2p_go_authorize_client(pin
)
141 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
143 dev
[2].p2p_find(social
=True, dev_type
="5-0050F204-1")
144 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
146 raise Exception("Unexpected P2P device found")
147 dev
[2].p2p_find(social
=True, dev_type
="1-0050F204-2")
148 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND ' + addr1
], timeout
=2)
150 raise Exception("P2P device not found")
152 def test_discovery_dev_id(dev
):
153 """P2P device discovery with Device ID filter"""
154 addr1
= dev
[1].p2p_dev_addr()
156 dev
[0].p2p_find(social
=True, dev_id
="02:03:04:05:06:07")
157 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
159 raise Exception("Unexpected P2P device found")
160 dev
[0].p2p_find(social
=True, dev_id
=addr1
)
161 ev
= dev
[0].wait_event(['P2P-DEVICE-FOUND'], timeout
=2)
163 raise Exception("P2P device not found")
165 def test_discovery_dev_id_go(dev
):
166 """P2P device discovery with Device ID filter on GO"""
167 addr1
= dev
[1].p2p_dev_addr()
168 res
= dev
[0].p2p_start_go(freq
="2412")
169 pin
= dev
[1].wps_read_pin()
170 dev
[0].p2p_go_authorize_client(pin
)
171 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, timeout
=60)
173 dev
[2].p2p_find(social
=True, dev_id
="02:03:04:05:06:07")
174 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND'], timeout
=1)
176 raise Exception("Unexpected P2P device found")
177 dev
[2].p2p_find(social
=True, dev_id
=addr1
)
178 ev
= dev
[2].wait_event(['P2P-DEVICE-FOUND ' + addr1
], timeout
=2)
180 raise Exception("P2P device not found")