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.
7 from remotehost import remote_compatible
9 logger = logging.getLogger()
12 from tshark import run_tshark
13 from p2p_utils import *
16 def test_p2p_ext_discovery(dev):
17 """P2P device discovery with vendor specific extensions"""
18 addr0 = dev[0].p2p_dev_addr()
19 addr1 = dev[1].p2p_dev_addr()
22 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd050011223344"):
23 raise Exception("VENDOR_ELEM_ADD failed")
24 res = dev[0].request("VENDOR_ELEM_GET 1")
25 if res != "dd050011223344":
26 raise Exception("Unexpected VENDOR_ELEM_GET result: " + res)
27 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd06001122335566"):
28 raise Exception("VENDOR_ELEM_ADD failed")
29 res = dev[0].request("VENDOR_ELEM_GET 1")
30 if res != "dd050011223344dd06001122335566":
31 raise Exception("Unexpected VENDOR_ELEM_GET result(2): " + res)
32 res = dev[0].request("VENDOR_ELEM_GET 2")
34 raise Exception("Unexpected VENDOR_ELEM_GET result(3): " + res)
35 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd050011223344"):
36 raise Exception("VENDOR_ELEM_REMOVE failed")
37 res = dev[0].request("VENDOR_ELEM_GET 1")
38 if res != "dd06001122335566":
39 raise Exception("Unexpected VENDOR_ELEM_GET result(4): " + res)
40 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd06001122335566"):
41 raise Exception("VENDOR_ELEM_REMOVE failed")
42 res = dev[0].request("VENDOR_ELEM_GET 1")
44 raise Exception("Unexpected VENDOR_ELEM_GET result(5): " + res)
45 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd050011223344dd06001122335566"):
46 raise Exception("VENDOR_ELEM_ADD failed(2)")
48 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd051122334455"):
49 raise Exception("Unexpected VENDOR_ELEM_REMOVE success")
50 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd"):
51 raise Exception("Unexpected VENDOR_ELEM_REMOVE success(2)")
52 if "FAIL" not in dev[0].request("VENDOR_ELEM_ADD 1 ddff"):
53 raise Exception("Unexpected VENDOR_ELEM_ADD success(3)")
56 if not dev[1].discover_peer(addr0):
57 raise Exception("Device discovery timed out")
58 if not dev[0].discover_peer(addr1):
59 raise Exception("Device discovery timed out")
61 peer = dev[1].get_peer(addr0)
62 if peer['vendor_elems'] != "dd050011223344dd06001122335566":
63 raise Exception("Vendor elements not reported correctly")
65 res = dev[0].request("VENDOR_ELEM_GET 1")
66 if res != "dd050011223344dd06001122335566":
67 raise Exception("Unexpected VENDOR_ELEM_GET result(6): " + res)
68 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd06001122335566"):
69 raise Exception("VENDOR_ELEM_REMOVE failed")
70 res = dev[0].request("VENDOR_ELEM_GET 1")
71 if res != "dd050011223344":
72 raise Exception("Unexpected VENDOR_ELEM_GET result(7): " + res)
74 dev[0].request("VENDOR_ELEM_REMOVE 1 *")
77 def test_p2p_ext_discovery_go(dev):
78 """P2P device discovery with vendor specific extensions for GO"""
79 addr0 = dev[0].p2p_dev_addr()
80 addr1 = dev[1].p2p_dev_addr()
83 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 2 dd050011223344dd06001122335566"):
84 raise Exception("VENDOR_ELEM_ADD failed")
85 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 3 dd050011223344dd06001122335566"):
86 raise Exception("VENDOR_ELEM_ADD failed")
87 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 12 dd050011223344dd06001122335566"):
88 raise Exception("VENDOR_ELEM_ADD failed")
90 dev[0].p2p_start_go(freq="2412")
91 if not dev[1].discover_peer(addr0):
92 raise Exception("Device discovery timed out")
93 peer = dev[1].get_peer(addr0)
94 if peer['vendor_elems'] != "dd050011223344dd06001122335566":
95 print peer['vendor_elems']
96 raise Exception("Vendor elements not reported correctly")
98 dev[0].request("VENDOR_ELEM_REMOVE 2 *")
99 dev[0].request("VENDOR_ELEM_REMOVE 3 *")
100 dev[0].request("VENDOR_ELEM_REMOVE 12 *")
102 def test_p2p_ext_vendor_elem_probe_req(dev):
103 """VENDOR_ELEM in P2P Probe Request frames"""
105 _test_p2p_ext_vendor_elem_probe_req(dev)
107 dev[0].request("VENDOR_ELEM_REMOVE 0 *")
109 def _test_p2p_ext_vendor_elem_probe_req(dev):
110 addr1 = dev[1].p2p_dev_addr()
111 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 0 dd050011223300"):
112 raise Exception("VENDOR_ELEM_ADD failed")
114 if not dev[0].discover_peer(addr1):
115 raise Exception("Device discovery timed out")
116 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
117 raise Exception("Failed to enable external management frame handling")
118 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
120 raise Exception("MGMT-RX timeout")
122 raise Exception("Not a Probe Request frame")
123 if "dd050011223300" not in ev:
124 raise Exception("Vendor element not found from Probe Request frame")
125 dev[0].p2p_stop_find()
126 dev[1].p2p_stop_find()
128 def test_p2p_ext_vendor_elem_pd_req(dev):
129 """VENDOR_ELEM in PD Request frames"""
131 _test_p2p_ext_vendor_elem_pd_req(dev)
133 dev[0].request("VENDOR_ELEM_REMOVE 4 *")
135 def _test_p2p_ext_vendor_elem_pd_req(dev):
136 addr0 = dev[0].p2p_dev_addr()
137 addr1 = dev[1].p2p_dev_addr()
138 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 4 dd050011223301"):
139 raise Exception("VENDOR_ELEM_ADD failed")
141 if not dev[0].discover_peer(addr1):
142 raise Exception("Device discovery timed out")
143 dev[0].p2p_stop_find()
144 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
145 raise Exception("Failed to enable external management frame handling")
146 dev[0].global_request("P2P_PROV_DISC " + addr1 + " display")
148 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
150 raise Exception("MGMT-RX timeout")
153 if "dd050011223301" not in ev:
154 raise Exception("Vendor element not found from PD Request frame")
155 dev[1].p2p_stop_find()
156 dev[0].p2p_stop_find()
158 def test_p2p_ext_vendor_elem_pd_resp(dev):
159 """VENDOR_ELEM in PD Response frames"""
161 _test_p2p_ext_vendor_elem_pd_resp(dev)
163 dev[0].request("VENDOR_ELEM_REMOVE 5 *")
165 def _test_p2p_ext_vendor_elem_pd_resp(dev):
166 addr0 = dev[0].p2p_dev_addr()
167 addr1 = dev[1].p2p_dev_addr()
168 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 5 dd050011223302"):
169 raise Exception("VENDOR_ELEM_ADD failed")
171 if not dev[1].discover_peer(addr0):
172 raise Exception("Device discovery timed out")
173 dev[1].p2p_stop_find()
174 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
175 raise Exception("Failed to enable external management frame handling")
176 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
178 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
180 raise Exception("MGMT-RX timeout")
183 if "dd050011223302" not in ev:
184 raise Exception("Vendor element not found from PD Response frame")
185 dev[0].p2p_stop_find()
186 dev[1].p2p_stop_find()
188 def test_p2p_ext_vendor_elem_go_neg_req(dev):
189 """VENDOR_ELEM in GO Negotiation Request frames"""
191 _test_p2p_ext_vendor_elem_go_neg_req(dev)
193 dev[0].request("VENDOR_ELEM_REMOVE 6 *")
195 def _test_p2p_ext_vendor_elem_go_neg_req(dev):
196 addr0 = dev[0].p2p_dev_addr()
197 addr1 = dev[1].p2p_dev_addr()
198 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 6 dd050011223303"):
199 raise Exception("VENDOR_ELEM_ADD failed")
201 if not dev[0].discover_peer(addr1):
202 raise Exception("Device discovery timed out")
203 dev[0].p2p_stop_find()
204 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
205 raise Exception("Failed to enable external management frame handling")
206 dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display")
208 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
210 raise Exception("MGMT-RX timeout")
213 if "dd050011223303" not in ev:
214 raise Exception("Vendor element not found from GO Negotiation Request frame")
215 dev[1].p2p_stop_find()
216 dev[0].p2p_stop_find()
218 def test_p2p_ext_vendor_elem_go_neg_resp(dev):
219 """VENDOR_ELEM in GO Negotiation Response frames"""
221 _test_p2p_ext_vendor_elem_go_neg_resp(dev)
223 dev[0].request("VENDOR_ELEM_REMOVE 7 *")
225 def _test_p2p_ext_vendor_elem_go_neg_resp(dev):
226 addr0 = dev[0].p2p_dev_addr()
227 addr1 = dev[1].p2p_dev_addr()
228 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 7 dd050011223304"):
229 raise Exception("VENDOR_ELEM_ADD failed")
231 if not dev[1].discover_peer(addr0):
232 raise Exception("Device discovery timed out")
233 dev[1].p2p_stop_find()
234 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
235 raise Exception("Failed to enable external management frame handling")
236 dev[1].global_request("P2P_CONNECT " + addr0 + " 12345670 display")
238 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
240 raise Exception("MGMT-RX timeout")
243 if "dd050011223304" not in ev:
244 raise Exception("Vendor element not found from GO Negotiation Response frame")
245 dev[0].p2p_stop_find()
246 dev[1].p2p_stop_find()
248 def test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params):
249 """VENDOR_ELEM in GO Negotiation Confirm frames"""
251 _test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params)
253 dev[0].request("VENDOR_ELEM_REMOVE 8 *")
255 def _test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params):
256 addr0 = dev[0].p2p_dev_addr()
257 addr1 = dev[1].p2p_dev_addr()
258 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 8 dd050011223305"):
259 raise Exception("VENDOR_ELEM_ADD failed")
262 dev[1].p2p_go_neg_auth(addr0, "12345670", "enter")
263 dev[0].p2p_go_neg_init(addr1, "12345678", "display")
264 dev[1].p2p_go_neg_auth_result(expect_failure=True)
266 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
267 "wifi_p2p.public_action.subtype == 2")
268 if "Vendor Specific Data: 3305" not in out:
269 raise Exception("Vendor element not found from GO Negotiation Confirm frame")
271 def test_p2p_ext_vendor_elem_invitation(dev):
272 """VENDOR_ELEM in Invitation frames"""
274 _test_p2p_ext_vendor_elem_invitation(dev)
276 dev[0].request("VENDOR_ELEM_REMOVE 9 *")
277 dev[0].request("VENDOR_ELEM_REMOVE 10 *")
279 def _test_p2p_ext_vendor_elem_invitation(dev):
280 addr0 = dev[0].p2p_dev_addr()
281 addr1 = dev[1].p2p_dev_addr()
283 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 9 dd050011223306"):
284 raise Exception("VENDOR_ELEM_ADD failed")
285 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 10 dd050011223307"):
286 raise Exception("VENDOR_ELEM_ADD failed")
288 if not dev[0].discover_peer(addr1):
289 raise Exception("Device discovery timed out")
290 peer = dev[0].get_peer(addr1)
291 dev[0].p2p_stop_find()
292 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
293 raise Exception("Failed to enable external management frame handling")
294 dev[0].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr1)
296 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
298 raise Exception("MGMT-RX timeout")
301 if "dd050011223306" not in ev:
302 raise Exception("Vendor element not found from Invitation Request frame")
303 dev[0].p2p_stop_find()
304 dev[1].p2p_stop_find()
307 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 0"):
308 raise Exception("Failed to disable external management frame handling")
309 if not dev[1].discover_peer(addr0):
310 raise Exception("Device discovery timed out")
311 peer = dev[1].get_peer(addr0)
312 dev[1].p2p_stop_find()
313 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
314 raise Exception("Failed to enable external management frame handling")
315 dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
317 ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
319 raise Exception("MGMT-RX timeout")
322 if "dd050011223307" not in ev:
323 raise Exception("Vendor element not found from Invitation Response frame")
324 dev[0].p2p_stop_find()
325 dev[1].p2p_stop_find()
327 def test_p2p_ext_vendor_elem_assoc(dev, apdev, params):
328 """VENDOR_ELEM in Association frames"""
330 _test_p2p_ext_vendor_elem_assoc(dev, apdev, params)
332 dev[0].request("VENDOR_ELEM_REMOVE 11 *")
333 dev[1].request("VENDOR_ELEM_REMOVE 12 *")
334 dev[0].request("VENDOR_ELEM_REMOVE 13 *")
336 def _test_p2p_ext_vendor_elem_assoc(dev, apdev, params):
337 addr0 = dev[0].p2p_dev_addr()
338 addr1 = dev[1].p2p_dev_addr()
340 res = dev[0].get_driver_status()
341 p2p_device = True if (int(res['capa.flags'], 0) & 0x20000000) else False
343 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 11 dd050011223308"):
344 raise Exception("VENDOR_ELEM_ADD failed")
345 if "OK" not in dev[1].request("VENDOR_ELEM_ADD 12 dd050011223309"):
346 raise Exception("VENDOR_ELEM_ADD failed")
347 if not p2p_device and "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd05001122330a"):
348 raise Exception("VENDOR_ELEM_ADD failed")
351 dev[1].p2p_go_neg_auth(addr0, "12345670", "enter", go_intent=15)
352 dev[0].p2p_go_neg_init(addr1, "12345670", "display", go_intent=0,
354 dev[1].p2p_go_neg_auth_result()
355 dev[1].remove_group()
356 dev[0].wait_go_ending_session()
358 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
359 "wlan.fc.type_subtype == 0x00", wait=False)
360 if "Vendor Specific Data: 3308" not in out:
361 raise Exception("Vendor element (P2P) not found from Association Request frame")
362 if not p2p_device and "Vendor Specific Data: 330a" not in out:
363 raise Exception("Vendor element (non-P2P) not found from Association Request frame")
365 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
366 "wlan.fc.type_subtype == 0x01", wait=False)
367 if "Vendor Specific Data: 3309" not in out:
368 raise Exception("Vendor element not found from Association Response frame")