public bool ConnectToAP(string profilename) { Log("Connecting to " + profilename); try { m_WlanApi.ProfileConnect(m_TestInterface.Id, profilename, new TimeSpan(0, 0, 30)); } catch (Exception e) { LogError("Failed to Connect to to ssid " + profilename + " with a timeout of 30s. Please refer to traces for details. Error: " + e.Message); return(false); } try { LogMajor("Waiting for full network connectivity"); m_LocalIP = Helpers.WaitForFullNetworkConnectivity(m_TestInterface.Id, DefaultTimeOuts.DefaultDHCPTimeout, m_AssociationConfiguration.ServiceAPChannelAddress, c_EchoPort, c_EchoByteStream); } catch (Exception e) { LogError("An error was encountered when waiting for full L3 connectivity, after connecting to [" + profilename + "] with a timeout of " + DefaultTimeOuts.DefaultDHCPTimeout + "ms. Please refer to traces for details. Error: " + e.Message); return(false); } return(true); }
public bool ConnectToNetwork(string ssid) { try { using (Wlan wlanApi = new Wlan()) { testLogger.LogComment("ConnectToNetwork"); var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; bool localConnectionNeeded = true; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { if (String.Compare(ssid, wlanInterface.Ssid, StringComparison.OrdinalIgnoreCase) == 0) { testLogger.LogComment("We already connected to the correct network."); localConnectionNeeded = false; } else { testLogger.LogComment("We already connected a different network. Disconnecting."); wlanApi.Disconnect(wlanInterface.Id, new TimeSpan(0, 0, 10)); Wlan.Sleep(1000); } } if (localConnectionNeeded) { testLogger.LogComment("Connecting to SSID {0}", ssid); wlanApi.TryScan(wlanInterface.Id, false, new TimeSpan(0, 0, 10)); wlanApi.ProfileConnect(wlanInterface.Id, ssid, new TimeSpan(0, 0, 30)); testLogger.LogComment("Connection Completed {0}", ssid); testLogger.LogComment("Waiting for DHCP to be stable"); Microsoft.Test.Networking.Kit.Helpers.WaitForWlanConnectivity(wlanInterface.Id, 1000 * 15, testLogger); } return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Connecting to the Wlan Profile {0}", ssid); testLogger.LogError(error.ToString()); return(false); } }
private void SleepWhileConnected(DateTime endTime, string profileName1) { testLogger.LogComment("SleepWhileConnected"); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State != WLAN_INTERFACE_STATE.wlan_interface_state_connected) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Connecting to {0}", profileName1)); wlanApi.ProfileConnect(wlanInterface.Id, profileName1, WlanStress.ConnectWait); } while (DateTime.Now < endTime) { int sleepTime = Random.Next(1, 60); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sleeping for {0} seconds", sleepTime)); WakeHelper.StaticD2Sleep(new TimeSpan(0, 0, sleepTime)); testLogger.LogComment("Verify we are still connected"); connectedAfterSleepAttempts++; if (VerifyWeAreConnected(wlanApi)) { testLogger.LogComment("We are still connected"); connectedAfterSleepSuccess++; } else { testLogger.LogComment("We are not still connected"); } Wlan.Sleep(1000); } } }
public bool ConnectToAP(string profilename) { // Before starting the connect, perform a scan Log("Triggering a scan"); try { Api.Scan(TestInterface.Id, false, new TimeSpan(0, 0, 10)); } catch (Exception e) { // This error is OK Log("Failed to do a scan. Please refer to traces for details. " + e.Message); } Log("Connecting to " + profilename); try { Api.ProfileConnect(TestInterface.Id, profilename, new TimeSpan(0, 0, 30)); } catch (Exception e) { LogError("Failed to do a profile connect to ssid " + profilename + " with a timeout of 30s. Please refer to traces for details. " + e.Message); return(false); } try { Helpers.WaitForFullNetworkConnectivity(TestInterface.Id, DefaultTimeOuts.DefaultDHCPTimeout, RoamingConfiguration.ServiceAPChannelAddress, EchoPort, EchoByteStream); } catch (Exception e) { LogError("An Error was encountered when waiting for full L3 connectivity, after connecting to " + profilename + " with a timeout of " + DefaultTimeOuts.DefaultDHCPTimeout + "ms. Please refer to traces for details." + e.Message); return(false); } return(true); }
private void ConnectForIntegrityCheck(ApConfigClient apConfigClient, int port, int streamBytes) { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { return; } if (apConfigCreated == false) { var currentConfig1 = WlanAccessPointHelper.CreateWirelessAccessPoint(AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password", AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password"); var currentConfig2 = WlanAccessPointHelper.CreateWirelessAccessPoint(AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password", AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password"); ConfiguredSSIDs configuredSSID1 = new ConfiguredSSIDs("", ""); ConfiguredSSIDs configuredSSID2 = new ConfiguredSSIDs("", ""); if (apConfigClient.ApplyConfiguration(routers[0], currentConfig1, out configuredSSID1)) { currentConfig1.SSID_24GHZ = configuredSSID1.TwoPoint4GhzSSID; currentConfig1.SSID_5GHZ = configuredSSID1.FiveghzSSID; testLogger.LogComment("Successfully applied the Configuration to AP[0]"); } else { testLogger.LogError("Unable to apply the configuration to AP [0]"); } testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Applying AP Configuration to AP[1] {0}", currentConfig2.SSID_24GHZ)); if (apConfigClient.ApplyConfiguration(routers[1], currentConfig2, out configuredSSID2)) { currentConfig2.SSID_24GHZ = configuredSSID1.TwoPoint4GhzSSID; currentConfig2.SSID_5GHZ = configuredSSID1.FiveghzSSID; testLogger.LogComment("Successfully applied the Configuration to AP[2]"); } else { testLogger.LogError("Unable to apply the configuration to AP[2]"); } string profile1; string profile2; profile1 = currentConfig1.CreateProfile24ghz(ConnectionMode.Manual, false); profileName1 = currentConfig1.SSID_24GHZ; profile2 = currentConfig2.CreateProfile24ghz(ConnectionMode.Manual, false); profileName2 = currentConfig2.SSID_24GHZ; testLogger.LogComment(profile1); wlanApi.CreateProfile(wlanInterface.Id, profile1); wlanApi.CreateProfile(wlanInterface.Id, profile2); testLogger.LogComment("Wait to allow APs to beacon"); Wlan.Sleep(10000); apConfigCreated = true; } int retries = 3; while (retries > 0) { retries--; testLogger.LogComment("Scan"); wlanApi.TryScan(wlanInterface.Id, false, ScanWait); try { testLogger.LogComment(String.Format(CultureInfo.InvariantCulture, "Attempt to Connect to SSID : {0}", profileName1)); wlanApi.ProfileConnect(wlanInterface.Id, profileName1, ConnectWait); break; } catch (Exception) { testLogger.LogComment("Connect failed."); if (retries == 0) { testLogger.LogError(String.Format(CultureInfo.InvariantCulture, "Could not connect to SSID: {0}", profileName1)); return; } } } testLogger.LogComment("Wait for DHCP"); Microsoft.Test.Networking.Kit.Helpers.WaitForWlanConnectivity(wlanInterface.Id, 1000 * 15, testLogger); } }
public void TestDot11wConnection() { Guid interfaceId; testLogger.LogComment("Testing 802.11w Connection to AP with SSID " + dot11wSSID + " and password " + dot11wPassword); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; interfaceId = wlanInterface.Id; // Delete Profile if present DisconnectAndDeleteProfile(wlanApi); // Scan testLogger.LogComment("Scan"); wlanApi.Scan(wlanInterface.Id, false, ScanWait); // Check to see if SSID is in scan list testLogger.LogComment("Check to see if SSID is in scan list"); var networkList = wlanApi.GetAvailableNetworkList(interfaceId); bool found = false; foreach (WlanNetwork network in networkList) { if (String.Compare(network.Ssid, dot11wSSID, StringComparison.Ordinal) == 0) { found = true; break; } } if (found == false) { testLogger.LogError("Could not find 11w router in scan list: " + dot11wSSID); testLogger.LogResult(TestResult.Failed); return; } else { testLogger.LogComment("Found the 11w router in the scan list: " + dot11wSSID); } // Create Profile string profile = GenerateProfile(); testLogger.LogComment("Creating Profile"); wlanApi.CreateProfile(interfaceId, profile); // Connect testLogger.LogComment("Connecting to AP"); wlanApi.ProfileConnect(interfaceId, dot11wSSID, new TimeSpan(0, 0, 30)); } // Check MFP Status bool mfpStatus = IsMfpNeogotiated(interfaceId); testLogger.LogComment("IsMfpNeogotiated == " + mfpStatus); if (mfpStatus == false) { testLogger.LogError("The device connected to the dot11w router but IsMfpNeogotiated == false"); testLogger.LogResult(TestResult.Failed); return; } if (enableSleepTest) { PowerManager powerManager; powerManager = new PowerManager(); // Wait for DHCP Stable testLogger.LogComment("Wait for DHCP to be stable"); Wlan.Sleep(1000 * 60 * 2); testLogger.LogComment("Going into Connected standby/Sleep for 1 minute"); powerManager.DeepestSleep(60); using (Wlan wlanApi = new Wlan()) { bool isConnected = IsConnected(wlanApi); if (isConnected == false) { testLogger.LogError("After waking from connected standby the device is no longer connected to the AP"); } else { testLogger.LogComment("After waking from connected standby the device is still connected to the AP"); } } // Check MFP Status mfpStatus = IsMfpNeogotiated(interfaceId); testLogger.LogComment("IsMfpNeogotiated == " + mfpStatus); if (mfpStatus == false) { testLogger.LogError("The device connected to the dot11w router but IsMfpNeogotiated == false"); return; } } }