2013-12-30 23:17:02 +01:00
|
|
|
# cfg80211 connect command (SME in the driver/firmware)
|
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
|
|
|
import time
|
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
import hostapd
|
|
|
|
from wpasupplicant import WpaSupplicant
|
2015-11-25 14:47:16 +01:00
|
|
|
from p2p_utils import *
|
2013-12-30 23:17:02 +01:00
|
|
|
|
|
|
|
def test_connect_cmd_open(dev, apdev):
|
|
|
|
"""Open connection using cfg80211 connect command"""
|
2014-03-02 19:44:05 +01:00
|
|
|
params = { "ssid": "sta-connect",
|
|
|
|
"manage_p2p": "1",
|
|
|
|
"allow_cross_connection": "1" }
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2014-03-02 19:44:05 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
2014-12-20 18:44:40 +01:00
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bg_scan_period="1")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-02 19:44:05 +01:00
|
|
|
wpas.request("DISCONNECT")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-03-02 19:44:05 +01:00
|
|
|
|
2014-10-26 14:48:57 +01:00
|
|
|
def test_connect_cmd_wep(dev, apdev):
|
|
|
|
"""WEP Open System using cfg80211 connect command"""
|
|
|
|
params = { "ssid": "sta-connect-wep", "wep_key0": '"hello"' }
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-10-26 14:48:57 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
wep_key0='"hello"')
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-10-26 14:48:57 +01:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
|
|
|
wpas.request("DISCONNECT")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-10-26 14:48:57 +01:00
|
|
|
|
|
|
|
def test_connect_cmd_wep_shared(dev, apdev):
|
|
|
|
"""WEP Shared key using cfg80211 connect command"""
|
|
|
|
params = { "ssid": "sta-connect-wep", "wep_key0": '"hello"',
|
|
|
|
"auth_algs": "2" }
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-10-26 14:48:57 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
id = wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
auth_alg="SHARED", wep_key0='"hello"')
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-10-26 14:48:57 +01:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.remove_network(id)
|
|
|
|
wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
auth_alg="OPEN SHARED", wep_key0='"hello"')
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-10-26 14:48:57 +01:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
|
|
|
wpas.request("DISCONNECT")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-10-26 14:48:57 +01:00
|
|
|
|
2014-03-02 19:44:05 +01:00
|
|
|
def test_connect_cmd_p2p_management(dev, apdev):
|
|
|
|
"""Open connection using cfg80211 connect command and AP using P2P management"""
|
|
|
|
params = { "ssid": "sta-connect",
|
|
|
|
"manage_p2p": "1",
|
|
|
|
"allow_cross_connection": "0" }
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2013-12-30 23:17:02 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2013-12-30 23:17:02 +01:00
|
|
|
wpas.request("DISCONNECT")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2013-12-30 23:17:02 +01:00
|
|
|
|
|
|
|
def test_connect_cmd_wpa2_psk(dev, apdev):
|
|
|
|
"""WPA2-PSK connection using cfg80211 connect command"""
|
|
|
|
params = hostapd.wpa2_params(ssid="sta-connect", passphrase="12345678")
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2013-12-30 23:17:02 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", psk="12345678", scan_freq="2412")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2013-12-30 23:17:02 +01:00
|
|
|
wpas.request("DISCONNECT")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2014-01-04 07:28:02 +01:00
|
|
|
|
|
|
|
def test_connect_cmd_concurrent_grpform_while_connecting(dev, apdev):
|
|
|
|
"""Concurrent P2P group formation while connecting to an AP using cfg80211 connect command"""
|
|
|
|
logger.info("Start connection to an infrastructure AP")
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
|
2014-01-04 07:28:02 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("test-open", key_mgmt="NONE", wait_connect=False)
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-01-04 07:28:02 +01:00
|
|
|
|
|
|
|
logger.info("Form a P2P group while connecting to an AP")
|
|
|
|
wpas.request("SET p2p_no_group_iface 0")
|
|
|
|
|
|
|
|
[i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412,
|
|
|
|
r_dev=wpas, r_freq=2412)
|
|
|
|
check_grpform_results(i_res, r_res)
|
|
|
|
remove_group(dev[0], wpas)
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-01-04 07:28:02 +01:00
|
|
|
|
|
|
|
logger.info("Confirm AP connection after P2P group removal")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(wpas, hapd)
|
2014-06-01 22:03:14 +02:00
|
|
|
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
2014-06-01 22:03:14 +02:00
|
|
|
def test_connect_cmd_reject_assoc(dev, apdev):
|
|
|
|
"""Connection using cfg80211 connect command getting rejected"""
|
|
|
|
params = { "ssid": "sta-connect",
|
|
|
|
"require_ht": "1" }
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2014-06-01 22:03:14 +02:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
disable_ht="1", wait_connect=False)
|
|
|
|
# Reject event gets reported twice since we force connect command to be used
|
|
|
|
# with a driver that supports auth+assoc for testing purposes.
|
|
|
|
for i in range(0, 2):
|
|
|
|
ev = wpas.wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=15)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Association rejection timed out")
|
|
|
|
if "status_code=27" not in ev:
|
|
|
|
raise Exception("Unexpected rejection status code")
|
2014-06-01 22:20:36 +02:00
|
|
|
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
2014-06-01 22:20:36 +02:00
|
|
|
def test_connect_cmd_disconnect_event(dev, apdev):
|
|
|
|
"""Connection using cfg80211 connect command getting disconnected by the AP"""
|
|
|
|
params = { "ssid": "sta-connect" }
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-06-01 22:20:36 +02:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
|
|
|
|
if "OK" not in hapd.request("DEAUTHENTICATE " + wpas.p2p_interface_addr()):
|
|
|
|
raise Exception("DEAUTHENTICATE command failed")
|
|
|
|
ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Disconnection event timed out")
|
|
|
|
# This event was actually based on deauthenticate event since we force
|
|
|
|
# connect command to be used with a driver that supports auth+assoc for
|
|
|
|
# testing purposes. Anyway, wait some time to allow the debug log to capture
|
|
|
|
# the following NL80211_CMD_DISCONNECT event.
|
|
|
|
time.sleep(0.1)
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-08-28 18:01:47 +02:00
|
|
|
|
2015-12-30 12:29:32 +01:00
|
|
|
# Clean up to avoid causing issue for following test cases
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=2)
|
|
|
|
wpas.flush_scan_cache()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
wpas.interface_remove("wlan5")
|
|
|
|
del wpas
|
|
|
|
|
2015-08-28 18:01:47 +02:00
|
|
|
def test_connect_cmd_roam(dev, apdev):
|
|
|
|
"""cfg80211 connect command to trigger roam"""
|
|
|
|
params = { "ssid": "sta-connect" }
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2015-08-28 18:01:47 +02:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-08-28 18:01:47 +02:00
|
|
|
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[1], params)
|
2015-10-03 23:35:12 +02:00
|
|
|
wpas.scan_for_bss(apdev[1]['bssid'], freq=2412, force_scan=True)
|
2015-08-28 18:01:47 +02:00
|
|
|
wpas.roam(apdev[1]['bssid'])
|
2015-10-04 00:42:42 +02:00
|
|
|
time.sleep(0.1)
|
|
|
|
wpas.request("DISCONNECT")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
2017-05-11 23:33:06 +02:00
|
|
|
|
|
|
|
def test_connect_cmd_bssid_hint(dev, apdev):
|
|
|
|
"""cfg80211 connect command with bssid_hint"""
|
|
|
|
params = { "ssid": "sta-connect" }
|
|
|
|
hostapd.add_ap(apdev[0], params)
|
|
|
|
hostapd.add_ap(apdev[1], params)
|
|
|
|
|
|
|
|
# This does not really give full coverage with mac80211_hwsim since the
|
|
|
|
# driver does not end up claiming support for driver-based BSS selection.
|
|
|
|
# Anyway, some test coverage can be achieved for setting the parameter and
|
|
|
|
# checking that it does not prevent connection with another BSSID.
|
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bssid_hint=apdev[0]['bssid'])
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
|
|
|
wpas.request("BSS_FLUSH 0")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bssid_hint='22:33:44:55:66:77')
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
|
|
|
|
# Additional coverage using ap_scan=2 to prevent scan entry -based selection
|
|
|
|
# within wpa_supplicant from overriding bssid_hint.
|
|
|
|
|
|
|
|
try:
|
|
|
|
if "OK" not in wpas.request("AP_SCAN 2"):
|
|
|
|
raise Exception("Failed to set AP_SCAN 2")
|
|
|
|
wpas.request("BSS_FLUSH 0")
|
|
|
|
wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412",
|
|
|
|
bssid_hint='22:33:44:55:66:77')
|
|
|
|
wpas.request("REMOVE_NETWORK all")
|
|
|
|
wpas.wait_disconnected()
|
|
|
|
wpas.dump_monitor()
|
|
|
|
finally:
|
|
|
|
wpas.request("AP_SCAN 1")
|
2019-02-25 20:58:28 +01:00
|
|
|
wpas.flush_scan_cache()
|