1 # P2P protocol tests for various messages
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
11 logger = logging.getLogger()
14 from test_p2p_persistent import form
15 from test_p2p_persistent import invite
17 MGMT_SUBTYPE_PROBE_REQ = 4
18 MGMT_SUBTYPE_ACTION = 13
19 ACTION_CATEG_PUBLIC = 4
24 P2P_INVITATION_REQ = 3
25 P2P_INVITATION_RESP = 4
29 P2P_PROV_DISC_RESP = 8
32 P2P_ATTR_MINOR_REASON_CODE = 1
33 P2P_ATTR_CAPABILITY = 2
34 P2P_ATTR_DEVICE_ID = 3
35 P2P_ATTR_GROUP_OWNER_INTENT = 4
36 P2P_ATTR_CONFIGURATION_TIMEOUT = 5
37 P2P_ATTR_LISTEN_CHANNEL = 6
38 P2P_ATTR_GROUP_BSSID = 7
39 P2P_ATTR_EXT_LISTEN_TIMING = 8
40 P2P_ATTR_INTENDED_INTERFACE_ADDR = 9
41 P2P_ATTR_MANAGEABILITY = 10
42 P2P_ATTR_CHANNEL_LIST = 11
43 P2P_ATTR_NOTICE_OF_ABSENCE = 12
44 P2P_ATTR_DEVICE_INFO = 13
45 P2P_ATTR_GROUP_INFO = 14
46 P2P_ATTR_GROUP_ID = 15
47 P2P_ATTR_INTERFACE = 16
48 P2P_ATTR_OPERATING_CHANNEL = 17
49 P2P_ATTR_INVITATION_FLAGS = 18
50 P2P_ATTR_OOB_GO_NEG_CHANNEL = 19
51 P2P_ATTR_VENDOR_SPECIFIC = 221
54 P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE = 1
55 P2P_SC_FAIL_INCOMPATIBLE_PARAMS = 2
56 P2P_SC_FAIL_LIMIT_REACHED = 3
57 P2P_SC_FAIL_INVALID_PARAMS = 4
58 P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE = 5
59 P2P_SC_FAIL_PREV_PROTOCOL_ERROR = 6
60 P2P_SC_FAIL_NO_COMMON_CHANNELS = 7
61 P2P_SC_FAIL_UNKNOWN_GROUP = 8
62 P2P_SC_FAIL_BOTH_GO_INTENT_15 = 9
63 P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD = 10
64 P2P_SC_FAIL_REJECTED_BY_USER = 11
66 WSC_ATTR_CONFIG_METHODS = 0x1008
69 WLAN_EID_SUPP_RATES = 1
70 WLAN_EID_VENDOR_SPECIFIC = 221
73 return struct.pack("<BB", WLAN_EID_SSID, len(ssid)) + ssid
76 return struct.pack("<BBBBBBBBBB", WLAN_EID_SUPP_RATES, 8,
77 2*6, 2*9, 2*12, 2*18, 2*24, 2*36, 2*48, 2*54)
80 return struct.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC, 4 + len(attrs),
81 0x50, 0x6f, 0x9a, 9) + attrs
84 return struct.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC, 4 + len(attrs),
85 0x00, 0x50, 0xf2, 4) + attrs
87 def wsc_attr_config_methods(methods=0):
88 return struct.pack(">HHH", WSC_ATTR_CONFIG_METHODS, 2, methods)
90 def p2p_attr_status(status=P2P_SC_SUCCESS):
91 return struct.pack("<BHB", P2P_ATTR_STATUS, 1, status)
93 def p2p_attr_minor_reason_code(code=0):
94 return struct.pack("<BHB", P2P_ATTR_MINOR_REASON_CODE, 1, code)
96 def p2p_attr_capability(dev_capab=0, group_capab=0):
97 return struct.pack("<BHBB", P2P_ATTR_CAPABILITY, 2, dev_capab, group_capab)
99 def p2p_attr_device_id(addr):
100 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
101 t = (P2P_ATTR_DEVICE_ID, 6) + val
102 return struct.pack('<BH6B', *t)
104 def p2p_attr_go_intent(go_intent=0, tie_breaker=0):
105 return struct.pack("<BHB", P2P_ATTR_GROUP_OWNER_INTENT, 1,
106 (go_intent << 1) | (tie_breaker & 0x01))
108 def p2p_attr_config_timeout(go_config_timeout=0, client_config_timeout=0):
109 return struct.pack("<BHBB", P2P_ATTR_CONFIGURATION_TIMEOUT, 2,
110 go_config_timeout, client_config_timeout)
112 def p2p_attr_listen_channel(op_class=81, chan=1):
113 return struct.pack("<BHBBBBB", P2P_ATTR_LISTEN_CHANNEL, 5,
114 0x58, 0x58, 0x04, op_class, chan)
116 def p2p_attr_group_bssid(addr):
117 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
118 t = (P2P_ATTR_GROUP_BSSID, 6) + val
119 return struct.pack('<BH6B', *t)
121 def p2p_attr_ext_listen_timing(period=0, interval=0):
122 return struct.pack("<BHHH", P2P_ATTR_EXT_LISTEN_TIMING, 4, period, interval)
124 def p2p_attr_intended_interface_addr(addr):
125 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
126 t = (P2P_ATTR_INTENDED_INTERFACE_ADDR, 6) + val
127 return struct.pack('<BH6B', *t)
129 def p2p_attr_manageability(bitmap=0):
130 return struct.pack("<BHB", P2P_ATTR_MANAGEABILITY, 1, bitmap)
132 def p2p_attr_channel_list():
133 return struct.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST, 16,
135 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
137 def p2p_attr_device_info(addr, name="Test", config_methods=0, dev_type="00010050F2040001"):
138 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
139 val2 = struct.unpack('8B', binascii.unhexlify(dev_type))
140 t = (P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 4 + len(name)) + val + (config_methods,) + val2 + (0,)
141 return struct.pack("<BH6BH8BB", *t) + struct.pack('>HH', 0x1011, len(name)) +name
143 def p2p_attr_group_id(addr, ssid):
144 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
145 t = (P2P_ATTR_GROUP_ID, 6 + len(ssid)) + val
146 return struct.pack('<BH6B', *t) + ssid
148 def p2p_attr_operating_channel(op_class=81, chan=1):
149 return struct.pack("<BHBBBBB", P2P_ATTR_OPERATING_CHANNEL, 5,
150 0x58, 0x58, 0x04, op_class, chan)
152 def p2p_attr_invitation_flags(bitmap=0):
153 return struct.pack("<BHB", P2P_ATTR_INVITATION_FLAGS, 1, bitmap)
155 def p2p_hdr_helper(dst, src, type=None, dialog_token=1, req=True):
157 msg['fc'] = MGMT_SUBTYPE_ACTION << 4
164 msg['payload'] = struct.pack("<BBBBBB",
165 ACTION_CATEG_PUBLIC, 9, 0x50, 0x6f, 0x9a, 9)
167 msg['payload'] += struct.pack("<B", type)
169 msg['payload'] += struct.pack("<B", dialog_token)
172 def p2p_hdr(dst, src, type=None, dialog_token=1):
173 return p2p_hdr_helper(dst, src, type, dialog_token, True)
175 def p2p_hdr_resp(dst, src, type=None, dialog_token=1):
176 return p2p_hdr_helper(dst, src, type, dialog_token, False)
178 def start_p2p(dev, apdev):
179 addr0 = dev[0].p2p_dev_addr()
181 dev[1].p2p_find(social=True)
182 ev = dev[1].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
184 raise Exception("Device discovery timed out")
185 dev[1].p2p_stop_find()
186 peer = dev[1].get_peer(addr0)
188 bssid = apdev[0]['bssid']
189 params = { 'ssid': "test", 'beacon_int': "2000" }
190 if peer['listen_freq'] == "2412":
191 params['channel'] = '1'
192 elif peer['listen_freq'] == "2437":
193 params['channel'] = '6'
194 elif peer['listen_freq'] == "2462":
195 params['channel'] = '11'
196 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
197 hapd.set("ext_mgmt_frame_handling", "1")
198 return addr0, bssid, hapd, int(params['channel'])
200 def p2p_probe(hapd, src, chan=1):
202 msg['fc'] = MGMT_SUBTYPE_PROBE_REQ << 4
203 msg['da'] = "ff:ff:ff:ff:ff:ff"
205 msg['bssid'] = "ff:ff:ff:ff:ff:ff"
206 attrs = p2p_attr_listen_channel(chan=chan)
207 msg['payload'] = ie_ssid("DIRECT-") + ie_supp_rates() + ie_p2p(attrs)
210 def parse_p2p_public_action(payload):
212 (category, action) = struct.unpack('BB', pos[0:2])
213 if category != ACTION_CATEG_PUBLIC:
218 (oui1,oui2,oui3,subtype) = struct.unpack('BBBB', pos[0:4])
219 if oui1 != 0x50 or oui2 != 0x6f or oui3 != 0x9a or subtype != 9:
222 (subtype,dialog_token) = struct.unpack('BB', pos[0:2])
224 p2p['subtype'] = subtype
225 p2p['dialog_token'] = dialog_token
227 p2p['elements'] = pos
229 (id,elen) = struct.unpack('BB', pos[0:2])
232 raise Exception("Truncated IE in P2P Public Action frame (elen=%d left=%d)" % (elen, len(pos)))
233 if id == WLAN_EID_VENDOR_SPECIFIC:
235 raise Exception("Too short vendor specific IE in P2P Public Action frame (elen=%d)" % elen)
236 (oui1,oui2,oui3,subtype) = struct.unpack('BBBB', pos[0:4])
237 if oui1 == 0x50 and oui2 == 0x6f and oui3 == 0x9a and subtype == 9:
239 p2p['p2p'] += pos[4:elen]
241 p2p['p2p'] = pos[4:elen]
242 if oui1 == 0x00 and oui2 == 0x50 and oui3 == 0xf2 and subtype == 4:
243 p2p['wsc'] = pos[4:elen]
246 raise Exception("Invalid element in P2P Public Action frame")
249 p2p['p2p_attrs'] = {}
252 (id,alen) = struct.unpack('<BH', pos[0:3])
255 logger.info("P2P payload: " + binascii.hexlify(p2p['p2p']))
256 raise Exception("Truncated P2P attribute in P2P Public Action frame (alen=%d left=%d p2p-payload=%d)" % (alen, len(pos), len(p2p['p2p'])))
257 p2p['p2p_attrs'][id] = pos[0:alen]
259 if P2P_ATTR_STATUS in p2p['p2p_attrs']:
260 p2p['p2p_status'] = struct.unpack('B', p2p['p2p_attrs'][P2P_ATTR_STATUS])[0]
263 p2p['wsc_attrs'] = {}
266 (id,alen) = struct.unpack('>HH', pos[0:4])
269 logger.info("WSC payload: " + binascii.hexlify(p2p['wsc']))
270 raise Exception("Truncated WSC attribute in P2P Public Action frame (alen=%d left=%d wsc-payload=%d)" % (alen, len(pos), len(p2p['wsc'])))
271 p2p['wsc_attrs'][id] = pos[0:alen]
276 def test_p2p_msg_empty(dev, apdev):
277 """P2P protocol test: empty P2P Public Action frame"""
278 dst, src, hapd, channel = start_p2p(dev, apdev)
279 msg = p2p_hdr(dst, src)
282 def test_p2p_msg_invitation_req(dev, apdev):
283 """P2P protocol tests for invitation request processing"""
284 dst, src, hapd, channel = start_p2p(dev, apdev)
286 # Empty P2P Invitation Request (missing dialog token)
287 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=None)
291 # Various p2p_parse() failure cases due to invalid attributes
293 # Too short attribute header
295 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
296 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
297 msg['payload'] += ie_p2p(attrs)
300 # Minimal attribute underflow
302 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
303 attrs = struct.pack("<BH", P2P_ATTR_CAPABILITY, 1)
304 msg['payload'] += ie_p2p(attrs)
307 # Large attribute underflow
309 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
310 attrs = struct.pack("<BHB", P2P_ATTR_CAPABILITY, 0xffff, 1)
311 msg['payload'] += ie_p2p(attrs)
314 # Too short Capability attribute
316 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
317 attrs = struct.pack("<BHB", P2P_ATTR_CAPABILITY, 1, 0)
318 msg['payload'] += ie_p2p(attrs)
321 # Too short Device ID attribute
323 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
324 val = struct.unpack('5B', binascii.unhexlify("1122334455"))
325 t = (P2P_ATTR_DEVICE_ID, 5) + val
326 attrs = struct.pack('<BH5B', *t)
327 msg['payload'] += ie_p2p(attrs)
330 # Too short GO Intent attribute
332 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
333 attrs = struct.pack("<BH", P2P_ATTR_GROUP_OWNER_INTENT, 0)
334 msg['payload'] += ie_p2p(attrs)
337 # Too short Status attribute
339 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
340 attrs = struct.pack("<BH", P2P_ATTR_STATUS, 0)
341 msg['payload'] += ie_p2p(attrs)
344 # null Listen channel and too short Listen Channel attribute
346 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
347 attrs = struct.pack("<BH", P2P_ATTR_LISTEN_CHANNEL, 0)
348 attrs += struct.pack("<BHB", P2P_ATTR_LISTEN_CHANNEL, 1, 0)
349 msg['payload'] += ie_p2p(attrs)
352 # null Operating channel and too short Operating Channel attribute
354 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
355 attrs = struct.pack("<BH", P2P_ATTR_OPERATING_CHANNEL, 0)
356 attrs += struct.pack("<BHB", P2P_ATTR_OPERATING_CHANNEL, 1, 0)
357 msg['payload'] += ie_p2p(attrs)
360 # Too short Channel List attribute
362 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
363 attrs = struct.pack("<BHBB", P2P_ATTR_CHANNEL_LIST, 2, 1, 2)
364 msg['payload'] += ie_p2p(attrs)
367 # Too short Device Info attribute
369 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
370 attrs = struct.pack("<BHBB", P2P_ATTR_DEVICE_INFO, 2, 1, 2)
371 msg['payload'] += ie_p2p(attrs)
374 # Truncated Secondary Device Types in Device Info attribute
376 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
377 attrs = struct.pack("<BH6BH8BB", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1,
380 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22,
382 msg['payload'] += ie_p2p(attrs)
385 # Missing Device Name in Device Info attribute
387 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
388 attrs = struct.pack("<BH6BH8BB8B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8,
391 0, 0, 0, 0, 0, 0, 0, 0,
393 1, 2, 3, 4, 5, 6, 7, 8)
394 msg['payload'] += ie_p2p(attrs)
397 # Invalid Device Name header in Device Info attribute
399 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
400 attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4,
403 0, 0, 0, 0, 0, 0, 0, 0,
405 1, 2, 3, 4, 5, 6, 7, 8,
407 msg['payload'] += ie_p2p(attrs)
410 # Invalid Device Name header length in Device Info attribute
412 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
413 attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4,
416 0, 0, 0, 0, 0, 0, 0, 0,
418 1, 2, 3, 4, 5, 6, 7, 8,
419 0x10, 0x11, 0xff, 0xff)
420 msg['payload'] += ie_p2p(attrs)
423 # Invalid Device Name header length in Device Info attribute
425 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
427 attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + len(devname),
430 0, 0, 0, 0, 0, 0, 0, 0,
432 1, 2, 3, 4, 5, 6, 7, 8,
433 0x10, 0x11, 0, len(devname) + 1) + devname
434 msg['payload'] += ie_p2p(attrs)
437 # Device Name filtering and too long Device Name in Device Info attribute
439 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
440 attrs = struct.pack("<BH6BH8BB8B4B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + 4,
443 0, 0, 0, 0, 0, 0, 0, 0,
445 1, 2, 3, 4, 5, 6, 7, 8,
448 devname = '123456789012345678901234567890123'
449 attrs += struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + len(devname),
452 0, 0, 0, 0, 0, 0, 0, 0,
454 1, 2, 3, 4, 5, 6, 7, 8,
455 0x10, 0x11, 0, len(devname)) + devname
456 msg['payload'] += ie_p2p(attrs)
459 # Too short Configuration Timeout attribute
461 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
462 attrs = struct.pack("<BHB", P2P_ATTR_CONFIGURATION_TIMEOUT, 1, 1)
463 msg['payload'] += ie_p2p(attrs)
466 # Too short Intended P2P Interface Address attribute
468 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
469 attrs = struct.pack("<BHB", P2P_ATTR_INTENDED_INTERFACE_ADDR, 1, 1)
470 msg['payload'] += ie_p2p(attrs)
473 # Too short P2P Group BSSID attribute
475 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
476 attrs = struct.pack("<BHB", P2P_ATTR_GROUP_BSSID, 1, 1)
477 msg['payload'] += ie_p2p(attrs)
480 # Too short P2P Group ID attribute
482 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
483 attrs = struct.pack("<BHB", P2P_ATTR_GROUP_ID, 1, 1)
484 msg['payload'] += ie_p2p(attrs)
487 # Too long P2P Group ID attribute
489 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
490 attrs = struct.pack("<BH6B", P2P_ATTR_GROUP_ID, 6 + 33, 0, 0, 0, 0, 0, 0) + "123456789012345678901234567890123"
491 msg['payload'] += ie_p2p(attrs)
494 # Too short Invitation Flags attribute
496 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
497 attrs = struct.pack("<BH", P2P_ATTR_INVITATION_FLAGS, 0)
498 msg['payload'] += ie_p2p(attrs)
501 # Valid and too short Manageability attribute
503 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
504 attrs = p2p_attr_manageability()
505 attrs += struct.pack("<BH", P2P_ATTR_MANAGEABILITY, 0)
506 msg['payload'] += ie_p2p(attrs)
509 # Too short NoA attribute
511 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
512 attrs = struct.pack("<BHB", P2P_ATTR_NOTICE_OF_ABSENCE, 1, 1)
513 msg['payload'] += ie_p2p(attrs)
516 # Valid and too short Extended Listen Timing attributes
518 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
519 attrs = p2p_attr_ext_listen_timing(period=100, interval=50)
520 attrs += struct.pack("<BHBBB", P2P_ATTR_EXT_LISTEN_TIMING, 3, 0, 0, 0)
521 msg['payload'] += ie_p2p(attrs)
524 # Valid and too short Minor Reason Code attributes
526 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
527 attrs = p2p_attr_minor_reason_code(code=2)
528 attrs += struct.pack("<BH", P2P_ATTR_MINOR_REASON_CODE, 0)
529 msg['payload'] += ie_p2p(attrs)
532 # Unknown attribute and too short OOB GO Negotiation Channel attribute
534 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
535 attrs = struct.pack("<BHB", 99, 1, 1)
536 attrs += struct.pack("<BHB", P2P_ATTR_OOB_GO_NEG_CHANNEL, 1, 1)
537 msg['payload'] += ie_p2p(attrs)
540 if hapd.mgmt_rx(timeout=0.5) is not None:
541 raise Exception("Unexpected management frame received")
543 dev[0].dump_monitor()
545 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
546 attrs = p2p_attr_config_timeout()
547 attrs += p2p_attr_invitation_flags()
548 attrs += p2p_attr_operating_channel()
549 attrs += p2p_attr_group_bssid(src)
550 attrs += p2p_attr_channel_list()
551 attrs += p2p_attr_group_id(src, "DIRECT-foo")
552 attrs += p2p_attr_device_info(src, config_methods=0x0108)
553 msg['payload'] += ie_p2p(attrs)
555 ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
557 raise Exception("Timeout on device found event")
558 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=5)
560 raise Exception("Timeout on invitation event " + str(dialog_token))
561 if hapd.mgmt_rx(timeout=1) is None:
562 raise Exception("No invitation response " + str(dialog_token))
565 dev[0].dump_monitor()
567 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
568 attrs = p2p_attr_config_timeout()
569 attrs += p2p_attr_invitation_flags()
570 attrs += p2p_attr_operating_channel()
571 attrs += p2p_attr_group_bssid(src)
572 attrs += p2p_attr_channel_list()
573 attrs += p2p_attr_group_id(src, "DIRECT-foo")
574 attrs += p2p_attr_device_info(src, config_methods=0x0108)
575 msg['payload'] += ie_p2p(attrs)
577 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=5)
579 raise Exception("Timeout on invitation event " + str(dialog_token))
580 if hapd.mgmt_rx(timeout=1) is None:
581 raise Exception("No invitation response " + str(dialog_token))
584 dev[0].dump_monitor()
586 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
587 #attrs = p2p_attr_config_timeout()
588 attrs = p2p_attr_invitation_flags()
589 attrs += p2p_attr_operating_channel()
590 attrs += p2p_attr_group_bssid(src)
591 attrs += p2p_attr_channel_list()
592 attrs += p2p_attr_group_id(src, "DIRECT-foo")
593 attrs += p2p_attr_device_info(src, config_methods=0x0108)
594 msg['payload'] += ie_p2p(attrs)
596 if hapd.mgmt_rx(timeout=1) is None:
597 raise Exception("No invitation response " + str(dialog_token))
600 dev[0].dump_monitor()
602 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
603 attrs = p2p_attr_config_timeout()
604 #attrs = p2p_attr_invitation_flags()
605 attrs += p2p_attr_operating_channel()
606 attrs += p2p_attr_group_bssid(src)
607 attrs += p2p_attr_channel_list()
608 attrs += p2p_attr_group_id(src, "DIRECT-foo")
609 attrs += p2p_attr_device_info(src, config_methods=0x0108)
610 msg['payload'] += ie_p2p(attrs)
612 if hapd.mgmt_rx(timeout=1) is None:
613 raise Exception("No invitation response " + str(dialog_token))
616 dev[0].dump_monitor()
618 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
619 attrs = p2p_attr_config_timeout()
620 attrs = p2p_attr_invitation_flags()
621 #attrs += p2p_attr_operating_channel()
622 attrs += p2p_attr_group_bssid(src)
623 attrs += p2p_attr_channel_list()
624 attrs += p2p_attr_group_id(src, "DIRECT-foo")
625 attrs += p2p_attr_device_info(src, config_methods=0x0108)
626 msg['payload'] += ie_p2p(attrs)
628 if hapd.mgmt_rx(timeout=1) is None:
629 raise Exception("No invitation response " + str(dialog_token))
632 dev[0].dump_monitor()
634 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
635 attrs = p2p_attr_config_timeout()
636 attrs = p2p_attr_invitation_flags()
637 attrs += p2p_attr_operating_channel()
638 #attrs += p2p_attr_group_bssid(src)
639 attrs += p2p_attr_channel_list()
640 attrs += p2p_attr_group_id(src, "DIRECT-foo")
641 attrs += p2p_attr_device_info(src, config_methods=0x0108)
642 msg['payload'] += ie_p2p(attrs)
644 if hapd.mgmt_rx(timeout=1) is None:
645 raise Exception("No invitation response " + str(dialog_token))
648 dev[0].dump_monitor()
650 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
651 attrs = p2p_attr_config_timeout()
652 attrs = p2p_attr_invitation_flags()
653 attrs += p2p_attr_operating_channel()
654 attrs += p2p_attr_group_bssid(src)
655 #attrs += p2p_attr_channel_list()
656 attrs += p2p_attr_group_id(src, "DIRECT-foo")
657 attrs += p2p_attr_device_info(src, config_methods=0x0108)
658 msg['payload'] += ie_p2p(attrs)
660 if hapd.mgmt_rx(timeout=1) is None:
661 raise Exception("No invitation response " + str(dialog_token))
664 dev[0].dump_monitor()
666 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
667 attrs = p2p_attr_config_timeout()
668 attrs = p2p_attr_invitation_flags()
669 attrs += p2p_attr_operating_channel()
670 attrs += p2p_attr_group_bssid(src)
671 attrs += p2p_attr_channel_list()
672 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
673 attrs += p2p_attr_device_info(src, config_methods=0x0108)
674 msg['payload'] += ie_p2p(attrs)
676 if hapd.mgmt_rx(timeout=1) is None:
677 raise Exception("No invitation response " + str(dialog_token))
680 dev[0].dump_monitor()
682 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
683 attrs = p2p_attr_config_timeout()
684 attrs = p2p_attr_invitation_flags()
685 attrs += p2p_attr_operating_channel()
686 attrs += p2p_attr_group_bssid(src)
687 attrs += p2p_attr_channel_list()
688 attrs += p2p_attr_group_id(src, "DIRECT-foo")
689 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
690 msg['payload'] += ie_p2p(attrs)
692 if hapd.mgmt_rx(timeout=1) is None:
693 raise Exception("No invitation response " + str(dialog_token))
696 dev[0].dump_monitor()
698 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
700 if hapd.mgmt_rx(timeout=1) is None:
701 raise Exception("No invitation response " + str(dialog_token))
703 def test_p2p_msg_invitation_req_unknown(dev, apdev):
704 """P2P protocol tests for invitation request from unknown peer"""
705 dst, src, hapd, channel = start_p2p(dev, apdev)
709 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
710 attrs = p2p_attr_config_timeout()
711 attrs += p2p_attr_invitation_flags()
712 attrs += p2p_attr_operating_channel()
713 attrs += p2p_attr_group_bssid(src)
714 attrs += p2p_attr_channel_list()
715 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
716 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
717 msg['payload'] += ie_p2p(attrs)
719 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=5)
721 raise Exception("Timeout on invitation event " + str(dialog_token))
722 if hapd.mgmt_rx(timeout=1) is None:
723 raise Exception("No invitation response " + str(dialog_token))
725 def test_p2p_msg_invitation_no_common_channels(dev, apdev):
726 """P2P protocol tests for invitation request without common channels"""
727 dst, src, hapd, channel = start_p2p(dev, apdev)
731 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
732 attrs = p2p_attr_config_timeout()
733 attrs += p2p_attr_invitation_flags()
734 attrs += p2p_attr_operating_channel()
735 attrs += p2p_attr_group_bssid(src)
736 attrs += struct.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST, 5,
739 attrs += p2p_attr_group_id(src, "DIRECT-foo")
740 attrs += p2p_attr_device_info(src, config_methods=0x0108)
741 msg['payload'] += ie_p2p(attrs)
743 if hapd.mgmt_rx(timeout=1) is None:
744 raise Exception("No invitation response " + str(dialog_token))
745 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=0.1)
747 raise Exception("Unexpected invitation event")
749 def test_p2p_msg_invitation_resp(dev, apdev):
750 """P2P protocol tests for invitation response processing"""
752 dev[0].dump_monitor()
753 dev[1].dump_monitor()
755 dst, src, hapd, channel = start_p2p(dev, apdev)
757 addr0 = dev[0].p2p_dev_addr()
758 addr1 = dev[1].p2p_dev_addr()
759 peer = dev[1].get_peer(addr0)
761 # P2P Invitation Response from unknown peer
762 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=1)
765 # P2P Invitation Response from peer that is not in invitation
766 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=2)
767 attrs = p2p_attr_status()
768 msg['payload'] += ie_p2p(attrs)
769 mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, peer['listen_freq'], binascii.hexlify(msg['payload'])))
772 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
773 raise Exception("Failed to enable external management frame handling")
775 invite(dev[0], dev[1])
776 rx_msg = dev[1].mgmt_rx()
778 raise Exception("MGMT-RX timeout")
779 p2p = parse_p2p_public_action(rx_msg['payload'])
781 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
782 if p2p['subtype'] != P2P_INVITATION_REQ:
783 raise Exception("Unexpected subtype %d" % p2p['subtype'])
785 # Invalid attribute to cause p2p_parse() failure
786 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
787 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
788 msg['payload'] += ie_p2p(attrs)
789 mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
791 invite(dev[0], dev[1])
792 rx_msg = dev[1].mgmt_rx()
794 raise Exception("MGMT-RX timeout")
795 p2p = parse_p2p_public_action(rx_msg['payload'])
797 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
798 if p2p['subtype'] != P2P_INVITATION_REQ:
799 raise Exception("Unexpected subtype %d" % p2p['subtype'])
801 # missing mandatory Status attribute
802 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
803 attrs = p2p_attr_channel_list()
804 msg['payload'] += ie_p2p(attrs)
805 mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
807 invite(dev[0], dev[1])
808 rx_msg = dev[1].mgmt_rx()
810 raise Exception("MGMT-RX timeout")
811 p2p = parse_p2p_public_action(rx_msg['payload'])
813 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
814 if p2p['subtype'] != P2P_INVITATION_REQ:
815 raise Exception("Unexpected subtype %d" % p2p['subtype'])
817 # no channel match (no common channel found at all)
818 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
819 attrs = p2p_attr_status()
820 attrs += struct.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST, 6,
823 msg['payload'] += ie_p2p(attrs)
824 mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
826 invite(dev[0], dev[1])
827 rx_msg = dev[1].mgmt_rx()
829 raise Exception("MGMT-RX timeout")
830 p2p = parse_p2p_public_action(rx_msg['payload'])
832 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
833 if p2p['subtype'] != P2P_INVITATION_REQ:
834 raise Exception("Unexpected subtype %d" % p2p['subtype'])
836 # no channel match (no acceptable P2P channel)
837 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
838 attrs = p2p_attr_status()
839 attrs += struct.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST, 6,
842 msg['payload'] += ie_p2p(attrs)
843 mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
845 invite(dev[0], dev[1])
846 rx_msg = dev[1].mgmt_rx()
848 raise Exception("MGMT-RX timeout")
849 p2p = parse_p2p_public_action(rx_msg['payload'])
851 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
852 if p2p['subtype'] != P2P_INVITATION_REQ:
853 raise Exception("Unexpected subtype %d" % p2p['subtype'])
855 # missing mandatory Channel List attribute (ignored as a workaround)
856 msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
857 attrs = p2p_attr_status()
858 msg['payload'] += ie_p2p(attrs)
859 mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
861 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15);
863 raise Exception("Group was not started")
865 def test_p2p_msg_pd_req(dev, apdev):
866 """P2P protocol tests for provision discovery request processing"""
867 dst, src, hapd, channel = start_p2p(dev, apdev)
870 # Too short attribute header
872 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
873 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
874 msg['payload'] += ie_p2p(attrs)
877 if hapd.mgmt_rx(timeout=0.5) is not None:
878 raise Exception("Unexpected management frame received")
882 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
884 msg['payload'] += ie_p2p(attrs)
886 if hapd.mgmt_rx(timeout=1) is None:
887 raise Exception("No PD response " + str(dialog_token))
892 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
893 attrs = wsc_attr_config_methods(methods=0x1008)
894 msg['payload'] += ie_wsc(attrs)
895 attrs = p2p_attr_capability()
896 attrs += p2p_attr_device_info(src, config_methods=0x0108)
897 msg['payload'] += ie_p2p(attrs)
899 ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
901 raise Exception("Timeout on device found event")
902 ev = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
904 raise Exception("Timeout on PD event")
905 if hapd.mgmt_rx(timeout=1) is None:
906 raise Exception("No PD response " + str(dialog_token))
911 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
912 attrs = wsc_attr_config_methods(methods=0x1008)
913 msg['payload'] += ie_wsc(attrs)
914 attrs = p2p_attr_capability()
915 attrs += p2p_attr_device_info(src, config_methods=0x0108)
916 attrs += p2p_attr_group_id("02:02:02:02:02:02", "DIRECT-foo")
917 msg['payload'] += ie_p2p(attrs)
919 if hapd.mgmt_rx(timeout=1) is None:
920 raise Exception("No PD response " + str(dialog_token))
921 ev = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=1)
923 raise Exception("Unexpected PD event")
925 # Listen channel is not yet known
926 if "FAIL" not in dev[0].global_request("P2P_PROV_DISC " + src + " display"):
927 raise Exception("Unexpected P2P_PROV_DISC success")
930 if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 02:03:04:05:06:07 display"):
931 raise Exception("Unexpected P2P_PROV_DISC success (2)")
933 def test_p2p_msg_pd(dev, apdev):
934 """P2P protocol tests for provision discovery request processing (known)"""
935 dst, src, hapd, channel = start_p2p(dev, apdev)
938 p2p_probe(hapd, src, chan=channel)
943 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
944 attrs = wsc_attr_config_methods(methods=0x1008)
945 msg['payload'] += ie_wsc(attrs)
946 attrs = p2p_attr_capability()
947 attrs += p2p_attr_device_info(src, config_methods=0x0108)
948 msg['payload'] += ie_p2p(attrs)
950 ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
952 raise Exception("Timeout on device found event")
953 ev = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
955 raise Exception("Timeout on PD event")
956 if hapd.mgmt_rx(timeout=1) is None:
957 raise Exception("No PD response " + str(dialog_token))
959 if "FAIL" in dev[0].global_request("P2P_PROV_DISC " + src + " display"):
960 raise Exception("Unexpected P2P_PROV_DISC failure")
961 frame = hapd.mgmt_rx(timeout=1)
963 raise Exception("No PD request " + str(dialog_token))
964 p2p = parse_p2p_public_action(frame['payload'])
966 raise Exception("Failed to parse PD request")
968 # invalid dialog token
969 msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
970 dialog_token=p2p['dialog_token'] + 1)
972 ev = dev[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout=0.1)
974 raise Exception("Unexpected PD result event")
977 msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
978 dialog_token=p2p['dialog_token'])
980 ev = dev[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout=5)
982 raise Exception("Timeout on PD result event")
985 msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
986 dialog_token=p2p['dialog_token'])
988 ev = dev[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout=0.1)
990 raise Exception("Unexpected PD result event")
992 def check_p2p_response(hapd, dialog_token, status):
993 resp = hapd.mgmt_rx(timeout=1)
995 raise Exception("No GO Neg Response " + str(dialog_token))
996 p2p = parse_p2p_public_action(resp['payload'])
998 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
999 if dialog_token != p2p['dialog_token']:
1000 raise Exception("Unexpected dialog token in response")
1001 if p2p['p2p_status'] != status:
1002 raise Exception("Unexpected status code %s in response (expected %d)" % (p2p['p2p_status'], status))
1004 def test_p2p_msg_go_neg_both_start(dev, apdev):
1005 """P2P protocol test for simultaneous GO Neg initiation"""
1006 addr0 = dev[0].p2p_dev_addr()
1007 addr1 = dev[1].p2p_dev_addr()
1009 dev[1].discover_peer(addr0)
1011 dev[0].discover_peer(addr1)
1013 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
1014 raise Exception("Failed to enable external management frame handling")
1015 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
1016 raise Exception("Failed to enable external management frame handling")
1017 dev[0].request("P2P_CONNECT {} pbc".format(addr1))
1018 dev[1].request("P2P_CONNECT {} pbc".format(addr0))
1019 msg = dev[0].mgmt_rx()
1021 raise Exception("MGMT-RX timeout")
1022 msg = dev[1].mgmt_rx()
1024 raise Exception("MGMT-RX timeout(2)")
1025 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 0"):
1026 raise Exception("Failed to disable external management frame handling")
1027 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=2)
1029 raise Exception("Unexpected GO Neg success")
1030 if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 0"):
1031 raise Exception("Failed to disable external management frame handling")
1032 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
1034 raise Exception("GO Neg did not succeed")
1035 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5);
1037 raise Exception("Group formation not succeed")
1038 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=5);
1040 raise Exception("Group formation not succeed")
1042 def test_p2p_msg_go_neg_req(dev, apdev):
1043 """P2P protocol tests for invitation request from unknown peer"""
1044 dst, src, hapd, channel = start_p2p(dev, apdev)
1049 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1050 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
1051 msg['payload'] += ie_p2p(attrs)
1053 frame = hapd.mgmt_rx(timeout=0.1)
1054 if frame is not None:
1056 raise Exception("Unexpected GO Neg Response")
1060 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1061 attrs = p2p_attr_capability()
1062 attrs += p2p_attr_go_intent()
1063 attrs += p2p_attr_config_timeout()
1064 #attrs += p2p_attr_listen_channel()
1065 attrs += p2p_attr_ext_listen_timing()
1066 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1067 attrs += p2p_attr_channel_list()
1068 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1069 attrs += p2p_attr_operating_channel()
1070 msg['payload'] += ie_p2p(attrs)
1072 if hapd.mgmt_rx(timeout=1) is None:
1073 raise Exception("No GO Neg Response " + str(dialog_token))
1077 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1078 attrs = p2p_attr_capability()
1079 attrs += p2p_attr_go_intent()
1080 attrs += p2p_attr_config_timeout()
1081 attrs += p2p_attr_listen_channel()
1082 attrs += p2p_attr_ext_listen_timing()
1083 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1084 attrs += p2p_attr_channel_list()
1085 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1086 #attrs += p2p_attr_operating_channel()
1087 msg['payload'] += ie_p2p(attrs)
1089 if hapd.mgmt_rx(timeout=1) is None:
1090 raise Exception("No GO Neg Response " + str(dialog_token))
1094 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1095 attrs = p2p_attr_capability()
1096 attrs += p2p_attr_go_intent()
1097 attrs += p2p_attr_config_timeout()
1098 attrs += p2p_attr_listen_channel()
1099 attrs += p2p_attr_ext_listen_timing()
1100 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1101 #attrs += p2p_attr_channel_list()
1102 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1103 attrs += p2p_attr_operating_channel()
1104 msg['payload'] += ie_p2p(attrs)
1106 if hapd.mgmt_rx(timeout=1) is None:
1107 raise Exception("No GO Neg Response " + str(dialog_token))
1111 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1112 attrs = p2p_attr_capability()
1113 attrs += p2p_attr_go_intent()
1114 attrs += p2p_attr_config_timeout()
1115 attrs += p2p_attr_listen_channel()
1116 attrs += p2p_attr_ext_listen_timing()
1117 #attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1118 attrs += p2p_attr_channel_list()
1119 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1120 attrs += p2p_attr_operating_channel()
1121 msg['payload'] += ie_p2p(attrs)
1123 if hapd.mgmt_rx(timeout=1) is None:
1124 raise Exception("No GO Neg Response " + str(dialog_token))
1128 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1129 attrs = p2p_attr_capability()
1130 attrs += p2p_attr_go_intent()
1131 attrs += p2p_attr_config_timeout()
1132 attrs += p2p_attr_listen_channel()
1133 attrs += p2p_attr_ext_listen_timing()
1134 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1135 attrs += p2p_attr_channel_list()
1136 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
1137 attrs += p2p_attr_operating_channel()
1138 msg['payload'] += ie_p2p(attrs)
1140 if hapd.mgmt_rx(timeout=1) is None:
1141 raise Exception("No GO Neg Response " + str(dialog_token))
1144 # SA != P2P Device address
1146 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1147 attrs = p2p_attr_capability()
1148 attrs += p2p_attr_go_intent()
1149 attrs += p2p_attr_config_timeout()
1150 attrs += p2p_attr_listen_channel()
1151 attrs += p2p_attr_ext_listen_timing()
1152 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1153 attrs += p2p_attr_channel_list()
1154 attrs += p2p_attr_device_info("02:02:02:02:02:02", config_methods=0x0108)
1155 attrs += p2p_attr_operating_channel()
1156 msg['payload'] += ie_p2p(attrs)
1158 if hapd.mgmt_rx(timeout=1) is None:
1159 raise Exception("No GO Neg Response " + str(dialog_token))
1162 # unexpected Status attribute
1164 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1165 attrs = p2p_attr_capability()
1166 attrs += p2p_attr_go_intent()
1167 attrs += p2p_attr_config_timeout()
1168 attrs += p2p_attr_listen_channel()
1169 attrs += p2p_attr_ext_listen_timing()
1170 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1171 attrs += p2p_attr_channel_list()
1172 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1173 attrs += p2p_attr_operating_channel()
1174 attrs += p2p_attr_status(status=P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
1175 msg['payload'] += ie_p2p(attrs)
1177 if hapd.mgmt_rx(timeout=1) is None:
1178 raise Exception("No GO Neg Response(1) " + str(dialog_token))
1181 # valid (with workarounds) GO Neg Req
1183 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1184 #attrs = p2p_attr_capability()
1185 #attrs += p2p_attr_go_intent()
1186 #attrs += p2p_attr_config_timeout()
1187 attrs = p2p_attr_listen_channel()
1188 attrs += p2p_attr_ext_listen_timing()
1189 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1190 attrs += p2p_attr_channel_list()
1191 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1192 attrs += p2p_attr_operating_channel()
1193 msg['payload'] += ie_p2p(attrs)
1195 check_p2p_response(hapd, dialog_token,
1196 P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
1197 ev = dev[0].wait_event(["P2P-GO-NEG-REQUEST"], timeout=1)
1199 raise Exception("Timeout on GO Neg event " + str(dialog_token))
1201 dev[0].request("P2P_CONNECT " + src + " 12345670 display auth")
1203 # ready - missing attributes (with workarounds) GO Neg Req
1206 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1207 #attrs = p2p_attr_capability()
1208 #attrs += p2p_attr_go_intent()
1209 #attrs += p2p_attr_config_timeout()
1210 attrs = p2p_attr_listen_channel()
1211 attrs += p2p_attr_ext_listen_timing()
1212 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1213 attrs += p2p_attr_channel_list()
1214 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1215 attrs += p2p_attr_operating_channel()
1216 msg['payload'] += ie_p2p(attrs)
1218 if hapd.mgmt_rx(timeout=1) is None:
1219 raise Exception("No GO Neg Response " + str(dialog_token))
1221 # ready - invalid GO Intent GO Neg Req
1224 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1225 #attrs = p2p_attr_capability()
1226 attrs = p2p_attr_go_intent(go_intent=16)
1227 #attrs += p2p_attr_config_timeout()
1228 attrs += p2p_attr_listen_channel()
1229 attrs += p2p_attr_ext_listen_timing()
1230 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1231 attrs += p2p_attr_channel_list()
1232 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1233 attrs += p2p_attr_operating_channel()
1234 msg['payload'] += ie_p2p(attrs)
1236 check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_INVALID_PARAMS)
1238 # ready - invalid Channel List
1241 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1242 attrs = p2p_attr_capability()
1243 attrs += p2p_attr_go_intent()
1244 attrs += p2p_attr_config_timeout()
1245 attrs += p2p_attr_listen_channel()
1246 attrs += p2p_attr_ext_listen_timing()
1247 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1248 attrs += struct.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST, 16,
1250 81, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
1251 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1252 attrs += p2p_attr_operating_channel()
1253 msg['payload'] += ie_p2p(attrs)
1255 check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_NO_COMMON_CHANNELS)
1257 # ready - invalid GO Neg Req (unsupported Device Password ID)
1260 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1261 attrs = p2p_attr_capability()
1262 attrs += p2p_attr_go_intent()
1263 attrs += p2p_attr_config_timeout()
1264 attrs += p2p_attr_listen_channel()
1265 attrs += p2p_attr_ext_listen_timing()
1266 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1267 # very long channel list
1268 attrs += struct.pack("<BH3BBB11B30B", P2P_ATTR_CHANNEL_LIST, 46,
1270 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
1271 1, 1, 1, 2, 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5,
1272 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 10, 1, 10)
1273 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1274 attrs += p2p_attr_operating_channel()
1275 msg['payload'] += ie_p2p(attrs)
1277 check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD)
1279 def mgmt_tx(dev, msg):
1280 for i in range(0, 20):
1281 if "FAIL" in dev.request(msg):
1282 raise Exception("Failed to send Action frame")
1283 ev = dev.wait_event(["MGMT-TX-STATUS"], timeout=10)
1285 raise Exception("Timeout on MGMT-TX-STATUS")
1286 if "result=SUCCESS" in ev:
1289 if "result=SUCCESS" not in ev:
1290 raise Exception("Peer did not ack Action frame")
1292 def rx_go_neg_req(dev):
1295 raise Exception("MGMT-RX timeout")
1296 p2p = parse_p2p_public_action(msg['payload'])
1298 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
1299 if p2p['subtype'] != P2P_GO_NEG_REQ:
1300 raise Exception("Unexpected subtype %d" % p2p['subtype'])
1301 p2p['freq'] = msg['freq']
1304 def rx_go_neg_conf(dev, status=None, dialog_token=None):
1307 raise Exception("MGMT-RX timeout")
1308 p2p = parse_p2p_public_action(msg['payload'])
1310 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
1311 if p2p['subtype'] != P2P_GO_NEG_CONF:
1312 raise Exception("Unexpected subtype %d" % p2p['subtype'])
1313 if dialog_token is not None and dialog_token != p2p['dialog_token']:
1314 raise Exception("Unexpected dialog token")
1315 if status is not None and p2p['p2p_status'] != status:
1316 raise Exception("Unexpected status %d" % p2p['p2p_status'])
1318 def check_p2p_go_neg_fail_event(dev, status):
1319 ev = dev.wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=5)
1321 raise Exception("GO Negotiation failure not reported")
1322 if "status=%d" % status not in ev:
1323 raise Exception("Unexpected failure reason: " + ev)
1325 def test_p2p_msg_go_neg_req_reject(dev, apdev):
1326 """P2P protocol tests for user reject incorrectly in GO Neg Req"""
1327 addr0 = dev[0].p2p_dev_addr()
1328 addr1 = dev[1].p2p_dev_addr()
1330 dev[1].discover_peer(addr0)
1331 dev[1].group_request("P2P_CONNECT " + addr0 + " pbc")
1332 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1334 raise Exception("Timeout on GO Neg Req")
1336 peer = dev[0].get_peer(addr1)
1337 dev[0].p2p_stop_find()
1339 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_REQ, dialog_token=123)
1340 attrs = p2p_attr_capability()
1341 attrs += p2p_attr_status(status=P2P_SC_FAIL_REJECTED_BY_USER)
1342 attrs += p2p_attr_go_intent()
1343 attrs += p2p_attr_config_timeout()
1344 attrs += p2p_attr_listen_channel()
1345 attrs += p2p_attr_ext_listen_timing()
1346 attrs += p2p_attr_intended_interface_addr(addr0)
1347 attrs += p2p_attr_channel_list()
1348 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1349 attrs += p2p_attr_operating_channel()
1350 msg['payload'] += ie_p2p(attrs)
1352 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
1354 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=5)
1356 raise Exception("GO Negotiation failure not reported")
1357 if "status=%d" % P2P_SC_FAIL_REJECTED_BY_USER not in ev:
1358 raise Exception("Unexpected failure reason: " + ev)
1360 def test_p2p_msg_unexpected_go_neg_resp(dev, apdev):
1361 """P2P protocol tests for unexpected GO Neg Resp"""
1362 addr0 = dev[0].p2p_dev_addr()
1363 addr1 = dev[1].p2p_dev_addr()
1365 dev[0].discover_peer(addr1)
1366 dev[0].p2p_stop_find()
1368 peer = dev[0].get_peer(addr1)
1370 logger.debug("GO Neg Resp without GO Neg session")
1371 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=123)
1372 attrs = p2p_attr_status()
1373 attrs += p2p_attr_capability()
1374 attrs += p2p_attr_go_intent()
1375 attrs += p2p_attr_config_timeout()
1376 attrs += p2p_attr_intended_interface_addr(addr0)
1377 attrs += p2p_attr_channel_list()
1378 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1379 attrs += p2p_attr_operating_channel()
1380 msg['payload'] += ie_p2p(attrs)
1381 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
1384 dev[1].discover_peer(addr0)
1386 logger.debug("Unexpected GO Neg Resp while waiting for new GO Neg session")
1387 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
1388 raise Exception("P2P_CONNECT failed")
1389 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1391 raise Exception("Timeout on GO Neg Req")
1392 dev[0].p2p_stop_find()
1393 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
1395 logger.debug("Invalid attribute in GO Neg Response")
1396 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=197)
1397 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
1398 msg['payload'] += ie_p2p(attrs)
1399 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
1400 frame = dev[0].mgmt_rx(timeout=0.1)
1401 if frame is not None:
1402 raise Exception("Unexpected GO Neg Confirm")
1404 logger.debug("GO Neg Resp with unexpected dialog token")
1405 dev[1].p2p_stop_find()
1406 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
1407 raise Exception("Failed to enable external management frame handling")
1409 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
1410 raise Exception("P2P_CONNECT failed(2)")
1411 p2p = rx_go_neg_req(dev[0])
1412 dev[0].p2p_stop_find()
1413 dialog_token = p2p['dialog_token']
1414 if dialog_token < 255:
1418 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1419 attrs = p2p_attr_status()
1420 attrs += p2p_attr_capability()
1421 attrs += p2p_attr_go_intent()
1422 attrs += p2p_attr_config_timeout()
1423 attrs += p2p_attr_intended_interface_addr(addr0)
1424 attrs += p2p_attr_channel_list()
1425 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1426 attrs += p2p_attr_operating_channel()
1427 msg['payload'] += ie_p2p(attrs)
1428 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1430 logger.debug("GO Neg Resp without Status")
1431 dev[1].p2p_stop_find()
1433 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
1434 raise Exception("P2P_CONNECT failed(2)")
1435 p2p = rx_go_neg_req(dev[0])
1436 dev[0].p2p_stop_find()
1437 dialog_token = p2p['dialog_token']
1438 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1439 #attrs = p2p_attr_status()
1440 attrs = p2p_attr_capability()
1441 attrs += p2p_attr_go_intent()
1442 attrs += p2p_attr_config_timeout()
1443 attrs += p2p_attr_intended_interface_addr(addr0)
1444 attrs += p2p_attr_channel_list()
1445 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1446 attrs += p2p_attr_operating_channel()
1447 msg['payload'] += ie_p2p(attrs)
1448 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1449 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1450 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1452 logger.debug("GO Neg Resp without Intended Address")
1453 dev[1].p2p_stop_find()
1455 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
1456 raise Exception("P2P_CONNECT failed(2)")
1457 p2p = rx_go_neg_req(dev[0])
1458 dev[0].p2p_stop_find()
1459 dialog_token = p2p['dialog_token']
1460 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1461 attrs = p2p_attr_status()
1462 #attrs += p2p_attr_capability()
1463 attrs += p2p_attr_go_intent()
1464 attrs += p2p_attr_config_timeout()
1465 #attrs += p2p_attr_intended_interface_addr(addr0)
1466 attrs += p2p_attr_channel_list()
1467 #attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1468 attrs += p2p_attr_operating_channel()
1469 msg['payload'] += ie_p2p(attrs)
1470 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1471 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1472 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1474 logger.debug("GO Neg Resp without GO Intent")
1475 dev[1].p2p_stop_find()
1477 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
1478 raise Exception("P2P_CONNECT failed(2)")
1479 p2p = rx_go_neg_req(dev[0])
1480 dev[0].p2p_stop_find()
1481 dialog_token = p2p['dialog_token']
1482 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1483 attrs = p2p_attr_status()
1484 attrs += p2p_attr_capability()
1485 #attrs += p2p_attr_go_intent()
1486 attrs += p2p_attr_config_timeout()
1487 attrs += p2p_attr_intended_interface_addr(addr0)
1488 attrs += p2p_attr_channel_list()
1489 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1490 attrs += p2p_attr_operating_channel()
1491 msg['payload'] += ie_p2p(attrs)
1492 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1493 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1494 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1496 logger.debug("GO Neg Resp with invalid GO Intent")
1497 dev[1].p2p_stop_find()
1499 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
1500 raise Exception("P2P_CONNECT failed(2)")
1501 p2p = rx_go_neg_req(dev[0])
1502 dev[0].p2p_stop_find()
1503 dialog_token = p2p['dialog_token']
1504 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1505 attrs = p2p_attr_status()
1506 attrs += p2p_attr_capability()
1507 attrs += p2p_attr_go_intent(go_intent=16)
1508 attrs += p2p_attr_config_timeout()
1509 attrs += p2p_attr_intended_interface_addr(addr0)
1510 attrs += p2p_attr_channel_list()
1511 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1512 attrs += p2p_attr_operating_channel()
1513 msg['payload'] += ie_p2p(attrs)
1514 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1515 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1516 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1518 logger.debug("GO Neg Resp with incompatible GO Intent")
1519 dev[1].p2p_stop_find()
1521 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15"):
1522 raise Exception("P2P_CONNECT failed(2)")
1523 p2p = rx_go_neg_req(dev[0])
1524 dev[0].p2p_stop_find()
1525 dialog_token = p2p['dialog_token']
1526 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1527 attrs = p2p_attr_status()
1528 attrs += p2p_attr_capability()
1529 attrs += p2p_attr_go_intent(go_intent=15)
1530 attrs += p2p_attr_config_timeout()
1531 attrs += p2p_attr_intended_interface_addr(addr0)
1532 attrs += p2p_attr_channel_list()
1533 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1534 attrs += p2p_attr_operating_channel()
1535 msg['payload'] += ie_p2p(attrs)
1536 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1537 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INCOMPATIBLE_PARAMS)
1538 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INCOMPATIBLE_PARAMS, dialog_token)
1540 logger.debug("GO Neg Resp without P2P Group ID")
1541 dev[1].p2p_stop_find()
1543 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
1544 raise Exception("P2P_CONNECT failed(2)")
1545 p2p = rx_go_neg_req(dev[0])
1546 dev[0].p2p_stop_find()
1547 dialog_token = p2p['dialog_token']
1548 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1549 attrs = p2p_attr_status()
1550 attrs += p2p_attr_capability()
1551 attrs += p2p_attr_go_intent(go_intent=15)
1552 attrs += p2p_attr_config_timeout()
1553 attrs += p2p_attr_intended_interface_addr(addr0)
1554 attrs += p2p_attr_channel_list()
1555 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1556 attrs += p2p_attr_operating_channel()
1557 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
1558 msg['payload'] += ie_p2p(attrs)
1559 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1560 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1561 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1563 logger.debug("GO Neg Resp without Operating Channel")
1564 dev[1].p2p_stop_find()
1566 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
1567 raise Exception("P2P_CONNECT failed(2)")
1568 p2p = rx_go_neg_req(dev[0])
1569 dev[0].p2p_stop_find()
1570 dialog_token = p2p['dialog_token']
1571 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1572 attrs = p2p_attr_status()
1573 attrs += p2p_attr_capability()
1574 attrs += p2p_attr_go_intent(go_intent=15)
1575 #attrs += p2p_attr_config_timeout()
1576 attrs += p2p_attr_intended_interface_addr(addr0)
1577 attrs += p2p_attr_channel_list()
1578 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1579 #attrs += p2p_attr_operating_channel()
1580 attrs += p2p_attr_group_id(addr0, "DIRECT-foo")
1581 msg['payload'] += ie_p2p(attrs)
1582 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1583 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1584 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1586 logger.debug("GO Neg Resp without Channel List")
1587 dev[1].p2p_stop_find()
1589 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
1590 raise Exception("P2P_CONNECT failed(2)")
1591 p2p = rx_go_neg_req(dev[0])
1592 dev[0].p2p_stop_find()
1593 dialog_token = p2p['dialog_token']
1594 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1595 attrs = p2p_attr_status()
1596 attrs += p2p_attr_capability()
1597 attrs += p2p_attr_go_intent(go_intent=15)
1598 attrs += p2p_attr_config_timeout()
1599 attrs += p2p_attr_intended_interface_addr(addr0)
1600 #attrs += p2p_attr_channel_list()
1601 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1602 attrs += p2p_attr_operating_channel()
1603 attrs += p2p_attr_group_id(addr0, "DIRECT-foo")
1604 msg['payload'] += ie_p2p(attrs)
1605 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1606 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
1607 rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
1609 logger.debug("GO Neg Resp without common channels")
1610 dev[1].p2p_stop_find()
1612 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
1613 raise Exception("P2P_CONNECT failed(2)")
1614 p2p = rx_go_neg_req(dev[0])
1615 dev[0].p2p_stop_find()
1616 dialog_token = p2p['dialog_token']
1617 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
1618 attrs = p2p_attr_status()
1619 attrs += p2p_attr_capability()
1620 attrs += p2p_attr_go_intent(go_intent=15)
1621 attrs += p2p_attr_config_timeout()
1622 attrs += p2p_attr_intended_interface_addr(addr0)
1623 attrs += struct.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST, 5,
1626 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1627 attrs += p2p_attr_operating_channel()
1628 attrs += p2p_attr_group_id(addr0, "DIRECT-foo")
1629 msg['payload'] += ie_p2p(attrs)
1630 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
1631 check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_NO_COMMON_CHANNELS)
1632 rx_go_neg_conf(dev[0], P2P_SC_FAIL_NO_COMMON_CHANNELS, dialog_token)