1 # P2P protocol tests for various messages
2 # Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
7 from remotehost
import remote_compatible
12 logger
= logging
.getLogger()
15 from p2p_utils
import *
16 from test_gas
import anqp_adv_proto
19 return struct
.pack("<BB", WLAN_EID_SSID
, len(ssid
)) + ssid
22 return struct
.pack("<BBBBBBBBBB", WLAN_EID_SUPP_RATES
, 8,
23 2*6, 2*9, 2*12, 2*18, 2*24, 2*36, 2*48, 2*54)
26 return struct
.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC
, 4 + len(attrs
),
27 0x50, 0x6f, 0x9a, 9) + attrs
30 return struct
.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC
, 4 + len(attrs
),
31 0x00, 0x50, 0xf2, 4) + attrs
33 def wsc_attr_config_methods(methods
=0):
34 return struct
.pack(">HHH", WSC_ATTR_CONFIG_METHODS
, 2, methods
)
36 def p2p_attr_status(status
=P2P_SC_SUCCESS
):
37 return struct
.pack("<BHB", P2P_ATTR_STATUS
, 1, status
)
39 def p2p_attr_minor_reason_code(code
=0):
40 return struct
.pack("<BHB", P2P_ATTR_MINOR_REASON_CODE
, 1, code
)
42 def p2p_attr_capability(dev_capab
=0, group_capab
=0):
43 return struct
.pack("<BHBB", P2P_ATTR_CAPABILITY
, 2, dev_capab
, group_capab
)
45 def p2p_attr_device_id(addr
):
46 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
47 t
= (P2P_ATTR_DEVICE_ID
, 6) + val
48 return struct
.pack('<BH6B', *t
)
50 def p2p_attr_go_intent(go_intent
=0, tie_breaker
=0):
51 return struct
.pack("<BHB", P2P_ATTR_GROUP_OWNER_INTENT
, 1,
52 (go_intent
<< 1) |
(tie_breaker
& 0x01))
54 def p2p_attr_config_timeout(go_config_timeout
=0, client_config_timeout
=0):
55 return struct
.pack("<BHBB", P2P_ATTR_CONFIGURATION_TIMEOUT
, 2,
56 go_config_timeout
, client_config_timeout
)
58 def p2p_attr_listen_channel(op_class
=81, chan
=1):
59 return struct
.pack("<BHBBBBB", P2P_ATTR_LISTEN_CHANNEL
, 5,
60 0x58, 0x58, 0x04, op_class
, chan
)
62 def p2p_attr_group_bssid(addr
):
63 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
64 t
= (P2P_ATTR_GROUP_BSSID
, 6) + val
65 return struct
.pack('<BH6B', *t
)
67 def p2p_attr_ext_listen_timing(period
=0, interval
=0):
68 return struct
.pack("<BHHH", P2P_ATTR_EXT_LISTEN_TIMING
, 4, period
, interval
)
70 def p2p_attr_intended_interface_addr(addr
):
71 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
72 t
= (P2P_ATTR_INTENDED_INTERFACE_ADDR
, 6) + val
73 return struct
.pack('<BH6B', *t
)
75 def p2p_attr_manageability(bitmap
=0):
76 return struct
.pack("<BHB", P2P_ATTR_MANAGEABILITY
, 1, bitmap
)
78 def p2p_attr_channel_list():
79 return struct
.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST
, 16,
81 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
83 def p2p_attr_device_info(addr
, name
="Test", config_methods
=0, dev_type
="00010050F2040001"):
84 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
85 val2
= struct
.unpack('8B', binascii
.unhexlify(dev_type
))
86 t
= (P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 4 + len(name
)) + val
88 return struct
.pack("<BH6B", *t
) + struct
.pack(">H", config_methods
) + struct
.pack("8BB", *t2
) + struct
.pack('>HH', 0x1011, len(name
)) +name
90 def p2p_attr_group_id(addr
, ssid
):
91 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
92 t
= (P2P_ATTR_GROUP_ID
, 6 + len(ssid
)) + val
93 return struct
.pack('<BH6B', *t
) + ssid
95 def p2p_attr_operating_channel(op_class
=81, chan
=1):
96 return struct
.pack("<BHBBBBB", P2P_ATTR_OPERATING_CHANNEL
, 5,
97 0x58, 0x58, 0x04, op_class
, chan
)
99 def p2p_attr_invitation_flags(bitmap
=0):
100 return struct
.pack("<BHB", P2P_ATTR_INVITATION_FLAGS
, 1, bitmap
)
102 def p2p_hdr_helper(dst
, src
, type=None, dialog_token
=1, req
=True):
104 msg
['fc'] = MGMT_SUBTYPE_ACTION
<< 4
111 msg
['payload'] = struct
.pack("<BBBBBB",
112 ACTION_CATEG_PUBLIC
, 9, 0x50, 0x6f, 0x9a, 9)
114 msg
['payload'] += struct
.pack("<B", type)
116 msg
['payload'] += struct
.pack("<B", dialog_token
)
119 def p2p_hdr(dst
, src
, type=None, dialog_token
=1):
120 return p2p_hdr_helper(dst
, src
, type, dialog_token
, True)
122 def p2p_hdr_resp(dst
, src
, type=None, dialog_token
=1):
123 return p2p_hdr_helper(dst
, src
, type, dialog_token
, False)
125 def start_p2p(dev
, apdev
):
126 addr0
= dev
[0].p2p_dev_addr()
128 dev
[1].p2p_find(social
=True)
129 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
131 raise Exception("Device discovery timed out")
132 dev
[1].p2p_stop_find()
133 peer
= dev
[1].get_peer(addr0
)
135 bssid
= apdev
[0]['bssid']
136 params
= { 'ssid': "test", 'beacon_int': "2000" }
137 if peer
['listen_freq'] == "2412":
138 params
['channel'] = '1'
139 elif peer
['listen_freq'] == "2437":
140 params
['channel'] = '6'
141 elif peer
['listen_freq'] == "2462":
142 params
['channel'] = '11'
143 hapd
= hostapd
.add_ap(apdev
[0], params
)
144 hapd
.set("ext_mgmt_frame_handling", "1")
145 return addr0
, bssid
, hapd
, int(params
['channel'])
147 def p2p_probe(hapd
, src
, chan
=1):
149 msg
['fc'] = MGMT_SUBTYPE_PROBE_REQ
<< 4
150 msg
['da'] = "ff:ff:ff:ff:ff:ff"
152 msg
['bssid'] = "ff:ff:ff:ff:ff:ff"
153 attrs
= p2p_attr_listen_channel(chan
=chan
)
154 msg
['payload'] = ie_ssid("DIRECT-") + ie_supp_rates() + ie_p2p(attrs
)
157 def parse_p2p_public_action(payload
):
159 (category
, action
) = struct
.unpack('BB', pos
[0:2])
160 if category
!= ACTION_CATEG_PUBLIC
:
165 (oui1
,oui2
,oui3
,subtype
) = struct
.unpack('BBBB', pos
[0:4])
166 if oui1
!= 0x50 or oui2
!= 0x6f or oui3
!= 0x9a or subtype
!= 9:
169 (subtype
,dialog_token
) = struct
.unpack('BB', pos
[0:2])
171 p2p
['subtype'] = subtype
172 p2p
['dialog_token'] = dialog_token
174 p2p
['elements'] = pos
176 (id,elen
) = struct
.unpack('BB', pos
[0:2])
179 raise Exception("Truncated IE in P2P Public Action frame (elen=%d left=%d)" % (elen
, len(pos
)))
180 if id == WLAN_EID_VENDOR_SPECIFIC
:
182 raise Exception("Too short vendor specific IE in P2P Public Action frame (elen=%d)" % elen
)
183 (oui1
,oui2
,oui3
,subtype
) = struct
.unpack('BBBB', pos
[0:4])
184 if oui1
== 0x50 and oui2
== 0x6f and oui3
== 0x9a and subtype
== 9:
186 p2p
['p2p'] += pos
[4:elen
]
188 p2p
['p2p'] = pos
[4:elen
]
189 if oui1
== 0x00 and oui2
== 0x50 and oui3
== 0xf2 and subtype
== 4:
190 p2p
['wsc'] = pos
[4:elen
]
193 raise Exception("Invalid element in P2P Public Action frame")
196 p2p
['p2p_attrs'] = {}
199 (id,alen
) = struct
.unpack('<BH', pos
[0:3])
202 logger
.info("P2P payload: " + binascii
.hexlify(p2p
['p2p']))
203 raise Exception("Truncated P2P attribute in P2P Public Action frame (alen=%d left=%d p2p-payload=%d)" % (alen
, len(pos
), len(p2p
['p2p'])))
204 p2p
['p2p_attrs'][id] = pos
[0:alen
]
206 if P2P_ATTR_STATUS
in p2p
['p2p_attrs']:
207 p2p
['p2p_status'] = struct
.unpack('B', p2p
['p2p_attrs'][P2P_ATTR_STATUS
])[0]
210 p2p
['wsc_attrs'] = {}
213 (id,alen
) = struct
.unpack('>HH', pos
[0:4])
216 logger
.info("WSC payload: " + binascii
.hexlify(p2p
['wsc']))
217 raise Exception("Truncated WSC attribute in P2P Public Action frame (alen=%d left=%d wsc-payload=%d)" % (alen
, len(pos
), len(p2p
['wsc'])))
218 p2p
['wsc_attrs'][id] = pos
[0:alen
]
224 def test_p2p_msg_empty(dev
, apdev
):
225 """P2P protocol test: empty P2P Public Action frame"""
226 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
227 msg
= p2p_hdr(dst
, src
)
231 def test_p2p_msg_long_ssid(dev
, apdev
):
232 """P2P protocol test: Too long SSID in P2P Public Action frame"""
233 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
235 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=1)
236 attrs
= p2p_attr_config_timeout()
237 attrs
+= p2p_attr_invitation_flags()
238 attrs
+= p2p_attr_operating_channel()
239 attrs
+= p2p_attr_group_bssid(src
)
240 attrs
+= p2p_attr_channel_list()
241 attrs
+= p2p_attr_group_id(src
, 'DIRECT-foo')
242 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
243 msg
['payload'] += ie_p2p(attrs
)
244 msg
['payload'] += ie_ssid(255 * 'A')
246 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
248 raise Exception("Timeout on device found event")
251 def test_p2p_msg_long_dev_name(dev
, apdev
):
252 """P2P protocol test: Too long Device Name in P2P Public Action frame"""
253 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
255 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=1)
256 attrs
= p2p_attr_config_timeout()
257 attrs
+= p2p_attr_invitation_flags()
258 attrs
+= p2p_attr_operating_channel()
259 attrs
+= p2p_attr_group_bssid(src
)
260 attrs
+= p2p_attr_channel_list()
261 attrs
+= p2p_attr_group_id(src
, 'DIRECT-foo')
262 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108,
263 name
="123456789012345678901234567890123")
264 msg
['payload'] += ie_p2p(attrs
)
266 ev
= dev
[0].wait_event(["P2P-DEVICE-FOUND"], timeout
=0.1)
268 raise Exception("Unexpected device found event")
270 def test_p2p_msg_invitation_req(dev
, apdev
):
271 """P2P protocol tests for invitation request processing"""
272 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
274 # Empty P2P Invitation Request (missing dialog token)
275 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=None)
279 # Various p2p_parse() failure cases due to invalid attributes
281 # Too short attribute header
283 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
284 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
285 msg
['payload'] += ie_p2p(attrs
)
288 # Minimal attribute underflow
290 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
291 attrs
= struct
.pack("<BH", P2P_ATTR_CAPABILITY
, 1)
292 msg
['payload'] += ie_p2p(attrs
)
295 # Large attribute underflow
297 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
298 attrs
= struct
.pack("<BHB", P2P_ATTR_CAPABILITY
, 0xffff, 1)
299 msg
['payload'] += ie_p2p(attrs
)
302 # Too short Capability attribute
304 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
305 attrs
= struct
.pack("<BHB", P2P_ATTR_CAPABILITY
, 1, 0)
306 msg
['payload'] += ie_p2p(attrs
)
309 # Too short Device ID attribute
311 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
312 val
= struct
.unpack('5B', binascii
.unhexlify("1122334455"))
313 t
= (P2P_ATTR_DEVICE_ID
, 5) + val
314 attrs
= struct
.pack('<BH5B', *t
)
315 msg
['payload'] += ie_p2p(attrs
)
318 # Too short GO Intent attribute
320 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
321 attrs
= struct
.pack("<BH", P2P_ATTR_GROUP_OWNER_INTENT
, 0)
322 msg
['payload'] += ie_p2p(attrs
)
325 # Too short Status attribute
327 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
328 attrs
= struct
.pack("<BH", P2P_ATTR_STATUS
, 0)
329 msg
['payload'] += ie_p2p(attrs
)
332 # null Listen channel and too short Listen Channel attribute
334 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
335 attrs
= struct
.pack("<BH", P2P_ATTR_LISTEN_CHANNEL
, 0)
336 attrs
+= struct
.pack("<BHB", P2P_ATTR_LISTEN_CHANNEL
, 1, 0)
337 msg
['payload'] += ie_p2p(attrs
)
340 # null Operating channel and too short Operating Channel attribute
342 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
343 attrs
= struct
.pack("<BH", P2P_ATTR_OPERATING_CHANNEL
, 0)
344 attrs
+= struct
.pack("<BHB", P2P_ATTR_OPERATING_CHANNEL
, 1, 0)
345 msg
['payload'] += ie_p2p(attrs
)
348 # Too short Channel List attribute
350 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
351 attrs
= struct
.pack("<BHBB", P2P_ATTR_CHANNEL_LIST
, 2, 1, 2)
352 msg
['payload'] += ie_p2p(attrs
)
355 # Too short Device Info attribute
357 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
358 attrs
= struct
.pack("<BHBB", P2P_ATTR_DEVICE_INFO
, 2, 1, 2)
359 msg
['payload'] += ie_p2p(attrs
)
362 # Truncated Secondary Device Types in Device Info attribute
364 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
365 attrs
= struct
.pack("<BH6BH8BB", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1,
368 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22,
370 msg
['payload'] += ie_p2p(attrs
)
373 # Missing Device Name in Device Info attribute
375 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
376 attrs
= struct
.pack("<BH6BH8BB8B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8,
379 0, 0, 0, 0, 0, 0, 0, 0,
381 1, 2, 3, 4, 5, 6, 7, 8)
382 msg
['payload'] += ie_p2p(attrs
)
385 # Invalid Device Name header in Device Info attribute
387 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
388 attrs
= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4,
391 0, 0, 0, 0, 0, 0, 0, 0,
393 1, 2, 3, 4, 5, 6, 7, 8,
395 msg
['payload'] += ie_p2p(attrs
)
398 # Invalid Device Name header length in Device Info attribute
400 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
401 attrs
= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4,
404 0, 0, 0, 0, 0, 0, 0, 0,
406 1, 2, 3, 4, 5, 6, 7, 8,
407 0x10, 0x11, 0xff, 0xff)
408 msg
['payload'] += ie_p2p(attrs
)
411 # Invalid Device Name header length in Device Info attribute
413 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
415 attrs
= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4 + len(devname
),
418 0, 0, 0, 0, 0, 0, 0, 0,
420 1, 2, 3, 4, 5, 6, 7, 8,
421 0x10, 0x11, 0, len(devname
) + 1) + devname
422 msg
['payload'] += ie_p2p(attrs
)
425 # Device Name filtering and too long Device Name in Device Info attribute
427 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
428 attrs
= struct
.pack("<BH6BH8BB8B4B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4 + 4,
431 0, 0, 0, 0, 0, 0, 0, 0,
433 1, 2, 3, 4, 5, 6, 7, 8,
436 devname
= '123456789012345678901234567890123'
437 attrs
+= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4 + len(devname
),
440 0, 0, 0, 0, 0, 0, 0, 0,
442 1, 2, 3, 4, 5, 6, 7, 8,
443 0x10, 0x11, 0, len(devname
)) + devname
444 msg
['payload'] += ie_p2p(attrs
)
447 # Too short Configuration Timeout attribute
449 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
450 attrs
= struct
.pack("<BHB", P2P_ATTR_CONFIGURATION_TIMEOUT
, 1, 1)
451 msg
['payload'] += ie_p2p(attrs
)
454 # Too short Intended P2P Interface Address attribute
456 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
457 attrs
= struct
.pack("<BHB", P2P_ATTR_INTENDED_INTERFACE_ADDR
, 1, 1)
458 msg
['payload'] += ie_p2p(attrs
)
461 # Too short P2P Group BSSID attribute
463 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
464 attrs
= struct
.pack("<BHB", P2P_ATTR_GROUP_BSSID
, 1, 1)
465 msg
['payload'] += ie_p2p(attrs
)
468 # Too short P2P Group ID attribute
470 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
471 attrs
= struct
.pack("<BHB", P2P_ATTR_GROUP_ID
, 1, 1)
472 msg
['payload'] += ie_p2p(attrs
)
475 # Too long P2P Group ID attribute
477 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
478 attrs
= struct
.pack("<BH6B", P2P_ATTR_GROUP_ID
, 6 + 33, 0, 0, 0, 0, 0, 0) + "123456789012345678901234567890123"
479 msg
['payload'] += ie_p2p(attrs
)
482 # Too short Invitation Flags attribute
484 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
485 attrs
= struct
.pack("<BH", P2P_ATTR_INVITATION_FLAGS
, 0)
486 msg
['payload'] += ie_p2p(attrs
)
489 # Valid and too short Manageability attribute
491 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
492 attrs
= p2p_attr_manageability()
493 attrs
+= struct
.pack("<BH", P2P_ATTR_MANAGEABILITY
, 0)
494 msg
['payload'] += ie_p2p(attrs
)
497 # Too short NoA attribute
499 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
500 attrs
= struct
.pack("<BHB", P2P_ATTR_NOTICE_OF_ABSENCE
, 1, 1)
501 msg
['payload'] += ie_p2p(attrs
)
504 # Valid and too short Extended Listen Timing attributes
506 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
507 attrs
= p2p_attr_ext_listen_timing(period
=100, interval
=50)
508 attrs
+= struct
.pack("<BHBBB", P2P_ATTR_EXT_LISTEN_TIMING
, 3, 0, 0, 0)
509 msg
['payload'] += ie_p2p(attrs
)
512 # Valid and too short Minor Reason Code attributes
514 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
515 attrs
= p2p_attr_minor_reason_code(code
=2)
516 attrs
+= struct
.pack("<BH", P2P_ATTR_MINOR_REASON_CODE
, 0)
517 msg
['payload'] += ie_p2p(attrs
)
520 # Unknown attribute and too short OOB GO Negotiation Channel attribute
522 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
523 attrs
= struct
.pack("<BHB", 99, 1, 1)
524 attrs
+= struct
.pack("<BHB", P2P_ATTR_OOB_GO_NEG_CHANNEL
, 1, 1)
525 msg
['payload'] += ie_p2p(attrs
)
528 # Too short Service Hash attribute
530 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
531 attrs
= struct
.pack("<BH5B", P2P_ATTR_SERVICE_HASH
, 5, 1, 2, 3, 4, 5)
532 msg
['payload'] += ie_p2p(attrs
)
535 # Too short Connection Capability attribute
537 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
538 attrs
= struct
.pack("<BH", P2P_ATTR_CONNECTION_CAPABILITY
, 0)
539 msg
['payload'] += ie_p2p(attrs
)
542 # Too short Advertisement ID attribute
544 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
545 attrs
= struct
.pack("<BH9B", P2P_ATTR_ADVERTISEMENT_ID
, 9, 1, 2, 3, 4, 5,
547 msg
['payload'] += ie_p2p(attrs
)
550 # Truncated and too short Service Instance attributes
552 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
553 attrs
= struct
.pack("<BH8B", P2P_ATTR_ADVERTISED_SERVICE
, 8, 1, 2, 3, 4, 5,
555 attrs
+= struct
.pack("<BH7B", P2P_ATTR_ADVERTISED_SERVICE
, 7, 1, 2, 3, 4, 5,
557 msg
['payload'] += ie_p2p(attrs
)
560 # Too short Session ID attribute
562 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
563 attrs
= struct
.pack("<BH4B", P2P_ATTR_SESSION_ID
, 4, 1, 2, 3, 4)
564 msg
['payload'] += ie_p2p(attrs
)
567 # Too short Feature Capability attribute
569 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
570 attrs
= struct
.pack("<BH", P2P_ATTR_FEATURE_CAPABILITY
, 0)
571 msg
['payload'] += ie_p2p(attrs
)
574 # Too short Persistent Group attribute
576 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
577 attrs
= struct
.pack("<BH5B", P2P_ATTR_PERSISTENT_GROUP
, 5, 1, 2, 3, 4, 5)
578 msg
['payload'] += ie_p2p(attrs
)
581 # Too long Persistent Group attribute
583 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
584 attrs
= struct
.pack("<BH9L3B", P2P_ATTR_PERSISTENT_GROUP
, 6 + 32 + 1,
585 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3)
586 msg
['payload'] += ie_p2p(attrs
)
589 if hapd
.mgmt_rx(timeout
=0.5) is not None:
590 raise Exception("Unexpected management frame received")
592 dev
[0].dump_monitor()
594 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
595 attrs
= p2p_attr_config_timeout()
596 attrs
+= p2p_attr_invitation_flags()
597 attrs
+= p2p_attr_operating_channel()
598 attrs
+= p2p_attr_group_bssid(src
)
599 attrs
+= p2p_attr_channel_list()
600 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
601 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
602 msg
['payload'] += ie_p2p(attrs
)
604 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
606 raise Exception("Timeout on device found event")
607 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout
=5)
609 raise Exception("Timeout on invitation event " + str(dialog_token
))
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 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout
=5)
628 raise Exception("Timeout on invitation event " + str(dialog_token
))
629 if hapd
.mgmt_rx(timeout
=1) is None:
630 raise Exception("No invitation response " + str(dialog_token
))
633 dev
[0].dump_monitor()
635 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
636 #attrs = p2p_attr_config_timeout()
637 attrs
= p2p_attr_invitation_flags()
638 attrs
+= p2p_attr_operating_channel()
639 attrs
+= p2p_attr_group_bssid(src
)
640 attrs
+= p2p_attr_channel_list()
641 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
642 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
643 msg
['payload'] += ie_p2p(attrs
)
645 if hapd
.mgmt_rx(timeout
=1) is None:
646 raise Exception("No invitation response " + str(dialog_token
))
649 dev
[0].dump_monitor()
651 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
652 attrs
= p2p_attr_config_timeout()
653 #attrs = p2p_attr_invitation_flags()
654 attrs
+= p2p_attr_operating_channel()
655 attrs
+= p2p_attr_group_bssid(src
)
656 attrs
+= p2p_attr_channel_list()
657 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
658 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
659 msg
['payload'] += ie_p2p(attrs
)
661 if hapd
.mgmt_rx(timeout
=1) is None:
662 raise Exception("No invitation response " + str(dialog_token
))
665 dev
[0].dump_monitor()
667 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
668 attrs
= p2p_attr_config_timeout()
669 attrs
= p2p_attr_invitation_flags()
670 #attrs += p2p_attr_operating_channel()
671 attrs
+= p2p_attr_group_bssid(src
)
672 attrs
+= p2p_attr_channel_list()
673 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
674 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
675 msg
['payload'] += ie_p2p(attrs
)
677 if hapd
.mgmt_rx(timeout
=1) is None:
678 raise Exception("No invitation response " + str(dialog_token
))
681 dev
[0].dump_monitor()
683 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
684 attrs
= p2p_attr_config_timeout()
685 attrs
= p2p_attr_invitation_flags()
686 attrs
+= p2p_attr_operating_channel()
687 #attrs += p2p_attr_group_bssid(src)
688 attrs
+= p2p_attr_channel_list()
689 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
690 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
691 msg
['payload'] += ie_p2p(attrs
)
693 if hapd
.mgmt_rx(timeout
=1) is None:
694 raise Exception("No invitation response " + str(dialog_token
))
697 dev
[0].dump_monitor()
699 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
700 attrs
= p2p_attr_config_timeout()
701 attrs
= p2p_attr_invitation_flags()
702 attrs
+= p2p_attr_operating_channel()
703 attrs
+= p2p_attr_group_bssid(src
)
704 #attrs += p2p_attr_channel_list()
705 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
706 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
707 msg
['payload'] += ie_p2p(attrs
)
709 if hapd
.mgmt_rx(timeout
=1) is None:
710 raise Exception("No invitation response " + str(dialog_token
))
713 dev
[0].dump_monitor()
715 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
716 attrs
= p2p_attr_config_timeout()
717 attrs
= p2p_attr_invitation_flags()
718 attrs
+= p2p_attr_operating_channel()
719 attrs
+= p2p_attr_group_bssid(src
)
720 attrs
+= p2p_attr_channel_list()
721 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
722 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
723 msg
['payload'] += ie_p2p(attrs
)
725 if hapd
.mgmt_rx(timeout
=1) is None:
726 raise Exception("No invitation response " + str(dialog_token
))
729 dev
[0].dump_monitor()
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
+= p2p_attr_channel_list()
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
))
745 dev
[0].dump_monitor()
747 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
749 if hapd
.mgmt_rx(timeout
=1) is None:
750 raise Exception("No invitation response " + str(dialog_token
))
752 # Unusable peer operating channel preference
754 dev
[0].dump_monitor()
756 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
757 attrs
= p2p_attr_config_timeout()
758 attrs
= p2p_attr_invitation_flags()
759 attrs
+= p2p_attr_operating_channel(chan
=15)
760 attrs
+= p2p_attr_group_bssid(src
)
761 attrs
+= p2p_attr_channel_list()
762 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
763 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
764 msg
['payload'] += ie_p2p(attrs
)
766 if hapd
.mgmt_rx(timeout
=1) is None:
767 raise Exception("No invitation response " + str(dialog_token
))
769 def test_p2p_msg_invitation_req_to_go(dev
, apdev
):
770 """P2P protocol tests for invitation request processing on GO device"""
771 res
= form(dev
[0], dev
[1])
772 dev
[0].dump_monitor()
773 dev
[1].dump_monitor()
774 addr0
= dev
[0].p2p_dev_addr()
775 addr1
= dev
[1].p2p_dev_addr()
776 peer
= dev
[1].get_peer(addr0
)
777 listen_freq
= peer
['listen_freq']
779 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
780 raise Exception("Failed to enable external management frame handling")
782 networks
= dev
[0].list_networks()
783 if len(networks
) != 1:
784 raise Exception("Unexpected number of networks")
785 if "[P2P-PERSISTENT]" not in networks
[0]['flags']:
786 raise Exception("Not the persistent group data")
787 dev
[0].p2p_start_go(persistent
=networks
[0]['id'], freq
=listen_freq
)
791 # Unusable peer operating channel preference
793 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_REQ
,
794 dialog_token
=dialog_token
)
795 attrs
= p2p_attr_config_timeout()
796 attrs
= p2p_attr_invitation_flags(bitmap
=1)
797 attrs
+= p2p_attr_operating_channel(chan
=15)
798 attrs
+= p2p_attr_channel_list()
799 attrs
+= p2p_attr_group_id(res
['go_dev_addr'], res
['ssid'])
800 attrs
+= p2p_attr_device_info(addr1
, config_methods
=0x0108)
801 msg
['payload'] += ie_p2p(attrs
)
803 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
805 rx_msg
= dev
[1].mgmt_rx()
807 raise Exception("MGMT-RX timeout")
808 p2p
= parse_p2p_public_action(rx_msg
['payload'])
810 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
811 if p2p
['subtype'] != P2P_INVITATION_RESP
:
812 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
813 if p2p
['p2p_status'] != 0:
814 raise Exception("Unexpected status %d" % p2p
['p2p_status'])
816 # Forced channel re-selection due to channel list
818 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_REQ
,
819 dialog_token
=dialog_token
)
820 attrs
= p2p_attr_config_timeout()
821 attrs
= p2p_attr_invitation_flags(bitmap
=1)
822 attrs
+= struct
.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST
, 6,
825 attrs
+= p2p_attr_group_id(res
['go_dev_addr'], res
['ssid'])
826 attrs
+= p2p_attr_device_info(addr1
, config_methods
=0x0108)
827 msg
['payload'] += ie_p2p(attrs
)
829 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
831 rx_msg
= dev
[1].mgmt_rx()
833 raise Exception("MGMT-RX timeout")
834 p2p
= parse_p2p_public_action(rx_msg
['payload'])
836 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
837 if p2p
['subtype'] != P2P_INVITATION_RESP
:
838 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
839 if p2p
['p2p_status'] != 7 and dev
[1].get_mcc() <= 1:
840 raise Exception("Unexpected status %d" % p2p
['p2p_status'])
843 def test_p2p_msg_invitation_req_unknown(dev
, apdev
):
844 """P2P protocol tests for invitation request from unknown peer"""
845 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
849 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
850 attrs
= p2p_attr_config_timeout()
851 attrs
+= p2p_attr_invitation_flags()
852 attrs
+= p2p_attr_operating_channel()
853 attrs
+= p2p_attr_group_bssid(src
)
854 attrs
+= p2p_attr_channel_list()
855 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
856 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
857 msg
['payload'] += ie_p2p(attrs
)
859 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout
=5)
861 raise Exception("Timeout on invitation event " + str(dialog_token
))
862 if hapd
.mgmt_rx(timeout
=1) is None:
863 raise Exception("No invitation response " + str(dialog_token
))
866 def test_p2p_msg_invitation_no_common_channels(dev
, apdev
):
867 """P2P protocol tests for invitation request without common channels"""
868 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
872 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
873 attrs
= p2p_attr_config_timeout()
874 attrs
+= p2p_attr_invitation_flags()
875 attrs
+= p2p_attr_operating_channel()
876 attrs
+= p2p_attr_group_bssid(src
)
877 attrs
+= struct
.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST
, 5,
880 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
881 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
882 msg
['payload'] += ie_p2p(attrs
)
884 if hapd
.mgmt_rx(timeout
=1) is None:
885 raise Exception("No invitation response " + str(dialog_token
))
886 ev
= dev
[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout
=0.1)
888 raise Exception("Unexpected invitation event")
890 def test_p2p_msg_invitation_resp(dev
, apdev
):
891 """P2P protocol tests for invitation response processing"""
893 dev
[0].dump_monitor()
894 dev
[1].dump_monitor()
896 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
898 addr0
= dev
[0].p2p_dev_addr()
899 addr1
= dev
[1].p2p_dev_addr()
900 peer
= dev
[1].get_peer(addr0
)
902 # P2P Invitation Response from unknown peer
903 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=1)
906 # P2P Invitation Response from peer that is not in invitation
907 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=2)
908 attrs
= p2p_attr_status()
909 msg
['payload'] += ie_p2p(attrs
)
910 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
913 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
914 raise Exception("Failed to enable external management frame handling")
916 invite(dev
[0], dev
[1])
917 rx_msg
= dev
[1].mgmt_rx()
919 raise Exception("MGMT-RX timeout")
920 p2p
= parse_p2p_public_action(rx_msg
['payload'])
922 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
923 if p2p
['subtype'] != P2P_INVITATION_REQ
:
924 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
926 # Invalid attribute to cause p2p_parse() failure
927 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
928 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
929 msg
['payload'] += ie_p2p(attrs
)
930 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
932 invite(dev
[0], dev
[1])
933 rx_msg
= dev
[1].mgmt_rx()
935 raise Exception("MGMT-RX timeout")
936 p2p
= parse_p2p_public_action(rx_msg
['payload'])
938 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
939 if p2p
['subtype'] != P2P_INVITATION_REQ
:
940 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
942 # missing mandatory Status attribute
943 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
944 attrs
= p2p_attr_channel_list()
945 msg
['payload'] += ie_p2p(attrs
)
946 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
948 invite(dev
[0], dev
[1])
949 rx_msg
= dev
[1].mgmt_rx()
951 raise Exception("MGMT-RX timeout")
952 p2p
= parse_p2p_public_action(rx_msg
['payload'])
954 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
955 if p2p
['subtype'] != P2P_INVITATION_REQ
:
956 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
958 # no channel match (no common channel found at all)
959 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
960 attrs
= p2p_attr_status()
961 attrs
+= struct
.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST
, 6,
964 msg
['payload'] += ie_p2p(attrs
)
965 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
967 invite(dev
[0], dev
[1])
968 rx_msg
= dev
[1].mgmt_rx()
970 raise Exception("MGMT-RX timeout")
971 p2p
= parse_p2p_public_action(rx_msg
['payload'])
973 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
974 if p2p
['subtype'] != P2P_INVITATION_REQ
:
975 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
977 # no channel match (no acceptable P2P channel)
978 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
979 attrs
= p2p_attr_status()
980 attrs
+= struct
.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST
, 6,
983 msg
['payload'] += ie_p2p(attrs
)
984 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
986 invite(dev
[0], dev
[1])
987 rx_msg
= dev
[1].mgmt_rx()
989 raise Exception("MGMT-RX timeout")
990 p2p
= parse_p2p_public_action(rx_msg
['payload'])
992 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
993 if p2p
['subtype'] != P2P_INVITATION_REQ
:
994 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
996 # missing mandatory Channel List attribute (ignored as a workaround)
997 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
998 attrs
= p2p_attr_status()
999 msg
['payload'] += ie_p2p(attrs
)
1000 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1002 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15);
1004 raise Exception("Group was not started")
1006 def test_p2p_msg_invitation_resend(dev
, apdev
):
1007 """P2P protocol tests for invitation resending on no-common-channels"""
1008 form(dev
[0], dev
[1])
1009 dev
[0].dump_monitor()
1010 dev
[1].dump_monitor()
1011 addr0
= dev
[0].p2p_dev_addr()
1012 addr1
= dev
[1].p2p_dev_addr()
1014 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
1015 raise Exception("Failed to enable external management frame handling")
1017 logger
.info("Forced channel in invitation")
1018 invite(dev
[0], dev
[1], extra
="freq=2422")
1019 rx_msg
= dev
[1].mgmt_rx()
1021 raise Exception("MGMT-RX timeout")
1022 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1024 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1025 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1026 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1027 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1028 dialog_token
=p2p
['dialog_token'])
1029 attrs
= p2p_attr_status(status
=P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1030 msg
['payload'] += ie_p2p(attrs
)
1031 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1032 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout
=15)
1034 raise Exception("Timeout on invitation result");
1035 if "status=7" not in ev
:
1036 raise Exception("Unexpected invitation result: " + ev
)
1038 logger
.info("Any channel allowed, only preference provided in invitation");
1039 invite(dev
[0], dev
[1], extra
="pref=2422")
1040 rx_msg
= dev
[1].mgmt_rx()
1042 raise Exception("MGMT-RX timeout")
1043 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1045 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1046 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1047 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1048 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1049 dialog_token
=p2p
['dialog_token'])
1050 attrs
= p2p_attr_status(status
=P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1051 msg
['payload'] += ie_p2p(attrs
)
1052 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 0"):
1053 raise Exception("Failed to disable external management frame handling")
1054 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1055 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout
=15)
1057 raise Exception("Timeout on invitation result");
1058 if "status=0" not in ev
:
1059 raise Exception("Unexpected invitation result: " + ev
)
1061 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15);
1063 raise Exception("Group was not started on dev0")
1064 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15);
1066 raise Exception("Group was not started on dev1")
1068 def test_p2p_msg_invitation_resend_duplicate(dev
, apdev
):
1069 """P2P protocol tests for invitation resending on no-common-channels and duplicated response"""
1070 form(dev
[0], dev
[1])
1071 dev
[0].dump_monitor()
1072 dev
[1].dump_monitor()
1073 addr0
= dev
[0].p2p_dev_addr()
1074 addr1
= dev
[1].p2p_dev_addr()
1076 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
1077 raise Exception("Failed to enable external management frame handling")
1079 logger
.info("Any channel allowed, only preference provided in invitation");
1080 invite(dev
[0], dev
[1], extra
="pref=2422")
1081 rx_msg
= dev
[1].mgmt_rx()
1083 raise Exception("MGMT-RX timeout")
1084 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1086 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1087 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1088 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1089 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1090 dialog_token
=p2p
['dialog_token'])
1091 attrs
= p2p_attr_status(status
=P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1092 msg
['payload'] += ie_p2p(attrs
)
1093 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1095 rx_msg
= dev
[1].mgmt_rx()
1097 raise Exception("MGMT-RX timeout")
1098 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1100 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1101 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1102 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1104 logger
.info("Retransmit duplicate of previous response")
1105 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1107 logger
.info("Transmit real response")
1108 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1109 dialog_token
=p2p
['dialog_token'])
1110 attrs
= p2p_attr_status(status
=P2P_SC_SUCCESS
)
1111 attrs
+= p2p_attr_channel_list()
1112 msg
['payload'] += ie_p2p(attrs
)
1113 if "FAIL" in dev
[1].request("MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload']))):
1114 raise Exception("Failed to transmit real response")
1115 dev
[1].request("SET ext_mgmt_frame_handling 0")
1117 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout
=10)
1119 raise Exception("Timeout on invitation result");
1120 if "status=0" not in ev
:
1121 raise Exception("Unexpected invitation result: " + ev
)
1122 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=10)
1124 raise Exception("Group formation timed out")
1125 dev
[0].group_form_result(ev
)
1126 dev
[0].remove_group()
1129 def test_p2p_msg_pd_req(dev
, apdev
):
1130 """P2P protocol tests for provision discovery request processing"""
1131 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1134 # Too short attribute header
1136 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1137 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
1138 msg
['payload'] += ie_p2p(attrs
)
1141 if hapd
.mgmt_rx(timeout
=0.5) is not None:
1142 raise Exception("Unexpected management frame received")
1146 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1148 msg
['payload'] += ie_p2p(attrs
)
1150 if hapd
.mgmt_rx(timeout
=1) is None:
1151 raise Exception("No PD response " + str(dialog_token
))
1156 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1157 attrs
= wsc_attr_config_methods(methods
=0x1008)
1158 msg
['payload'] += ie_wsc(attrs
)
1159 attrs
= p2p_attr_capability()
1160 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1161 msg
['payload'] += ie_p2p(attrs
)
1163 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
1165 raise Exception("Timeout on device found event")
1166 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=5)
1168 raise Exception("Timeout on PD event")
1169 if hapd
.mgmt_rx(timeout
=1) is None:
1170 raise Exception("No PD response " + str(dialog_token
))
1175 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1176 attrs
= wsc_attr_config_methods(methods
=0x1008)
1177 msg
['payload'] += ie_wsc(attrs
)
1178 attrs
= p2p_attr_capability()
1179 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1180 attrs
+= p2p_attr_group_id("02:02:02:02:02:02", "DIRECT-foo")
1181 msg
['payload'] += ie_p2p(attrs
)
1183 if hapd
.mgmt_rx(timeout
=1) is None:
1184 raise Exception("No PD response " + str(dialog_token
))
1185 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=1)
1187 raise Exception("Unexpected PD event")
1189 # Listen channel is not yet known
1190 if "FAIL" not in dev
[0].global_request("P2P_PROV_DISC " + src
+ " display"):
1191 raise Exception("Unexpected P2P_PROV_DISC success")
1194 if "FAIL" not in dev
[0].global_request("P2P_PROV_DISC 02:03:04:05:06:07 display"):
1195 raise Exception("Unexpected P2P_PROV_DISC success (2)")
1197 def test_p2p_msg_pd(dev
, apdev
):
1198 """P2P protocol tests for provision discovery request processing (known)"""
1199 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1202 p2p_probe(hapd
, src
, chan
=channel
)
1207 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1208 attrs
= wsc_attr_config_methods(methods
=0x1008)
1209 msg
['payload'] += ie_wsc(attrs
)
1210 attrs
= p2p_attr_capability()
1211 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1212 msg
['payload'] += ie_p2p(attrs
)
1214 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
1216 raise Exception("Timeout on device found event")
1217 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=5)
1219 raise Exception("Timeout on PD event")
1220 if hapd
.mgmt_rx(timeout
=1) is None:
1221 raise Exception("No PD response " + str(dialog_token
))
1223 if "FAIL" in dev
[0].global_request("P2P_PROV_DISC " + src
+ " display"):
1224 raise Exception("Unexpected P2P_PROV_DISC failure")
1225 frame
= hapd
.mgmt_rx(timeout
=1)
1227 raise Exception("No PD request " + str(dialog_token
))
1228 p2p
= parse_p2p_public_action(frame
['payload'])
1230 raise Exception("Failed to parse PD request")
1232 # invalid dialog token
1233 msg
= p2p_hdr_resp(dst
, src
, type=P2P_PROV_DISC_RESP
,
1234 dialog_token
=p2p
['dialog_token'] + 1)
1236 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=0.1)
1238 raise Exception("Unexpected PD result event")
1240 # valid dialog token
1241 msg
= p2p_hdr_resp(dst
, src
, type=P2P_PROV_DISC_RESP
,
1242 dialog_token
=p2p
['dialog_token'])
1244 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=5)
1246 raise Exception("Timeout on PD result event")
1248 # valid dialog token
1249 msg
= p2p_hdr_resp(dst
, src
, type=P2P_PROV_DISC_RESP
,
1250 dialog_token
=p2p
['dialog_token'])
1252 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=0.1)
1254 raise Exception("Unexpected PD result event")
1256 def check_p2p_response(hapd
, dialog_token
, status
):
1257 resp
= hapd
.mgmt_rx(timeout
=2)
1259 raise Exception("No GO Neg Response " + str(dialog_token
))
1260 p2p
= parse_p2p_public_action(resp
['payload'])
1262 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1263 if dialog_token
!= p2p
['dialog_token']:
1264 raise Exception("Unexpected dialog token in response")
1265 if p2p
['p2p_status'] != status
:
1266 raise Exception("Unexpected status code %s in response (expected %d)" % (p2p
['p2p_status'], status
))
1268 def test_p2p_msg_go_neg_both_start(dev
, apdev
):
1269 """P2P protocol test for simultaneous GO Neg initiation"""
1270 addr0
= dev
[0].p2p_dev_addr()
1271 addr1
= dev
[1].p2p_dev_addr()
1273 dev
[1].discover_peer(addr0
)
1275 dev
[0].discover_peer(addr1
)
1277 if "FAIL" in dev
[0].request("SET ext_mgmt_frame_handling 1"):
1278 raise Exception("Failed to enable external management frame handling")
1279 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
1280 raise Exception("Failed to enable external management frame handling")
1281 dev
[0].request("P2P_CONNECT {} pbc".format(addr1
))
1282 dev
[1].request("P2P_CONNECT {} pbc".format(addr0
))
1283 msg
= dev
[0].mgmt_rx()
1285 raise Exception("MGMT-RX timeout")
1286 msg
= dev
[1].mgmt_rx()
1288 raise Exception("MGMT-RX timeout(2)")
1289 if "FAIL" in dev
[0].request("SET ext_mgmt_frame_handling 0"):
1290 raise Exception("Failed to disable external management frame handling")
1291 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=2)
1293 raise Exception("Unexpected GO Neg success")
1294 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 0"):
1295 raise Exception("Failed to disable external management frame handling")
1296 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=10)
1298 raise Exception("GO Neg did not succeed")
1299 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=5);
1301 raise Exception("Group formation not succeed")
1302 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=5);
1304 raise Exception("Group formation not succeed")
1306 def test_p2p_msg_go_neg_req(dev
, apdev
):
1307 """P2P protocol tests for invitation request from unknown peer"""
1308 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1313 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1314 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
1315 msg
['payload'] += ie_p2p(attrs
)
1317 frame
= hapd
.mgmt_rx(timeout
=0.1)
1318 if frame
is not None:
1320 raise Exception("Unexpected GO Neg Response")
1324 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1325 attrs
= p2p_attr_capability()
1326 attrs
+= p2p_attr_go_intent()
1327 attrs
+= p2p_attr_config_timeout()
1328 #attrs += p2p_attr_listen_channel()
1329 attrs
+= p2p_attr_ext_listen_timing()
1330 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1331 attrs
+= p2p_attr_channel_list()
1332 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1333 attrs
+= p2p_attr_operating_channel()
1334 msg
['payload'] += ie_p2p(attrs
)
1336 if hapd
.mgmt_rx(timeout
=2) is None:
1337 raise Exception("No GO Neg Response " + str(dialog_token
))
1341 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1342 attrs
= p2p_attr_capability()
1343 attrs
+= p2p_attr_go_intent()
1344 attrs
+= p2p_attr_config_timeout()
1345 attrs
+= p2p_attr_listen_channel()
1346 attrs
+= p2p_attr_ext_listen_timing()
1347 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1348 attrs
+= p2p_attr_channel_list()
1349 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1350 #attrs += p2p_attr_operating_channel()
1351 msg
['payload'] += ie_p2p(attrs
)
1353 if hapd
.mgmt_rx(timeout
=2) is None:
1354 raise Exception("No GO Neg Response " + str(dialog_token
))
1358 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1359 attrs
= p2p_attr_capability()
1360 attrs
+= p2p_attr_go_intent()
1361 attrs
+= p2p_attr_config_timeout()
1362 attrs
+= p2p_attr_listen_channel()
1363 attrs
+= p2p_attr_ext_listen_timing()
1364 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1365 #attrs += p2p_attr_channel_list()
1366 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1367 attrs
+= p2p_attr_operating_channel()
1368 msg
['payload'] += ie_p2p(attrs
)
1370 if hapd
.mgmt_rx(timeout
=2) is None:
1371 raise Exception("No GO Neg Response " + str(dialog_token
))
1375 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1376 attrs
= p2p_attr_capability()
1377 attrs
+= p2p_attr_go_intent()
1378 attrs
+= p2p_attr_config_timeout()
1379 attrs
+= p2p_attr_listen_channel()
1380 attrs
+= p2p_attr_ext_listen_timing()
1381 #attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1382 attrs
+= p2p_attr_channel_list()
1383 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1384 attrs
+= p2p_attr_operating_channel()
1385 msg
['payload'] += ie_p2p(attrs
)
1387 if hapd
.mgmt_rx(timeout
=2) is None:
1388 raise Exception("No GO Neg Response " + str(dialog_token
))
1392 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1393 attrs
= p2p_attr_capability()
1394 attrs
+= p2p_attr_go_intent()
1395 attrs
+= p2p_attr_config_timeout()
1396 attrs
+= p2p_attr_listen_channel()
1397 attrs
+= p2p_attr_ext_listen_timing()
1398 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1399 attrs
+= p2p_attr_channel_list()
1400 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
1401 attrs
+= p2p_attr_operating_channel()
1402 msg
['payload'] += ie_p2p(attrs
)
1404 if hapd
.mgmt_rx(timeout
=2) is None:
1405 raise Exception("No GO Neg Response " + str(dialog_token
))
1408 # SA != P2P Device address
1410 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1411 attrs
= p2p_attr_capability()
1412 attrs
+= p2p_attr_go_intent()
1413 attrs
+= p2p_attr_config_timeout()
1414 attrs
+= p2p_attr_listen_channel()
1415 attrs
+= p2p_attr_ext_listen_timing()
1416 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1417 attrs
+= p2p_attr_channel_list()
1418 attrs
+= p2p_attr_device_info("02:02:02:02:02:02", config_methods
=0x0108)
1419 attrs
+= p2p_attr_operating_channel()
1420 msg
['payload'] += ie_p2p(attrs
)
1422 if hapd
.mgmt_rx(timeout
=2) is None:
1423 raise Exception("No GO Neg Response " + str(dialog_token
))
1426 # unexpected Status attribute
1428 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1429 attrs
= p2p_attr_capability()
1430 attrs
+= p2p_attr_go_intent()
1431 attrs
+= p2p_attr_config_timeout()
1432 attrs
+= p2p_attr_listen_channel()
1433 attrs
+= p2p_attr_ext_listen_timing()
1434 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1435 attrs
+= p2p_attr_channel_list()
1436 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1437 attrs
+= p2p_attr_operating_channel()
1438 attrs
+= p2p_attr_status(status
=P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
)
1439 msg
['payload'] += ie_p2p(attrs
)
1441 if hapd
.mgmt_rx(timeout
=2) is None:
1442 raise Exception("No GO Neg Response(1) " + str(dialog_token
))
1445 # valid (with workarounds) GO Neg Req
1447 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1448 #attrs = p2p_attr_capability()
1449 #attrs += p2p_attr_go_intent()
1450 #attrs += p2p_attr_config_timeout()
1451 attrs
= p2p_attr_listen_channel()
1452 attrs
+= p2p_attr_ext_listen_timing()
1453 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1454 attrs
+= p2p_attr_channel_list()
1455 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1456 attrs
+= p2p_attr_operating_channel()
1457 msg
['payload'] += ie_p2p(attrs
)
1459 check_p2p_response(hapd
, dialog_token
,
1460 P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
)
1461 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=2)
1463 raise Exception("Timeout on GO Neg event " + str(dialog_token
))
1465 dev
[0].request("P2P_CONNECT " + src
+ " 12345670 display auth")
1467 # ready - missing attributes (with workarounds) GO Neg Req
1470 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1471 #attrs = p2p_attr_capability()
1472 #attrs += p2p_attr_go_intent()
1473 #attrs += p2p_attr_config_timeout()
1474 attrs
= p2p_attr_listen_channel()
1475 attrs
+= p2p_attr_ext_listen_timing()
1476 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1477 attrs
+= p2p_attr_channel_list()
1478 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1479 attrs
+= p2p_attr_operating_channel()
1480 msg
['payload'] += ie_p2p(attrs
)
1482 if hapd
.mgmt_rx(timeout
=2) is None:
1483 raise Exception("No GO Neg Response " + str(dialog_token
))
1485 # ready - invalid GO Intent GO Neg Req
1488 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1489 #attrs = p2p_attr_capability()
1490 attrs
= p2p_attr_go_intent(go_intent
=16)
1491 #attrs += p2p_attr_config_timeout()
1492 attrs
+= p2p_attr_listen_channel()
1493 attrs
+= p2p_attr_ext_listen_timing()
1494 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1495 attrs
+= p2p_attr_channel_list()
1496 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1497 attrs
+= p2p_attr_operating_channel()
1498 msg
['payload'] += ie_p2p(attrs
)
1500 check_p2p_response(hapd
, dialog_token
, P2P_SC_FAIL_INVALID_PARAMS
)
1502 # ready - invalid Channel List
1505 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1506 attrs
= p2p_attr_capability()
1507 attrs
+= p2p_attr_go_intent()
1508 attrs
+= p2p_attr_config_timeout()
1509 attrs
+= p2p_attr_listen_channel()
1510 attrs
+= p2p_attr_ext_listen_timing()
1511 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1512 attrs
+= struct
.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST
, 16,
1514 81, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
1515 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1516 attrs
+= p2p_attr_operating_channel()
1517 msg
['payload'] += ie_p2p(attrs
)
1519 check_p2p_response(hapd
, dialog_token
, P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1521 # ready - invalid GO Neg Req (unsupported Device Password ID)
1524 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1525 attrs
= p2p_attr_capability()
1526 attrs
+= p2p_attr_go_intent()
1527 attrs
+= p2p_attr_config_timeout()
1528 attrs
+= p2p_attr_listen_channel()
1529 attrs
+= p2p_attr_ext_listen_timing()
1530 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1531 # very long channel list
1532 attrs
+= struct
.pack("<BH3BBB11B30B", P2P_ATTR_CHANNEL_LIST
, 46,
1534 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
1535 1, 1, 1, 2, 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5,
1536 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 10, 1, 10)
1537 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1538 attrs
+= p2p_attr_operating_channel()
1539 msg
['payload'] += ie_p2p(attrs
)
1541 check_p2p_response(hapd
, dialog_token
, P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD
)
1543 def mgmt_tx(dev
, msg
):
1544 for i
in range(0, 20):
1545 if "FAIL" in dev
.request(msg
):
1546 raise Exception("Failed to send Action frame")
1547 ev
= dev
.wait_event(["MGMT-TX-STATUS"], timeout
=10)
1549 raise Exception("Timeout on MGMT-TX-STATUS")
1550 if "result=SUCCESS" in ev
:
1553 if "result=SUCCESS" not in ev
:
1554 raise Exception("Peer did not ack Action frame")
1556 def rx_go_neg_req(dev
):
1559 raise Exception("MGMT-RX timeout")
1560 p2p
= parse_p2p_public_action(msg
['payload'])
1562 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1563 if p2p
['subtype'] != P2P_GO_NEG_REQ
:
1564 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1565 p2p
['freq'] = msg
['freq']
1568 def rx_go_neg_conf(dev
, status
=None, dialog_token
=None):
1571 raise Exception("MGMT-RX timeout")
1572 p2p
= parse_p2p_public_action(msg
['payload'])
1574 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1575 if p2p
['subtype'] != P2P_GO_NEG_CONF
:
1576 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1577 if dialog_token
is not None and dialog_token
!= p2p
['dialog_token']:
1578 raise Exception("Unexpected dialog token")
1579 if status
is not None and p2p
['p2p_status'] != status
:
1580 raise Exception("Unexpected status %d" % p2p
['p2p_status'])
1582 def check_p2p_go_neg_fail_event(dev
, status
):
1583 ev
= dev
.wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=5)
1585 raise Exception("GO Negotiation failure not reported")
1586 if "status=%d" % status
not in ev
:
1587 raise Exception("Unexpected failure reason: " + ev
)
1589 def test_p2p_msg_go_neg_req_reject(dev
, apdev
):
1590 """P2P protocol tests for user reject incorrectly in GO Neg Req"""
1591 addr0
= dev
[0].p2p_dev_addr()
1592 addr1
= dev
[1].p2p_dev_addr()
1594 dev
[1].discover_peer(addr0
)
1595 dev
[1].group_request("P2P_CONNECT " + addr0
+ " pbc")
1596 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
1598 raise Exception("Timeout on GO Neg Req")
1600 peer
= dev
[0].get_peer(addr1
)
1601 dev
[0].p2p_stop_find()
1603 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_REQ
, dialog_token
=123)
1604 attrs
= p2p_attr_capability()
1605 attrs
+= p2p_attr_status(status
=P2P_SC_FAIL_REJECTED_BY_USER
)
1606 attrs
+= p2p_attr_go_intent()
1607 attrs
+= p2p_attr_config_timeout()
1608 attrs
+= p2p_attr_listen_channel()
1609 attrs
+= p2p_attr_ext_listen_timing()
1610 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1611 attrs
+= p2p_attr_channel_list()
1612 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1613 attrs
+= p2p_attr_operating_channel()
1614 msg
['payload'] += ie_p2p(attrs
)
1616 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1618 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=5)
1620 raise Exception("GO Negotiation failure not reported")
1621 if "status=%d" % P2P_SC_FAIL_REJECTED_BY_USER
not in ev
:
1622 raise Exception("Unexpected failure reason: " + ev
)
1624 def test_p2p_msg_unexpected_go_neg_resp(dev
, apdev
):
1625 """P2P protocol tests for unexpected GO Neg Resp"""
1626 addr0
= dev
[0].p2p_dev_addr()
1627 addr1
= dev
[1].p2p_dev_addr()
1629 dev
[0].discover_peer(addr1
)
1630 dev
[0].p2p_stop_find()
1632 peer
= dev
[0].get_peer(addr1
)
1634 logger
.debug("GO Neg Resp without GO Neg session")
1635 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=123)
1636 attrs
= p2p_attr_status()
1637 attrs
+= p2p_attr_capability()
1638 attrs
+= p2p_attr_go_intent()
1639 attrs
+= p2p_attr_config_timeout()
1640 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1641 attrs
+= p2p_attr_channel_list()
1642 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1643 attrs
+= p2p_attr_operating_channel()
1644 msg
['payload'] += ie_p2p(attrs
)
1645 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1648 dev
[1].discover_peer(addr0
)
1650 logger
.debug("Unexpected GO Neg Resp while waiting for new GO Neg session")
1651 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1652 raise Exception("P2P_CONNECT failed")
1653 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
1655 raise Exception("Timeout on GO Neg Req")
1656 dev
[0].p2p_stop_find()
1657 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1659 logger
.debug("Invalid attribute in GO Neg Response")
1660 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=197)
1661 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
1662 msg
['payload'] += ie_p2p(attrs
)
1663 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1664 frame
= dev
[0].mgmt_rx(timeout
=0.1)
1665 if frame
is not None:
1666 raise Exception("Unexpected GO Neg Confirm")
1668 logger
.debug("GO Neg Resp with unexpected dialog token")
1669 dev
[1].p2p_stop_find()
1670 if "FAIL" in dev
[0].request("SET ext_mgmt_frame_handling 1"):
1671 raise Exception("Failed to enable external management frame handling")
1673 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1674 raise Exception("P2P_CONNECT failed(2)")
1675 p2p
= rx_go_neg_req(dev
[0])
1676 dev
[0].p2p_stop_find()
1677 dialog_token
= p2p
['dialog_token']
1678 if dialog_token
< 255:
1682 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1683 attrs
= p2p_attr_status()
1684 attrs
+= p2p_attr_capability()
1685 attrs
+= p2p_attr_go_intent()
1686 attrs
+= p2p_attr_config_timeout()
1687 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1688 attrs
+= p2p_attr_channel_list()
1689 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1690 attrs
+= p2p_attr_operating_channel()
1691 msg
['payload'] += ie_p2p(attrs
)
1692 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1694 logger
.debug("GO Neg Resp without Status")
1695 dev
[1].p2p_stop_find()
1697 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1698 raise Exception("P2P_CONNECT failed(2)")
1699 p2p
= rx_go_neg_req(dev
[0])
1700 dev
[0].p2p_stop_find()
1701 dialog_token
= p2p
['dialog_token']
1702 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1703 #attrs = p2p_attr_status()
1704 attrs
= p2p_attr_capability()
1705 attrs
+= p2p_attr_go_intent()
1706 attrs
+= p2p_attr_config_timeout()
1707 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1708 attrs
+= p2p_attr_channel_list()
1709 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1710 attrs
+= p2p_attr_operating_channel()
1711 msg
['payload'] += ie_p2p(attrs
)
1712 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1713 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1714 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1716 logger
.debug("GO Neg Resp without Intended Address")
1717 dev
[1].p2p_stop_find()
1719 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1720 raise Exception("P2P_CONNECT failed(2)")
1721 p2p
= rx_go_neg_req(dev
[0])
1722 dev
[0].p2p_stop_find()
1723 dialog_token
= p2p
['dialog_token']
1724 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1725 attrs
= p2p_attr_status()
1726 #attrs += p2p_attr_capability()
1727 attrs
+= p2p_attr_go_intent()
1728 attrs
+= p2p_attr_config_timeout()
1729 #attrs += p2p_attr_intended_interface_addr(addr0)
1730 attrs
+= p2p_attr_channel_list()
1731 #attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1732 attrs
+= p2p_attr_operating_channel()
1733 msg
['payload'] += ie_p2p(attrs
)
1734 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1735 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1736 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1738 logger
.debug("GO Neg Resp without GO Intent")
1739 dev
[1].p2p_stop_find()
1741 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1742 raise Exception("P2P_CONNECT failed(2)")
1743 p2p
= rx_go_neg_req(dev
[0])
1744 dev
[0].p2p_stop_find()
1745 dialog_token
= p2p
['dialog_token']
1746 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1747 attrs
= p2p_attr_status()
1748 attrs
+= p2p_attr_capability()
1749 #attrs += p2p_attr_go_intent()
1750 attrs
+= p2p_attr_config_timeout()
1751 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1752 attrs
+= p2p_attr_channel_list()
1753 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1754 attrs
+= p2p_attr_operating_channel()
1755 msg
['payload'] += ie_p2p(attrs
)
1756 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1757 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1758 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1760 logger
.debug("GO Neg Resp with invalid GO Intent")
1761 dev
[1].p2p_stop_find()
1763 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1764 raise Exception("P2P_CONNECT failed(2)")
1765 p2p
= rx_go_neg_req(dev
[0])
1766 dev
[0].p2p_stop_find()
1767 dialog_token
= p2p
['dialog_token']
1768 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1769 attrs
= p2p_attr_status()
1770 attrs
+= p2p_attr_capability()
1771 attrs
+= p2p_attr_go_intent(go_intent
=16)
1772 attrs
+= p2p_attr_config_timeout()
1773 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1774 attrs
+= p2p_attr_channel_list()
1775 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1776 attrs
+= p2p_attr_operating_channel()
1777 msg
['payload'] += ie_p2p(attrs
)
1778 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1779 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1780 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1782 logger
.debug("GO Neg Resp with incompatible GO Intent")
1783 dev
[1].p2p_stop_find()
1785 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=15"):
1786 raise Exception("P2P_CONNECT failed(2)")
1787 p2p
= rx_go_neg_req(dev
[0])
1788 dev
[0].p2p_stop_find()
1789 dialog_token
= p2p
['dialog_token']
1790 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1791 attrs
= p2p_attr_status()
1792 attrs
+= p2p_attr_capability()
1793 attrs
+= p2p_attr_go_intent(go_intent
=15)
1794 attrs
+= p2p_attr_config_timeout()
1795 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1796 attrs
+= p2p_attr_channel_list()
1797 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1798 attrs
+= p2p_attr_operating_channel()
1799 msg
['payload'] += ie_p2p(attrs
)
1800 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1801 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INCOMPATIBLE_PARAMS
)
1802 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INCOMPATIBLE_PARAMS
, dialog_token
)
1804 logger
.debug("GO Neg Resp without P2P Group ID")
1805 dev
[1].p2p_stop_find()
1807 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1808 raise Exception("P2P_CONNECT failed(2)")
1809 p2p
= rx_go_neg_req(dev
[0])
1810 dev
[0].p2p_stop_find()
1811 dialog_token
= p2p
['dialog_token']
1812 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1813 attrs
= p2p_attr_status()
1814 attrs
+= p2p_attr_capability()
1815 attrs
+= p2p_attr_go_intent(go_intent
=15)
1816 attrs
+= p2p_attr_config_timeout()
1817 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1818 attrs
+= p2p_attr_channel_list()
1819 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1820 attrs
+= p2p_attr_operating_channel()
1821 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
1822 msg
['payload'] += ie_p2p(attrs
)
1823 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1824 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1825 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1827 logger
.debug("GO Neg Resp without Operating Channel")
1828 dev
[1].p2p_stop_find()
1830 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1831 raise Exception("P2P_CONNECT failed(2)")
1832 p2p
= rx_go_neg_req(dev
[0])
1833 dev
[0].p2p_stop_find()
1834 dialog_token
= p2p
['dialog_token']
1835 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1836 attrs
= p2p_attr_status()
1837 attrs
+= p2p_attr_capability()
1838 attrs
+= p2p_attr_go_intent(go_intent
=15)
1839 #attrs += p2p_attr_config_timeout()
1840 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1841 attrs
+= p2p_attr_channel_list()
1842 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1843 #attrs += p2p_attr_operating_channel()
1844 attrs
+= p2p_attr_group_id(addr0
, "DIRECT-foo")
1845 msg
['payload'] += ie_p2p(attrs
)
1846 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1847 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1848 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1850 logger
.debug("GO Neg Resp without Channel List")
1851 dev
[1].p2p_stop_find()
1853 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1854 raise Exception("P2P_CONNECT failed(2)")
1855 p2p
= rx_go_neg_req(dev
[0])
1856 dev
[0].p2p_stop_find()
1857 dialog_token
= p2p
['dialog_token']
1858 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1859 attrs
= p2p_attr_status()
1860 attrs
+= p2p_attr_capability()
1861 attrs
+= p2p_attr_go_intent(go_intent
=15)
1862 attrs
+= p2p_attr_config_timeout()
1863 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1864 #attrs += p2p_attr_channel_list()
1865 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1866 attrs
+= p2p_attr_operating_channel()
1867 attrs
+= p2p_attr_group_id(addr0
, "DIRECT-foo")
1868 msg
['payload'] += ie_p2p(attrs
)
1869 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1870 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1871 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1873 logger
.debug("GO Neg Resp without common channels")
1874 dev
[1].p2p_stop_find()
1876 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1877 raise Exception("P2P_CONNECT failed(2)")
1878 p2p
= rx_go_neg_req(dev
[0])
1879 dev
[0].p2p_stop_find()
1880 dialog_token
= p2p
['dialog_token']
1881 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1882 attrs
= p2p_attr_status()
1883 attrs
+= p2p_attr_capability()
1884 attrs
+= p2p_attr_go_intent(go_intent
=15)
1885 attrs
+= p2p_attr_config_timeout()
1886 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1887 attrs
+= struct
.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST
, 5,
1890 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1891 attrs
+= p2p_attr_operating_channel()
1892 attrs
+= p2p_attr_group_id(addr0
, "DIRECT-foo")
1893 msg
['payload'] += ie_p2p(attrs
)
1894 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1895 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1896 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_NO_COMMON_CHANNELS
, dialog_token
)
1898 def test_p2p_msg_group_info(dev
):
1899 """P2P protocol tests for Group Info parsing"""
1901 _test_p2p_msg_group_info(dev
)
1903 dev
[0].request("VENDOR_ELEM_REMOVE 2 *")
1905 def _test_p2p_msg_group_info(dev
):
1906 tests
= [ "dd08506f9a090e010001",
1907 "dd08506f9a090e010000",
1908 "dd20506f9a090e190018" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "ff",
1909 "dd20506f9a090e190018" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00",
1910 "dd24506f9a090e1d001c" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00" + "00000000",
1911 "dd24506f9a090e1d001c" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00" + "10110001",
1912 "dd24506f9a090e1d001c" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00" + "1011ffff" ]
1914 dev
[0].request("VENDOR_ELEM_REMOVE 2 *")
1915 if "OK" not in dev
[0].request("VENDOR_ELEM_ADD 2 " + t
):
1916 raise Exception("VENDOR_ELEM_ADD failed")
1917 dev
[0].p2p_start_go(freq
=2412)
1918 bssid
= dev
[0].get_group_status_field('bssid')
1919 dev
[2].request("BSS_FLUSH 0")
1920 dev
[2].scan_for_bss(bssid
, freq
=2412, force_scan
=True)
1921 bss
= dev
[2].request("BSS " + bssid
)
1922 if 'p2p_group_client' in bss
:
1923 raise Exception("Unexpected p2p_group_client")
1924 dev
[0].remove_group()
1926 MGMT_SUBTYPE_ACTION
= 13
1927 ACTION_CATEG_PUBLIC
= 4
1929 GAS_INITIAL_REQUEST
= 10
1930 GAS_INITIAL_RESPONSE
= 11
1931 GAS_COMEBACK_REQUEST
= 12
1932 GAS_COMEBACK_RESPONSE
= 13
1934 def gas_hdr(dst
, src
, type, req
=True, dialog_token
=0):
1936 msg
['fc'] = MGMT_SUBTYPE_ACTION
<< 4
1943 if dialog_token
is None:
1944 msg
['payload'] = struct
.pack("<BB", ACTION_CATEG_PUBLIC
, type)
1946 msg
['payload'] = struct
.pack("<BBB", ACTION_CATEG_PUBLIC
, type,
1951 def test_p2p_msg_sd(dev
, apdev
):
1952 """P2P protocol tests for service discovery messages"""
1953 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1955 logger
.debug("Truncated GAS Initial Request - no Dialog Token field")
1956 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
, dialog_token
=None)
1959 logger
.debug("Truncated GAS Initial Request - no Advertisement Protocol element")
1960 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1963 logger
.debug("Truncated GAS Initial Request - no Advertisement Protocol element length")
1964 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1965 msg
['payload'] += struct
.pack('B', 108)
1968 logger
.debug("Invalid GAS Initial Request - unexpected IE")
1969 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1970 msg
['payload'] += struct
.pack('BB', 0, 0)
1973 logger
.debug("Truncated GAS Initial Request - too short Advertisement Protocol element")
1974 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1975 msg
['payload'] += struct
.pack('BB', 108, 0)
1978 logger
.debug("Truncated GAS Initial Request - too short Advertisement Protocol element 2")
1979 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1980 msg
['payload'] += struct
.pack('BBB', 108, 1, 127)
1983 logger
.debug("Invalid GAS Initial Request - unsupported GAS advertisement protocol id 255")
1984 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1985 msg
['payload'] += struct
.pack('BBBB', 108, 2, 127, 255)
1988 logger
.debug("Truncated GAS Initial Request - no Query Request length field")
1989 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1990 msg
['payload'] += anqp_adv_proto()
1993 logger
.debug("Truncated GAS Initial Request - too short Query Request length field")
1994 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1995 msg
['payload'] += anqp_adv_proto()
1996 msg
['payload'] += struct
.pack('<B', 0)
1999 logger
.debug("Truncated GAS Initial Request - too short Query Request field (minimum underflow)")
2000 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2001 msg
['payload'] += anqp_adv_proto()
2002 msg
['payload'] += struct
.pack('<H', 1)
2005 logger
.debug("Truncated GAS Initial Request - too short Query Request field (maximum underflow)")
2006 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2007 msg
['payload'] += anqp_adv_proto()
2008 msg
['payload'] += struct
.pack('<H', 65535)
2011 logger
.debug("Truncated GAS Initial Request - too short Query Request field")
2012 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2013 msg
['payload'] += anqp_adv_proto()
2014 msg
['payload'] += struct
.pack('<H', 0)
2017 logger
.debug("Invalid GAS Initial Request - unsupported ANQP Info ID 65535")
2018 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2019 msg
['payload'] += anqp_adv_proto()
2020 msg
['payload'] += struct
.pack('<HHH', 4, 65535, 0)
2023 logger
.debug("Invalid GAS Initial Request - invalid ANQP Query Request length (truncated frame)")
2024 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2025 msg
['payload'] += anqp_adv_proto()
2026 msg
['payload'] += struct
.pack('<HHH', 4, 56797, 65535)
2029 logger
.debug("Invalid GAS Initial Request - invalid ANQP Query Request length (too short Query Request to contain OUI + OUI-type)")
2030 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2031 msg
['payload'] += anqp_adv_proto()
2032 msg
['payload'] += struct
.pack('<HHH', 4, 56797, 0)
2035 logger
.debug("Invalid GAS Initial Request - unsupported ANQP vendor OUI-type")
2036 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2037 msg
['payload'] += anqp_adv_proto()
2038 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a00)
2039 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2042 logger
.debug("Truncated GAS Initial Request - no Service Update Indicator")
2043 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2044 msg
['payload'] += anqp_adv_proto()
2045 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a09)
2046 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2049 logger
.debug("Truncated GAS Initial Request - truncated Service Update Indicator")
2050 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2051 msg
['payload'] += anqp_adv_proto()
2052 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a09)
2053 req
+= struct
.pack('<B', 0)
2054 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2057 logger
.debug("Unexpected GAS Initial Response")
2059 msg
= gas_hdr(dst
, src
, GAS_INITIAL_RESPONSE
)
2060 msg
['payload'] += struct
.pack('<HH', 0, 0)
2061 msg
['payload'] += anqp_adv_proto()
2062 msg
['payload'] += struct
.pack('<H', 0)
2065 logger
.debug("Truncated GAS Comeback Request - no Dialog Token field")
2066 msg
= gas_hdr(dst
, src
, GAS_COMEBACK_REQUEST
, dialog_token
=None)
2069 logger
.debug("GAS Comeback Request - no pending SD response fragment available")
2070 msg
= gas_hdr(dst
, src
, GAS_COMEBACK_REQUEST
)
2073 logger
.debug("Unexpected GAS Comeback Response")
2075 msg
= gas_hdr(dst
, src
, GAS_COMEBACK_RESPONSE
)
2076 msg
['payload'] += struct
.pack('<HBH', 0, 0, 0)
2077 msg
['payload'] += anqp_adv_proto()
2078 msg
['payload'] += struct
.pack('<H', 0)
2081 logger
.debug("Minimal GAS Initial Request")
2083 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2084 msg
['payload'] += anqp_adv_proto()
2085 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a09)
2086 req
+= struct
.pack('<H', 0)
2087 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2089 resp
= hapd
.mgmt_rx()
2091 raise Exception("No response to minimal GAS Initial Request")