1 # P2P vendor specific extension tests
2 # Copyright (c) 2014-2015, Qualcomm Atheros, Inc.
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 tshark import run_tshark
12 from p2p_utils import *
14 def test_p2p_ext_discovery(dev):
15 """P2P device discovery with vendor specific extensions"""
16 addr0 = dev[0].p2p_dev_addr()
17 addr1 = dev[1].p2p_dev_addr()
20 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd050011223344"):
21 raise Exception("VENDOR_ELEM_ADD failed")
22 res = dev[0].request("VENDOR_ELEM_GET 1")
23 if res != "dd050011223344":
24 raise Exception("Unexpected VENDOR_ELEM_GET result: " + res)
25 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd06001122335566"):
26 raise Exception("VENDOR_ELEM_ADD failed")
27 res = dev[0].request("VENDOR_ELEM_GET 1")
28 if res != "dd050011223344dd06001122335566":
29 raise Exception("Unexpected VENDOR_ELEM_GET result(2): " + res)
30 res = dev[0].request("VENDOR_ELEM_GET 2")
32 raise Exception("Unexpected VENDOR_ELEM_GET result(3): " + res)
33 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd050011223344"):
34 raise Exception("VENDOR_ELEM_REMOVE failed")
35 res = dev[0].request("VENDOR_ELEM_GET 1")
36 if res != "dd06001122335566":
37 raise Exception("Unexpected VENDOR_ELEM_GET result(4): " + res)
38 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd06001122335566"):
39 raise Exception("VENDOR_ELEM_REMOVE failed")
40 res = dev[0].request("VENDOR_ELEM_GET 1")
42 raise Exception("Unexpected VENDOR_ELEM_GET result(5): " + res)
43 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd050011223344dd06001122335566"):
44 raise Exception("VENDOR_ELEM_ADD failed(2)")
46 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd051122334455"):
47 raise Exception("Unexpected VENDOR_ELEM_REMOVE success")
48 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd"):
49 raise Exception("Unexpected VENDOR_ELEM_REMOVE success(2)")
50 if "FAIL" not in dev[0].request("VENDOR_ELEM_ADD 1 ddff"):
51 raise Exception("Unexpected VENDOR_ELEM_ADD success(3)")
54 if not dev[1].discover_peer(addr0):
55 raise Exception("Device discovery timed out")
56 if not dev[0].discover_peer(addr1):
57 raise Exception("Device discovery timed out")
59 peer = dev[1].get_peer(addr0)
60 if peer['vendor_elems'] != "dd050011223344dd06001122335566":
61 raise Exception("Vendor elements not reported correctly")
63 res = dev[0].request("VENDOR_ELEM_GET 1")
64 if res != "dd050011223344dd06001122335566":
65 raise Exception("Unexpected VENDOR_ELEM_GET result(6): " + res)
66 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd06001122335566"):
67 raise Exception("VENDOR_ELEM_REMOVE failed")
68 res = dev[0].request("VENDOR_ELEM_GET 1")
69 if res != "dd050011223344":
70 raise Exception("Unexpected VENDOR_ELEM_GET result(7): " + res)
72 dev[0].request("VENDOR_ELEM_REMOVE 1 *")
74 def test_p2p_ext_discovery_go(dev):
75 """P2P device discovery with vendor specific extensions for GO"""
76 addr0 = dev[0].p2p_dev_addr()
77 addr1 = dev[1].p2p_dev_addr()
80 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 2 dd050011223344dd06001122335566"):
81 raise Exception("VENDOR_ELEM_ADD failed")
82 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 3 dd050011223344dd06001122335566"):
83 raise Exception("VENDOR_ELEM_ADD failed")
84 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 12 dd050011223344dd06001122335566"):
85 raise Exception("VENDOR_ELEM_ADD failed")
87 dev[0].p2p_start_go(freq="2412")
88 if not dev[1].discover_peer(addr0):
89 raise Exception("Device discovery timed out")
90 peer = dev[1].get_peer(addr0)
91 if peer['vendor_elems'] != "dd050011223344dd06001122335566":
92 print peer['vendor_elems']
93 raise Exception("Vendor elements not reported correctly")
95 dev[0].request("VENDOR_ELEM_REMOVE 2 *")
96 dev[0].request("VENDOR_ELEM_REMOVE 3 *")
97 dev[0].request("VENDOR_ELEM_REMOVE 12 *")
99 def test_p2p_ext_vendor_elem_probe_req(dev):
100 """VENDOR_ELEM in P2P Probe Request frames"""
102 _test_p2p_ext_vendor_elem_probe_req(dev)
104 dev[0].request("VENDOR_ELEM_REMOVE 0 *")
106 def _test_p2p_ext_vendor_elem_probe_req(dev):
107 addr1 = dev[1].p2p_dev_addr()
108 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 0 dd050011223300"):
109 raise Exception("VENDOR_ELEM_ADD failed")
111 if not dev[0].discover_peer(addr1):
112 raise Exception("Device discovery timed out")
113 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
114 raise Exception("Failed to enable external management frame handling")
115 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
117 raise Exception("MGMT-RX timeout")
119 raise Exception("Not a Probe Request frame")
120 if "dd050011223300" not in ev:
121 raise Exception("Vendor element not found from Probe Request frame")
122 dev[0].p2p_stop_find()
123 dev[1].p2p_stop_find()
125 def test_p2p_ext_vendor_elem_pd_req(dev):
126 """VENDOR_ELEM in PD Request frames"""
128 _test_p2p_ext_vendor_elem_pd_req(dev)
130 dev[0].request("VENDOR_ELEM_REMOVE 4 *")
132 def _test_p2p_ext_vendor_elem_pd_req(dev):
133 addr0 = dev[0].p2p_dev_addr()
134 addr1 = dev[1].p2p_dev_addr()
135 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 4 dd050011223301"):
136 raise Exception("VENDOR_ELEM_ADD failed")
138 if not dev[0].discover_peer(addr1):
139 raise Exception("Device discovery timed out")
140 dev[0].p2p_stop_find()
141 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
142 raise Exception("Failed to enable external management frame handling")
143 dev[0].global_request("P2P_PROV_DISC " + addr1 + " display")
145 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
147 raise Exception("MGMT-RX timeout")
150 if "dd050011223301" not in ev:
151 raise Exception("Vendor element not found from PD Request frame")
152 dev[1].p2p_stop_find()
153 dev[0].p2p_stop_find()
155 def test_p2p_ext_vendor_elem_pd_resp(dev):
156 """VENDOR_ELEM in PD Response frames"""
158 _test_p2p_ext_vendor_elem_pd_resp(dev)
160 dev[0].request("VENDOR_ELEM_REMOVE 5 *")
162 def _test_p2p_ext_vendor_elem_pd_resp(dev):
163 addr0 = dev[0].p2p_dev_addr()
164 addr1 = dev[1].p2p_dev_addr()
165 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 5 dd050011223302"):
166 raise Exception("VENDOR_ELEM_ADD failed")
168 if not dev[1].discover_peer(addr0):
169 raise Exception("Device discovery timed out")
170 dev[1].p2p_stop_find()
171 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
172 raise Exception("Failed to enable external management frame handling")
173 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
175 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
177 raise Exception("MGMT-RX timeout")
180 if "dd050011223302" not in ev:
181 raise Exception("Vendor element not found from PD Response frame")
182 dev[0].p2p_stop_find()
183 dev[1].p2p_stop_find()
185 def test_p2p_ext_vendor_elem_go_neg_req(dev):
186 """VENDOR_ELEM in GO Negotiation Request frames"""
188 _test_p2p_ext_vendor_elem_go_neg_req(dev)
190 dev[0].request("VENDOR_ELEM_REMOVE 6 *")
192 def _test_p2p_ext_vendor_elem_go_neg_req(dev):
193 addr0 = dev[0].p2p_dev_addr()
194 addr1 = dev[1].p2p_dev_addr()
195 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 6 dd050011223303"):
196 raise Exception("VENDOR_ELEM_ADD failed")
198 if not dev[0].discover_peer(addr1):
199 raise Exception("Device discovery timed out")
200 dev[0].p2p_stop_find()
201 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
202 raise Exception("Failed to enable external management frame handling")
203 dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display")
205 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
207 raise Exception("MGMT-RX timeout")
210 if "dd050011223303" not in ev:
211 raise Exception("Vendor element not found from GO Negotiation Request frame")
212 dev[1].p2p_stop_find()
213 dev[0].p2p_stop_find()
215 def test_p2p_ext_vendor_elem_go_neg_resp(dev):
216 """VENDOR_ELEM in GO Negotiation Response frames"""
218 _test_p2p_ext_vendor_elem_go_neg_resp(dev)
220 dev[0].request("VENDOR_ELEM_REMOVE 7 *")
222 def _test_p2p_ext_vendor_elem_go_neg_resp(dev):
223 addr0 = dev[0].p2p_dev_addr()
224 addr1 = dev[1].p2p_dev_addr()
225 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 7 dd050011223304"):
226 raise Exception("VENDOR_ELEM_ADD failed")
228 if not dev[1].discover_peer(addr0):
229 raise Exception("Device discovery timed out")
230 dev[1].p2p_stop_find()
231 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
232 raise Exception("Failed to enable external management frame handling")
233 dev[1].global_request("P2P_CONNECT " + addr0 + " 12345670 display")
235 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
237 raise Exception("MGMT-RX timeout")
240 if "dd050011223304" not in ev:
241 raise Exception("Vendor element not found from GO Negotiation Response frame")
242 dev[0].p2p_stop_find()
243 dev[1].p2p_stop_find()
245 def test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params):
246 """VENDOR_ELEM in GO Negotiation Confirm frames"""
248 _test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params)
250 dev[0].request("VENDOR_ELEM_REMOVE 8 *")
252 def _test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params):
253 addr0 = dev[0].p2p_dev_addr()
254 addr1 = dev[1].p2p_dev_addr()
255 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 8 dd050011223305"):
256 raise Exception("VENDOR_ELEM_ADD failed")
259 dev[1].p2p_go_neg_auth(addr0, "12345670", "enter")
260 dev[0].p2p_go_neg_init(addr1, "12345678", "display")
261 dev[1].p2p_go_neg_auth_result(expect_failure=True)
263 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
264 "wifi_p2p.public_action.subtype == 2")
265 if "Vendor Specific Data: 3305" not in out:
266 raise Exception("Vendor element not found from GO Negotiation Confirm frame")
268 def test_p2p_ext_vendor_elem_invitation(dev):
269 """VENDOR_ELEM in Invitation frames"""
271 _test_p2p_ext_vendor_elem_invitation(dev)
273 dev[0].request("VENDOR_ELEM_REMOVE 9 *")
274 dev[0].request("VENDOR_ELEM_REMOVE 10 *")
276 def _test_p2p_ext_vendor_elem_invitation(dev):
277 addr0 = dev[0].p2p_dev_addr()
278 addr1 = dev[1].p2p_dev_addr()
280 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 9 dd050011223306"):
281 raise Exception("VENDOR_ELEM_ADD failed")
282 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 10 dd050011223307"):
283 raise Exception("VENDOR_ELEM_ADD failed")
285 if not dev[0].discover_peer(addr1):
286 raise Exception("Device discovery timed out")
287 peer = dev[0].get_peer(addr1)
288 dev[0].p2p_stop_find()
289 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
290 raise Exception("Failed to enable external management frame handling")
291 dev[0].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr1)
293 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
295 raise Exception("MGMT-RX timeout")
298 if "dd050011223306" not in ev:
299 raise Exception("Vendor element not found from Invitation Request frame")
300 dev[0].p2p_stop_find()
301 dev[1].p2p_stop_find()
304 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 0"):
305 raise Exception("Failed to disable external management frame handling")
306 if not dev[1].discover_peer(addr0):
307 raise Exception("Device discovery timed out")
308 peer = dev[1].get_peer(addr0)
309 dev[1].p2p_stop_find()
310 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
311 raise Exception("Failed to enable external management frame handling")
312 dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
314 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
316 raise Exception("MGMT-RX timeout")
319 if "dd050011223307" not in ev:
320 raise Exception("Vendor element not found from Invitation Response frame")
321 dev[0].p2p_stop_find()
322 dev[1].p2p_stop_find()
324 def test_p2p_ext_vendor_elem_assoc(dev, apdev, params):
325 """VENDOR_ELEM in Association frames"""
327 _test_p2p_ext_vendor_elem_assoc(dev, apdev, params)
329 dev[0].request("VENDOR_ELEM_REMOVE 11 *")
330 dev[1].request("VENDOR_ELEM_REMOVE 12 *")
331 dev[0].request("VENDOR_ELEM_REMOVE 13 *")
333 def _test_p2p_ext_vendor_elem_assoc(dev, apdev, params):
334 addr0 = dev[0].p2p_dev_addr()
335 addr1 = dev[1].p2p_dev_addr()
336 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 11 dd050011223308"):
337 raise Exception("VENDOR_ELEM_ADD failed")
338 if "OK" not in dev[1].request("VENDOR_ELEM_ADD 12 dd050011223309"):
339 raise Exception("VENDOR_ELEM_ADD failed")
340 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd05001122330a"):
341 raise Exception("VENDOR_ELEM_ADD failed")
344 dev[1].p2p_go_neg_auth(addr0, "12345670", "enter", go_intent=15)
345 dev[0].p2p_go_neg_init(addr1, "12345670", "display", go_intent=0,
347 dev[1].p2p_go_neg_auth_result()
348 dev[1].remove_group()
349 dev[0].wait_go_ending_session()
351 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
352 "wlan.fc.type_subtype == 0x00", wait=False)
353 if "Vendor Specific Data: 3308" not in out:
354 raise Exception("Vendor element (P2P) not found from Association Request frame")
355 if "Vendor Specific Data: 330a" not in out:
356 raise Exception("Vendor element (non-P2P) not found from Association Request frame")
358 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
359 "wlan.fc.type_subtype == 0x01", wait=False)
360 if "Vendor Specific Data: 3309" not in out:
361 raise Exception("Vendor element not found from Association Response frame")