Exemple #1
0
        public bool CreateProfile(string profile, string profileName)
        {
            try
            {
                using (Wlan wlanApi = new Wlan())
                {
                    testLogger.LogTrace("CreateProfile");
                    var wlanInterfaceList = wlanApi.EnumWlanInterfaces();
                    if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false)
                    {
                        return(false);
                    }
                    var wlanInterface = wlanInterfaceList[0];

                    testLogger.LogComment("Creating Profile {0}", profileName);
                    wlanApi.CreateProfile(wlanInterface.Id, profile);

                    return(true);
                }
            }
            catch (Exception error)
            {
                testLogger.LogError("Error encountered while Creating the Wlan Profile {0}", profileName);
                testLogger.LogError(error.ToString());
                return(false);
            }
        }
Exemple #2
0
        public bool DisconnectNetwork()
        {
            testLogger.LogComment("Disconnecting from WLAN");
            try
            {
                using (Wlan wlanApi = new Wlan())
                {
                    var wlanInterfaceList = wlanApi.EnumWlanInterfaces();
                    if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false)
                    {
                        return(false);
                    }

                    var wlanInterface = wlanInterfaceList[0];

                    if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected)
                    {
                        testLogger.LogComment("Disconnecting from WLAN network {0}", wlanInterface.Ssid);
                        wlanApi.Disconnect(wlanInterface.Id, new TimeSpan(0, 0, 10));
                    }

                    return(true);
                }
            }
            catch (Exception error)
            {
                testLogger.LogError("Error encountered while Disconnecting from the WLAN Network");
                testLogger.LogError(error.ToString());
                return(false);
            }
        }
Exemple #3
0
        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);
            }
        }