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()
15 MGMT_SUBTYPE_PROBE_REQ = 4
16 MGMT_SUBTYPE_ACTION = 13
17 ACTION_CATEG_PUBLIC = 4
22 P2P_INVITATION_REQ = 3
23 P2P_INVITATION_RESP = 4
27 P2P_PROV_DISC_RESP = 8
30 P2P_ATTR_MINOR_REASON_CODE = 1
31 P2P_ATTR_CAPABILITY = 2
32 P2P_ATTR_DEVICE_ID = 3
33 P2P_ATTR_GROUP_OWNER_INTENT = 4
34 P2P_ATTR_CONFIGURATION_TIMEOUT = 5
35 P2P_ATTR_LISTEN_CHANNEL = 6
36 P2P_ATTR_GROUP_BSSID = 7
37 P2P_ATTR_EXT_LISTEN_TIMING = 8
38 P2P_ATTR_INTENDED_INTERFACE_ADDR = 9
39 P2P_ATTR_MANAGEABILITY = 10
40 P2P_ATTR_CHANNEL_LIST = 11
41 P2P_ATTR_NOTICE_OF_ABSENCE = 12
42 P2P_ATTR_DEVICE_INFO = 13
43 P2P_ATTR_GROUP_INFO = 14
44 P2P_ATTR_GROUP_ID = 15
45 P2P_ATTR_INTERFACE = 16
46 P2P_ATTR_OPERATING_CHANNEL = 17
47 P2P_ATTR_INVITATION_FLAGS = 18
48 P2P_ATTR_OOB_GO_NEG_CHANNEL = 19
49 P2P_ATTR_VENDOR_SPECIFIC = 221
52 P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE = 1
53 P2P_SC_FAIL_INCOMPATIBLE_PARAMS = 2
54 P2P_SC_FAIL_LIMIT_REACHED = 3
55 P2P_SC_FAIL_INVALID_PARAMS = 4
56 P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE = 5
57 P2P_SC_FAIL_PREV_PROTOCOL_ERROR = 6
58 P2P_SC_FAIL_NO_COMMON_CHANNELS = 7
59 P2P_SC_FAIL_UNKNOWN_GROUP = 8
60 P2P_SC_FAIL_BOTH_GO_INTENT_15 = 9
61 P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD = 10
62 P2P_SC_FAIL_REJECTED_BY_USER = 11
64 WSC_ATTR_CONFIG_METHODS = 0x1008
67 WLAN_EID_SUPP_RATES = 1
68 WLAN_EID_VENDOR_SPECIFIC = 221
71 return struct.pack("<BB", WLAN_EID_SSID, len(ssid)) + ssid
74 return struct.pack("<BBBBBBBBBB", WLAN_EID_SUPP_RATES, 8,
75 2*6, 2*9, 2*12, 2*18, 2*24, 2*36, 2*48, 2*54)
78 return struct.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC, 4 + len(attrs),
79 0x50, 0x6f, 0x9a, 9) + attrs
82 return struct.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC, 4 + len(attrs),
83 0x00, 0x50, 0xf2, 4) + attrs
85 def wsc_attr_config_methods(methods=0):
86 return struct.pack(">HHH", WSC_ATTR_CONFIG_METHODS, 2, methods)
88 def p2p_attr_status(status=P2P_SC_SUCCESS):
89 return struct.pack("<BHB", P2P_ATTR_STATUS, 1, status)
91 def p2p_attr_minor_reason_code(code=0):
92 return struct.pack("<BHB", P2P_ATTR_MINOR_REASON_CODE, 1, code)
94 def p2p_attr_capability(dev_capab=0, group_capab=0):
95 return struct.pack("<BHBB", P2P_ATTR_CAPABILITY, 2, dev_capab, group_capab)
97 def p2p_attr_device_id(addr):
98 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
99 t = (P2P_ATTR_DEVICE_ID, 6) + val
100 return struct.pack('<BH6B', *t)
102 def p2p_attr_go_intent(go_intent=0, tie_breaker=0):
103 return struct.pack("<BHB", P2P_ATTR_GROUP_OWNER_INTENT, 1,
104 (go_intent << 1) | (tie_breaker & 0x01))
106 def p2p_attr_config_timeout(go_config_timeout=0, client_config_timeout=0):
107 return struct.pack("<BHBB", P2P_ATTR_CONFIGURATION_TIMEOUT, 2,
108 go_config_timeout, client_config_timeout)
110 def p2p_attr_listen_channel(op_class=81, chan=1):
111 return struct.pack("<BHBBBBB", P2P_ATTR_LISTEN_CHANNEL, 5,
112 0x58, 0x58, 0x04, op_class, chan)
114 def p2p_attr_group_bssid(addr):
115 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
116 t = (P2P_ATTR_GROUP_BSSID, 6) + val
117 return struct.pack('<BH6B', *t)
119 def p2p_attr_ext_listen_timing(period=0, interval=0):
120 return struct.pack("<BHHH", P2P_ATTR_EXT_LISTEN_TIMING, 4, period, interval)
122 def p2p_attr_intended_interface_addr(addr):
123 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
124 t = (P2P_ATTR_INTENDED_INTERFACE_ADDR, 6) + val
125 return struct.pack('<BH6B', *t)
127 def p2p_attr_manageability(bitmap=0):
128 return struct.pack("<BHB", P2P_ATTR_MANAGEABILITY, 1, bitmap)
130 def p2p_attr_channel_list():
131 return struct.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST, 16,
133 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
135 def p2p_attr_device_info(addr, name="Test", config_methods=0, dev_type="00010050F2040001"):
136 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
137 val2 = struct.unpack('8B', binascii.unhexlify(dev_type))
138 t = (P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 4 + len(name)) + val + (config_methods,) + val2 + (0,)
139 return struct.pack("<BH6BH8BB", *t) + struct.pack('>HH', 0x1011, len(name)) +name
141 def p2p_attr_group_id(addr, ssid):
142 val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
143 t = (P2P_ATTR_GROUP_ID, 6 + len(ssid)) + val
144 return struct.pack('<BH6B', *t) + ssid
146 def p2p_attr_operating_channel(op_class=81, chan=1):
147 return struct.pack("<BHBBBBB", P2P_ATTR_OPERATING_CHANNEL, 5,
148 0x58, 0x58, 0x04, op_class, chan)
150 def p2p_attr_invitation_flags(bitmap=0):
151 return struct.pack("<BHB", P2P_ATTR_INVITATION_FLAGS, 1, bitmap)
153 def p2p_hdr_helper(dst, src, type=None, dialog_token=1, req=True):
155 msg['fc'] = MGMT_SUBTYPE_ACTION << 4
162 msg['payload'] = struct.pack("<BBBBBB",
163 ACTION_CATEG_PUBLIC, 9, 0x50, 0x6f, 0x9a, 9)
165 msg['payload'] += struct.pack("<B", type)
167 msg['payload'] += struct.pack("<B", dialog_token)
170 def p2p_hdr(dst, src, type=None, dialog_token=1):
171 return p2p_hdr_helper(dst, src, type, dialog_token, True)
173 def p2p_hdr_resp(dst, src, type=None, dialog_token=1):
174 return p2p_hdr_helper(dst, src, type, dialog_token, False)
176 def start_p2p(dev, apdev):
177 addr0 = dev[0].p2p_dev_addr()
179 dev[1].p2p_find(social=True)
180 ev = dev[1].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
182 raise Exception("Device discovery timed out")
183 dev[1].p2p_stop_find()
184 peer = dev[1].get_peer(addr0)
186 bssid = apdev[0]['bssid']
187 params = { 'ssid': "test", 'beacon_int': "2000" }
188 if peer['listen_freq'] == "2412":
189 params['channel'] = '1'
190 elif peer['listen_freq'] == "2437":
191 params['channel'] = '6'
192 elif peer['listen_freq'] == "2462":
193 params['channel'] = '11'
194 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
195 hapd.set("ext_mgmt_frame_handling", "1")
196 return addr0, bssid, hapd, int(params['channel'])
198 def p2p_probe(hapd, src, chan=1):
200 msg['fc'] = MGMT_SUBTYPE_PROBE_REQ << 4
201 msg['da'] = "ff:ff:ff:ff:ff:ff"
203 msg['bssid'] = "ff:ff:ff:ff:ff:ff"
204 attrs = p2p_attr_listen_channel(chan=chan)
205 msg['payload'] = ie_ssid("DIRECT-") + ie_supp_rates() + ie_p2p(attrs)
208 def parse_p2p_public_action(payload):
210 (category, action) = struct.unpack('BB', pos[0:2])
211 if category != ACTION_CATEG_PUBLIC:
216 (oui1,oui2,oui3,subtype) = struct.unpack('BBBB', pos[0:4])
217 if oui1 != 0x50 or oui2 != 0x6f or oui3 != 0x9a or subtype != 9:
220 (subtype,dialog_token) = struct.unpack('BB', pos[0:2])
222 p2p['subtype'] = subtype
223 p2p['dialog_token'] = dialog_token
225 p2p['elements'] = pos
227 (id,elen) = struct.unpack('BB', pos[0:2])
230 raise Exception("Truncated IE in P2P Public Action frame (elen=%d left=%d)" % (elen, len(pos)))
231 if id == WLAN_EID_VENDOR_SPECIFIC:
233 raise Exception("Too short vendor specific IE in P2P Public Action frame (elen=%d)" % elen)
234 (oui1,oui2,oui3,subtype) = struct.unpack('BBBB', pos[0:4])
235 if oui1 == 0x50 and oui2 == 0x6f and oui3 == 0x9a and subtype == 9:
237 p2p['p2p'] += pos[4:elen]
239 p2p['p2p'] = pos[4:elen]
240 if oui1 == 0x00 and oui2 == 0x50 and oui3 == 0xf2 and subtype == 4:
241 p2p['wsc'] = pos[4:elen]
244 raise Exception("Invalid element in P2P Public Action frame")
247 p2p['p2p_attrs'] = {}
250 (id,alen) = struct.unpack('<BH', pos[0:3])
253 logger.info("P2P payload: " + binascii.hexlify(p2p['p2p']))
254 raise Exception("Truncated P2P attribute in P2P Public Action frame (alen=%d left=%d p2p-payload=%d)" % (alen, len(pos), len(p2p['p2p'])))
255 p2p['p2p_attrs'][id] = pos[0:alen]
257 if P2P_ATTR_STATUS in p2p['p2p_attrs']:
258 p2p['p2p_status'] = struct.unpack('B', p2p['p2p_attrs'][P2P_ATTR_STATUS])[0]
261 p2p['wsc_attrs'] = {}
264 (id,alen) = struct.unpack('>HH', pos[0:4])
267 logger.info("WSC payload: " + binascii.hexlify(p2p['wsc']))
268 raise Exception("Truncated WSC attribute in P2P Public Action frame (alen=%d left=%d wsc-payload=%d)" % (alen, len(pos), len(p2p['wsc'])))
269 p2p['wsc_attrs'][id] = pos[0:alen]
274 def test_p2p_msg_empty(dev, apdev):
275 """P2P protocol test: empty P2P Public Action frame"""
276 dst, src, hapd, channel = start_p2p(dev, apdev)
277 msg = p2p_hdr(dst, src)
280 def test_p2p_msg_invitation_req(dev, apdev):
281 """P2P protocol tests for invitation request processing"""
282 dst, src, hapd, channel = start_p2p(dev, apdev)
284 # Empty P2P Invitation Request (missing dialog token)
285 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=None)
289 # Various p2p_parse() failure cases due to invalid attributes
291 # Too short attribute header
293 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
294 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
295 msg['payload'] += ie_p2p(attrs)
298 # Minimal attribute underflow
300 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
301 attrs = struct.pack("<BH", P2P_ATTR_CAPABILITY, 1)
302 msg['payload'] += ie_p2p(attrs)
305 # Large attribute underflow
307 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
308 attrs = struct.pack("<BHB", P2P_ATTR_CAPABILITY, 0xffff, 1)
309 msg['payload'] += ie_p2p(attrs)
312 # Too short Capability attribute
314 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
315 attrs = struct.pack("<BHB", P2P_ATTR_CAPABILITY, 1, 0)
316 msg['payload'] += ie_p2p(attrs)
319 # Too short Device ID attribute
321 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
322 val = struct.unpack('5B', binascii.unhexlify("1122334455"))
323 t = (P2P_ATTR_DEVICE_ID, 5) + val
324 attrs = struct.pack('<BH5B', *t)
325 msg['payload'] += ie_p2p(attrs)
328 # Too short GO Intent attribute
330 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
331 attrs = struct.pack("<BH", P2P_ATTR_GROUP_OWNER_INTENT, 0)
332 msg['payload'] += ie_p2p(attrs)
335 # Too short Status attribute
337 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
338 attrs = struct.pack("<BH", P2P_ATTR_STATUS, 0)
339 msg['payload'] += ie_p2p(attrs)
342 # null Listen channel and too short Listen Channel attribute
344 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
345 attrs = struct.pack("<BH", P2P_ATTR_LISTEN_CHANNEL, 0)
346 attrs += struct.pack("<BHB", P2P_ATTR_LISTEN_CHANNEL, 1, 0)
347 msg['payload'] += ie_p2p(attrs)
350 # null Operating channel and too short Operating Channel attribute
352 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
353 attrs = struct.pack("<BH", P2P_ATTR_OPERATING_CHANNEL, 0)
354 attrs += struct.pack("<BHB", P2P_ATTR_OPERATING_CHANNEL, 1, 0)
355 msg['payload'] += ie_p2p(attrs)
358 # Too short Channel List attribute
360 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
361 attrs = struct.pack("<BHBB", P2P_ATTR_CHANNEL_LIST, 2, 1, 2)
362 msg['payload'] += ie_p2p(attrs)
365 # Too short Device Info attribute
367 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
368 attrs = struct.pack("<BHBB", P2P_ATTR_DEVICE_INFO, 2, 1, 2)
369 msg['payload'] += ie_p2p(attrs)
372 # Truncated Secondary Device Types in Device Info attribute
374 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
375 attrs = struct.pack("<BH6BH8BB", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1,
378 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22,
380 msg['payload'] += ie_p2p(attrs)
383 # Missing Device Name in Device Info attribute
385 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
386 attrs = struct.pack("<BH6BH8BB8B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8,
389 0, 0, 0, 0, 0, 0, 0, 0,
391 1, 2, 3, 4, 5, 6, 7, 8)
392 msg['payload'] += ie_p2p(attrs)
395 # Invalid Device Name header in Device Info attribute
397 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
398 attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4,
401 0, 0, 0, 0, 0, 0, 0, 0,
403 1, 2, 3, 4, 5, 6, 7, 8,
405 msg['payload'] += ie_p2p(attrs)
408 # Invalid Device Name header length in Device Info attribute
410 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
411 attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4,
414 0, 0, 0, 0, 0, 0, 0, 0,
416 1, 2, 3, 4, 5, 6, 7, 8,
417 0x10, 0x11, 0xff, 0xff)
418 msg['payload'] += ie_p2p(attrs)
421 # Invalid Device Name header length in Device Info attribute
423 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
425 attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + len(devname),
428 0, 0, 0, 0, 0, 0, 0, 0,
430 1, 2, 3, 4, 5, 6, 7, 8,
431 0x10, 0x11, 0, len(devname) + 1) + devname
432 msg['payload'] += ie_p2p(attrs)
435 # Device Name filtering and too long Device Name in Device Info attribute
437 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
438 attrs = struct.pack("<BH6BH8BB8B4B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + 4,
441 0, 0, 0, 0, 0, 0, 0, 0,
443 1, 2, 3, 4, 5, 6, 7, 8,
446 devname = '123456789012345678901234567890123'
447 attrs += struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + len(devname),
450 0, 0, 0, 0, 0, 0, 0, 0,
452 1, 2, 3, 4, 5, 6, 7, 8,
453 0x10, 0x11, 0, len(devname)) + devname
454 msg['payload'] += ie_p2p(attrs)
457 # Too short Configuration Timeout attribute
459 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
460 attrs = struct.pack("<BHB", P2P_ATTR_CONFIGURATION_TIMEOUT, 1, 1)
461 msg['payload'] += ie_p2p(attrs)
464 # Too short Intended P2P Interface Address attribute
466 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
467 attrs = struct.pack("<BHB", P2P_ATTR_INTENDED_INTERFACE_ADDR, 1, 1)
468 msg['payload'] += ie_p2p(attrs)
471 # Too short P2P Group BSSID attribute
473 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
474 attrs = struct.pack("<BHB", P2P_ATTR_GROUP_BSSID, 1, 1)
475 msg['payload'] += ie_p2p(attrs)
478 # Too short P2P Group ID attribute
480 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
481 attrs = struct.pack("<BHB", P2P_ATTR_GROUP_ID, 1, 1)
482 msg['payload'] += ie_p2p(attrs)
485 # Too long P2P Group ID attribute
487 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
488 attrs = struct.pack("<BH6B", P2P_ATTR_GROUP_ID, 6 + 33, 0, 0, 0, 0, 0, 0) + "123456789012345678901234567890123"
489 msg['payload'] += ie_p2p(attrs)
492 # Too short Invitation Flags attribute
494 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
495 attrs = struct.pack("<BH", P2P_ATTR_INVITATION_FLAGS, 0)
496 msg['payload'] += ie_p2p(attrs)
499 # Valid and too short Manageability attribute
501 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
502 attrs = p2p_attr_manageability()
503 attrs += struct.pack("<BH", P2P_ATTR_MANAGEABILITY, 0)
504 msg['payload'] += ie_p2p(attrs)
507 # Too short NoA attribute
509 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
510 attrs = struct.pack("<BHB", P2P_ATTR_NOTICE_OF_ABSENCE, 1, 1)
511 msg['payload'] += ie_p2p(attrs)
514 # Valid and too short Extended Listen Timing attributes
516 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
517 attrs = p2p_attr_ext_listen_timing(period=100, interval=50)
518 attrs += struct.pack("<BHBBB", P2P_ATTR_EXT_LISTEN_TIMING, 3, 0, 0, 0)
519 msg['payload'] += ie_p2p(attrs)
522 # Valid and too short Minor Reason Code attributes
524 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
525 attrs = p2p_attr_minor_reason_code(code=2)
526 attrs += struct.pack("<BH", P2P_ATTR_MINOR_REASON_CODE, 0)
527 msg['payload'] += ie_p2p(attrs)
530 # Unknown attribute and too short OOB GO Negotiation Channel attribute
532 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
533 attrs = struct.pack("<BHB", 99, 1, 1)
534 attrs += struct.pack("<BHB", P2P_ATTR_OOB_GO_NEG_CHANNEL, 1, 1)
535 msg['payload'] += ie_p2p(attrs)
538 if hapd.mgmt_rx(timeout=0.5) is not None:
539 raise Exception("Unexpected management frame received")
541 dev[0].dump_monitor()
543 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
544 attrs = p2p_attr_config_timeout()
545 attrs += p2p_attr_invitation_flags()
546 attrs += p2p_attr_operating_channel()
547 attrs += p2p_attr_group_bssid(src)
548 attrs += p2p_attr_channel_list()
549 attrs += p2p_attr_group_id(src, "DIRECT-foo")
550 attrs += p2p_attr_device_info(src, config_methods=0x0108)
551 msg['payload'] += ie_p2p(attrs)
553 ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
555 raise Exception("Timeout on device found event")
556 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=5)
558 raise Exception("Timeout on invitation event " + str(dialog_token))
559 if hapd.mgmt_rx(timeout=1) is None:
560 raise Exception("No invitation response " + str(dialog_token))
563 dev[0].dump_monitor()
565 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
566 attrs = p2p_attr_config_timeout()
567 attrs += p2p_attr_invitation_flags()
568 attrs += p2p_attr_operating_channel()
569 attrs += p2p_attr_group_bssid(src)
570 attrs += p2p_attr_channel_list()
571 attrs += p2p_attr_group_id(src, "DIRECT-foo")
572 attrs += p2p_attr_device_info(src, config_methods=0x0108)
573 msg['payload'] += ie_p2p(attrs)
575 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=5)
577 raise Exception("Timeout on invitation event " + str(dialog_token))
578 if hapd.mgmt_rx(timeout=1) is None:
579 raise Exception("No invitation response " + str(dialog_token))
582 dev[0].dump_monitor()
584 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
585 #attrs = p2p_attr_config_timeout()
586 attrs = p2p_attr_invitation_flags()
587 attrs += p2p_attr_operating_channel()
588 attrs += p2p_attr_group_bssid(src)
589 attrs += p2p_attr_channel_list()
590 attrs += p2p_attr_group_id(src, "DIRECT-foo")
591 attrs += p2p_attr_device_info(src, config_methods=0x0108)
592 msg['payload'] += ie_p2p(attrs)
594 if hapd.mgmt_rx(timeout=1) is None:
595 raise Exception("No invitation response " + str(dialog_token))
598 dev[0].dump_monitor()
600 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
601 attrs = p2p_attr_config_timeout()
602 #attrs = p2p_attr_invitation_flags()
603 attrs += p2p_attr_operating_channel()
604 attrs += p2p_attr_group_bssid(src)
605 attrs += p2p_attr_channel_list()
606 attrs += p2p_attr_group_id(src, "DIRECT-foo")
607 attrs += p2p_attr_device_info(src, config_methods=0x0108)
608 msg['payload'] += ie_p2p(attrs)
610 if hapd.mgmt_rx(timeout=1) is None:
611 raise Exception("No invitation response " + str(dialog_token))
614 dev[0].dump_monitor()
616 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
617 attrs = p2p_attr_config_timeout()
618 attrs = p2p_attr_invitation_flags()
619 #attrs += p2p_attr_operating_channel()
620 attrs += p2p_attr_group_bssid(src)
621 attrs += p2p_attr_channel_list()
622 attrs += p2p_attr_group_id(src, "DIRECT-foo")
623 attrs += p2p_attr_device_info(src, config_methods=0x0108)
624 msg['payload'] += ie_p2p(attrs)
626 if hapd.mgmt_rx(timeout=1) is None:
627 raise Exception("No invitation response " + str(dialog_token))
630 dev[0].dump_monitor()
632 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
633 attrs = p2p_attr_config_timeout()
634 attrs = p2p_attr_invitation_flags()
635 attrs += p2p_attr_operating_channel()
636 #attrs += p2p_attr_group_bssid(src)
637 attrs += p2p_attr_channel_list()
638 attrs += p2p_attr_group_id(src, "DIRECT-foo")
639 attrs += p2p_attr_device_info(src, config_methods=0x0108)
640 msg['payload'] += ie_p2p(attrs)
642 if hapd.mgmt_rx(timeout=1) is None:
643 raise Exception("No invitation response " + str(dialog_token))
646 dev[0].dump_monitor()
648 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
649 attrs = p2p_attr_config_timeout()
650 attrs = p2p_attr_invitation_flags()
651 attrs += p2p_attr_operating_channel()
652 attrs += p2p_attr_group_bssid(src)
653 #attrs += p2p_attr_channel_list()
654 attrs += p2p_attr_group_id(src, "DIRECT-foo")
655 attrs += p2p_attr_device_info(src, config_methods=0x0108)
656 msg['payload'] += ie_p2p(attrs)
658 if hapd.mgmt_rx(timeout=1) is None:
659 raise Exception("No invitation response " + str(dialog_token))
662 dev[0].dump_monitor()
664 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
665 attrs = p2p_attr_config_timeout()
666 attrs = p2p_attr_invitation_flags()
667 attrs += p2p_attr_operating_channel()
668 attrs += p2p_attr_group_bssid(src)
669 attrs += p2p_attr_channel_list()
670 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
671 attrs += p2p_attr_device_info(src, config_methods=0x0108)
672 msg['payload'] += ie_p2p(attrs)
674 if hapd.mgmt_rx(timeout=1) is None:
675 raise Exception("No invitation response " + str(dialog_token))
678 dev[0].dump_monitor()
680 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
681 attrs = p2p_attr_config_timeout()
682 attrs = p2p_attr_invitation_flags()
683 attrs += p2p_attr_operating_channel()
684 attrs += p2p_attr_group_bssid(src)
685 attrs += p2p_attr_channel_list()
686 attrs += p2p_attr_group_id(src, "DIRECT-foo")
687 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
688 msg['payload'] += ie_p2p(attrs)
690 if hapd.mgmt_rx(timeout=1) is None:
691 raise Exception("No invitation response " + str(dialog_token))
694 dev[0].dump_monitor()
696 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
698 if hapd.mgmt_rx(timeout=1) is None:
699 raise Exception("No invitation response " + str(dialog_token))
701 def test_p2p_msg_invitation_req_unknown(dev, apdev):
702 """P2P protocol tests for invitation request from unknown peer"""
703 dst, src, hapd, channel = start_p2p(dev, apdev)
707 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
708 attrs = p2p_attr_config_timeout()
709 attrs += p2p_attr_invitation_flags()
710 attrs += p2p_attr_operating_channel()
711 attrs += p2p_attr_group_bssid(src)
712 attrs += p2p_attr_channel_list()
713 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
714 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
715 msg['payload'] += ie_p2p(attrs)
717 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=5)
719 raise Exception("Timeout on invitation event " + str(dialog_token))
720 if hapd.mgmt_rx(timeout=1) is None:
721 raise Exception("No invitation response " + str(dialog_token))
723 def test_p2p_msg_invitation_no_common_channels(dev, apdev):
724 """P2P protocol tests for invitation request without common channels"""
725 dst, src, hapd, channel = start_p2p(dev, apdev)
729 msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
730 attrs = p2p_attr_config_timeout()
731 attrs += p2p_attr_invitation_flags()
732 attrs += p2p_attr_operating_channel()
733 attrs += p2p_attr_group_bssid(src)
734 attrs += struct.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST, 5,
737 attrs += p2p_attr_group_id(src, "DIRECT-foo")
738 attrs += p2p_attr_device_info(src, config_methods=0x0108)
739 msg['payload'] += ie_p2p(attrs)
741 if hapd.mgmt_rx(timeout=1) is None:
742 raise Exception("No invitation response " + str(dialog_token))
743 ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=0.1)
745 raise Exception("Unexpected invitation event")
747 def test_p2p_msg_pd_req(dev, apdev):
748 """P2P protocol tests for provision discovery request processing"""
749 dst, src, hapd, channel = start_p2p(dev, apdev)
752 # Too short attribute header
754 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
755 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
756 msg['payload'] += ie_p2p(attrs)
759 if hapd.mgmt_rx(timeout=0.5) is not None:
760 raise Exception("Unexpected management frame received")
764 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
766 msg['payload'] += ie_p2p(attrs)
768 if hapd.mgmt_rx(timeout=1) is None:
769 raise Exception("No PD response " + str(dialog_token))
774 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
775 attrs = wsc_attr_config_methods(methods=0x1008)
776 msg['payload'] += ie_wsc(attrs)
777 attrs = p2p_attr_capability()
778 attrs += p2p_attr_device_info(src, config_methods=0x0108)
779 msg['payload'] += ie_p2p(attrs)
781 ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
783 raise Exception("Timeout on device found event")
784 ev = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
786 raise Exception("Timeout on PD event")
787 if hapd.mgmt_rx(timeout=1) is None:
788 raise Exception("No PD response " + str(dialog_token))
793 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
794 attrs = wsc_attr_config_methods(methods=0x1008)
795 msg['payload'] += ie_wsc(attrs)
796 attrs = p2p_attr_capability()
797 attrs += p2p_attr_device_info(src, config_methods=0x0108)
798 attrs += p2p_attr_group_id("02:02:02:02:02:02", "DIRECT-foo")
799 msg['payload'] += ie_p2p(attrs)
801 if hapd.mgmt_rx(timeout=1) is None:
802 raise Exception("No PD response " + str(dialog_token))
803 ev = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=1)
805 raise Exception("Unexpected PD event")
807 # Listen channel is not yet known
808 if "FAIL" not in dev[0].global_request("P2P_PROV_DISC " + src + " display"):
809 raise Exception("Unexpected P2P_PROV_DISC success")
812 if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 02:03:04:05:06:07 display"):
813 raise Exception("Unexpected P2P_PROV_DISC success (2)")
815 def test_p2p_msg_pd(dev, apdev):
816 """P2P protocol tests for provision discovery request processing (known)"""
817 dst, src, hapd, channel = start_p2p(dev, apdev)
820 p2p_probe(hapd, src, chan=channel)
825 msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
826 attrs = wsc_attr_config_methods(methods=0x1008)
827 msg['payload'] += ie_wsc(attrs)
828 attrs = p2p_attr_capability()
829 attrs += p2p_attr_device_info(src, config_methods=0x0108)
830 msg['payload'] += ie_p2p(attrs)
832 ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
834 raise Exception("Timeout on device found event")
835 ev = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
837 raise Exception("Timeout on PD event")
838 if hapd.mgmt_rx(timeout=1) is None:
839 raise Exception("No PD response " + str(dialog_token))
841 if "FAIL" in dev[0].global_request("P2P_PROV_DISC " + src + " display"):
842 raise Exception("Unexpected P2P_PROV_DISC failure")
843 frame = hapd.mgmt_rx(timeout=1)
845 raise Exception("No PD request " + str(dialog_token))
846 p2p = parse_p2p_public_action(frame['payload'])
848 raise Exception("Failed to parse PD request")
850 # invalid dialog token
851 msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
852 dialog_token=p2p['dialog_token'] + 1)
854 ev = dev[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout=0.1)
856 raise Exception("Unexpected PD result event")
859 msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
860 dialog_token=p2p['dialog_token'])
862 ev = dev[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout=5)
864 raise Exception("Timeout on PD result event")
867 msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
868 dialog_token=p2p['dialog_token'])
870 ev = dev[0].wait_event(["P2P-PROV-DISC-FAILURE"], timeout=0.1)
872 raise Exception("Unexpected PD result event")
874 def check_p2p_response(hapd, dialog_token, status):
875 resp = hapd.mgmt_rx(timeout=1)
877 raise Exception("No GO Neg Response " + str(dialog_token))
878 p2p = parse_p2p_public_action(resp['payload'])
880 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
881 if dialog_token != p2p['dialog_token']:
882 raise Exception("Unexpected dialog token in response")
883 if p2p['p2p_status'] != status:
884 raise Esception("Unexpected status code %s in response (expected %d)" % (p2p['p2p_status'], status))
886 def test_p2p_msg_go_neg_req(dev, apdev):
887 """P2P protocol tests for invitation request from unknown peer"""
888 dst, src, hapd, channel = start_p2p(dev, apdev)
893 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
894 attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
895 msg['payload'] += ie_p2p(attrs)
897 frame = hapd.mgmt_rx(timeout=0.1)
898 if frame is not None:
900 raise Exception("Unexpected GO Neg Response")
904 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
905 attrs = p2p_attr_capability()
906 attrs += p2p_attr_go_intent()
907 attrs += p2p_attr_config_timeout()
908 #attrs += p2p_attr_listen_channel()
909 attrs += p2p_attr_ext_listen_timing()
910 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
911 attrs += p2p_attr_channel_list()
912 attrs += p2p_attr_device_info(src, config_methods=0x0108)
913 attrs += p2p_attr_operating_channel()
914 msg['payload'] += ie_p2p(attrs)
916 if hapd.mgmt_rx(timeout=1) is None:
917 raise Exception("No GO Neg Response " + str(dialog_token))
921 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
922 attrs = p2p_attr_capability()
923 attrs += p2p_attr_go_intent()
924 attrs += p2p_attr_config_timeout()
925 attrs += p2p_attr_listen_channel()
926 attrs += p2p_attr_ext_listen_timing()
927 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
928 attrs += p2p_attr_channel_list()
929 attrs += p2p_attr_device_info(src, config_methods=0x0108)
930 #attrs += p2p_attr_operating_channel()
931 msg['payload'] += ie_p2p(attrs)
933 if hapd.mgmt_rx(timeout=1) is None:
934 raise Exception("No GO Neg Response " + str(dialog_token))
938 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
939 attrs = p2p_attr_capability()
940 attrs += p2p_attr_go_intent()
941 attrs += p2p_attr_config_timeout()
942 attrs += p2p_attr_listen_channel()
943 attrs += p2p_attr_ext_listen_timing()
944 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
945 #attrs += p2p_attr_channel_list()
946 attrs += p2p_attr_device_info(src, config_methods=0x0108)
947 attrs += p2p_attr_operating_channel()
948 msg['payload'] += ie_p2p(attrs)
950 if hapd.mgmt_rx(timeout=1) is None:
951 raise Exception("No GO Neg Response " + str(dialog_token))
955 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
956 attrs = p2p_attr_capability()
957 attrs += p2p_attr_go_intent()
958 attrs += p2p_attr_config_timeout()
959 attrs += p2p_attr_listen_channel()
960 attrs += p2p_attr_ext_listen_timing()
961 #attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
962 attrs += p2p_attr_channel_list()
963 attrs += p2p_attr_device_info(src, config_methods=0x0108)
964 attrs += p2p_attr_operating_channel()
965 msg['payload'] += ie_p2p(attrs)
967 if hapd.mgmt_rx(timeout=1) is None:
968 raise Exception("No GO Neg Response " + str(dialog_token))
972 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
973 attrs = p2p_attr_capability()
974 attrs += p2p_attr_go_intent()
975 attrs += p2p_attr_config_timeout()
976 attrs += p2p_attr_listen_channel()
977 attrs += p2p_attr_ext_listen_timing()
978 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
979 attrs += p2p_attr_channel_list()
980 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
981 attrs += p2p_attr_operating_channel()
982 msg['payload'] += ie_p2p(attrs)
984 if hapd.mgmt_rx(timeout=1) is None:
985 raise Exception("No GO Neg Response " + str(dialog_token))
988 # SA != P2P Device address
990 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
991 attrs = p2p_attr_capability()
992 attrs += p2p_attr_go_intent()
993 attrs += p2p_attr_config_timeout()
994 attrs += p2p_attr_listen_channel()
995 attrs += p2p_attr_ext_listen_timing()
996 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
997 attrs += p2p_attr_channel_list()
998 attrs += p2p_attr_device_info("02:02:02:02:02:02", config_methods=0x0108)
999 attrs += p2p_attr_operating_channel()
1000 msg['payload'] += ie_p2p(attrs)
1002 if hapd.mgmt_rx(timeout=1) is None:
1003 raise Exception("No GO Neg Response " + str(dialog_token))
1006 # unexpected Status attribute
1008 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1009 attrs = p2p_attr_capability()
1010 attrs += p2p_attr_go_intent()
1011 attrs += p2p_attr_config_timeout()
1012 attrs += p2p_attr_listen_channel()
1013 attrs += p2p_attr_ext_listen_timing()
1014 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1015 attrs += p2p_attr_channel_list()
1016 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1017 attrs += p2p_attr_operating_channel()
1018 attrs += p2p_attr_status(status=P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
1019 msg['payload'] += ie_p2p(attrs)
1021 if hapd.mgmt_rx(timeout=1) is None:
1022 raise Exception("No GO Neg Response(1) " + str(dialog_token))
1025 # valid (with workarounds) GO Neg Req
1027 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1028 #attrs = p2p_attr_capability()
1029 #attrs += p2p_attr_go_intent()
1030 #attrs += p2p_attr_config_timeout()
1031 attrs = p2p_attr_listen_channel()
1032 attrs += p2p_attr_ext_listen_timing()
1033 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1034 attrs += p2p_attr_channel_list()
1035 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1036 attrs += p2p_attr_operating_channel()
1037 msg['payload'] += ie_p2p(attrs)
1039 check_p2p_response(hapd, dialog_token,
1040 P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
1041 ev = dev[0].wait_event(["P2P-GO-NEG-REQUEST"], timeout=1)
1043 raise Exception("Timeout on GO Neg event " + str(dialog_token))
1045 dev[0].request("P2P_CONNECT " + src + " 12345670 display auth")
1047 # ready - missing attributes (with workarounds) GO Neg Req
1050 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1051 #attrs = p2p_attr_capability()
1052 #attrs += p2p_attr_go_intent()
1053 #attrs += p2p_attr_config_timeout()
1054 attrs = p2p_attr_listen_channel()
1055 attrs += p2p_attr_ext_listen_timing()
1056 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1057 attrs += p2p_attr_channel_list()
1058 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1059 attrs += p2p_attr_operating_channel()
1060 msg['payload'] += ie_p2p(attrs)
1062 if hapd.mgmt_rx(timeout=1) is None:
1063 raise Exception("No GO Neg Response " + str(dialog_token))
1065 # ready - invalid GO Intent GO Neg Req
1068 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1069 #attrs = p2p_attr_capability()
1070 attrs = p2p_attr_go_intent(go_intent=16)
1071 #attrs += p2p_attr_config_timeout()
1072 attrs += p2p_attr_listen_channel()
1073 attrs += p2p_attr_ext_listen_timing()
1074 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1075 attrs += p2p_attr_channel_list()
1076 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1077 attrs += p2p_attr_operating_channel()
1078 msg['payload'] += ie_p2p(attrs)
1080 check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_INVALID_PARAMS)
1082 # ready - invalid Channel List
1085 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1086 attrs = p2p_attr_capability()
1087 attrs += p2p_attr_go_intent()
1088 attrs += p2p_attr_config_timeout()
1089 attrs += p2p_attr_listen_channel()
1090 attrs += p2p_attr_ext_listen_timing()
1091 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1092 attrs += struct.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST, 16,
1094 81, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
1095 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1096 attrs += p2p_attr_operating_channel()
1097 msg['payload'] += ie_p2p(attrs)
1099 check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_NO_COMMON_CHANNELS)
1101 # ready - invalid GO Neg Req (unsupported Device Password ID)
1104 msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
1105 attrs = p2p_attr_capability()
1106 attrs += p2p_attr_go_intent()
1107 attrs += p2p_attr_config_timeout()
1108 attrs += p2p_attr_listen_channel()
1109 attrs += p2p_attr_ext_listen_timing()
1110 attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1111 # very long channel list
1112 attrs += struct.pack("<BH3BBB11B30B", P2P_ATTR_CHANNEL_LIST, 46,
1114 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
1115 1, 1, 1, 2, 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5,
1116 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 10, 1, 10)
1117 attrs += p2p_attr_device_info(src, config_methods=0x0108)
1118 attrs += p2p_attr_operating_channel()
1119 msg['payload'] += ie_p2p(attrs)
1121 check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD)
1123 def test_p2p_msg_go_neg_req_reject(dev, apdev):
1124 """P2P protocol tests for user reject incorrectly in GO Neg Req"""
1125 addr0 = dev[0].p2p_dev_addr()
1126 addr1 = dev[1].p2p_dev_addr()
1128 dev[1].discover_peer(addr0)
1129 dev[1].group_request("P2P_CONNECT " + addr0 + " pbc")
1130 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1132 raise Exception("Timeout on GO Neg Req")
1134 peer = dev[0].get_peer(addr1)
1135 dev[0].p2p_stop_find()
1137 msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_REQ, dialog_token=123)
1138 attrs = p2p_attr_capability()
1139 attrs += p2p_attr_status(status=P2P_SC_FAIL_REJECTED_BY_USER)
1140 attrs += p2p_attr_go_intent()
1141 attrs += p2p_attr_config_timeout()
1142 attrs += p2p_attr_listen_channel()
1143 attrs += p2p_attr_ext_listen_timing()
1144 attrs += p2p_attr_intended_interface_addr(addr0)
1145 attrs += p2p_attr_channel_list()
1146 attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1147 attrs += p2p_attr_operating_channel()
1148 msg['payload'] += ie_p2p(attrs)
1150 for i in range(0, 20):
1151 if "FAIL" in dev[0].request("MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload']))):
1152 raise Exception("Failed to send Action frame")
1153 ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
1155 raise Exception("Timeout on MGMT-TX-STATUS")
1156 if "result=SUCCESS" in ev:
1159 if "result=SUCCESS" not in ev:
1160 raise Exception("Peer did not ack GO Neg Req")
1162 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=5)
1164 raise Exception("GO Negotiation failure not reported")
1165 if "status=%d" % P2P_SC_FAIL_REJECTED_BY_USER not in ev:
1166 raise Exception("Unexpected failure reason: " + ev)