From 05ef25a642d624efd95fadf6df168f8e7e39bf01 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 2 Mar 2014 13:18:18 +0200 Subject: [PATCH] tests: Add protocol tests for P2P message processing This commit includes number of test frames for attribute parsing. Invitation Request and Provision Discovery processing is also covered. Signed-off-by: Jouni Malinen --- tests/hwsim/test_p2p_messages.py | 1038 ++++++++++++++++++++++++++++++ 1 file changed, 1038 insertions(+) create mode 100644 tests/hwsim/test_p2p_messages.py diff --git a/tests/hwsim/test_p2p_messages.py b/tests/hwsim/test_p2p_messages.py new file mode 100644 index 000000000..4558c5f7f --- /dev/null +++ b/tests/hwsim/test_p2p_messages.py @@ -0,0 +1,1038 @@ +# P2P protocol tests for various messages +# Copyright (c) 2014, Jouni Malinen +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import binascii +import struct +import time + +import hostapd + +MGMT_SUBTYPE_PROBE_REQ = 4 +MGMT_SUBTYPE_ACTION = 13 +ACTION_CATEG_PUBLIC = 4 + +P2P_GO_NEG_REQ = 0 +P2P_GO_NEG_RESP = 1 +P2P_GO_NEG_CONF = 2 +P2P_INVITATION_REQ = 3 +P2P_INVITATION_RESP = 4 +P2P_DEV_DISC_REQ = 5 +P2P_DEV_DISC_RESP = 6 +P2P_PROV_DISC_REQ = 7 +P2P_PROV_DISC_RESP = 8 + +P2P_ATTR_STATUS = 0 +P2P_ATTR_MINOR_REASON_CODE = 1 +P2P_ATTR_CAPABILITY = 2 +P2P_ATTR_DEVICE_ID = 3 +P2P_ATTR_GROUP_OWNER_INTENT = 4 +P2P_ATTR_CONFIGURATION_TIMEOUT = 5 +P2P_ATTR_LISTEN_CHANNEL = 6 +P2P_ATTR_GROUP_BSSID = 7 +P2P_ATTR_EXT_LISTEN_TIMING = 8 +P2P_ATTR_INTENDED_INTERFACE_ADDR = 9 +P2P_ATTR_MANAGEABILITY = 10 +P2P_ATTR_CHANNEL_LIST = 11 +P2P_ATTR_NOTICE_OF_ABSENCE = 12 +P2P_ATTR_DEVICE_INFO = 13 +P2P_ATTR_GROUP_INFO = 14 +P2P_ATTR_GROUP_ID = 15 +P2P_ATTR_INTERFACE = 16 +P2P_ATTR_OPERATING_CHANNEL = 17 +P2P_ATTR_INVITATION_FLAGS = 18 +P2P_ATTR_OOB_GO_NEG_CHANNEL = 19 +P2P_ATTR_VENDOR_SPECIFIC = 221 + +P2P_SC_SUCCESS = 0 +P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE = 1 +P2P_SC_FAIL_INCOMPATIBLE_PARAMS = 2 +P2P_SC_FAIL_LIMIT_REACHED = 3 +P2P_SC_FAIL_INVALID_PARAMS = 4 +P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE = 5 +P2P_SC_FAIL_PREV_PROTOCOL_ERROR = 6 +P2P_SC_FAIL_NO_COMMON_CHANNELS = 7 +P2P_SC_FAIL_UNKNOWN_GROUP = 8 +P2P_SC_FAIL_BOTH_GO_INTENT_15 = 9 +P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD = 10 +P2P_SC_FAIL_REJECTED_BY_USER = 11 + +WSC_ATTR_CONFIG_METHODS = 0x1008 + +WLAN_EID_SSID = 0 +WLAN_EID_SUPP_RATES = 1 +WLAN_EID_VENDOR_SPECIFIC = 221 + +def ie_ssid(ssid): + return struct.pack("HHH", WSC_ATTR_CONFIG_METHODS, 2, methods) + +def p2p_attr_status(status=P2P_SC_SUCCESS): + return struct.pack("HH', 0x1011, len(name)) +name + +def p2p_attr_group_id(addr, ssid): + val = struct.unpack('6B', binascii.unhexlify(addr.replace(':',''))) + t = (P2P_ATTR_GROUP_ID, 6 + len(ssid)) + val + return struct.pack('