diff --git a/tests/hwsim/test_p2p_messages.py b/tests/hwsim/test_p2p_messages.py index c86622c8e..bd7ce6a2d 100644 --- a/tests/hwsim/test_p2p_messages.py +++ b/tests/hwsim/test_p2p_messages.py @@ -11,6 +11,8 @@ import logging logger = logging.getLogger() import hostapd +from test_p2p_persistent import form +from test_p2p_persistent import invite MGMT_SUBTYPE_PROBE_REQ = 4 MGMT_SUBTYPE_ACTION = 13 @@ -744,6 +746,122 @@ def test_p2p_msg_invitation_no_common_channels(dev, apdev): if ev is not None: raise Exception("Unexpected invitation event") +def test_p2p_msg_invitation_resp(dev, apdev): + """P2P protocol tests for invitation response processing""" + form(dev[0], dev[1]) + dev[0].dump_monitor() + dev[1].dump_monitor() + + dst, src, hapd, channel = start_p2p(dev, apdev) + + addr0 = dev[0].p2p_dev_addr() + addr1 = dev[1].p2p_dev_addr() + peer = dev[1].get_peer(addr0) + + # P2P Invitation Response from unknown peer + msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=1) + hapd.mgmt_tx(msg) + + # P2P Invitation Response from peer that is not in invitation + msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=2) + attrs = p2p_attr_status() + msg['payload'] += ie_p2p(attrs) + mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=50 no_cck=1 action={}".format(addr0, addr0, peer['listen_freq'], binascii.hexlify(msg['payload']))) + time.sleep(0.1) + + if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"): + raise Exception("Failed to enable external management frame handling") + + invite(dev[0], dev[1]) + rx_msg = dev[1].mgmt_rx() + if rx_msg is None: + raise Exception("MGMT-RX timeout") + p2p = parse_p2p_public_action(rx_msg['payload']) + if p2p is None: + raise Exception("Not a P2P Public Action frame " + str(dialog_token)) + if p2p['subtype'] != P2P_INVITATION_REQ: + raise Exception("Unexpected subtype %d" % p2p['subtype']) + + # Invalid attribute to cause p2p_parse() failure + msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token']) + attrs = struct.pack("