private bool VerifyAPsAreInScanList(string ssid) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Verify SSID {0} is in scan list", ssid)); 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]; wlanApi.TryScan(wlanInterface.Id, true, new TimeSpan(0, 0, 10)); Collection <WlanNetwork> list = wlanApi.GetAvailableNetworkList(wlanInterface.Id); bool found = false; foreach (var network in list) { if (String.Compare(network.Ssid, ssid, StringComparison.OrdinalIgnoreCase) == 0) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Found SSID {0}", ssid)); found = true; break; } } if (found == false) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Did not find SSID {0}", ssid)); } return(found); } }
public override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 5, 0)); TimeSpan waiterTimeout = new TimeSpan(0, 0, 10); 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]; while (DateTime.Now < endTime) { if (Random.Next(0, 2) == 1) { // Slow Scan testLogger.LogComment("Slow Scan"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Scanning..."); wlanApi.TryScan(wlanInterface.Id, false, WlanStress.ScanWait); testLogger.LogComment("Scanning...Complete"); SlowScans++; } } else { // Fast Scan testLogger.LogComment("Fast Scan"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Start Fast Scan"); wlanApi.TryScan(wlanInterface.Id, false); FastScans++; } testLogger.LogComment("Sleeping for a few seconds to allow the driver to calm down"); Wlan.Sleep(10000); } } } }
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 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 override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 5, 0)); TimeSpan waiterTimeout = new TimeSpan(0, 0, 10); 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]; var radioStateList = wlanApi.GetRadioState(wlanInterface); if (radioStateList[0].SoftwareRadioState == RadioState.Off) { testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOnSetup = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOnSetup.Wait(waiterTimeout); } try { while (DateTime.Now < endTime) { if (Random.Next(0, 2) == 1) { // Slow toggle testLogger.LogComment("Slow Toggle"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Turning Radio Off"); SlowToggles++; WlanNotificationWaiter waiterOff = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, false); waiterOff.Wait(waiterTimeout); testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOn = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOn.Wait(waiterTimeout); } } else { // Fast Toggle testLogger.LogComment("Fast Toggle"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Turning Radio Off"); FastToggles++; wlanApi.SetRadioState(wlanInterface, 0, false); Wlan.Sleep(Random.Next(100, 750)); testLogger.LogComment("Turning Radio On"); wlanApi.SetRadioState(wlanInterface, 0, true); Wlan.Sleep(Random.Next(100, 750)); } testLogger.LogComment("Sleeping for a few seconds to allow the driver to calm down"); Wlan.Sleep(10000); } ScanAttempts++; testLogger.LogComment("Scanning"); wlanApi.TryScan(wlanInterface.Id, true, WlanStress.ScanWait); var list = wlanApi.GetAvailableNetworkList(wlanInterface.Id); if (list.Count > 0) { ScanSuccess++; } else { testLogger.LogComment("Scanning failed"); } } } finally { radioStateList = wlanApi.GetRadioState(wlanInterface); if (radioStateList[0].SoftwareRadioState == RadioState.Off) { testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOnCleanup = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOnCleanup.Wait(waiterTimeout); } } } }