diff --git a/tests/hwsim/test_p2p_discovery.py b/tests/hwsim/test_p2p_discovery.py index 8fd4af4bc..d555e02c2 100644 --- a/tests/hwsim/test_p2p_discovery.py +++ b/tests/hwsim/test_p2p_discovery.py @@ -119,3 +119,64 @@ def test_discovery_group_client(dev): ev = dev[1].wait_event(["P2P-GO-NEG-REQUEST"]) if ev is None: raise Exception("Timeout on waiting for GO Negotiation Request") + +def test_discovery_dev_type(dev): + """P2P device discovery with Device Type filter""" + dev[1].request("SET sec_device_type 1-0050F204-2") + dev[1].p2p_listen() + dev[0].p2p_find(social=True, dev_type="5-0050F204-1") + ev = dev[0].wait_event(['P2P-DEVICE-FOUND'], timeout=1) + if ev: + raise Exception("Unexpected P2P device found") + dev[0].p2p_find(social=True, dev_type="1-0050F204-2") + ev = dev[0].wait_event(['P2P-DEVICE-FOUND'], timeout=1) + if ev is None: + raise Exception("P2P device not found") + +def test_discovery_dev_type_go(dev): + """P2P device discovery with Device Type filter on GO""" + addr1 = dev[1].p2p_dev_addr() + dev[1].request("SET sec_device_type 1-0050F204-2") + res = dev[0].p2p_start_go(freq="2412") + pin = dev[1].wps_read_pin() + dev[0].p2p_go_authorize_client(pin) + dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) + + dev[2].p2p_find(social=True, dev_type="5-0050F204-1") + ev = dev[2].wait_event(['P2P-DEVICE-FOUND'], timeout=1) + if ev: + raise Exception("Unexpected P2P device found") + dev[2].p2p_find(social=True, dev_type="1-0050F204-2") + ev = dev[2].wait_event(['P2P-DEVICE-FOUND ' + addr1], timeout=1) + if ev is None: + raise Exception("P2P device not found") + +def test_discovery_dev_id(dev): + """P2P device discovery with Device ID filter""" + addr1 = dev[1].p2p_dev_addr() + dev[1].p2p_listen() + dev[0].p2p_find(social=True, dev_id="02:03:04:05:06:07") + ev = dev[0].wait_event(['P2P-DEVICE-FOUND'], timeout=1) + if ev: + raise Exception("Unexpected P2P device found") + dev[0].p2p_find(social=True, dev_id=addr1) + ev = dev[0].wait_event(['P2P-DEVICE-FOUND'], timeout=1) + if ev is None: + raise Exception("P2P device not found") + +def test_discovery_dev_id_go(dev): + """P2P device discovery with Device ID filter on GO""" + addr1 = dev[1].p2p_dev_addr() + res = dev[0].p2p_start_go(freq="2412") + pin = dev[1].wps_read_pin() + dev[0].p2p_go_authorize_client(pin) + dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) + + dev[2].p2p_find(social=True, dev_id="02:03:04:05:06:07") + ev = dev[2].wait_event(['P2P-DEVICE-FOUND'], timeout=1) + if ev: + raise Exception("Unexpected P2P device found") + dev[2].p2p_find(social=True, dev_id=addr1) + ev = dev[2].wait_event(['P2P-DEVICE-FOUND ' + addr1], timeout=1) + if ev is None: + raise Exception("P2P device not found") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 403a89f32..5a9a70f95 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -278,10 +278,15 @@ class WpaSupplicant: def p2p_listen(self): return self.global_request("P2P_LISTEN") - def p2p_find(self, social=False): + def p2p_find(self, social=False, dev_id=None, dev_type=None): + cmd = "P2P_FIND" if social: - return self.global_request("P2P_FIND type=social") - return self.global_request("P2P_FIND") + cmd = cmd + " type=social" + if dev_id: + cmd = cmd + " dev_id=" + dev_id + if dev_type: + cmd = cmd + " dev_type=" + dev_type + return self.global_request(cmd) def p2p_stop_find(self): return self.global_request("P2P_STOP_FIND")