def test_nfc_wps_password_token_sta(dev, apdev): """NFC tag with password token on the station/Enrollee""" dev[0].request("SET ignore_old_scan_res 1") ssid = "test-wps-nfc-pw-token-conf" params = ap_wps_params(ssid) hostapd.add_ap(apdev[0]['ifname'], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step using password token from station") pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = hapd.request("WPS_NFC_TAG_READ " + pw) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to hostapd") dev[0].dump_monitor() res = dev[0].request("WPS_NFC") if "FAIL" in res: raise Exception("Failed to start Enrollee using NFC password token") ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out") check_wpa2_connection(dev[0], apdev[0], ssid)
def test_nfc_wps_password_token_sta(dev, apdev): """NFC tag with password token on the station/Enrollee""" ssid = "test-wps-nfc-pw-token-conf" params = ap_wps_params(ssid) hostapd.add_ap(apdev[0], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step using password token from station") wps = dev[0].request("WPS_NFC_TOKEN WPS").rstrip() if "FAIL" in wps: raise Exception("Failed to generate password token (WPS only)") pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = hapd.request("WPS_NFC_TAG_READ " + pw) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to hostapd") dev[0].dump_monitor() res = dev[0].request("WPS_NFC") if "FAIL" in res: raise Exception("Failed to start Enrollee using NFC password token") dev[0].wait_connected(timeout=30) check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
def test_nfc_wps_config_token(dev, apdev): """NFC tag with configuration token from AP""" ssid = "test-wps-nfc-conf-token" params = ap_wps_params(ssid) hostapd.add_ap(apdev[0], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("NFC configuration token from AP to station") conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip() if "FAIL" in conf: raise Exception("Failed to generate configuration token") dev[0].dump_monitor() res = dev[0].request("WPS_NFC_TAG_READ " + conf) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to wpa_supplicant") dev[0].wait_connected(timeout=15) check_wpa2_connection(dev[0], apdev[0], hapd, ssid) with alloc_fail(hapd, 1, "wps_get_oob_cred"): conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip() if "FAIL" not in conf: raise Exception( "Unexpected configuration token received during OOM")
def test_nfc_wps_password_token_sta_init(dev, apdev): """Initial AP configuration with first WPS NFC Enrollee""" ssid = "test-wps-nfc-pw-token-init" hostapd.add_ap(apdev[0], { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step using password token from station") pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = hapd.request("WPS_NFC_TAG_READ " + pw) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to hostapd") dev[0].dump_monitor() res = dev[0].request("WPS_NFC") if "FAIL" in res: raise Exception("Failed to start Enrollee using NFC password token") dev[0].wait_connected(timeout=30) check_wpa2_connection(dev[0], apdev[0], hapd, ssid, mixed=True)
def test_wnm_sleep_mode_rsn_pmf(dev, apdev): """WNM Sleep Mode - RSN with PMF""" wt = Wlantest() wt.flush() wt.add_passphrase("12345678") params = hostapd.wpa2_params("test-wnm-rsn", "12345678") params["wpa_key_mgmt"] = "WPA-PSK-SHA256" params["ieee80211w"] = "2" params["time_advertisement"] = "2" params["time_zone"] = "EST5" params["wnm_sleep_mode"] = "1" params["bss_transition"] = "1" hostapd.add_ap(apdev[0]['ifname'], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") check_wnm_sleep_mode_enter_exit(hapd, dev[0])
def test_nfc_wps_config_token_init(dev, apdev): """NFC tag with configuration token from AP with auto configuration""" dev[0].request("SET ignore_old_scan_res 1") ssid = "test-wps-nfc-conf-token-init" hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("NFC configuration token from AP to station") conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip() if "FAIL" in conf: raise Exception("Failed to generate configuration token") dev[0].dump_monitor() res = dev[0].request("WPS_NFC_TAG_READ " + conf) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to wpa_supplicant") ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15) if ev is None: raise Exception("Association with the AP timed out") check_wpa2_connection(dev[0], apdev[0], ssid, mixed=True)
def test_nfc_wps_password_token_sta_init(dev, apdev): """Initial AP configuration with first WPS NFC Enrollee""" dev[0].request("SET ignore_old_scan_res 1") ssid = "test-wps-nfc-pw-token-init" hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step using password token from station") pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = hapd.request("WPS_NFC_TAG_READ " + pw) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to hostapd") dev[0].dump_monitor() res = dev[0].request("WPS_NFC") if "FAIL" in res: raise Exception("Failed to start Enrollee using NFC password token") ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15) if ev is None: raise Exception("Association with the AP timed out") check_wpa2_connection(dev[0], apdev[0], ssid, mixed=True)
def test_ap_pmf_required(dev, apdev): """WPA2-PSK AP with PMF required""" ssid = "test-pmf-required" wt = Wlantest() wt.flush() wt.add_passphrase("12345678") params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") params["wpa_key_mgmt"] = "WPA-PSK-SHA256" params["ieee80211w"] = "2" hostapd.add_ap(apdev[0]['ifname'], params) dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) dev[1].connect(ssid, psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname']) hapd = hostapd.Hostapd(apdev[0]['ifname']) hapd.request("SA_QUERY " + dev[0].p2p_interface_addr()) hapd.request("SA_QUERY " + dev[1].p2p_interface_addr()) wt.require_ap_pmf_mandatory(apdev[0]['bssid']) wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr()) wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr()) time.sleep(0.1) if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'], dev[0].p2p_interface_addr()) < 1: raise Exception("STA did not reply to SA Query") if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'], dev[1].p2p_interface_addr()) < 1: raise Exception("STA did not reply to SA Query")
def setup_tdls(sta0, sta1, ap, reverse=False, expect_fail=False): logger.info("Setup TDLS") hapd = hostapd.Hostapd(ap['ifname']) check_connectivity(sta0, sta1, hapd) bssid = ap['bssid'] addr0 = sta0.p2p_interface_addr() addr1 = sta1.p2p_interface_addr() wt = Wlantest() wt.tdls_clear(bssid, addr0, addr1); wt.tdls_clear(bssid, addr1, addr0); sta0.tdls_setup(addr1) time.sleep(1) if expect_fail: tdls_check_ap(sta0, sta1, bssid, addr0, addr1) return if reverse: addr1 = sta0.p2p_interface_addr() addr0 = sta1.p2p_interface_addr() conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr0, addr1); if conf == 0: raise Exception("No TDLS Setup Confirm (success) seen") tdls_check_dl(sta0, sta1, bssid, addr0, addr1) check_connectivity(sta0, sta1, hapd)
def test_wnm_disassoc_imminent(dev, apdev): """WNM Disassociation Imminent""" params = { "ssid": "test-wnm", "time_advertisement": "2", "time_zone": "EST5", "wnm_sleep_mode": "1", "bss_transition": "1" } hostapd.add_ap(apdev[0]['ifname'], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") addr = dev[0].p2p_interface_addr() hapd.request("DISASSOC_IMMINENT " + addr + " 10") ev = dev[0].wait_event(["WNM: Disassociation Imminent"]) if ev is None: raise Exception("Timeout while waiting for disassociation imminent") if "Disassociation Timer 10" not in ev: raise Exception("Unexpected disassociation imminent contents") ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) if ev is None: raise Exception("Timeout while waiting for re-connection scan")
def test_ap_wps_new_version_sta(dev, apdev): """WPS compatibility with new version number on the station""" ssid = "test-wps-ver" hostapd.add_ap( apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step") hapd.request("WPS_PBC") dev[0].dump_monitor() dev[0].request("SET wps_version_number 0x43") dev[0].request("SET wps_vendor_ext_m1 000137100100020001") dev[0].request("WPS_PBC") ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out")
def test_ap_wps_conf_pin_2sta(dev, apdev): """Two stations trying to use WPS PIN at the same time""" ssid = "test-wps-conf-pin2" hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step") pin = "12345670" pin2 = "55554444" hapd.request("WPS_PIN " + dev[0].get_status_field("uuid") + " " + pin) hapd.request("WPS_PIN " + dev[1].get_status_field("uuid") + " " + pin) dev[0].dump_monitor() dev[1].dump_monitor() dev[0].request("WPS_PIN any " + pin) dev[1].request("WPS_PIN any " + pin) ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out") ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out")
def _test_nfc_wps_er_handover(dev, apdev): ssid = "wps-nfc-er-handover" start_ap_er(dev[0], apdev[0], ssid) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step using connection handover") req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to to hostapd") dev[1].dump_monitor() res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to to wpa_supplicant") dev[1].wait_connected(timeout=15) check_wpa2_connection(dev[1], apdev[0], hapd, ssid)
def test_ap_wps_conf_pin(dev, apdev): """WPS PIN provisioning with configured AP""" ssid = "test-wps-conf-pin" hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step") pin = dev[0].wps_read_pin() hapd.request("WPS_PIN any " + pin) dev[0].dump_monitor() dev[0].request("WPS_PIN any " + pin) ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out") status = dev[0].get_status() if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: raise Exception("Not fully connected") if status['ssid'] != ssid: raise Exception("Unexpected SSID") if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': raise Exception("Unexpected encryption configuration") if status['key_mgmt'] != 'WPA2-PSK': raise Exception("Unexpected key_mgmt") dev[1].scan(freq="2412") bss = dev[1].get_bss(apdev[0]['bssid']) if "[WPS-AUTH]" in bss['flags']: raise Exception("WPS-AUTH flag not cleared") logger.info("Try to connect from another station using the same PIN") dev[1].request("WPS_PIN any " + pin) ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Operation timed out") if "WPS-M2D" not in ev: raise Exception("Unexpected WPS operation started")
def test_ap_bss_config_file(dev, apdev, params): """hostapd BSS config file""" pidfile = params['prefix'] + ".hostapd.pid" logfile = params['prefix'] + ".hostapd-log" prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd') if not os.path.exists(prg): prg = '../../hostapd/hostapd' phy = get_phy(apdev[0]) confname1 = hostapd.cfg_file(apdev[0], "bss-1.conf") confname2 = hostapd.cfg_file(apdev[0], "bss-2.conf") confname3 = hostapd.cfg_file(apdev[0], "bss-3.conf") cmd = [ prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, '-S', '-T', '-b', phy + ':' + confname1, '-b', phy + ':' + confname2, '-b', phy + ':' + confname3 ] res = subprocess.check_call(cmd) if res != 0: raise Exception("Could not start hostapd: %s" % str(res)) multi_check(apdev[0], dev, [True, True, True]) for i in range(0, 3): dev[i].request("DISCONNECT") hapd = hostapd.Hostapd(apdev[0]['ifname']) hapd.ping() if "OK" not in hapd.request("TERMINATE"): raise Exception("Failed to terminate hostapd process") ev = hapd.wait_event(["CTRL-EVENT-TERMINATING"], timeout=15) if ev is None: raise Exception("CTRL-EVENT-TERMINATING not seen") for i in range(30): time.sleep(0.1) if not os.path.exists(pidfile): break if os.path.exists(pidfile): raise Exception("PID file exits after process termination")
def test_ap_qosmap(dev, apdev): """QoS mapping""" drv_flags = dev[0].get_driver_status_field("capa.flags") if int(drv_flags, 0) & 0x40000000 == 0: return "skip" ssid = "test-qosmap" params = {"ssid": ssid} params[ 'qos_map_set'] = '53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,55' hostapd.add_ap(apdev[0]['ifname'], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") time.sleep(0.1) check_qos_map(apdev[0], dev[0], 53, 2) check_qos_map(apdev[0], dev[0], 22, 6) check_qos_map(apdev[0], dev[0], 8, 0) check_qos_map(apdev[0], dev[0], 15, 0) check_qos_map(apdev[0], dev[0], 0, 1) check_qos_map(apdev[0], dev[0], 7, 1) check_qos_map(apdev[0], dev[0], 16, 3) check_qos_map(apdev[0], dev[0], 31, 3) check_qos_map(apdev[0], dev[0], 32, 4) check_qos_map(apdev[0], dev[0], 39, 4) check_qos_map(apdev[0], dev[0], 40, 6) check_qos_map(apdev[0], dev[0], 47, 6) check_qos_map(apdev[0], dev[0], 48, 7) check_qos_map(apdev[0], dev[0], 55, 7) hapd = hostapd.Hostapd(apdev[0]['ifname']) hapd.request( "SET_QOS_MAP_SET 22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,55" ) hapd.request("SEND_QOS_MAP_CONF " + dev[0].get_status_field("address")) check_qos_map(apdev[0], dev[0], 53, 7) check_qos_map(apdev[0], dev[0], 22, 6) check_qos_map(apdev[0], dev[0], 48, 7) check_qos_map(apdev[0], dev[0], 55, 7) check_qos_map(apdev[0], dev[0], 56, 56 >> 3) check_qos_map(apdev[0], dev[0], 63, 63 >> 3)
def test_nfc_wps_er_pw_token(dev, apdev): """WPS NFC password token from Enrollee to ER""" ssid = "wps-nfc-er-pw-token" start_ap_er(dev[0], apdev[0], ssid) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step using password token from station") dev[1].request("SET ignore_old_scan_res 1") pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = dev[0].request("WPS_NFC_TAG_READ " + pw) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to WPS ER") dev[0].dump_monitor() res = dev[1].request("WPS_NFC") if "FAIL" in res: raise Exception("Failed to start Enrollee using NFC password token") ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) if ev is None: raise Exception("WPS ER did not report success") ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15) if ev is None: raise Exception("Association with the AP timed out") check_wpa2_connection(dev[1], apdev[0], hapd, ssid)
def test_ap_hs20_gas_frag_while_associated(dev, apdev): """Hotspot 2.0 connection with fragmented GAS query while associated""" bssid = apdev[0]['bssid'] params = hs20_ap_params() params['hessid'] = bssid hostapd.add_ap(apdev[0]['ifname'], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) hapd.set("gas_frag_limit", "50") dev[0].request("SET ignore_old_scan_res 1") dev[0].hs20_enable() id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "******", 'password': "******", 'domain': "example.com" }) interworking_select(dev[0], bssid, "home") interworking_connect(dev[0], bssid, "TTLS") logger.info("Verifying GAS query while associated") dev[0].request("FETCH_ANQP") for i in range(0, 6): ev = dev[0].wait_event(["RX-ANQP"], timeout=5) if ev is None: raise Exception("Operation timed out")
def test_ap_wps_pbc_overlap_2sta(dev, apdev): """WPS PBC session overlap with two active STAs""" ssid = "test-wps-pbc-overlap" hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step") hapd.request("WPS_PBC") dev[0].dump_monitor() dev[1].dump_monitor() dev[0].request("WPS_PBC") dev[1].request("WPS_PBC") ev = dev[0].wait_event(["WPS-M2D"], timeout=15) if ev is None: raise Exception("PBC session overlap not detected (dev0)") if "config_error=12" not in ev: raise Exception("PBC session overlap not correctly reported (dev0)") ev = dev[1].wait_event(["WPS-M2D"], timeout=15) if ev is None: raise Exception("PBC session overlap not detected (dev1)") if "config_error=12" not in ev: raise Exception("PBC session overlap not correctly reported (dev1)")
def __init__(self, connect_string): print "init" self.missing_AP = False try: AP_interface = findap.findap() self.myap = hostapd.Hostapd(AP_interface) except: print "AP missing will just print enceded beacon" self.missing_AP = True self.encode_beacon = rospy.ServiceProxy('gf_beacon_encoding', gf_encoding) self.beacon_dict = {} self.previous_beacon_dict = {} vehicle = connect(connect_string, wait_ready=True) vehicle.add_attribute_listener('location.global_relative_frame', self.location_callback) # vehicle.add_attribute_listener('location.local_frame', # self.location_callback) vehicle.add_attribute_listener('groundspeed', self.location_callback) vehicle.add_attribute_listener('battery', self.location_callback) vehicle.add_attribute_listener('heading', self.location_callback) vehicle.add_attribute_listener('vehicle.mode.name', self.location_callback)
def test_ap_wps_check_pin(dev, apdev): """Verify PIN checking through control interface""" hostapd.add_ap( apdev[0]['ifname'], { "ssid": "wps", "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) hapd = hostapd.Hostapd(apdev[0]['ifname']) for t in [("12345670", "12345670"), ("12345678", "FAIL-CHECKSUM"), ("1234-5670", "12345670"), ("1234 5670", "12345670"), ("1-2.3:4 5670", "12345670")]: res = hapd.request("WPS_CHECK_PIN " + t[0]).rstrip('\n') res2 = dev[0].request("WPS_CHECK_PIN " + t[0]).rstrip('\n') if res != res2: raise Exception("Unexpected difference in WPS_CHECK_PIN responses") if res != t[1]: raise Exception( "Incorrect WPS_CHECK_PIN response {} (expected {})".format( res, t[1]))
def test_ap_pmf_required(dev, apdev): """WPA2-PSK AP with PMF required""" ssid = "test-pmf-required" wt = Wlantest() wt.flush() wt.add_passphrase("12345678") params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") params["wpa_key_mgmt"] = "WPA-PSK-SHA256"; params["ieee80211w"] = "2"; hapd = hostapd.add_ap(apdev[0]['ifname'], params) key_mgmt = hapd.get_config()['key_mgmt'] if key_mgmt.split(' ')[0] != "WPA-PSK-SHA256": raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") if "[WPA2-PSK-SHA256-CCMP]" not in dev[0].request("SCAN_RESULTS"): raise Exception("Scan results missing RSN element info") hwsim_utils.test_connectivity(dev[0], hapd) dev[1].connect(ssid, psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") hwsim_utils.test_connectivity(dev[1], hapd) hapd = hostapd.Hostapd(apdev[0]['ifname']) hapd.request("SA_QUERY " + dev[0].p2p_interface_addr()) hapd.request("SA_QUERY " + dev[1].p2p_interface_addr()) wt.require_ap_pmf_mandatory(apdev[0]['bssid']) wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr()) wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr()) time.sleep(0.1) if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'], dev[0].p2p_interface_addr()) < 1: raise Exception("STA did not reply to SA Query") if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'], dev[1].p2p_interface_addr()) < 1: raise Exception("STA did not reply to SA Query")
def test_ap_enable_disable_reenable(dev, apdev): """Enable, disable, re-enable AP""" ifname = apdev[0]['ifname'] hapd_global = hostapd.HostapdGlobal() hapd_global.add(ifname) hapd = hostapd.Hostapd(ifname) hapd.set_defaults() hapd.set("ssid", "dynamic") hapd.enable() ev = hapd.wait_event(["AP-ENABLED"], timeout=30) if ev is None: raise Exception("AP startup timed out") dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412") hapd.disable() ev = hapd.wait_event(["AP-DISABLED"], timeout=30) if ev is None: raise Exception("AP disabling timed out") dev[0].wait_disconnected(timeout=10) hapd.enable() ev = hapd.wait_event(["AP-ENABLED"], timeout=30) if ev is None: raise Exception("AP startup timed out") dev[1].connect("dynamic", key_mgmt="NONE", scan_freq="2412") dev[0].wait_connected(timeout=10)
def test_ap_multi_bss_acs(dev, apdev): """hostapd start with a multi-BSS configuration file using ACS""" ifname = apdev[0]['ifname'] # make sure the current channel is on 2.4 GHz band as a workaround for the # limited survey functionality in mac80211_hwsim hostapd.add_ap(ifname, {"ssid": "test"}) time.sleep(0.1) hapd_global = hostapd.HostapdGlobal() hapd_global.remove(ifname) # start the actual test hostapd.add_iface(ifname, 'multi-bss-acs.conf') hapd = hostapd.Hostapd(ifname) hapd.enable() wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 2400: raise Exception("Unexpected frequency") dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq) dev[1].connect("bss-2", psk="12345678", scan_freq=freq) dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
def test_ap_wps_conf(dev, apdev): """WPS PBC provisioning with configured AP""" ssid = "test-wps-conf" hostapd.add_ap( apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("WPS provisioning step") hapd.request("WPS_PBC") dev[0].dump_monitor() dev[0].request("WPS_PBC") ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out") status = dev[0].get_status() if status['wpa_state'] != 'COMPLETED': raise Exception("Not fully connected") if status['bssid'] != apdev[0]['bssid']: raise Exception("Unexpected BSSID") if status['ssid'] != ssid: raise Exception("Unexpected SSID") if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': raise Exception("Unexpected encryption configuration") if status['key_mgmt'] != 'WPA2-PSK': raise Exception("Unexpected key_mgmt") sta = hapd.get_sta(dev[0].p2p_interface_addr()) if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": raise Exception("Device name not available in STA command")
def test_nfc_wps_handover(dev, apdev): """Connect to WPS AP with NFC connection handover""" ssid = "test-wps-nfc-handover" params = ap_wps_params(ssid) hostapd.add_ap(apdev[0]['ifname'], params) hapd = hostapd.Hostapd(apdev[0]['ifname']) logger.info("NFC connection handover") req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to to hostapd") dev[0].dump_monitor() res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to to wpa_supplicant") ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30) if ev is None: raise Exception("Association with the AP timed out") check_wpa2_connection(dev[0], apdev[0], ssid)
def get_instance(self): """Return the Hostapd/WpaSupplicant instance""" if self.instance is None: self.instance = hostapd.Hostapd(self.iface) return self.instance
def ap_vlan_iface_cleanup_multibss(dev, apdev, cfgfile): # AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID # check that multiple bss do not interfere with each other with respect # to deletion of bridge and tagged interface. if not netifaces_imported: raise HwsimSkip("python module netifaces not available") try: ap_vlan_iface_cleanup_multibss_cleanup() ap_vlan_iface_test_and_prepare_environ() as_params = { "ssid": "as", "beacon_int": "2000", "radius_server_clients": "auth_serv/radius_clients.conf", "radius_server_auth_port": '18128', "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", "ca_cert": "auth_serv/ca.pem", "server_cert": "auth_serv/server.pem", "private_key": "auth_serv/server.key", "vlan_naming": "1" } authserv = hostapd.add_ap(apdev[1], as_params) # start the actual test hapd = hostapd.add_iface(apdev[0], cfgfile) hapd1 = hostapd.Hostapd("wlan3-2", 1) hapd1.enable() ifaces = netifaces.interfaces() if "brvlan1" in ifaces: raise Exception("bridge brvlan1 already exists before") if "brvlan2" in ifaces: raise Exception("bridge brvlan2 already exists before") dev[0].connect("bss-1", key_mgmt="WPA-EAP", eap="PAX", identity="vlan1", password_hex="0123456789abcdef0123456789abcdef", scan_freq="2412") ifaces = netifaces.interfaces() if not("brvlan1" in ifaces): raise Exception("bridge brvlan1 was not created") hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") if not iface_is_in_bridge("brvlan1", "dummy0.1"): raise Exception("dummy0.1 not in brvlan1") dev[1].connect("bss-2", key_mgmt="WPA-EAP", eap="PAX", identity="vlan1", password_hex="0123456789abcdef0123456789abcdef", scan_freq="2412") hwsim_utils.test_connectivity_iface(dev[1], hapd1, "brvlan1") if not iface_is_in_bridge("brvlan1", "dummy0.1"): raise Exception("dummy0.1 not in brvlan1") authserv.disable() authserv.set('eap_user_file', "auth_serv/eap_user_vlan.conf") authserv.enable() logger.info("wlan0 -> VLAN 2") dev[0].dump_monitor() dev[0].request("REAUTHENTICATE") ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) if ev is None: raise Exception("EAP reauthentication timed out") ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=5) if ev is None: raise Exception("4-way handshake after reauthentication timed out") state = dev[0].get_status_field('wpa_state') if state != "COMPLETED": raise Exception("Unexpected state after reauth: " + state) ifaces = netifaces.interfaces() if not ("brvlan1" in ifaces): raise Exception("bridge brvlan1 has been removed too early") hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan2", max_tries=5) if not iface_is_in_bridge("brvlan2", "dummy0.2"): raise Exception("dummy0.2 not in brvlan2") logger.info("test wlan1 == VLAN 1") hwsim_utils.test_connectivity_iface(dev[1], hapd1, "brvlan1") if not iface_is_in_bridge("brvlan1", "dummy0.1"): raise Exception("dummy0.1 not in brvlan1") logger.info("wlan1 -> VLAN 2") dev[1].dump_monitor() dev[1].request("REAUTHENTICATE") ev = dev[1].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) if ev is None: raise Exception("EAP reauthentication timed out") ev = dev[1].wait_event(["WPA: Key negotiation completed"], timeout=5) if ev is None: raise Exception("4-way handshake after reauthentication timed out") state = dev[1].get_status_field('wpa_state') if state != "COMPLETED": raise Exception("Unexpected state after reauth: " + state) # it can take some time for data connectivity to be updated hwsim_utils.test_connectivity_iface(dev[1], hapd1, "brvlan2", max_tries=5) logger.info("test wlan0 == VLAN 2") hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan2") if not iface_is_in_bridge("brvlan2", "dummy0.2"): raise Exception("dummy0.2 not in brvlan2") ifaces = netifaces.interfaces() if "brvlan1" in ifaces: raise Exception("bridge brvlan1 has not been cleaned up") # disconnect dev0 first to test a corner case dev[0].request("DISCONNECT") dev[0].wait_disconnected() dev[1].request("DISCONNECT") dev[1].wait_disconnected() # station removal needs some time for i in range(5): time.sleep(1) ifaces = netifaces.interfaces() if "brvlan2" not in ifaces: break ifaces = netifaces.interfaces() if "brvlan2" in ifaces: raise Exception("bridge brvlan2 has not been cleaned up") hapd.request("DISABLE") finally: ap_vlan_iface_cleanup_multibss_cleanup()
def start(self): if self.ifname != None: hapd = hostapd.Hostapd(self.ifname) self.changed = self.wait_hapd_reg_change(hapd)
def start_ap(ap): params = hs20_ap_params() params['hessid'] = ap['bssid'] hostapd.add_ap(ap['ifname'], params) return hostapd.Hostapd(ap['ifname'])