]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_wifi_display.py
1 # Wi-Fi Display 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()
15 from test_p2p_autogo
import connect_cli
16 from test_p2p_persistent
import form
, invite
, invite_from_cli
, invite_from_go
18 def test_wifi_display(dev
):
19 """Wi-Fi Display extensions to P2P"""
20 wfd_devinfo
= "00411c440028"
21 dev
[0].request("SET wifi_display 1")
22 dev
[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo
)
23 if wfd_devinfo
not in dev
[0].request("WFD_SUBELEM_GET 0"):
24 raise Exception("Could not fetch back configured subelement")
27 dev
[0].request("WFD_SUBELEM_SET 1 0006020304050607")
29 dev
[0].request("WFD_SUBELEM_SET 6 000700000000000000")
31 dev
[0].request("WFD_SUBELEM_SET 9 0000")
32 # WFD Extended Capability
33 dev
[0].request("WFD_SUBELEM_SET 7 00020000")
34 # WFD Content Protection
36 dev
[0].request("WFD_SUBELEM_SET 5 " + prot
)
38 video
= "0015" + "010203040506070809101112131415161718192021"
39 dev
[0].request("WFD_SUBELEM_SET 3 " + video
)
40 # WFD 3D Video Formats
41 video_3d
= "0011" + "0102030405060708091011121314151617"
42 dev
[0].request("WFD_SUBELEM_SET 4 " + video_3d
)
44 audio
= "000f" + "010203040506070809101112131415"
45 dev
[0].request("WFD_SUBELEM_SET 2 " + audio
)
47 elems
= dev
[0].request("WFD_SUBELEM_GET all")
48 if wfd_devinfo
not in elems
:
49 raise Exception("Could not fetch back configured subelements")
51 wfd_devinfo2
= "00001c440028"
52 dev
[1].request("SET wifi_display 1")
53 dev
[1].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2
)
54 if wfd_devinfo2
not in dev
[1].request("WFD_SUBELEM_GET 0"):
55 raise Exception("Could not fetch back configured subelement")
58 if "FAIL" in dev
[1].request("P2P_SERV_DISC_REQ " + dev
[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
59 raise Exception("Setting SD request failed")
60 dev
[1].p2p_find(social
=True)
61 ev
= dev
[0].wait_global_event(["P2P-SERV-DISC-REQ"], timeout
=10)
63 raise Exception("Device discovery request not reported")
64 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
66 raise Exception("Device discovery timed out")
67 if "wfd_dev_info=0x" + wfd_devinfo
not in ev
:
68 raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
70 raise Exception("new=1 flag missing from P2P-DEVICE-FOUND event")
71 ev
= dev
[1].wait_global_event(["P2P-SERV-DISC-RESP"], timeout
=5)
73 raise Exception("Service discovery timed out")
75 raise Exception("WFD Content Protection missing from WSD response")
77 raise Exception("WFD Video Formats missing from WSD response")
78 if video_3d
not in ev
:
79 raise Exception("WFD 3D Video Formats missing from WSD response")
81 raise Exception("WFD Audio Formats missing from WSD response")
84 dev
[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2
)
85 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
87 raise Exception("Peer info update timed out")
89 raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
90 if "wfd_dev_info=0x" + wfd_devinfo2
not in ev
:
91 raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
93 dev
[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo
)
94 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
96 raise Exception("Peer info update timed out")
98 raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
99 if "wfd_dev_info=0x" + wfd_devinfo
not in ev
:
100 raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
102 pin
= dev
[0].wps_read_pin()
103 dev
[0].p2p_go_neg_auth(dev
[1].p2p_dev_addr(), pin
, 'display')
104 res1
= dev
[1].p2p_go_neg_init(dev
[0].p2p_dev_addr(), pin
, 'enter', timeout
=20, go_intent
=15)
105 res2
= dev
[0].p2p_go_neg_auth_result()
107 bss
= dev
[0].get_bss("p2p_dev_addr=" + dev
[1].p2p_dev_addr())
108 if bss
['bssid'] != dev
[1].p2p_interface_addr():
109 raise Exception("Unexpected BSSID in the BSS entry for the GO")
110 if wfd_devinfo2
not in bss
['wfd_subelems']:
111 raise Exception("Could not see wfd_subelems in GO's BSS entry")
112 peer
= dev
[0].get_peer(dev
[1].p2p_dev_addr())
113 if wfd_devinfo2
not in peer
['wfd_subelems']:
114 raise Exception("Could not see wfd_subelems in GO's peer entry")
115 peer
= dev
[1].get_peer(dev
[0].p2p_dev_addr())
116 if wfd_devinfo
not in peer
['wfd_subelems']:
117 raise Exception("Could not see wfd_subelems in client's peer entry")
119 wfd_devinfo3
= "00001c440028"
120 dev
[2].request("SET wifi_display 1")
121 dev
[2].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo3
)
122 dev
[2].p2p_find(social
=True)
123 ev
= dev
[2].wait_event(["P2P-DEVICE-FOUND"], timeout
=5)
125 raise Exception("Device discovery timed out")
126 if dev
[1].p2p_dev_addr() not in ev
:
127 ev
= dev
[2].wait_event(["P2P-DEVICE-FOUND"], timeout
=5)
129 raise Exception("Device discovery timed out")
130 if dev
[1].p2p_dev_addr() not in ev
:
131 raise Exception("Could not discover GO")
132 if "wfd_dev_info=0x" + wfd_devinfo2
not in ev
:
133 raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
134 bss
= dev
[2].get_bss("p2p_dev_addr=" + dev
[1].p2p_dev_addr())
135 if bss
['bssid'] != dev
[1].p2p_interface_addr():
136 raise Exception("Unexpected BSSID in the BSS entry for the GO")
137 if wfd_devinfo2
not in bss
['wfd_subelems']:
138 raise Exception("Could not see wfd_subelems in GO's BSS entry")
139 peer
= dev
[2].get_peer(dev
[1].p2p_dev_addr())
140 if wfd_devinfo2
not in peer
['wfd_subelems']:
141 raise Exception("Could not see wfd_subelems in GO's peer entry")
142 dev
[2].p2p_stop_find()
144 if dev
[0].request("WFD_SUBELEM_GET 2") != audio
:
145 raise Exception("Unexpected WFD_SUBELEM_GET 2 value")
146 if dev
[0].request("WFD_SUBELEM_GET 3") != video
:
147 raise Exception("Unexpected WFD_SUBELEM_GET 3 value")
148 if dev
[0].request("WFD_SUBELEM_GET 4") != video_3d
:
149 raise Exception("Unexpected WFD_SUBELEM_GET 42 value")
150 if dev
[0].request("WFD_SUBELEM_GET 5") != prot
:
151 raise Exception("Unexpected WFD_SUBELEM_GET 5 value")
152 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET "):
153 raise Exception("Unexpected WFD_SUBELEM_SET success")
154 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET 6"):
155 raise Exception("Unexpected WFD_SUBELEM_SET success")
156 if "OK" not in dev
[0].request("WFD_SUBELEM_SET 6 "):
157 raise Exception("Unexpected WFD_SUBELEM_SET failure")
158 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET 6 0"):
159 raise Exception("Unexpected WFD_SUBELEM_SET success")
160 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET 6 0q"):
161 raise Exception("Unexpected WFD_SUBELEM_SET success")
162 if dev
[0].request("WFD_SUBELEM_GET 6") != "":
163 raise Exception("Unexpected WFD_SUBELEM_GET 6 response")
164 if dev
[0].request("WFD_SUBELEM_GET 8") != "":
165 raise Exception("Unexpected WFD_SUBELEM_GET 8 response")
167 if dev
[0].global_request("WFD_SUBELEM_GET 2") != audio
:
168 raise Exception("Unexpected WFD_SUBELEM_GET 2 value from global interface")
169 if "OK" not in dev
[0].global_request("WFD_SUBELEM_SET 1 0006020304050608"):
170 raise Exception("WFD_SUBELEM_SET failed on global interface")
171 if dev
[0].request("WFD_SUBELEM_GET 1") != "0006020304050608":
172 raise Exception("Unexpected WFD_SUBELEM_GET 1 value (per-interface)")
174 elems
= dev
[0].request("WFD_SUBELEM_GET all")
175 if "OK" not in dev
[0].request("WFD_SUBELEM_SET all " + elems
):
176 raise Exception("WFD_SUBELEM_SET all failed")
177 if dev
[0].request("WFD_SUBELEM_GET all") != elems
:
178 raise Exception("Mismatch in WFS_SUBELEM_SET/GET all")
179 test
= "00000600411c440028"
180 if "OK" not in dev
[0].request("WFD_SUBELEM_SET all " + test
):
181 raise Exception("WFD_SUBELEM_SET all failed")
182 if dev
[0].request("WFD_SUBELEM_GET all") != test
:
183 raise Exception("Mismatch in WFS_SUBELEM_SET/GET all")
185 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET all qwerty"):
186 raise Exception("Invalid WFD_SUBELEM_SET all succeeded")
187 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET all 11"):
188 raise Exception("Invalid WFD_SUBELEM_SET all succeeded")
189 dev
[0].request("WFD_SUBELEM_SET all 112233445566")
190 dev
[0].request("WFD_SUBELEM_SET all ff0000fe0000fd00")
192 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET 300 112233"):
193 raise Exception("Invalid WFD_SUBELEM_SET 300 succeeded")
194 if "FAIL" not in dev
[0].request("WFD_SUBELEM_SET -1 112233"):
195 raise Exception("Invalid WFD_SUBELEM_SET -1 succeeded")
196 if "FAIL" not in dev
[0].request("WFD_SUBELEM_GET 300"):
197 raise Exception("Invalid WFD_SUBELEM_GET 300 succeeded")
198 if "FAIL" not in dev
[0].request("WFD_SUBELEM_GET -1"):
199 raise Exception("Invalid WFD_SUBELEM_GET -1 succeeded")
201 dev
[0].request("SET wifi_display 0")
202 dev
[1].request("SET wifi_display 0")
203 dev
[2].request("SET wifi_display 0")
205 def enable_wifi_display(dev
):
206 dev
.request("SET wifi_display 1")
207 dev
.request("WFD_SUBELEM_SET 0 000600411c440028")
209 def test_wifi_display_go_invite(dev
):
210 """P2P GO with Wi-Fi Display inviting a client to join"""
211 addr0
= dev
[0].p2p_dev_addr()
212 addr1
= dev
[1].p2p_dev_addr()
215 enable_wifi_display(dev
[0])
216 enable_wifi_display(dev
[1])
217 enable_wifi_display(dev
[2])
220 if not dev
[0].discover_peer(addr1
, social
=True):
221 raise Exception("Peer " + addr1
+ " not found")
223 if not dev
[1].discover_peer(addr0
, social
=True):
224 raise Exception("Peer " + addr0
+ " not found")
227 logger
.info("Authorize invitation")
228 pin
= dev
[1].wps_read_pin()
229 dev
[1].global_request("P2P_CONNECT " + addr0
+ " " + pin
+ " join auth")
231 dev
[0].p2p_start_go(freq
=2412)
233 # Add test client to the group
234 connect_cli(dev
[0], dev
[2], social
=True, freq
=2412)
236 logger
.info("Invite peer to join the group")
237 dev
[0].p2p_go_authorize_client(pin
)
238 dev
[0].global_request("P2P_INVITE group=" + dev
[0].group_ifname
+ " peer=" + addr1
)
239 ev
= dev
[1].wait_global_event(["P2P-INVITATION-RECEIVED",
240 "P2P-GROUP-STARTED"], timeout
=20)
242 raise Exception("Timeout on invitation on peer")
243 if "P2P-INVITATION-RECEIVED" in ev
:
244 raise Exception("Unexpected request to accept pre-authorized invitation")
246 dev
[0].remove_group()
247 dev
[1].wait_go_ending_session()
248 dev
[2].wait_go_ending_session()
251 dev
[0].request("SET wifi_display 0")
252 dev
[1].request("SET wifi_display 0")
253 dev
[2].request("SET wifi_display 0")
255 def test_wifi_display_persistent_group(dev
):
256 """P2P persistent group formation and re-invocation with Wi-Fi Display enabled"""
258 enable_wifi_display(dev
[0])
259 enable_wifi_display(dev
[1])
260 enable_wifi_display(dev
[2])
263 peer
= dev
[1].get_peer(dev
[0].p2p_dev_addr())
264 listen_freq
= peer
['listen_freq']
265 invite_from_cli(dev
[0], dev
[1])
266 invite_from_go(dev
[0], dev
[1])
268 dev
[0].dump_monitor()
269 dev
[1].dump_monitor()
270 networks
= dev
[0].list_networks()
271 if len(networks
) != 1:
272 raise Exception("Unexpected number of networks")
273 if "[P2P-PERSISTENT]" not in networks
[0]['flags']:
274 raise Exception("Not the persistent group data")
275 if "OK" not in dev
[0].global_request("P2P_GROUP_ADD persistent=" + networks
[0]['id'] + " freq=" + listen_freq
):
276 raise Exception("Could not start GO")
277 connect_cli(dev
[0], dev
[2], social
=True, freq
=listen_freq
)
278 dev
[0].dump_monitor()
279 dev
[1].dump_monitor()
280 invite(dev
[1], dev
[0])
281 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=30)
283 raise Exception("Timeout on group re-invocation (on client)")
284 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=0.1)
286 raise Exception("Unexpected P2P-GROUP-START on GO")
287 hwsim_utils
.test_connectivity_p2p(dev
[0], dev
[1])
290 dev
[0].request("SET wifi_display 0")
291 dev
[1].request("SET wifi_display 0")
292 dev
[2].request("SET wifi_display 0")
294 def test_wifi_display_invalid_subelem(dev
):
295 """Wi-Fi Display and invalid subelement parsing"""
296 addr1
= dev
[1].p2p_dev_addr()
299 enable_wifi_display(dev
[0])
300 enable_wifi_display(dev
[1])
301 dev
[1].request("WFD_SUBELEM_SET 0 ffff00411c440028")
304 dev
[0].p2p_find(social
=True)
305 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
307 raise Exception("Device discovery timed out")
308 if "wfd_dev_info=" in ev
:
309 raise Exception("Invalid WFD subelement was shown")
312 dev
[0].request("SET wifi_display 0")
313 dev
[1].request("SET wifi_display 0")