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.
11 logger
= logging
.getLogger()
14 from p2p_utils
import *
15 from test_gas
import anqp_adv_proto
18 return struct
.pack("<BB", WLAN_EID_SSID
, len(ssid
)) + ssid
21 return struct
.pack("<BBBBBBBBBB", WLAN_EID_SUPP_RATES
, 8,
22 2*6, 2*9, 2*12, 2*18, 2*24, 2*36, 2*48, 2*54)
25 return struct
.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC
, 4 + len(attrs
),
26 0x50, 0x6f, 0x9a, 9) + attrs
29 return struct
.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC
, 4 + len(attrs
),
30 0x00, 0x50, 0xf2, 4) + attrs
32 def wsc_attr_config_methods(methods
=0):
33 return struct
.pack(">HHH", WSC_ATTR_CONFIG_METHODS
, 2, methods
)
35 def p2p_attr_status(status
=P2P_SC_SUCCESS
):
36 return struct
.pack("<BHB", P2P_ATTR_STATUS
, 1, status
)
38 def p2p_attr_minor_reason_code(code
=0):
39 return struct
.pack("<BHB", P2P_ATTR_MINOR_REASON_CODE
, 1, code
)
41 def p2p_attr_capability(dev_capab
=0, group_capab
=0):
42 return struct
.pack("<BHBB", P2P_ATTR_CAPABILITY
, 2, dev_capab
, group_capab
)
44 def p2p_attr_device_id(addr
):
45 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
46 t
= (P2P_ATTR_DEVICE_ID
, 6) + val
47 return struct
.pack('<BH6B', *t
)
49 def p2p_attr_go_intent(go_intent
=0, tie_breaker
=0):
50 return struct
.pack("<BHB", P2P_ATTR_GROUP_OWNER_INTENT
, 1,
51 (go_intent
<< 1) |
(tie_breaker
& 0x01))
53 def p2p_attr_config_timeout(go_config_timeout
=0, client_config_timeout
=0):
54 return struct
.pack("<BHBB", P2P_ATTR_CONFIGURATION_TIMEOUT
, 2,
55 go_config_timeout
, client_config_timeout
)
57 def p2p_attr_listen_channel(op_class
=81, chan
=1):
58 return struct
.pack("<BHBBBBB", P2P_ATTR_LISTEN_CHANNEL
, 5,
59 0x58, 0x58, 0x04, op_class
, chan
)
61 def p2p_attr_group_bssid(addr
):
62 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
63 t
= (P2P_ATTR_GROUP_BSSID
, 6) + val
64 return struct
.pack('<BH6B', *t
)
66 def p2p_attr_ext_listen_timing(period
=0, interval
=0):
67 return struct
.pack("<BHHH", P2P_ATTR_EXT_LISTEN_TIMING
, 4, period
, interval
)
69 def p2p_attr_intended_interface_addr(addr
):
70 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
71 t
= (P2P_ATTR_INTENDED_INTERFACE_ADDR
, 6) + val
72 return struct
.pack('<BH6B', *t
)
74 def p2p_attr_manageability(bitmap
=0):
75 return struct
.pack("<BHB", P2P_ATTR_MANAGEABILITY
, 1, bitmap
)
77 def p2p_attr_channel_list():
78 return struct
.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST
, 16,
80 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
82 def p2p_attr_device_info(addr
, name
="Test", config_methods
=0, dev_type
="00010050F2040001"):
83 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
84 val2
= struct
.unpack('8B', binascii
.unhexlify(dev_type
))
85 t
= (P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 4 + len(name
)) + val
87 return struct
.pack("<BH6B", *t
) + struct
.pack(">H", config_methods
) + struct
.pack("8BB", *t2
) + struct
.pack('>HH', 0x1011, len(name
)) +name
89 def p2p_attr_group_id(addr
, ssid
):
90 val
= struct
.unpack('6B', binascii
.unhexlify(addr
.replace(':','')))
91 t
= (P2P_ATTR_GROUP_ID
, 6 + len(ssid
)) + val
92 return struct
.pack('<BH6B', *t
) + ssid
94 def p2p_attr_operating_channel(op_class
=81, chan
=1):
95 return struct
.pack("<BHBBBBB", P2P_ATTR_OPERATING_CHANNEL
, 5,
96 0x58, 0x58, 0x04, op_class
, chan
)
98 def p2p_attr_invitation_flags(bitmap
=0):
99 return struct
.pack("<BHB", P2P_ATTR_INVITATION_FLAGS
, 1, bitmap
)
101 def p2p_hdr_helper(dst
, src
, type=None, dialog_token
=1, req
=True):
103 msg
['fc'] = MGMT_SUBTYPE_ACTION
<< 4
110 msg
['payload'] = struct
.pack("<BBBBBB",
111 ACTION_CATEG_PUBLIC
, 9, 0x50, 0x6f, 0x9a, 9)
113 msg
['payload'] += struct
.pack("<B", type)
115 msg
['payload'] += struct
.pack("<B", dialog_token
)
118 def p2p_hdr(dst
, src
, type=None, dialog_token
=1):
119 return p2p_hdr_helper(dst
, src
, type, dialog_token
, True)
121 def p2p_hdr_resp(dst
, src
, type=None, dialog_token
=1):
122 return p2p_hdr_helper(dst
, src
, type, dialog_token
, False)
124 def start_p2p(dev
, apdev
):
125 addr0
= dev
[0].p2p_dev_addr()
127 dev
[1].p2p_find(social
=True)
128 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
130 raise Exception("Device discovery timed out")
131 dev
[1].p2p_stop_find()
132 peer
= dev
[1].get_peer(addr0
)
134 bssid
= apdev
[0]['bssid']
135 params
= { 'ssid': "test", 'beacon_int': "2000" }
136 if peer
['listen_freq'] == "2412":
137 params
['channel'] = '1'
138 elif peer
['listen_freq'] == "2437":
139 params
['channel'] = '6'
140 elif peer
['listen_freq'] == "2462":
141 params
['channel'] = '11'
142 hapd
= hostapd
.add_ap(apdev
[0], params
)
143 hapd
.set("ext_mgmt_frame_handling", "1")
144 return addr0
, bssid
, hapd
, int(params
['channel'])
146 def p2p_probe(hapd
, src
, chan
=1):
148 msg
['fc'] = MGMT_SUBTYPE_PROBE_REQ
<< 4
149 msg
['da'] = "ff:ff:ff:ff:ff:ff"
151 msg
['bssid'] = "ff:ff:ff:ff:ff:ff"
152 attrs
= p2p_attr_listen_channel(chan
=chan
)
153 msg
['payload'] = ie_ssid("DIRECT-") + ie_supp_rates() + ie_p2p(attrs
)
156 def parse_p2p_public_action(payload
):
158 (category
, action
) = struct
.unpack('BB', pos
[0:2])
159 if category
!= ACTION_CATEG_PUBLIC
:
164 (oui1
,oui2
,oui3
,subtype
) = struct
.unpack('BBBB', pos
[0:4])
165 if oui1
!= 0x50 or oui2
!= 0x6f or oui3
!= 0x9a or subtype
!= 9:
168 (subtype
,dialog_token
) = struct
.unpack('BB', pos
[0:2])
170 p2p
['subtype'] = subtype
171 p2p
['dialog_token'] = dialog_token
173 p2p
['elements'] = pos
175 (id,elen
) = struct
.unpack('BB', pos
[0:2])
178 raise Exception("Truncated IE in P2P Public Action frame (elen=%d left=%d)" % (elen
, len(pos
)))
179 if id == WLAN_EID_VENDOR_SPECIFIC
:
181 raise Exception("Too short vendor specific IE in P2P Public Action frame (elen=%d)" % elen
)
182 (oui1
,oui2
,oui3
,subtype
) = struct
.unpack('BBBB', pos
[0:4])
183 if oui1
== 0x50 and oui2
== 0x6f and oui3
== 0x9a and subtype
== 9:
185 p2p
['p2p'] += pos
[4:elen
]
187 p2p
['p2p'] = pos
[4:elen
]
188 if oui1
== 0x00 and oui2
== 0x50 and oui3
== 0xf2 and subtype
== 4:
189 p2p
['wsc'] = pos
[4:elen
]
192 raise Exception("Invalid element in P2P Public Action frame")
195 p2p
['p2p_attrs'] = {}
198 (id,alen
) = struct
.unpack('<BH', pos
[0:3])
201 logger
.info("P2P payload: " + binascii
.hexlify(p2p
['p2p']))
202 raise Exception("Truncated P2P attribute in P2P Public Action frame (alen=%d left=%d p2p-payload=%d)" % (alen
, len(pos
), len(p2p
['p2p'])))
203 p2p
['p2p_attrs'][id] = pos
[0:alen
]
205 if P2P_ATTR_STATUS
in p2p
['p2p_attrs']:
206 p2p
['p2p_status'] = struct
.unpack('B', p2p
['p2p_attrs'][P2P_ATTR_STATUS
])[0]
209 p2p
['wsc_attrs'] = {}
212 (id,alen
) = struct
.unpack('>HH', pos
[0:4])
215 logger
.info("WSC payload: " + binascii
.hexlify(p2p
['wsc']))
216 raise Exception("Truncated WSC attribute in P2P Public Action frame (alen=%d left=%d wsc-payload=%d)" % (alen
, len(pos
), len(p2p
['wsc'])))
217 p2p
['wsc_attrs'][id] = pos
[0:alen
]
222 def test_p2p_msg_empty(dev
, apdev
):
223 """P2P protocol test: empty P2P Public Action frame"""
224 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
225 msg
= p2p_hdr(dst
, src
)
228 def test_p2p_msg_long_ssid(dev
, apdev
):
229 """P2P protocol test: Too long SSID in P2P Public Action frame"""
230 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
232 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=1)
233 attrs
= p2p_attr_config_timeout()
234 attrs
+= p2p_attr_invitation_flags()
235 attrs
+= p2p_attr_operating_channel()
236 attrs
+= p2p_attr_group_bssid(src
)
237 attrs
+= p2p_attr_channel_list()
238 attrs
+= p2p_attr_group_id(src
, 'DIRECT-foo')
239 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
240 msg
['payload'] += ie_p2p(attrs
)
241 msg
['payload'] += ie_ssid(255 * 'A')
243 ev
= dev
[0].wait_event(["P2P-DEVICE-FOUND"], timeout
=5)
245 raise Exception("Timeout on device found event")
247 def test_p2p_msg_long_dev_name(dev
, apdev
):
248 """P2P protocol test: Too long Device Name in P2P Public Action frame"""
249 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
251 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=1)
252 attrs
= p2p_attr_config_timeout()
253 attrs
+= p2p_attr_invitation_flags()
254 attrs
+= p2p_attr_operating_channel()
255 attrs
+= p2p_attr_group_bssid(src
)
256 attrs
+= p2p_attr_channel_list()
257 attrs
+= p2p_attr_group_id(src
, 'DIRECT-foo')
258 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108,
259 name
="123456789012345678901234567890123")
260 msg
['payload'] += ie_p2p(attrs
)
262 ev
= dev
[0].wait_event(["P2P-DEVICE-FOUND"], timeout
=0.1)
264 raise Exception("Unexpected device found event")
266 def test_p2p_msg_invitation_req(dev
, apdev
):
267 """P2P protocol tests for invitation request processing"""
268 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
270 # Empty P2P Invitation Request (missing dialog token)
271 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=None)
275 # Various p2p_parse() failure cases due to invalid attributes
277 # Too short attribute header
279 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
280 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
281 msg
['payload'] += ie_p2p(attrs
)
284 # Minimal attribute underflow
286 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
287 attrs
= struct
.pack("<BH", P2P_ATTR_CAPABILITY
, 1)
288 msg
['payload'] += ie_p2p(attrs
)
291 # Large attribute underflow
293 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
294 attrs
= struct
.pack("<BHB", P2P_ATTR_CAPABILITY
, 0xffff, 1)
295 msg
['payload'] += ie_p2p(attrs
)
298 # Too short Capability attribute
300 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
301 attrs
= struct
.pack("<BHB", P2P_ATTR_CAPABILITY
, 1, 0)
302 msg
['payload'] += ie_p2p(attrs
)
305 # Too short Device ID attribute
307 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
308 val
= struct
.unpack('5B', binascii
.unhexlify("1122334455"))
309 t
= (P2P_ATTR_DEVICE_ID
, 5) + val
310 attrs
= struct
.pack('<BH5B', *t
)
311 msg
['payload'] += ie_p2p(attrs
)
314 # Too short GO Intent attribute
316 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
317 attrs
= struct
.pack("<BH", P2P_ATTR_GROUP_OWNER_INTENT
, 0)
318 msg
['payload'] += ie_p2p(attrs
)
321 # Too short Status attribute
323 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
324 attrs
= struct
.pack("<BH", P2P_ATTR_STATUS
, 0)
325 msg
['payload'] += ie_p2p(attrs
)
328 # null Listen channel and too short Listen Channel attribute
330 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
331 attrs
= struct
.pack("<BH", P2P_ATTR_LISTEN_CHANNEL
, 0)
332 attrs
+= struct
.pack("<BHB", P2P_ATTR_LISTEN_CHANNEL
, 1, 0)
333 msg
['payload'] += ie_p2p(attrs
)
336 # null Operating channel and too short Operating Channel attribute
338 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
339 attrs
= struct
.pack("<BH", P2P_ATTR_OPERATING_CHANNEL
, 0)
340 attrs
+= struct
.pack("<BHB", P2P_ATTR_OPERATING_CHANNEL
, 1, 0)
341 msg
['payload'] += ie_p2p(attrs
)
344 # Too short Channel List attribute
346 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
347 attrs
= struct
.pack("<BHBB", P2P_ATTR_CHANNEL_LIST
, 2, 1, 2)
348 msg
['payload'] += ie_p2p(attrs
)
351 # Too short Device Info attribute
353 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
354 attrs
= struct
.pack("<BHBB", P2P_ATTR_DEVICE_INFO
, 2, 1, 2)
355 msg
['payload'] += ie_p2p(attrs
)
358 # Truncated Secondary Device Types in Device Info attribute
360 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
361 attrs
= struct
.pack("<BH6BH8BB", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1,
364 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22,
366 msg
['payload'] += ie_p2p(attrs
)
369 # Missing Device Name in Device Info attribute
371 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
372 attrs
= struct
.pack("<BH6BH8BB8B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8,
375 0, 0, 0, 0, 0, 0, 0, 0,
377 1, 2, 3, 4, 5, 6, 7, 8)
378 msg
['payload'] += ie_p2p(attrs
)
381 # Invalid Device Name header in Device Info attribute
383 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
384 attrs
= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4,
387 0, 0, 0, 0, 0, 0, 0, 0,
389 1, 2, 3, 4, 5, 6, 7, 8,
391 msg
['payload'] += ie_p2p(attrs
)
394 # Invalid Device Name header length in Device Info attribute
396 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
397 attrs
= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4,
400 0, 0, 0, 0, 0, 0, 0, 0,
402 1, 2, 3, 4, 5, 6, 7, 8,
403 0x10, 0x11, 0xff, 0xff)
404 msg
['payload'] += ie_p2p(attrs
)
407 # Invalid Device Name header length in Device Info attribute
409 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 + len(devname
),
414 0, 0, 0, 0, 0, 0, 0, 0,
416 1, 2, 3, 4, 5, 6, 7, 8,
417 0x10, 0x11, 0, len(devname
) + 1) + devname
418 msg
['payload'] += ie_p2p(attrs
)
421 # Device Name filtering and too long Device Name in Device Info attribute
423 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
424 attrs
= struct
.pack("<BH6BH8BB8B4B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4 + 4,
427 0, 0, 0, 0, 0, 0, 0, 0,
429 1, 2, 3, 4, 5, 6, 7, 8,
432 devname
= '123456789012345678901234567890123'
433 attrs
+= struct
.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO
, 6 + 2 + 8 + 1 + 8 + 4 + len(devname
),
436 0, 0, 0, 0, 0, 0, 0, 0,
438 1, 2, 3, 4, 5, 6, 7, 8,
439 0x10, 0x11, 0, len(devname
)) + devname
440 msg
['payload'] += ie_p2p(attrs
)
443 # Too short Configuration Timeout attribute
445 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
446 attrs
= struct
.pack("<BHB", P2P_ATTR_CONFIGURATION_TIMEOUT
, 1, 1)
447 msg
['payload'] += ie_p2p(attrs
)
450 # Too short Intended P2P Interface Address attribute
452 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
453 attrs
= struct
.pack("<BHB", P2P_ATTR_INTENDED_INTERFACE_ADDR
, 1, 1)
454 msg
['payload'] += ie_p2p(attrs
)
457 # Too short P2P Group BSSID attribute
459 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
460 attrs
= struct
.pack("<BHB", P2P_ATTR_GROUP_BSSID
, 1, 1)
461 msg
['payload'] += ie_p2p(attrs
)
464 # Too short P2P Group ID attribute
466 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
467 attrs
= struct
.pack("<BHB", P2P_ATTR_GROUP_ID
, 1, 1)
468 msg
['payload'] += ie_p2p(attrs
)
471 # Too long P2P Group ID attribute
473 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
474 attrs
= struct
.pack("<BH6B", P2P_ATTR_GROUP_ID
, 6 + 33, 0, 0, 0, 0, 0, 0) + "123456789012345678901234567890123"
475 msg
['payload'] += ie_p2p(attrs
)
478 # Too short Invitation Flags attribute
480 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
481 attrs
= struct
.pack("<BH", P2P_ATTR_INVITATION_FLAGS
, 0)
482 msg
['payload'] += ie_p2p(attrs
)
485 # Valid and too short Manageability attribute
487 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
488 attrs
= p2p_attr_manageability()
489 attrs
+= struct
.pack("<BH", P2P_ATTR_MANAGEABILITY
, 0)
490 msg
['payload'] += ie_p2p(attrs
)
493 # Too short NoA attribute
495 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
496 attrs
= struct
.pack("<BHB", P2P_ATTR_NOTICE_OF_ABSENCE
, 1, 1)
497 msg
['payload'] += ie_p2p(attrs
)
500 # Valid and too short Extended Listen Timing attributes
502 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
503 attrs
= p2p_attr_ext_listen_timing(period
=100, interval
=50)
504 attrs
+= struct
.pack("<BHBBB", P2P_ATTR_EXT_LISTEN_TIMING
, 3, 0, 0, 0)
505 msg
['payload'] += ie_p2p(attrs
)
508 # Valid and too short Minor Reason Code attributes
510 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
511 attrs
= p2p_attr_minor_reason_code(code
=2)
512 attrs
+= struct
.pack("<BH", P2P_ATTR_MINOR_REASON_CODE
, 0)
513 msg
['payload'] += ie_p2p(attrs
)
516 # Unknown attribute and too short OOB GO Negotiation Channel attribute
518 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
519 attrs
= struct
.pack("<BHB", 99, 1, 1)
520 attrs
+= struct
.pack("<BHB", P2P_ATTR_OOB_GO_NEG_CHANNEL
, 1, 1)
521 msg
['payload'] += ie_p2p(attrs
)
524 # Too short Service Hash attribute
526 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
527 attrs
= struct
.pack("<BH5B", P2P_ATTR_SERVICE_HASH
, 5, 1, 2, 3, 4, 5)
528 msg
['payload'] += ie_p2p(attrs
)
531 # Too short Connection Capability attribute
533 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
534 attrs
= struct
.pack("<BH", P2P_ATTR_CONNECTION_CAPABILITY
, 0)
535 msg
['payload'] += ie_p2p(attrs
)
538 # Too short Advertisement ID attribute
540 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
541 attrs
= struct
.pack("<BH9B", P2P_ATTR_ADVERTISEMENT_ID
, 9, 1, 2, 3, 4, 5,
543 msg
['payload'] += ie_p2p(attrs
)
546 # Truncated and too short Service Instance attributes
548 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
549 attrs
= struct
.pack("<BH8B", P2P_ATTR_ADVERTISED_SERVICE
, 8, 1, 2, 3, 4, 5,
551 attrs
+= struct
.pack("<BH7B", P2P_ATTR_ADVERTISED_SERVICE
, 7, 1, 2, 3, 4, 5,
553 msg
['payload'] += ie_p2p(attrs
)
556 # Too short Session ID attribute
558 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
559 attrs
= struct
.pack("<BH4B", P2P_ATTR_SESSION_ID
, 4, 1, 2, 3, 4)
560 msg
['payload'] += ie_p2p(attrs
)
563 # Too short Feature Capability attribute
565 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
566 attrs
= struct
.pack("<BH", P2P_ATTR_FEATURE_CAPABILITY
, 0)
567 msg
['payload'] += ie_p2p(attrs
)
570 # Too short Persistent Group attribute
572 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
573 attrs
= struct
.pack("<BH5B", P2P_ATTR_PERSISTENT_GROUP
, 5, 1, 2, 3, 4, 5)
574 msg
['payload'] += ie_p2p(attrs
)
577 # Too long Persistent Group attribute
579 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
580 attrs
= struct
.pack("<BH9L3B", P2P_ATTR_PERSISTENT_GROUP
, 6 + 32 + 1,
581 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3)
582 msg
['payload'] += ie_p2p(attrs
)
585 if hapd
.mgmt_rx(timeout
=0.5) is not None:
586 raise Exception("Unexpected management frame received")
588 dev
[0].dump_monitor()
590 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
591 attrs
= p2p_attr_config_timeout()
592 attrs
+= p2p_attr_invitation_flags()
593 attrs
+= p2p_attr_operating_channel()
594 attrs
+= p2p_attr_group_bssid(src
)
595 attrs
+= p2p_attr_channel_list()
596 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
597 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
598 msg
['payload'] += ie_p2p(attrs
)
600 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
602 raise Exception("Timeout on device found event")
603 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout
=5)
605 raise Exception("Timeout on invitation event " + str(dialog_token
))
606 if hapd
.mgmt_rx(timeout
=1) is None:
607 raise Exception("No invitation response " + str(dialog_token
))
610 dev
[0].dump_monitor()
612 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
613 attrs
= p2p_attr_config_timeout()
614 attrs
+= p2p_attr_invitation_flags()
615 attrs
+= p2p_attr_operating_channel()
616 attrs
+= p2p_attr_group_bssid(src
)
617 attrs
+= p2p_attr_channel_list()
618 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
619 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
620 msg
['payload'] += ie_p2p(attrs
)
622 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout
=5)
624 raise Exception("Timeout on invitation event " + str(dialog_token
))
625 if hapd
.mgmt_rx(timeout
=1) is None:
626 raise Exception("No invitation response " + str(dialog_token
))
629 dev
[0].dump_monitor()
631 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
632 #attrs = p2p_attr_config_timeout()
633 attrs
= p2p_attr_invitation_flags()
634 attrs
+= p2p_attr_operating_channel()
635 attrs
+= p2p_attr_group_bssid(src
)
636 attrs
+= p2p_attr_channel_list()
637 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
638 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
639 msg
['payload'] += ie_p2p(attrs
)
641 if hapd
.mgmt_rx(timeout
=1) is None:
642 raise Exception("No invitation response " + str(dialog_token
))
645 dev
[0].dump_monitor()
647 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
648 attrs
= p2p_attr_config_timeout()
649 #attrs = p2p_attr_invitation_flags()
650 attrs
+= p2p_attr_operating_channel()
651 attrs
+= p2p_attr_group_bssid(src
)
652 attrs
+= p2p_attr_channel_list()
653 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
654 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
655 msg
['payload'] += ie_p2p(attrs
)
657 if hapd
.mgmt_rx(timeout
=1) is None:
658 raise Exception("No invitation response " + str(dialog_token
))
661 dev
[0].dump_monitor()
663 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
664 attrs
= p2p_attr_config_timeout()
665 attrs
= p2p_attr_invitation_flags()
666 #attrs += p2p_attr_operating_channel()
667 attrs
+= p2p_attr_group_bssid(src
)
668 attrs
+= p2p_attr_channel_list()
669 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
670 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
671 msg
['payload'] += ie_p2p(attrs
)
673 if hapd
.mgmt_rx(timeout
=1) is None:
674 raise Exception("No invitation response " + str(dialog_token
))
677 dev
[0].dump_monitor()
679 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
680 attrs
= p2p_attr_config_timeout()
681 attrs
= p2p_attr_invitation_flags()
682 attrs
+= p2p_attr_operating_channel()
683 #attrs += p2p_attr_group_bssid(src)
684 attrs
+= p2p_attr_channel_list()
685 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
686 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
687 msg
['payload'] += ie_p2p(attrs
)
689 if hapd
.mgmt_rx(timeout
=1) is None:
690 raise Exception("No invitation response " + str(dialog_token
))
693 dev
[0].dump_monitor()
695 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
696 attrs
= p2p_attr_config_timeout()
697 attrs
= p2p_attr_invitation_flags()
698 attrs
+= p2p_attr_operating_channel()
699 attrs
+= p2p_attr_group_bssid(src
)
700 #attrs += p2p_attr_channel_list()
701 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
702 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
703 msg
['payload'] += ie_p2p(attrs
)
705 if hapd
.mgmt_rx(timeout
=1) is None:
706 raise Exception("No invitation response " + str(dialog_token
))
709 dev
[0].dump_monitor()
711 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
712 attrs
= p2p_attr_config_timeout()
713 attrs
= p2p_attr_invitation_flags()
714 attrs
+= p2p_attr_operating_channel()
715 attrs
+= p2p_attr_group_bssid(src
)
716 attrs
+= p2p_attr_channel_list()
717 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
718 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
719 msg
['payload'] += ie_p2p(attrs
)
721 if hapd
.mgmt_rx(timeout
=1) is None:
722 raise Exception("No invitation response " + str(dialog_token
))
725 dev
[0].dump_monitor()
727 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
728 attrs
= p2p_attr_config_timeout()
729 attrs
= p2p_attr_invitation_flags()
730 attrs
+= p2p_attr_operating_channel()
731 attrs
+= p2p_attr_group_bssid(src
)
732 attrs
+= p2p_attr_channel_list()
733 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
734 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
735 msg
['payload'] += ie_p2p(attrs
)
737 if hapd
.mgmt_rx(timeout
=1) is None:
738 raise Exception("No invitation response " + str(dialog_token
))
741 dev
[0].dump_monitor()
743 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
745 if hapd
.mgmt_rx(timeout
=1) is None:
746 raise Exception("No invitation response " + str(dialog_token
))
748 # Unusable peer operating channel preference
750 dev
[0].dump_monitor()
752 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
753 attrs
= p2p_attr_config_timeout()
754 attrs
= p2p_attr_invitation_flags()
755 attrs
+= p2p_attr_operating_channel(chan
=15)
756 attrs
+= p2p_attr_group_bssid(src
)
757 attrs
+= p2p_attr_channel_list()
758 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
759 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
760 msg
['payload'] += ie_p2p(attrs
)
762 if hapd
.mgmt_rx(timeout
=1) is None:
763 raise Exception("No invitation response " + str(dialog_token
))
765 def test_p2p_msg_invitation_req_to_go(dev
, apdev
):
766 """P2P protocol tests for invitation request processing on GO device"""
767 res
= form(dev
[0], dev
[1])
768 dev
[0].dump_monitor()
769 dev
[1].dump_monitor()
770 addr0
= dev
[0].p2p_dev_addr()
771 addr1
= dev
[1].p2p_dev_addr()
772 peer
= dev
[1].get_peer(addr0
)
773 listen_freq
= peer
['listen_freq']
775 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
776 raise Exception("Failed to enable external management frame handling")
778 networks
= dev
[0].list_networks()
779 if len(networks
) != 1:
780 raise Exception("Unexpected number of networks")
781 if "[P2P-PERSISTENT]" not in networks
[0]['flags']:
782 raise Exception("Not the persistent group data")
783 dev
[0].p2p_start_go(persistent
=networks
[0]['id'], freq
=listen_freq
)
787 # Unusable peer operating channel preference
789 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_REQ
,
790 dialog_token
=dialog_token
)
791 attrs
= p2p_attr_config_timeout()
792 attrs
= p2p_attr_invitation_flags(bitmap
=1)
793 attrs
+= p2p_attr_operating_channel(chan
=15)
794 attrs
+= p2p_attr_channel_list()
795 attrs
+= p2p_attr_group_id(res
['go_dev_addr'], res
['ssid'])
796 attrs
+= p2p_attr_device_info(addr1
, config_methods
=0x0108)
797 msg
['payload'] += ie_p2p(attrs
)
799 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
801 rx_msg
= dev
[1].mgmt_rx()
803 raise Exception("MGMT-RX timeout")
804 p2p
= parse_p2p_public_action(rx_msg
['payload'])
806 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
807 if p2p
['subtype'] != P2P_INVITATION_RESP
:
808 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
809 if p2p
['p2p_status'] != 0:
810 raise Exception("Unexpected status %d" % p2p
['p2p_status'])
812 # Forced channel re-selection due to channel list
814 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_REQ
,
815 dialog_token
=dialog_token
)
816 attrs
= p2p_attr_config_timeout()
817 attrs
= p2p_attr_invitation_flags(bitmap
=1)
818 attrs
+= struct
.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST
, 6,
821 attrs
+= p2p_attr_group_id(res
['go_dev_addr'], res
['ssid'])
822 attrs
+= p2p_attr_device_info(addr1
, config_methods
=0x0108)
823 msg
['payload'] += ie_p2p(attrs
)
825 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
827 rx_msg
= dev
[1].mgmt_rx()
829 raise Exception("MGMT-RX timeout")
830 p2p
= parse_p2p_public_action(rx_msg
['payload'])
832 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
833 if p2p
['subtype'] != P2P_INVITATION_RESP
:
834 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
835 if p2p
['p2p_status'] != 7 and dev
[1].get_mcc() <= 1:
836 raise Exception("Unexpected status %d" % p2p
['p2p_status'])
838 def test_p2p_msg_invitation_req_unknown(dev
, apdev
):
839 """P2P protocol tests for invitation request from unknown peer"""
840 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
844 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
845 attrs
= p2p_attr_config_timeout()
846 attrs
+= p2p_attr_invitation_flags()
847 attrs
+= p2p_attr_operating_channel()
848 attrs
+= p2p_attr_group_bssid(src
)
849 attrs
+= p2p_attr_channel_list()
850 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
851 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
852 msg
['payload'] += ie_p2p(attrs
)
854 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout
=5)
856 raise Exception("Timeout on invitation event " + str(dialog_token
))
857 if hapd
.mgmt_rx(timeout
=1) is None:
858 raise Exception("No invitation response " + str(dialog_token
))
860 def test_p2p_msg_invitation_no_common_channels(dev
, apdev
):
861 """P2P protocol tests for invitation request without common channels"""
862 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
866 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_REQ
, dialog_token
=dialog_token
)
867 attrs
= p2p_attr_config_timeout()
868 attrs
+= p2p_attr_invitation_flags()
869 attrs
+= p2p_attr_operating_channel()
870 attrs
+= p2p_attr_group_bssid(src
)
871 attrs
+= struct
.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST
, 5,
874 attrs
+= p2p_attr_group_id(src
, "DIRECT-foo")
875 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
876 msg
['payload'] += ie_p2p(attrs
)
878 if hapd
.mgmt_rx(timeout
=1) is None:
879 raise Exception("No invitation response " + str(dialog_token
))
880 ev
= dev
[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout
=0.1)
882 raise Exception("Unexpected invitation event")
884 def test_p2p_msg_invitation_resp(dev
, apdev
):
885 """P2P protocol tests for invitation response processing"""
887 dev
[0].dump_monitor()
888 dev
[1].dump_monitor()
890 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
892 addr0
= dev
[0].p2p_dev_addr()
893 addr1
= dev
[1].p2p_dev_addr()
894 peer
= dev
[1].get_peer(addr0
)
896 # P2P Invitation Response from unknown peer
897 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=1)
900 # P2P Invitation Response from peer that is not in invitation
901 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=2)
902 attrs
= p2p_attr_status()
903 msg
['payload'] += ie_p2p(attrs
)
904 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
907 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
908 raise Exception("Failed to enable external management frame handling")
910 invite(dev
[0], dev
[1])
911 rx_msg
= dev
[1].mgmt_rx()
913 raise Exception("MGMT-RX timeout")
914 p2p
= parse_p2p_public_action(rx_msg
['payload'])
916 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
917 if p2p
['subtype'] != P2P_INVITATION_REQ
:
918 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
920 # Invalid attribute to cause p2p_parse() failure
921 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
922 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
923 msg
['payload'] += ie_p2p(attrs
)
924 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
926 invite(dev
[0], dev
[1])
927 rx_msg
= dev
[1].mgmt_rx()
929 raise Exception("MGMT-RX timeout")
930 p2p
= parse_p2p_public_action(rx_msg
['payload'])
932 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
933 if p2p
['subtype'] != P2P_INVITATION_REQ
:
934 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
936 # missing mandatory Status attribute
937 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
938 attrs
= p2p_attr_channel_list()
939 msg
['payload'] += ie_p2p(attrs
)
940 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
942 invite(dev
[0], dev
[1])
943 rx_msg
= dev
[1].mgmt_rx()
945 raise Exception("MGMT-RX timeout")
946 p2p
= parse_p2p_public_action(rx_msg
['payload'])
948 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
949 if p2p
['subtype'] != P2P_INVITATION_REQ
:
950 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
952 # no channel match (no common channel found at all)
953 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
954 attrs
= p2p_attr_status()
955 attrs
+= struct
.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST
, 6,
958 msg
['payload'] += ie_p2p(attrs
)
959 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
961 invite(dev
[0], dev
[1])
962 rx_msg
= dev
[1].mgmt_rx()
964 raise Exception("MGMT-RX timeout")
965 p2p
= parse_p2p_public_action(rx_msg
['payload'])
967 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
968 if p2p
['subtype'] != P2P_INVITATION_REQ
:
969 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
971 # no channel match (no acceptable P2P channel)
972 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
973 attrs
= p2p_attr_status()
974 attrs
+= struct
.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST
, 6,
977 msg
['payload'] += ie_p2p(attrs
)
978 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
980 invite(dev
[0], dev
[1])
981 rx_msg
= dev
[1].mgmt_rx()
983 raise Exception("MGMT-RX timeout")
984 p2p
= parse_p2p_public_action(rx_msg
['payload'])
986 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
987 if p2p
['subtype'] != P2P_INVITATION_REQ
:
988 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
990 # missing mandatory Channel List attribute (ignored as a workaround)
991 msg
= p2p_hdr(dst
, src
, type=P2P_INVITATION_RESP
, dialog_token
=p2p
['dialog_token'])
992 attrs
= p2p_attr_status()
993 msg
['payload'] += ie_p2p(attrs
)
994 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
996 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15);
998 raise Exception("Group was not started")
1000 def test_p2p_msg_invitation_resend(dev
, apdev
):
1001 """P2P protocol tests for invitation resending on no-common-channels"""
1002 form(dev
[0], dev
[1])
1003 dev
[0].dump_monitor()
1004 dev
[1].dump_monitor()
1005 addr0
= dev
[0].p2p_dev_addr()
1006 addr1
= dev
[1].p2p_dev_addr()
1008 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
1009 raise Exception("Failed to enable external management frame handling")
1011 logger
.info("Forced channel in invitation")
1012 invite(dev
[0], dev
[1], extra
="freq=2422")
1013 rx_msg
= dev
[1].mgmt_rx()
1015 raise Exception("MGMT-RX timeout")
1016 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1018 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1019 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1020 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1021 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1022 dialog_token
=p2p
['dialog_token'])
1023 attrs
= p2p_attr_status(status
=P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1024 msg
['payload'] += ie_p2p(attrs
)
1025 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1026 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout
=15)
1028 raise Exception("Timeout on invitation result");
1029 if "status=7" not in ev
:
1030 raise Exception("Unexpected invitation result: " + ev
)
1032 logger
.info("Any channel allowed, only preference provided in invitation");
1033 invite(dev
[0], dev
[1], extra
="pref=2422")
1034 rx_msg
= dev
[1].mgmt_rx()
1036 raise Exception("MGMT-RX timeout")
1037 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1039 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1040 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1041 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1042 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1043 dialog_token
=p2p
['dialog_token'])
1044 attrs
= p2p_attr_status(status
=P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1045 msg
['payload'] += ie_p2p(attrs
)
1046 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 0"):
1047 raise Exception("Failed to disable external management frame handling")
1048 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1049 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout
=15)
1051 raise Exception("Timeout on invitation result");
1052 if "status=0" not in ev
:
1053 raise Exception("Unexpected invitation result: " + ev
)
1055 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15);
1057 raise Exception("Group was not started on dev0")
1058 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15);
1060 raise Exception("Group was not started on dev1")
1062 def test_p2p_msg_invitation_resend_duplicate(dev
, apdev
):
1063 """P2P protocol tests for invitation resending on no-common-channels and duplicated response"""
1064 form(dev
[0], dev
[1])
1065 dev
[0].dump_monitor()
1066 dev
[1].dump_monitor()
1067 addr0
= dev
[0].p2p_dev_addr()
1068 addr1
= dev
[1].p2p_dev_addr()
1070 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
1071 raise Exception("Failed to enable external management frame handling")
1073 logger
.info("Any channel allowed, only preference provided in invitation");
1074 invite(dev
[0], dev
[1], extra
="pref=2422")
1075 rx_msg
= dev
[1].mgmt_rx()
1077 raise Exception("MGMT-RX timeout")
1078 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1080 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1081 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1082 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1083 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1084 dialog_token
=p2p
['dialog_token'])
1085 attrs
= p2p_attr_status(status
=P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1086 msg
['payload'] += ie_p2p(attrs
)
1087 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1089 rx_msg
= dev
[1].mgmt_rx()
1091 raise Exception("MGMT-RX timeout")
1092 p2p
= parse_p2p_public_action(rx_msg
['payload'])
1094 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1095 if p2p
['subtype'] != P2P_INVITATION_REQ
:
1096 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1098 logger
.info("Retransmit duplicate of previous response")
1099 mgmt_tx(dev
[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0
, addr0
, rx_msg
['freq'], binascii
.hexlify(msg
['payload'])))
1101 logger
.info("Transmit real response")
1102 msg
= p2p_hdr(addr0
, addr1
, type=P2P_INVITATION_RESP
,
1103 dialog_token
=p2p
['dialog_token'])
1104 attrs
= p2p_attr_status(status
=P2P_SC_SUCCESS
)
1105 attrs
+= p2p_attr_channel_list()
1106 msg
['payload'] += ie_p2p(attrs
)
1107 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']))):
1108 raise Exception("Failed to transmit real response")
1109 dev
[1].request("SET ext_mgmt_frame_handling 0")
1111 ev
= dev
[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout
=10)
1113 raise Exception("Timeout on invitation result");
1114 if "status=0" not in ev
:
1115 raise Exception("Unexpected invitation result: " + ev
)
1116 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=10)
1118 raise Exception("Group formation timed out")
1119 dev
[0].group_form_result(ev
)
1120 dev
[0].remove_group()
1122 def test_p2p_msg_pd_req(dev
, apdev
):
1123 """P2P protocol tests for provision discovery request processing"""
1124 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1127 # Too short attribute header
1129 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1130 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
1131 msg
['payload'] += ie_p2p(attrs
)
1134 if hapd
.mgmt_rx(timeout
=0.5) is not None:
1135 raise Exception("Unexpected management frame received")
1139 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1141 msg
['payload'] += ie_p2p(attrs
)
1143 if hapd
.mgmt_rx(timeout
=1) is None:
1144 raise Exception("No PD response " + str(dialog_token
))
1149 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1150 attrs
= wsc_attr_config_methods(methods
=0x1008)
1151 msg
['payload'] += ie_wsc(attrs
)
1152 attrs
= p2p_attr_capability()
1153 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1154 msg
['payload'] += ie_p2p(attrs
)
1156 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
1158 raise Exception("Timeout on device found event")
1159 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=5)
1161 raise Exception("Timeout on PD event")
1162 if hapd
.mgmt_rx(timeout
=1) is None:
1163 raise Exception("No PD response " + str(dialog_token
))
1168 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1169 attrs
= wsc_attr_config_methods(methods
=0x1008)
1170 msg
['payload'] += ie_wsc(attrs
)
1171 attrs
= p2p_attr_capability()
1172 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1173 attrs
+= p2p_attr_group_id("02:02:02:02:02:02", "DIRECT-foo")
1174 msg
['payload'] += ie_p2p(attrs
)
1176 if hapd
.mgmt_rx(timeout
=1) is None:
1177 raise Exception("No PD response " + str(dialog_token
))
1178 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=1)
1180 raise Exception("Unexpected PD event")
1182 # Listen channel is not yet known
1183 if "FAIL" not in dev
[0].global_request("P2P_PROV_DISC " + src
+ " display"):
1184 raise Exception("Unexpected P2P_PROV_DISC success")
1187 if "FAIL" not in dev
[0].global_request("P2P_PROV_DISC 02:03:04:05:06:07 display"):
1188 raise Exception("Unexpected P2P_PROV_DISC success (2)")
1190 def test_p2p_msg_pd(dev
, apdev
):
1191 """P2P protocol tests for provision discovery request processing (known)"""
1192 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1195 p2p_probe(hapd
, src
, chan
=channel
)
1200 msg
= p2p_hdr(dst
, src
, type=P2P_PROV_DISC_REQ
, dialog_token
=dialog_token
)
1201 attrs
= wsc_attr_config_methods(methods
=0x1008)
1202 msg
['payload'] += ie_wsc(attrs
)
1203 attrs
= p2p_attr_capability()
1204 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1205 msg
['payload'] += ie_p2p(attrs
)
1207 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
1209 raise Exception("Timeout on device found event")
1210 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=5)
1212 raise Exception("Timeout on PD event")
1213 if hapd
.mgmt_rx(timeout
=1) is None:
1214 raise Exception("No PD response " + str(dialog_token
))
1216 if "FAIL" in dev
[0].global_request("P2P_PROV_DISC " + src
+ " display"):
1217 raise Exception("Unexpected P2P_PROV_DISC failure")
1218 frame
= hapd
.mgmt_rx(timeout
=1)
1220 raise Exception("No PD request " + str(dialog_token
))
1221 p2p
= parse_p2p_public_action(frame
['payload'])
1223 raise Exception("Failed to parse PD request")
1225 # invalid dialog token
1226 msg
= p2p_hdr_resp(dst
, src
, type=P2P_PROV_DISC_RESP
,
1227 dialog_token
=p2p
['dialog_token'] + 1)
1229 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=0.1)
1231 raise Exception("Unexpected PD result event")
1233 # valid dialog token
1234 msg
= p2p_hdr_resp(dst
, src
, type=P2P_PROV_DISC_RESP
,
1235 dialog_token
=p2p
['dialog_token'])
1237 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=5)
1239 raise Exception("Timeout on PD result event")
1241 # valid dialog token
1242 msg
= p2p_hdr_resp(dst
, src
, type=P2P_PROV_DISC_RESP
,
1243 dialog_token
=p2p
['dialog_token'])
1245 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=0.1)
1247 raise Exception("Unexpected PD result event")
1249 def check_p2p_response(hapd
, dialog_token
, status
):
1250 resp
= hapd
.mgmt_rx(timeout
=2)
1252 raise Exception("No GO Neg Response " + str(dialog_token
))
1253 p2p
= parse_p2p_public_action(resp
['payload'])
1255 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1256 if dialog_token
!= p2p
['dialog_token']:
1257 raise Exception("Unexpected dialog token in response")
1258 if p2p
['p2p_status'] != status
:
1259 raise Exception("Unexpected status code %s in response (expected %d)" % (p2p
['p2p_status'], status
))
1261 def test_p2p_msg_go_neg_both_start(dev
, apdev
):
1262 """P2P protocol test for simultaneous GO Neg initiation"""
1263 addr0
= dev
[0].p2p_dev_addr()
1264 addr1
= dev
[1].p2p_dev_addr()
1266 dev
[1].discover_peer(addr0
)
1268 dev
[0].discover_peer(addr1
)
1270 if "FAIL" in dev
[0].request("SET ext_mgmt_frame_handling 1"):
1271 raise Exception("Failed to enable external management frame handling")
1272 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 1"):
1273 raise Exception("Failed to enable external management frame handling")
1274 dev
[0].request("P2P_CONNECT {} pbc".format(addr1
))
1275 dev
[1].request("P2P_CONNECT {} pbc".format(addr0
))
1276 msg
= dev
[0].mgmt_rx()
1278 raise Exception("MGMT-RX timeout")
1279 msg
= dev
[1].mgmt_rx()
1281 raise Exception("MGMT-RX timeout(2)")
1282 if "FAIL" in dev
[0].request("SET ext_mgmt_frame_handling 0"):
1283 raise Exception("Failed to disable external management frame handling")
1284 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=2)
1286 raise Exception("Unexpected GO Neg success")
1287 if "FAIL" in dev
[1].request("SET ext_mgmt_frame_handling 0"):
1288 raise Exception("Failed to disable external management frame handling")
1289 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout
=10)
1291 raise Exception("GO Neg did not succeed")
1292 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=5);
1294 raise Exception("Group formation not succeed")
1295 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=5);
1297 raise Exception("Group formation not succeed")
1299 def test_p2p_msg_go_neg_req(dev
, apdev
):
1300 """P2P protocol tests for invitation request from unknown peer"""
1301 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1306 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1307 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
1308 msg
['payload'] += ie_p2p(attrs
)
1310 frame
= hapd
.mgmt_rx(timeout
=0.1)
1311 if frame
is not None:
1313 raise Exception("Unexpected GO Neg Response")
1317 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1318 attrs
= p2p_attr_capability()
1319 attrs
+= p2p_attr_go_intent()
1320 attrs
+= p2p_attr_config_timeout()
1321 #attrs += p2p_attr_listen_channel()
1322 attrs
+= p2p_attr_ext_listen_timing()
1323 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1324 attrs
+= p2p_attr_channel_list()
1325 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1326 attrs
+= p2p_attr_operating_channel()
1327 msg
['payload'] += ie_p2p(attrs
)
1329 if hapd
.mgmt_rx(timeout
=2) is None:
1330 raise Exception("No GO Neg Response " + str(dialog_token
))
1334 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1335 attrs
= p2p_attr_capability()
1336 attrs
+= p2p_attr_go_intent()
1337 attrs
+= p2p_attr_config_timeout()
1338 attrs
+= p2p_attr_listen_channel()
1339 attrs
+= p2p_attr_ext_listen_timing()
1340 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1341 attrs
+= p2p_attr_channel_list()
1342 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1343 #attrs += p2p_attr_operating_channel()
1344 msg
['payload'] += ie_p2p(attrs
)
1346 if hapd
.mgmt_rx(timeout
=2) is None:
1347 raise Exception("No GO Neg Response " + str(dialog_token
))
1351 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1352 attrs
= p2p_attr_capability()
1353 attrs
+= p2p_attr_go_intent()
1354 attrs
+= p2p_attr_config_timeout()
1355 attrs
+= p2p_attr_listen_channel()
1356 attrs
+= p2p_attr_ext_listen_timing()
1357 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1358 #attrs += p2p_attr_channel_list()
1359 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1360 attrs
+= p2p_attr_operating_channel()
1361 msg
['payload'] += ie_p2p(attrs
)
1363 if hapd
.mgmt_rx(timeout
=2) is None:
1364 raise Exception("No GO Neg Response " + str(dialog_token
))
1368 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1369 attrs
= p2p_attr_capability()
1370 attrs
+= p2p_attr_go_intent()
1371 attrs
+= p2p_attr_config_timeout()
1372 attrs
+= p2p_attr_listen_channel()
1373 attrs
+= p2p_attr_ext_listen_timing()
1374 #attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1375 attrs
+= p2p_attr_channel_list()
1376 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1377 attrs
+= p2p_attr_operating_channel()
1378 msg
['payload'] += ie_p2p(attrs
)
1380 if hapd
.mgmt_rx(timeout
=2) is None:
1381 raise Exception("No GO Neg Response " + str(dialog_token
))
1385 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1386 attrs
= p2p_attr_capability()
1387 attrs
+= p2p_attr_go_intent()
1388 attrs
+= p2p_attr_config_timeout()
1389 attrs
+= p2p_attr_listen_channel()
1390 attrs
+= p2p_attr_ext_listen_timing()
1391 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1392 attrs
+= p2p_attr_channel_list()
1393 #attrs += p2p_attr_device_info(src, config_methods=0x0108)
1394 attrs
+= p2p_attr_operating_channel()
1395 msg
['payload'] += ie_p2p(attrs
)
1397 if hapd
.mgmt_rx(timeout
=2) is None:
1398 raise Exception("No GO Neg Response " + str(dialog_token
))
1401 # SA != P2P Device address
1403 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1404 attrs
= p2p_attr_capability()
1405 attrs
+= p2p_attr_go_intent()
1406 attrs
+= p2p_attr_config_timeout()
1407 attrs
+= p2p_attr_listen_channel()
1408 attrs
+= p2p_attr_ext_listen_timing()
1409 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1410 attrs
+= p2p_attr_channel_list()
1411 attrs
+= p2p_attr_device_info("02:02:02:02:02:02", config_methods
=0x0108)
1412 attrs
+= p2p_attr_operating_channel()
1413 msg
['payload'] += ie_p2p(attrs
)
1415 if hapd
.mgmt_rx(timeout
=2) is None:
1416 raise Exception("No GO Neg Response " + str(dialog_token
))
1419 # unexpected Status attribute
1421 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1422 attrs
= p2p_attr_capability()
1423 attrs
+= p2p_attr_go_intent()
1424 attrs
+= p2p_attr_config_timeout()
1425 attrs
+= p2p_attr_listen_channel()
1426 attrs
+= p2p_attr_ext_listen_timing()
1427 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1428 attrs
+= p2p_attr_channel_list()
1429 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1430 attrs
+= p2p_attr_operating_channel()
1431 attrs
+= p2p_attr_status(status
=P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
)
1432 msg
['payload'] += ie_p2p(attrs
)
1434 if hapd
.mgmt_rx(timeout
=2) is None:
1435 raise Exception("No GO Neg Response(1) " + str(dialog_token
))
1438 # valid (with workarounds) GO Neg Req
1440 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1441 #attrs = p2p_attr_capability()
1442 #attrs += p2p_attr_go_intent()
1443 #attrs += p2p_attr_config_timeout()
1444 attrs
= p2p_attr_listen_channel()
1445 attrs
+= p2p_attr_ext_listen_timing()
1446 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1447 attrs
+= p2p_attr_channel_list()
1448 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1449 attrs
+= p2p_attr_operating_channel()
1450 msg
['payload'] += ie_p2p(attrs
)
1452 check_p2p_response(hapd
, dialog_token
,
1453 P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
)
1454 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=2)
1456 raise Exception("Timeout on GO Neg event " + str(dialog_token
))
1458 dev
[0].request("P2P_CONNECT " + src
+ " 12345670 display auth")
1460 # ready - missing attributes (with workarounds) GO Neg Req
1463 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1464 #attrs = p2p_attr_capability()
1465 #attrs += p2p_attr_go_intent()
1466 #attrs += p2p_attr_config_timeout()
1467 attrs
= p2p_attr_listen_channel()
1468 attrs
+= p2p_attr_ext_listen_timing()
1469 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1470 attrs
+= p2p_attr_channel_list()
1471 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1472 attrs
+= p2p_attr_operating_channel()
1473 msg
['payload'] += ie_p2p(attrs
)
1475 if hapd
.mgmt_rx(timeout
=2) is None:
1476 raise Exception("No GO Neg Response " + str(dialog_token
))
1478 # ready - invalid GO Intent GO Neg Req
1481 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1482 #attrs = p2p_attr_capability()
1483 attrs
= p2p_attr_go_intent(go_intent
=16)
1484 #attrs += p2p_attr_config_timeout()
1485 attrs
+= p2p_attr_listen_channel()
1486 attrs
+= p2p_attr_ext_listen_timing()
1487 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1488 attrs
+= p2p_attr_channel_list()
1489 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1490 attrs
+= p2p_attr_operating_channel()
1491 msg
['payload'] += ie_p2p(attrs
)
1493 check_p2p_response(hapd
, dialog_token
, P2P_SC_FAIL_INVALID_PARAMS
)
1495 # ready - invalid Channel List
1498 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1499 attrs
= p2p_attr_capability()
1500 attrs
+= p2p_attr_go_intent()
1501 attrs
+= p2p_attr_config_timeout()
1502 attrs
+= p2p_attr_listen_channel()
1503 attrs
+= p2p_attr_ext_listen_timing()
1504 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1505 attrs
+= struct
.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST
, 16,
1507 81, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
1508 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1509 attrs
+= p2p_attr_operating_channel()
1510 msg
['payload'] += ie_p2p(attrs
)
1512 check_p2p_response(hapd
, dialog_token
, P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1514 # ready - invalid GO Neg Req (unsupported Device Password ID)
1517 msg
= p2p_hdr(dst
, src
, type=P2P_GO_NEG_REQ
, dialog_token
=dialog_token
)
1518 attrs
= p2p_attr_capability()
1519 attrs
+= p2p_attr_go_intent()
1520 attrs
+= p2p_attr_config_timeout()
1521 attrs
+= p2p_attr_listen_channel()
1522 attrs
+= p2p_attr_ext_listen_timing()
1523 attrs
+= p2p_attr_intended_interface_addr("02:02:02:02:02:02")
1524 # very long channel list
1525 attrs
+= struct
.pack("<BH3BBB11B30B", P2P_ATTR_CHANNEL_LIST
, 46,
1527 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
1528 1, 1, 1, 2, 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5,
1529 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 10, 1, 10)
1530 attrs
+= p2p_attr_device_info(src
, config_methods
=0x0108)
1531 attrs
+= p2p_attr_operating_channel()
1532 msg
['payload'] += ie_p2p(attrs
)
1534 check_p2p_response(hapd
, dialog_token
, P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD
)
1536 def mgmt_tx(dev
, msg
):
1537 for i
in range(0, 20):
1538 if "FAIL" in dev
.request(msg
):
1539 raise Exception("Failed to send Action frame")
1540 ev
= dev
.wait_event(["MGMT-TX-STATUS"], timeout
=10)
1542 raise Exception("Timeout on MGMT-TX-STATUS")
1543 if "result=SUCCESS" in ev
:
1546 if "result=SUCCESS" not in ev
:
1547 raise Exception("Peer did not ack Action frame")
1549 def rx_go_neg_req(dev
):
1552 raise Exception("MGMT-RX timeout")
1553 p2p
= parse_p2p_public_action(msg
['payload'])
1555 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1556 if p2p
['subtype'] != P2P_GO_NEG_REQ
:
1557 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1558 p2p
['freq'] = msg
['freq']
1561 def rx_go_neg_conf(dev
, status
=None, dialog_token
=None):
1564 raise Exception("MGMT-RX timeout")
1565 p2p
= parse_p2p_public_action(msg
['payload'])
1567 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
1568 if p2p
['subtype'] != P2P_GO_NEG_CONF
:
1569 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
1570 if dialog_token
is not None and dialog_token
!= p2p
['dialog_token']:
1571 raise Exception("Unexpected dialog token")
1572 if status
is not None and p2p
['p2p_status'] != status
:
1573 raise Exception("Unexpected status %d" % p2p
['p2p_status'])
1575 def check_p2p_go_neg_fail_event(dev
, status
):
1576 ev
= dev
.wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=5)
1578 raise Exception("GO Negotiation failure not reported")
1579 if "status=%d" % status
not in ev
:
1580 raise Exception("Unexpected failure reason: " + ev
)
1582 def test_p2p_msg_go_neg_req_reject(dev
, apdev
):
1583 """P2P protocol tests for user reject incorrectly in GO Neg Req"""
1584 addr0
= dev
[0].p2p_dev_addr()
1585 addr1
= dev
[1].p2p_dev_addr()
1587 dev
[1].discover_peer(addr0
)
1588 dev
[1].group_request("P2P_CONNECT " + addr0
+ " pbc")
1589 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
1591 raise Exception("Timeout on GO Neg Req")
1593 peer
= dev
[0].get_peer(addr1
)
1594 dev
[0].p2p_stop_find()
1596 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_REQ
, dialog_token
=123)
1597 attrs
= p2p_attr_capability()
1598 attrs
+= p2p_attr_status(status
=P2P_SC_FAIL_REJECTED_BY_USER
)
1599 attrs
+= p2p_attr_go_intent()
1600 attrs
+= p2p_attr_config_timeout()
1601 attrs
+= p2p_attr_listen_channel()
1602 attrs
+= p2p_attr_ext_listen_timing()
1603 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1604 attrs
+= p2p_attr_channel_list()
1605 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1606 attrs
+= p2p_attr_operating_channel()
1607 msg
['payload'] += ie_p2p(attrs
)
1609 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1611 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout
=5)
1613 raise Exception("GO Negotiation failure not reported")
1614 if "status=%d" % P2P_SC_FAIL_REJECTED_BY_USER
not in ev
:
1615 raise Exception("Unexpected failure reason: " + ev
)
1617 def test_p2p_msg_unexpected_go_neg_resp(dev
, apdev
):
1618 """P2P protocol tests for unexpected GO Neg Resp"""
1619 addr0
= dev
[0].p2p_dev_addr()
1620 addr1
= dev
[1].p2p_dev_addr()
1622 dev
[0].discover_peer(addr1
)
1623 dev
[0].p2p_stop_find()
1625 peer
= dev
[0].get_peer(addr1
)
1627 logger
.debug("GO Neg Resp without GO Neg session")
1628 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=123)
1629 attrs
= p2p_attr_status()
1630 attrs
+= p2p_attr_capability()
1631 attrs
+= p2p_attr_go_intent()
1632 attrs
+= p2p_attr_config_timeout()
1633 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1634 attrs
+= p2p_attr_channel_list()
1635 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1636 attrs
+= p2p_attr_operating_channel()
1637 msg
['payload'] += ie_p2p(attrs
)
1638 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1641 dev
[1].discover_peer(addr0
)
1643 logger
.debug("Unexpected GO Neg Resp while waiting for new GO Neg session")
1644 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1645 raise Exception("P2P_CONNECT failed")
1646 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
1648 raise Exception("Timeout on GO Neg Req")
1649 dev
[0].p2p_stop_find()
1650 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1652 logger
.debug("Invalid attribute in GO Neg Response")
1653 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=197)
1654 attrs
= struct
.pack("<BB", P2P_ATTR_CAPABILITY
, 0)
1655 msg
['payload'] += ie_p2p(attrs
)
1656 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr1
, peer
['listen_freq'], binascii
.hexlify(msg
['payload'])))
1657 frame
= dev
[0].mgmt_rx(timeout
=0.1)
1658 if frame
is not None:
1659 raise Exception("Unexpected GO Neg Confirm")
1661 logger
.debug("GO Neg Resp with unexpected dialog token")
1662 dev
[1].p2p_stop_find()
1663 if "FAIL" in dev
[0].request("SET ext_mgmt_frame_handling 1"):
1664 raise Exception("Failed to enable external management frame handling")
1666 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1667 raise Exception("P2P_CONNECT failed(2)")
1668 p2p
= rx_go_neg_req(dev
[0])
1669 dev
[0].p2p_stop_find()
1670 dialog_token
= p2p
['dialog_token']
1671 if dialog_token
< 255:
1675 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1676 attrs
= p2p_attr_status()
1677 attrs
+= p2p_attr_capability()
1678 attrs
+= p2p_attr_go_intent()
1679 attrs
+= p2p_attr_config_timeout()
1680 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1681 attrs
+= p2p_attr_channel_list()
1682 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1683 attrs
+= p2p_attr_operating_channel()
1684 msg
['payload'] += ie_p2p(attrs
)
1685 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1687 logger
.debug("GO Neg Resp without Status")
1688 dev
[1].p2p_stop_find()
1690 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1691 raise Exception("P2P_CONNECT failed(2)")
1692 p2p
= rx_go_neg_req(dev
[0])
1693 dev
[0].p2p_stop_find()
1694 dialog_token
= p2p
['dialog_token']
1695 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1696 #attrs = p2p_attr_status()
1697 attrs
= p2p_attr_capability()
1698 attrs
+= p2p_attr_go_intent()
1699 attrs
+= p2p_attr_config_timeout()
1700 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1701 attrs
+= p2p_attr_channel_list()
1702 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1703 attrs
+= p2p_attr_operating_channel()
1704 msg
['payload'] += ie_p2p(attrs
)
1705 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1706 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1707 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1709 logger
.debug("GO Neg Resp without Intended Address")
1710 dev
[1].p2p_stop_find()
1712 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1713 raise Exception("P2P_CONNECT failed(2)")
1714 p2p
= rx_go_neg_req(dev
[0])
1715 dev
[0].p2p_stop_find()
1716 dialog_token
= p2p
['dialog_token']
1717 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1718 attrs
= p2p_attr_status()
1719 #attrs += p2p_attr_capability()
1720 attrs
+= p2p_attr_go_intent()
1721 attrs
+= p2p_attr_config_timeout()
1722 #attrs += p2p_attr_intended_interface_addr(addr0)
1723 attrs
+= p2p_attr_channel_list()
1724 #attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
1725 attrs
+= p2p_attr_operating_channel()
1726 msg
['payload'] += ie_p2p(attrs
)
1727 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1728 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1729 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1731 logger
.debug("GO Neg Resp without GO Intent")
1732 dev
[1].p2p_stop_find()
1734 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1735 raise Exception("P2P_CONNECT failed(2)")
1736 p2p
= rx_go_neg_req(dev
[0])
1737 dev
[0].p2p_stop_find()
1738 dialog_token
= p2p
['dialog_token']
1739 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1740 attrs
= p2p_attr_status()
1741 attrs
+= p2p_attr_capability()
1742 #attrs += p2p_attr_go_intent()
1743 attrs
+= p2p_attr_config_timeout()
1744 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1745 attrs
+= p2p_attr_channel_list()
1746 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1747 attrs
+= p2p_attr_operating_channel()
1748 msg
['payload'] += ie_p2p(attrs
)
1749 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1750 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1751 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1753 logger
.debug("GO Neg Resp with invalid GO Intent")
1754 dev
[1].p2p_stop_find()
1756 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc"):
1757 raise Exception("P2P_CONNECT failed(2)")
1758 p2p
= rx_go_neg_req(dev
[0])
1759 dev
[0].p2p_stop_find()
1760 dialog_token
= p2p
['dialog_token']
1761 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1762 attrs
= p2p_attr_status()
1763 attrs
+= p2p_attr_capability()
1764 attrs
+= p2p_attr_go_intent(go_intent
=16)
1765 attrs
+= p2p_attr_config_timeout()
1766 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1767 attrs
+= p2p_attr_channel_list()
1768 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1769 attrs
+= p2p_attr_operating_channel()
1770 msg
['payload'] += ie_p2p(attrs
)
1771 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1772 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1773 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1775 logger
.debug("GO Neg Resp with incompatible GO Intent")
1776 dev
[1].p2p_stop_find()
1778 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=15"):
1779 raise Exception("P2P_CONNECT failed(2)")
1780 p2p
= rx_go_neg_req(dev
[0])
1781 dev
[0].p2p_stop_find()
1782 dialog_token
= p2p
['dialog_token']
1783 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1784 attrs
= p2p_attr_status()
1785 attrs
+= p2p_attr_capability()
1786 attrs
+= p2p_attr_go_intent(go_intent
=15)
1787 attrs
+= p2p_attr_config_timeout()
1788 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1789 attrs
+= p2p_attr_channel_list()
1790 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1791 attrs
+= p2p_attr_operating_channel()
1792 msg
['payload'] += ie_p2p(attrs
)
1793 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1794 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INCOMPATIBLE_PARAMS
)
1795 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INCOMPATIBLE_PARAMS
, dialog_token
)
1797 logger
.debug("GO Neg Resp without P2P Group ID")
1798 dev
[1].p2p_stop_find()
1800 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1801 raise Exception("P2P_CONNECT failed(2)")
1802 p2p
= rx_go_neg_req(dev
[0])
1803 dev
[0].p2p_stop_find()
1804 dialog_token
= p2p
['dialog_token']
1805 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1806 attrs
= p2p_attr_status()
1807 attrs
+= p2p_attr_capability()
1808 attrs
+= p2p_attr_go_intent(go_intent
=15)
1809 attrs
+= p2p_attr_config_timeout()
1810 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1811 attrs
+= p2p_attr_channel_list()
1812 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1813 attrs
+= p2p_attr_operating_channel()
1814 #attrs += p2p_attr_group_id(src, "DIRECT-foo")
1815 msg
['payload'] += ie_p2p(attrs
)
1816 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1817 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1818 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1820 logger
.debug("GO Neg Resp without Operating Channel")
1821 dev
[1].p2p_stop_find()
1823 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1824 raise Exception("P2P_CONNECT failed(2)")
1825 p2p
= rx_go_neg_req(dev
[0])
1826 dev
[0].p2p_stop_find()
1827 dialog_token
= p2p
['dialog_token']
1828 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1829 attrs
= p2p_attr_status()
1830 attrs
+= p2p_attr_capability()
1831 attrs
+= p2p_attr_go_intent(go_intent
=15)
1832 #attrs += p2p_attr_config_timeout()
1833 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1834 attrs
+= p2p_attr_channel_list()
1835 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1836 #attrs += p2p_attr_operating_channel()
1837 attrs
+= p2p_attr_group_id(addr0
, "DIRECT-foo")
1838 msg
['payload'] += ie_p2p(attrs
)
1839 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1840 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1841 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1843 logger
.debug("GO Neg Resp without Channel List")
1844 dev
[1].p2p_stop_find()
1846 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1847 raise Exception("P2P_CONNECT failed(2)")
1848 p2p
= rx_go_neg_req(dev
[0])
1849 dev
[0].p2p_stop_find()
1850 dialog_token
= p2p
['dialog_token']
1851 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1852 attrs
= p2p_attr_status()
1853 attrs
+= p2p_attr_capability()
1854 attrs
+= p2p_attr_go_intent(go_intent
=15)
1855 attrs
+= p2p_attr_config_timeout()
1856 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1857 #attrs += p2p_attr_channel_list()
1858 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1859 attrs
+= p2p_attr_operating_channel()
1860 attrs
+= p2p_attr_group_id(addr0
, "DIRECT-foo")
1861 msg
['payload'] += ie_p2p(attrs
)
1862 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1863 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_INVALID_PARAMS
)
1864 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_INVALID_PARAMS
, dialog_token
)
1866 logger
.debug("GO Neg Resp without common channels")
1867 dev
[1].p2p_stop_find()
1869 if "FAIL" in dev
[1].global_request("P2P_CONNECT " + addr0
+ " pbc go_intent=0"):
1870 raise Exception("P2P_CONNECT failed(2)")
1871 p2p
= rx_go_neg_req(dev
[0])
1872 dev
[0].p2p_stop_find()
1873 dialog_token
= p2p
['dialog_token']
1874 msg
= p2p_hdr(addr1
, addr0
, type=P2P_GO_NEG_RESP
, dialog_token
=dialog_token
)
1875 attrs
= p2p_attr_status()
1876 attrs
+= p2p_attr_capability()
1877 attrs
+= p2p_attr_go_intent(go_intent
=15)
1878 attrs
+= p2p_attr_config_timeout()
1879 attrs
+= p2p_attr_intended_interface_addr(addr0
)
1880 attrs
+= struct
.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST
, 5,
1883 attrs
+= p2p_attr_device_info(addr0
, config_methods
=0x0108)
1884 attrs
+= p2p_attr_operating_channel()
1885 attrs
+= p2p_attr_group_id(addr0
, "DIRECT-foo")
1886 msg
['payload'] += ie_p2p(attrs
)
1887 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1
, addr1
, p2p
['freq'], binascii
.hexlify(msg
['payload'])))
1888 check_p2p_go_neg_fail_event(dev
[1], P2P_SC_FAIL_NO_COMMON_CHANNELS
)
1889 rx_go_neg_conf(dev
[0], P2P_SC_FAIL_NO_COMMON_CHANNELS
, dialog_token
)
1891 def test_p2p_msg_group_info(dev
):
1892 """P2P protocol tests for Group Info parsing"""
1894 _test_p2p_msg_group_info(dev
)
1896 dev
[0].request("VENDOR_ELEM_REMOVE 2 *")
1898 def _test_p2p_msg_group_info(dev
):
1899 tests
= [ "dd08506f9a090e010001",
1900 "dd08506f9a090e010000",
1901 "dd20506f9a090e190018" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "ff",
1902 "dd20506f9a090e190018" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00",
1903 "dd24506f9a090e1d001c" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00" + "00000000",
1904 "dd24506f9a090e1d001c" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00" + "10110001",
1905 "dd24506f9a090e1d001c" + "112233445566" + "aabbccddeeff" + "00" + "0000" + "0000000000000000" + "00" + "1011ffff" ]
1907 dev
[0].request("VENDOR_ELEM_REMOVE 2 *")
1908 if "OK" not in dev
[0].request("VENDOR_ELEM_ADD 2 " + t
):
1909 raise Exception("VENDOR_ELEM_ADD failed")
1910 dev
[0].p2p_start_go(freq
=2412)
1911 bssid
= dev
[0].get_group_status_field('bssid')
1912 dev
[2].request("BSS_FLUSH 0")
1913 dev
[2].scan_for_bss(bssid
, freq
=2412, force_scan
=True)
1914 bss
= dev
[2].request("BSS " + bssid
)
1915 if 'p2p_group_client' in bss
:
1916 raise Exception("Unexpected p2p_group_client")
1917 dev
[0].remove_group()
1919 MGMT_SUBTYPE_ACTION
= 13
1920 ACTION_CATEG_PUBLIC
= 4
1922 GAS_INITIAL_REQUEST
= 10
1923 GAS_INITIAL_RESPONSE
= 11
1924 GAS_COMEBACK_REQUEST
= 12
1925 GAS_COMEBACK_RESPONSE
= 13
1927 def gas_hdr(dst
, src
, type, req
=True, dialog_token
=0):
1929 msg
['fc'] = MGMT_SUBTYPE_ACTION
<< 4
1936 if dialog_token
is None:
1937 msg
['payload'] = struct
.pack("<BB", ACTION_CATEG_PUBLIC
, type)
1939 msg
['payload'] = struct
.pack("<BBB", ACTION_CATEG_PUBLIC
, type,
1943 def test_p2p_msg_sd(dev
, apdev
):
1944 """P2P protocol tests for service discovery messages"""
1945 dst
, src
, hapd
, channel
= start_p2p(dev
, apdev
)
1947 logger
.debug("Truncated GAS Initial Request - no Dialog Token field")
1948 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
, dialog_token
=None)
1951 logger
.debug("Truncated GAS Initial Request - no Advertisement Protocol element")
1952 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1955 logger
.debug("Truncated GAS Initial Request - no Advertisement Protocol element length")
1956 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1957 msg
['payload'] += struct
.pack('B', 108)
1960 logger
.debug("Invalid GAS Initial Request - unexpected IE")
1961 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1962 msg
['payload'] += struct
.pack('BB', 0, 0)
1965 logger
.debug("Truncated GAS Initial Request - too short Advertisement Protocol element")
1966 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1967 msg
['payload'] += struct
.pack('BB', 108, 0)
1970 logger
.debug("Truncated GAS Initial Request - too short Advertisement Protocol element 2")
1971 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1972 msg
['payload'] += struct
.pack('BBB', 108, 1, 127)
1975 logger
.debug("Invalid GAS Initial Request - unsupported GAS advertisement protocol id 255")
1976 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1977 msg
['payload'] += struct
.pack('BBBB', 108, 2, 127, 255)
1980 logger
.debug("Truncated GAS Initial Request - no Query Request length field")
1981 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1982 msg
['payload'] += anqp_adv_proto()
1985 logger
.debug("Truncated GAS Initial Request - too short Query Request length field")
1986 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1987 msg
['payload'] += anqp_adv_proto()
1988 msg
['payload'] += struct
.pack('<B', 0)
1991 logger
.debug("Truncated GAS Initial Request - too short Query Request field (minimum underflow)")
1992 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1993 msg
['payload'] += anqp_adv_proto()
1994 msg
['payload'] += struct
.pack('<H', 1)
1997 logger
.debug("Truncated GAS Initial Request - too short Query Request field (maximum underflow)")
1998 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
1999 msg
['payload'] += anqp_adv_proto()
2000 msg
['payload'] += struct
.pack('<H', 65535)
2003 logger
.debug("Truncated GAS Initial Request - too short Query Request field")
2004 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2005 msg
['payload'] += anqp_adv_proto()
2006 msg
['payload'] += struct
.pack('<H', 0)
2009 logger
.debug("Invalid GAS Initial Request - unsupported ANQP Info ID 65535")
2010 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2011 msg
['payload'] += anqp_adv_proto()
2012 msg
['payload'] += struct
.pack('<HHH', 4, 65535, 0)
2015 logger
.debug("Invalid GAS Initial Request - invalid ANQP Query Request length (truncated frame)")
2016 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2017 msg
['payload'] += anqp_adv_proto()
2018 msg
['payload'] += struct
.pack('<HHH', 4, 56797, 65535)
2021 logger
.debug("Invalid GAS Initial Request - invalid ANQP Query Request length (too short Query Request to contain OUI + OUI-type)")
2022 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2023 msg
['payload'] += anqp_adv_proto()
2024 msg
['payload'] += struct
.pack('<HHH', 4, 56797, 0)
2027 logger
.debug("Invalid GAS Initial Request - unsupported ANQP vendor OUI-type")
2028 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2029 msg
['payload'] += anqp_adv_proto()
2030 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a00)
2031 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2034 logger
.debug("Truncated GAS Initial Request - no Service Update Indicator")
2035 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2036 msg
['payload'] += anqp_adv_proto()
2037 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a09)
2038 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2041 logger
.debug("Truncated GAS Initial Request - truncated Service Update Indicator")
2042 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2043 msg
['payload'] += anqp_adv_proto()
2044 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a09)
2045 req
+= struct
.pack('<B', 0)
2046 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2049 logger
.debug("Unexpected GAS Initial Response")
2051 msg
= gas_hdr(dst
, src
, GAS_INITIAL_RESPONSE
)
2052 msg
['payload'] += struct
.pack('<HH', 0, 0)
2053 msg
['payload'] += anqp_adv_proto()
2054 msg
['payload'] += struct
.pack('<H', 0)
2057 logger
.debug("Truncated GAS Comeback Request - no Dialog Token field")
2058 msg
= gas_hdr(dst
, src
, GAS_COMEBACK_REQUEST
, dialog_token
=None)
2061 logger
.debug("GAS Comeback Request - no pending SD response fragment available")
2062 msg
= gas_hdr(dst
, src
, GAS_COMEBACK_REQUEST
)
2065 logger
.debug("Unexpected GAS Comeback Response")
2067 msg
= gas_hdr(dst
, src
, GAS_COMEBACK_RESPONSE
)
2068 msg
['payload'] += struct
.pack('<HBH', 0, 0, 0)
2069 msg
['payload'] += anqp_adv_proto()
2070 msg
['payload'] += struct
.pack('<H', 0)
2073 logger
.debug("Minimal GAS Initial Request")
2075 msg
= gas_hdr(dst
, src
, GAS_INITIAL_REQUEST
)
2076 msg
['payload'] += anqp_adv_proto()
2077 req
= struct
.pack('<HH', 56797, 4) + struct
.pack('>L', 0x506f9a09)
2078 req
+= struct
.pack('<H', 0)
2079 msg
['payload'] += struct
.pack('<H', len(req
)) + req
2081 resp
= hapd
.mgmt_rx()
2083 raise Exception("No response to minimal GAS Initial Request")